Getting Type Mismatch Error when calling CWnd::InvokeHelper

305 views Asked by At

So I have tried to debug the program and as soon as I get into the Windows API function calls things get a little crazy, plus there isn't much help with debugging those files because I can't change them anyways. Basically what I am stuck on is the following two functions that I can change (FYI this is really old code and the program works in 32bit versions but when converted to 64bit this problem occurred):

void CSalvoPage::AdviseScrollingButtonPanel()
{
    if ( m_SBPCookie == 0 )
    {
        IUnknown * pSinkUnk;
        long * pCookie = &m_SBPCookie;
        m_spSBPControlSink->QueryInterface(IID_IUnknown, (void **) &pSinkUnk);

        if (pSinkUnk != NULL)
        {
            m_SalvoButtons.AddListener(pSinkUnk, pCookie);//here is the problem~~~~
            pSinkUnk->Release();
        }
    }
}

Then we have the AddListener call which does this

void CNvButtonPanel::AddListener(LPUNKNOWN pUnk, long* pCookie)
{
    static BYTE parms[] =
        VTS_UNKNOWN VTS_PI4;
    InvokeHelper(0x16, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
         pUnk, pCookie);
}

I know for a fact that the InvokeHelper function throws the exception through debugging. All I seem to understand is that parms[] lets the InvokeHelper know what types of parameters it's getting and how many. I looked up the definitions and found that in fact

VTS_UNKNOWN = "\x0D" //IUNKNOWN*

and

VTS_PI4 = "\x43" //a 'long*'

Therefore I am telling the InvokeHelper the correct types of parameters to expect so I don't understand why I get a Type Mismatch Error in a popup window everytime I run the program... Any ideas as to why my InvokeHelper throws the Type Mismatch Error?

I have tried to look into the InvokeHelper method documentation and it's really confusing... What I do know is that it throws the COleException mentioned in the documentation and the SCODE returned from the Invoke method is -2147352571

[id(22), helpstring("method AddListener")] 
            HRESULT AddListener(
                [in] IUnknown * pUnk,
                [out] IUnknown ** pCookie
                );
1

There are 1 answers

0
RAZ_Muh_Taz On BEST ANSWER

I was able to fix the issue by doing what RbMm suggested which was to change the function AddListener and RemoveListener functions to match the types declared in the .idl file.

void AddListener(LPUNKNOWN pUnk, LPUNKNOWN* pCookie);
void RemoveListener(LPUNKNOWN pCookie);

The functions now correctly match the types defined in the .idl file

[id(22), helpstring("method AddListener")] 
    HRESULT AddListener(
        [in] IUnknown * pUnk,
        [out] IUnknown ** pCookie
        );

[id(23), helpstring("method RemoveListener")] 
    HRESULT RemoveListener(
        [in] IUnknown * pCookie
        );