问题描述
我知道 VC++6.0 是很古老的语言,但我别无选择,我只是在维护一个现有的程序,我遇到了这个错误
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
这是我的代码
HRESULT hr = CoInitialize(NULL);
// Create the interface pointer.
IModulePtr pI(__uuidof(RPTAModuleInterface)); //the error is here
调试和使用f11
后,程序转到COMIP.H
,代码如下
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
}
}
这是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?
更新
在我的 RPTAInterface.tlh
中,我看到了 RPTAModuleInterface
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()
抛出您没有捕捉到的 _com_error
异常.您需要将代码包装在 try/catch
中,例如:
_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
// ...
}
显然 CoCreateInstance()
失败了.机器上可能没有安装为 RPTAModuleInterface
注册 CoClass 的库,因此无法创建它.但是您必须查看实际的 HRESULT
才能确定 CoCreateInstance()
失败的原因.
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.
这篇关于vc++ 中未处理的异常 - HRESULT 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!