Solved

DLL COM Object Instantiation

Posted on 2000-04-17
17
447 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 100 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now