COM Connection Points: Problem to call an function out of an sink class
-
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. Now I want to call an function „ OnShowMessageDlg “ out of this Csink class and after that I’ll become the following error message from my compiler: Linker error: LNK2001: unresolved external symbol public: __thiscall ""public: void __thiscall CSink::OnShowMessageDlg(struct IMsgDlg *,short *)" (?OnShowMessageDlg@CSink@@QAEXPAUIMsgDlg@@PAF@Z)". Can someone give me a hint what there could be wrong? Or what I must do to use these function? Is the .idl file and the .h file correct? I didn’t find the functions OnShowMessageDlg and OnConfigurationApply in the .h file? I know, this should be basics I must know. I hope the two books I’ve ordered will arrive as soon as possible. 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_I
-
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. Now I want to call an function „ OnShowMessageDlg “ out of this Csink class and after that I’ll become the following error message from my compiler: Linker error: LNK2001: unresolved external symbol public: __thiscall ""public: void __thiscall CSink::OnShowMessageDlg(struct IMsgDlg *,short *)" (?OnShowMessageDlg@CSink@@QAEXPAUIMsgDlg@@PAF@Z)". Can someone give me a hint what there could be wrong? Or what I must do to use these function? Is the .idl file and the .h file correct? I didn’t find the functions OnShowMessageDlg and OnConfigurationApply in the .h file? I know, this should be basics I must know. I hope the two books I’ve ordered will arrive as soon as possible. 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_I
If you have timelimits in learning and implementing the task, you better should use a high-level COM-Wrapper like MFC oder ATL, then you must not implement the standard-interfaced like IUnknown or IDispatch youself. I think there must be lots of examples on codeproject. The error-message tells you to implement the function OnShowMessageDlg(). This is a function call from the com-server into your com-client, so you need an implementation.
-
If you have timelimits in learning and implementing the task, you better should use a high-level COM-Wrapper like MFC oder ATL, then you must not implement the standard-interfaced like IUnknown or IDispatch youself. I think there must be lots of examples on codeproject. The error-message tells you to implement the function OnShowMessageDlg(). This is a function call from the com-server into your com-client, so you need an implementation.
If you have timelimits in learning and implementing the task.. This is the main problem. The COM server I must use is an .exe file. Is it the easiest way to create an new ATL project? Is there any Wizard with that I can implement the code from the .exe file / COM server in this new project? Until now I use OleView to create the .idl file from the COM server. Can I then use the files from the ATL project in my C++ project?
-
If you have timelimits in learning and implementing the task.. This is the main problem. The COM server I must use is an .exe file. Is it the easiest way to create an new ATL project? Is there any Wizard with that I can implement the code from the .exe file / COM server in this new project? Until now I use OleView to create the .idl file from the COM server. Can I then use the files from the ATL project in my C++ project?
The easiest way to use a COM server that has a type library (which should be most of them) is to use #import[^]. The easiest way to implement a connection point sink (a.k.a. an event sink) is to use ATL and create a class derived from IDispEventSimpleImpl. See this post[^] of mine for an example that handles an event raised by Excel.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p