I am relatively new to COM programming and I am trying to get access to third party DCOM component (EXE module) from my client program on C++(VC6). I suppose that this component was written in VB6. First I have made a simple client program on VB6 and it work smooth with DCOM component.

Below is the example of client's VB6 code, which I’am tring translate to: VC++

Private cDevConnector As DevControlC.DevControlConnector
Private WithEvents cCtrl As DevControlC.DevControl

Set cDevConnector = New DevControlC.DevControlConnector
Set cCtrl = cDevConnector.DevControl
Call cCtrl.DevControlInitialize

I’ve used OLE View utility to get interface’s definitions (idl, tlb, h files) from the component and use these data.

Below is the example of my C++ code:

void InitCOMInterface(HWND hWnd)
{
CoInitialize(NULL) ;
DevControlC::_DevControlConnectorPtr pDevConnector = NULL;
DevControlC::_DevControlPtr pCtrl;

HRESULT hr = pDevConnector.CreateInstance (__uuidof (DevControlC:evControlConnector));

if (FAILED(hr)) {
...
return;
}

pCtrl = pDevConnector ->GetDevControl ();
if (NULL!= pCtrl) {

short status;
hr = pObj->SemControlInitialize (&status);
//here error rises...
}

pDevConnector.Release();
CoUninitialize() ;

return;
}
I can get pointer to _DevControl interface (pCtrl) via _DevControlConnector interface (I can’t call it directly because of its properties). The error arises when I’am trying to call DevControlInitialize() method of the _DevControl interface. The error message is:

Module:
"File: i386/chkesp.c
Line: 42
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

The _ DevControl:evControlInitialize() method is declared in header file (header was extracted from component by OLE View utility ) as:

#if defined(__cplusplus) && !defined(CINTERFACE)

MIDL_INTERFACE("50DC6152-FD65-4E74-BACD-C9D932A3391A")
_ DevControl : public IDispatch
{
public:
....
virtual /* [id] */ HRESULT STDMETHODCALLTYPE DevControlInitialize(
/* [retval][out] */ short __RPC_FAR *__MIDL_0047) = 0;

What is wrong in my call of DevControlInitialize() method. Thank you in advance.