• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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\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
SD_Adept
Asked:
SD_Adept
  • 5
  • 5
  • 4
  • +2
1 Solution
 
thinhCommented:
Hi SD_Adept,
How do you declare smart pointer IUserList. Could you post some code.

Thinh.
0
 
thinhCommented:
Hi SD_Adept,
How do you declare smart pointer IUserList. Could you post some code.

Thinh.
0
 
ShaunWildeCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
SD_AdeptAuthor Commented:

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
 
SD_AdeptAuthor Commented:
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
 
ShaunWildeCommented:
what does your #import statement look like ?
0
 
ShaunWildeCommented:
> 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
 
mandhjoCommented:
If you want to use a smart pointer, you should declare your variable as...

IUserListPtr m_iUserList

(note the "Ptr")
0
 
mandhjoCommented:
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
 
SD_AdeptAuthor Commented:
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
 
GlennDeanCommented:
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
 
ShaunWildeCommented:
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
 
SD_AdeptAuthor Commented:
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
 
mandhjoCommented:
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
 
SD_AdeptAuthor Commented:
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
 
mandhjoCommented:
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
 
ShaunWildeCommented:
> 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now