Unhandled exception in vC ++ - HRESULT failed

I know that VC ++ 6.0 is a very old language, but I have no choice, I just support an existing program, and I encounter this error

Unhandled exception in Assess.exe (KERNELBASE.DLL): 0xE06D7363: Microsoft C++ Exception

And here is my code

 HRESULT hr = CoInitialize(NULL);

// Create the interface pointer.
IModulePtr pI(__uuidof(RPTAModuleInterface)); //the error is here

After debugging and using, the f11program switches to COMIP.Hand here is the code

explicit _com_ptr_t(const CLSID& clsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw(_com_error)
    : m_pInterface(NULL)
{
    HRESULT hr = CreateInstance(clsid, pOuter, dwClsContext); 
    //the program goes to CreateInstance Method

    if (FAILED(hr) && (hr != E_NOINTERFACE)) {
        _com_issue_error(hr); 
        //the program goes here and show the error msg
    }
}

And so CreateInstance

HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()
{
    HRESULT hr;

    _Release();

    if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
        IUnknown* pIUnknown;

        hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));

        if (FAILED(hr)) { 
           // the program goes here and return the hr
            return hr;
        }

        hr = OleRun(pIUnknown);

        if (SUCCEEDED(hr)) {
            hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
        }

        pIUnknown->Release();
    }
    else {
        hr = CoCreateInstance(rclsid, pOuter, dwClsContext, GetIID(), reinterpret_cast<void**>(&m_pInterface));
    }

    return hr;
}

I do not know what kind of error this is, this is the header file, and I think there is no error. Any idea how to fix this thing?

Update

RPTAInterface.tlhI saw an ad in mineRPTAModuleInterface

struct /* coclass */ RPTAModuleInterface;

struct __declspec(uuid("d6134a6a-a08e-36ab-a4c0-c03c35aad201"))
RPTAModuleInterface;
+4
source share
1 answer

_com_issue_error()throws an exception _com_errorthat you do not catch. You need to wrap your code in try/catch, for example:

try
{
    IModulePtr pI(__uuidof(RPTAModuleInterface));
    // ... 
}
catch(const _com_error& e)
{
    // e.Error() will return the HRESULT value
    // ...
}

, CoCreateInstance() . , ​​, CoClass RPTAModuleInterface, . HRESULT, , CoCreateInstance() .

+3

Source: https://habr.com/ru/post/1570394/


All Articles