ATL structures break on COM objects from dll

-1

So, we are currently upgrading an ancient program from visual studio 2008 (where everything works) to 2017. We use a dll, whose classes the application connects to through ATL and a project-dependency.

Unfortunately all attempts at calling functions from these classes return exceptions, presumably because it can't find them.

The dll's classes are successfully added to the registry through regedit when built, and the uuids correspond correctly with the registered values. The classes can also be found in the OLE/COM-viewer.

It also only breaks when attempting to call from one of our classes. An attempt to call functions from IDispatch, which the classes in question inherits from, worked correctly.

In the below code the first attempt 'm_pRenderer' throws the exception. The second attempt 'test2' does not enter it's if-statement as CoCreateInstance returns a bad variable type-error

HRESULT res = CoCreateInstance(__uuidof(CBSNullRenderer), NULL, CLSCTX_INPROC_SERVER, __uuidof(IDispatch), (void**)&m_pRenderer);
Log("\nCreateInstance: %ld", res);

ICBSNullRendererPtr test2 = NULL;

HRESULT res2 = CoCreateInstance(__uuidof(CBSNullRenderer), NULL, CLSCTX_INPROC_SERVER, __uuidof(ICBSNullRenderer), (void**)&test2);
Log("\nres2: %ld", res2);


wireHWND mainHwnd = (wireHWND)GetParent(p_hWnd);

if(mainHwnd == NULL)
    Log("\nWARNING mainHWND is NULL!");

try {
    if (test2)
    {
        Log("\nDid create NullRenderer!");
        test2->SetMainWnd(mainHwnd);
    }
    if (m_pRenderer)
    {
        Log("\nDid create NullRenderer!");
        m_pRenderer->SetMainWnd(mainHwnd);
    }
}
catch (...)
{

}

Which breaks on line 2 for m_pRenderer for:

inline HRESULT ICBSNullRenderer::SetMainWnd ( wireHWND hwnd ) {
    HRESULT _hr = raw_SetMainWnd(hwnd);

    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
        return _hr;
}

In the dll's .tli file.

The error creates an "Exception Thrown" dialog with the following:

Exception thrown at 0x00007FF9153ED7F2 (oleaut32.dll) in AnimgramPro.exe: 0xC0000005: Access violation executing location 0x00007FF9153ED7F2

We also attempted to use QueryInterface on the m_pRenderer with the nullrenderer's uuid. This ended in another bad variable type-error.

Any advice or information of the errors which could be associated would be greatly appreciated.

c++
dll
atl
asked on Stack Overflow Sep 13, 2017 by Kasper Ingdahl Andkjær • edited Sep 13, 2017 by Kasper Ingdahl Andkjær

1 Answer

-1

So, I solved the problem. Apparently properly calling a dll-function in my program requires that 'Common Language Runtime Support' is turned off and that 'Whole Program Optimization' is set to 'Use Link Time Code Generation'

answered on Stack Overflow Sep 19, 2017 by Kasper Ingdahl Andkjær • edited Dec 16, 2019 by Kasper Ingdahl Andkjær

User contributions licensed under CC BY-SA 3.0