SD_Adept
asked on
DLL COM Object Instantiation
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\use robjects.t lh(107) : see declaration of 'IUserList'
E:\iwire\UsersBO\Users.cpp (64) : warning C4259: 'long __stdcall IUnknown::QueryInterface(c onst 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::GetTypeInfoCoun t(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(uns igned 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(c onst 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,con st 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?
E:\iwire\UsersBO\Users.cpp
e:\iwire\usersbo\debug\use
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\unknwn
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\unknwn
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\unknwn
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\oaidl.
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\oaidl.
E:\iwire\UsersBO\Users.cpp
c:\program files\microsoft visual studio\vc98\include\oaidl.
E:\iwire\UsersBO\Users.cpp
t defined
those are a few (there are more). What is going on here and how do I instance my object?
Hi SD_Adept,
How do you declare smart pointer IUserList. Could you post some code.
Thinh.
How do you declare smart pointer IUserList. Could you post some code.
Thinh.
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_? ??);
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_?
ASKER
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......
ASKER
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!!!
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!!!
what does your #import statement look like ?
> ptrUserList.Create(CLSID_? ??);
should be CreateInstance :)
> I will say that IUserList *m_piUserList; does work
you will have to create an instance of it
should be CreateInstance :)
> I will say that IUserList *m_piUserList; does work
you will have to create an instance of it
If you want to use a smart pointer, you should declare your variable as...
IUserListPtr m_iUserList
(note the "Ptr")
IUserListPtr m_iUserList
(note the "Ptr")
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.
ASKER
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. :/
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
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
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
again I ask what does you #import statement look like as your problem may be as simple as not using the correct namespace
ASKER
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).
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?
>>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?
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> HRESULT hrReturn = m_iUserList.CreateInstance (CLSID_Use rList); // the CLSID will be declared in the .tlh file generated by the import.
I mentioned this earlier :)
I mentioned this earlier :)
How do you declare smart pointer IUserList. Could you post some code.
Thinh.