4

I know the VC++6.0 is very old language, but i don't have a choice, i am just maintaining 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 f11 the program goes to COMIP.H and 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 Here is the 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 don't know what's the error here, this is header file and i think there's no error here. Any Idea how to fix this thing?

Updated

in my RPTAInterface.tlh i saw the declaration of RPTAModuleInterface

struct /* coclass */ RPTAModuleInterface;

struct __declspec(uuid("d6134a6a-a08e-36ab-a4c0-c03c35aad201"))
RPTAModuleInterface;
Wielder
  • 156
  • 2
  • 15

1 Answers1

3

_com_issue_error() throws a _com_error exception that you are not catching. You need to wrap your code in a try/catch, eg:

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

Clearly CoCreateInstance() is failing. There is likely no library installed on the machine that registers the CoClass for RPTAModuleInterface, so it cannot be created. But you will have to look at the actual HRESULT to be sure why CoCreateInstance() is failing.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • The error says `0x0022a360 Class not registered` How can i fix it? Help me pls – Wielder Jan 08 '15 at 03:05
  • You have to make sure the EXE/DLL that implements the class you are trying to access is actually installed and registered with the OS. Assuming it is, I have a feeling that `RPTAModuleInterface` is probably the wrong value to use. Its looks like it might be an interface identifier rather than a class identifier. `CoCreateInstance()` is expecting a class identifier, not an interface identifier. You do understand the difference between them, right? Where did you get the idea to use `__uuidof(RPTAModuleInterface)` to begin with? – Remy Lebeau Jan 08 '15 at 03:45
  • that's not my code, they just saw error on application and the error comes from that code, and i really don't understands what's the meaning of that.. by the way the `RPTAModuleInterface` declared as `struct /* coclass */ RPTAModuleInterface;` – Wielder Jan 08 '15 at 03:51
  • If `RPTAModuleInterface` is the correct CoClass, then the EXE/DLL that implements the CoClass is not registered with the OS. You are going to have to hunt down which application that belongs to and make sure it is installed correctly, we can't do that for you here. And BTW, `0x0022a360` is not a failure `HRESULT` value, are you sure that is the actual `HRESULT` that `CoCreateInstance()` is returning? The `"Class not registered"` error message is normally associated with `HRESULT` value `0x80040154` instead. – Remy Lebeau Jan 08 '15 at 04:39
  • i just add quick watch and put e.ErrorMessage(); and the value is `0x0022a360 Class not registered` – Wielder Jan 08 '15 at 05:20
  • i try to search .dll files in the folder of my application and saw RPTAInterface.dll and i tried to register it using regsvr32 but it didn't work, and then i saw that RPTAInterface.dll.config is the complete name of this app, how can i register the .dll.config file? – Wielder Jan 08 '15 at 06:11
  • A .config file is a strong hint that this server was implemented in .NET. Which are registered a different way, regsvr32 cannot work. You could try Regasm.exe but it is rather important to get support from the software owner so you know how to do this properly. – Hans Passant Jan 08 '15 at 09:25
  • regasm.exe is part of the .NET framework, which is a Windows system component that you can [download from Microsoft](http://www.microsoft.com/net/downloads) if you don't already have it (you likely already do). – Remy Lebeau Jan 09 '15 at 03:46
  • i found it, what file should i register? .tlb? – Wielder Jan 09 '15 at 03:48