vc++中未处理的异常 - HRESULT失败

4

我知道VC++6.0是一种非常古老的语言,但是我别无选择,我只是在维护一个现有的程序,并且我遇到了这个错误。

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,以下是代码:

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;
}

我不知道这里出了什么错误,这是头文件,我认为这里没有错误。有什么办法可以解决这个问题吗?
更新:
在我的RPTAInterface.tlh文件中,我看到了RPTAModuleInterface的声明。
struct /* coclass */ RPTAModuleInterface;

struct __declspec(uuid("d6134a6a-a08e-36ab-a4c0-c03c35aad201"))
RPTAModuleInterface;
1个回答

3

_com_issue_error()会抛出一个_com_error异常,你没有捕获这个异常。你需要用try/catch来包裹你的代码,例如:

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

显然,CoCreateInstance()方法出现了问题。机器上很可能没有安装注册RPTAModuleInterface的CoClass的库,所以无法创建它。但是您必须查看实际的HRESULT来确定为什么CoCreateInstance()失败。


你必须确保实现你要访问的类的EXE/DLL已经安装并在操作系统中注册。假设已经完成,我有一种感觉RPTAModuleInterface可能不是正确的值。它看起来更像是一个接口标识符而不是一个类标识符。CoCreateInstance()需要一个类标识符而不是一个接口标识符。你明白它们之间的区别吗?你从哪里得到使用__uuidof(RPTAModuleInterface)的想法呢? - Remy Lebeau
如果 RPTAModuleInterface 是正确的 CoClass,则实现 CoClass 的 EXE/DLL 未在操作系统中注册。 您需要查找属于哪个应用程序并确保其已正确安装,我们无法在此处为您执行此操作。 另外,0x0022a360 不是失败的 HRESULT 值,您确定这是 CoCreateInstance() 返回的实际 HRESULT 吗? “类未注册”错误消息通常与 HRESULT0x80040154 相关联。 - Remy Lebeau
我试图在我的应用程序文件夹中搜索.dll文件,看到了RPTAInterface.dll,然后尝试使用regsvr32进行注册,但失败了,然后发现RPTAInterface.dll.config是这个应用程序的完整名称。我要如何注册.dll.config文件? - Wielder
regasm.exe是.NET框架的一部分,它是Windows系统组件之一。如果您还没有.NET框架,可以从微软官网下载(但您很可能已经拥有它)。 - Remy Lebeau
我找到了它,应该注册哪个文件?.tlb文件吗? - Wielder
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接