COM Connection Points: Problem to create an instance of an s

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

COM Connection Points: Problem to create an instance of an s

Postby jke » Tue Sep 08, 2009 5:48 am

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
.
.
}

*************************************************************************************************
jke
 
Posts: 10
Joined: Fri Apr 11, 2008 1:51 am

Re: COM Connection Points: Problem to create an instance of an s

Postby MXP » Tue Sep 08, 2009 1:34 pm

You have not defined all the methods your class needs to implement. Right now your compile is complaining that you havent implemented IUnknown::QueryInterface. I also see that you havent implemented AddRef and Release as well as whatever other methods IDispatch is meant to provide.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Re: COM Connection Points: Problem to create an instance of an s

Postby jke » Wed Sep 09, 2009 1:04 am

Hi Colin Jeanne,

thanks for the reply. I've found the mistake and now I can go on with the next step.
jke
 
Posts: 10
Joined: Fri Apr 11, 2008 1:51 am


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 3 guests