CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Calling convention error while trying to call COM sever function

    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.

  2. #2
    Join Date
    Jul 2011
    Posts
    3

    Re: Calling convention error while trying to call COM sever function

    [QUOTE=akvolog;2026424]
    short status;
    hr = pObj->SemControlInitialize (&status);
    //here error rises...
    QUOTE]

    Sorry for mistyping, must be:
    hr = pObj->DevControlInitialize (&status);

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Calling convention error while trying to call COM sever function

    The ESP corruption is typically a result of compiling with different calling convention, but not limited to. So in your case it's most probably a trivial stack corruption because of buffer overflow or something.
    Best regards,
    Igor

  4. #4
    Join Date
    Jul 2011
    Posts
    3

    Re: Calling convention error while trying to call COM sever function

    Thank you for your answer.

    Using the description of the third party component interfaces, I wrote a similar COM component (emulation) in VB. Similar code of VC client works with my new component without problems.

    Ivan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured