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;
_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.
来源:https://stackoverflow.com/questions/27832181/unhandled-exception-in-vc-hresult-failed