Sign in to follow this  
Juergen_80

COM Connection Points: Problem to create an instance of an sink object.

Recommended Posts

Hi All, I’m an absolutely newbie in the COM technology and I have a little tricky question. I hope there’s someone out there who can help me with my problem. I have an .idl / .h / .c file and I integrated them in my VisualStudio 2005 C++ project. After that I’ve searched on the MSDN Library how I can connect an COM Server from my project. I’ve found a little example (http://msdn.microsoft.com/en-us/magazine/cc163361.aspx) and tried to do it on the same way. I’ve created an Csink class and tried to create an instance of this sink object to pass to the server. But the problem now I get from my compiler is the following error message: „error C2259: 'CSink': cannot instantiate abstract class due to following members: 'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract“. Thiss Error message will come in the c++ file after the „pSink = new CSink();“ line. The thing I need is that I must call the „ OnShowMessageDlg “ and the „ OnConfigurationApply “ functions out of the .idl file in my main c++ function. I’ve put all the code here below in this entry. I hope that could help you to become an overview about my problem. Is the solution I’ve tried with the sink object correct or should I use another way to do this? Please let me know if you need any other information. Thanks for ANY help. Juergen ************************************************************************************************* .idl file . . . // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface ITEST2; dispinterface ITESTEvents; . . . [ uuid(6775FB91-B5BE-11D6-A996-0050BA24C7B9), version(1.1), helpstring("Event dispatch interface for TEST") ] dispinterface ITESTEvents { properties: methods: [id(0x00000001)] void OnConfigurationApply([in, out] VARIANT_BOOL* pAccept); [id(0x00000002)] void OnShowMessageDlg( [in] IMsgDlg* pIMsg, [out, retval] VARIANT_BOOL* Result); }; . . . . coclass TESTv2 { [default] interface ITEST2; [default, source] dispinterface ITESTEvents; }; ************************************************************************************************* .h file . . . EXTERN_C const IID DIID_ITESTEvents; #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("6775FB91-B5BE-11D6-A996-0050BA24C7B9") ITESTEvents : public IDispatch { }; #else /* C style interface */ typedef struct ITESTEventsVtbl { BEGIN_INTERFACE HRESULT ( STDMETHODCALLTYPE *QueryInterface )( ITESTEvents * This, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject); . . . ************************************************************************************************* .c file . . . MIDL_DEFINE_GUID(IID, IID_ITEST2,0xF560F761,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9); MIDL_DEFINE_GUID(IID, DIID_ITESTEvents,0x6775FB91,0xB5BE,0x11D6,0xA9,0x96,0x00,0x50,0xBA,0x24,0xC7,0xB9); MIDL_DEFINE_GUID(CLSID, CLSID_TESTv2,0xF560F763,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9); . . . ************************************************************************************************* .c++ file class CSink : public ITESTEvents { private: DWORD m_dwRefCount; public: CSink::CSink() {m_dwRefCount = 0;} CSink::~CSink() {} void OnConfigurationApply(VARIANT_BOOL* pAccept); void OnShowMessageDlg(IMsgDlg* pIMsg, VARIANT_BOOL* Result); }; void main(){ . . . CSink *pSink; pSink = new CSink(); // ERROR MESSAGE . . } *************************************************************************************************

Share this post


Link to post
Share on other sites
Hi Kimmi,

thanks for this hint. I've found an similar example and I've tried to make my code like this. But now I can't go on because of the error message I'll become. But anyway thanks for your help.

Does anyone have some other ideas?

Best regards,

Juergen

Share this post


Link to post
Share on other sites
You have to implement the QueryInterface method on your own. Just look into the declaration of IDisplatch to see which methods are abstract.
In this tutorial you can see a simple example from Microsoft, where a simple IDispatch interface is implemented.

Edit: You can use code tags to make your code more readable. Just look into the FAQ to learn how to do this.

Greetings,
Kimmi

[Edited by - Kimmi on September 8, 2009 8:37:08 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this