Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DLL COM Object Instantiation

Posted on 2000-04-17
17
Medium Priority
?
455 Views
Last Modified: 2013-11-25
I have a COM Object IUserList that lives in a DLL and is a pure ATL COM object (free threaded, supports ierrorinfo, dual interface).  When I go to use it in another program as a smart pointer IUserList or try using it with CComObject< I get a huge number of errors like the following

E:\iwire\UsersBO\Users.cpp(64) : error C2259: 'IUserList' : cannot instantiate abstract class due to following members:
        e:\iwire\usersbo\debug\userobjects.tlh(107) : see declaration of 'IUserList'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(113) : see declaration of 'AddRef'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'unsigned long __stdcall IUnknown::Release(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(115) : see declaration of 'Release'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'long __stdcall IDispatch::GetTypeInfoCount(unsigned int *)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2697) : see declaration of 'GetTypeInfoCount'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'long __stdcall IDispatch::GetTypeInfo(unsigned int,unsigned long,struct ITypeInfo ** )' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2700) : see declaration of 'GetTypeInfo'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'long __stdcall IDispatch::GetIDsOfNames(const struct _GUID &,unsigned short ** ,unsigned int,unsigned long,long *)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\oaidl.h(2705) : see declaration of 'GetIDsOfNames'
E:\iwire\UsersBO\Users.cpp(64) : warning C4259: 'long __stdcall IDispatch::Invoke(long,const struct _GUID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)' : pure virtual function was no
t defined


those are a few (there are more).  What is going on here and how do I instance my object?
0
Comment
Question by:SD_Adept
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
  • +2
17 Comments
 

Expert Comment

by:thinh
ID: 2724928
Hi SD_Adept,
How do you declare smart pointer IUserList. Could you post some code.

Thinh.
0
 

Expert Comment

by:thinh
ID: 2724940
Hi SD_Adept,
How do you declare smart pointer IUserList. Could you post some code.

Thinh.
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2725419
an easy way is to use the #import method

example

#import "yourdll.dll" no_namespaces named_guids

the above statement generates 2 files (.tli,.tlh) that can be found in the output directory for that build

then you can use the smart pointers that are generated within

IUserListPtr ptrUserList;

ptrUserList.Create(CLSID_???);

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:SD_Adept
ID: 2725495

I am indeed using the import statement.  And for whatever reason, it doesn't create the right stuff, or the stuff it does create, requires something else of which I am not aware......
0
 
LVL 1

Author Comment

by:SD_Adept
ID: 2725498
I am trying to use it by doing

IUserList m_iUserList;

also, i tried

CComObject<IUserList> m_iUserList;

although, I will say that IUserList *m_piUserList; does work, but that doesn't give me the object!!!  
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2725778
what does your #import statement look like ?
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2725801
> ptrUserList.Create(CLSID_???);

should be CreateInstance :)

> I will say that IUserList *m_piUserList; does work

you will have to create an instance of it


0
 
LVL 4

Expert Comment

by:mandhjo
ID: 2727453
If you want to use a smart pointer, you should declare your variable as...

IUserListPtr m_iUserList

(note the "Ptr")
0
 
LVL 4

Expert Comment

by:mandhjo
ID: 2727455
Are you specifically including any headers?  This could be your problem.  The #import will give all the declarations that you need.  If you were also including a header file that declared your object, you could be having problems.
0
 
LVL 1

Author Comment

by:SD_Adept
ID: 2727883
it seems that I can run CreateInstance (api) and get it to work.  But I am fully unable to use the smart pointers, which is what this is all about in the first place.  :/
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 2728390
Are you using CComObject in an AppWizard generated program?  If so, then you have to add full ATL support for your program. To do this, you need to do 3 things:
1.  In stdafx.h, add
    #include <atlbase.h>
    extern CComModule _Module;
    #include <atlcom.h>
2.  In stdafx.cpp, add #include <atlimpl.cpp>
3.  In your app's .cpp file, add
    CComModule _Module
    as a global variable.  Then in your InitInstance function, add
     _Module.Init(NULL,NULL);
     AfxOleInit();

   Glenn
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2729998
or you can use the C++ template version _com_ptr_t without requiring com support which is what #import uses and is defined in <comdef.h>

again I ask what does you #import statement look like as your problem may be as simple as not using the correct namespace
0
 
LVL 1

Author Comment

by:SD_Adept
ID: 2738571
its not a matter of not having COM support.  Its a matter of not being able to instance a COM object I've created in a DLL within a COM/ATL system service.  It keeps giving me errors (which pasted at the very beginning of this question).
0
 
LVL 4

Expert Comment

by:mandhjo
ID: 2738826
How are you declaring your smart pointer?  In your comment on 4/18 you said that you are declaring your pointer as...


>>IUserList m_iUserList;
>>also, i tried
>>CComObject<IUserList> m_iUserList;

To use it as a smart pointer, you should declare it as I mentioned above...

IUserListPtr m_iUserList;

Note the *Ptr* at the end of IUserList.  Are you doing this?
0
 
LVL 1

Author Comment

by:SD_Adept
ID: 2744456
like I said earlier.  I can do that.  But that only gives me a pointer that I can't use because the interface hasn't been instanced yet.  Or am I missing something?
0
 
LVL 4

Accepted Solution

by:
mandhjo earned 300 total points
ID: 2744522
Once that is done, all that you have to do is create an instance of the COM object that implements your interface (or get it by some other means).  To create one, use this code:


HRESULT hrReturn = m_iUserList.CreateInstance(CLSID_UserList); // the CLSID will be declared in the .tlh file generated by the import.

Once you have an instance, you can use the member functions of the COM Object.

Does that help?
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2746676
> HRESULT hrReturn = m_iUserList.CreateInstance(CLSID_UserList); // the CLSID will be declared in the .tlh file generated by the import.

I mentioned this earlier :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question