“课程未注册"哪一堂课? [英] "class not registered" which class?

查看:29
本文介绍了“课程未注册"哪一堂课?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个代码:

try {
    ISomeObject pObj(__uuidof(SomeClass));
    ISomeObject pObj2(__uuidof(SomeOtherClass));
} catch ( _com_error& e ) {
    // Log what failed
}

即我有一段代码可以实例化我的对象.有时(错误安装)它会失败,因为某些类没有正确注册.(我没有特别的问题,这里只是一般性的讨论.)

I.e. I have a block of code which instanciates my objects. Sometimes (a bad install) it failes because some class wasn't properly registered. (I don't have a particular problem, rather general discussion here.)

有什么方法可以从捕获的异常或其他方式意识到哪个类失败了?A 考虑过自己做一个包装器来存储像 gLastCreateAttemptUuid 这样的变量,但感觉很麻烦.

Is there some way to, from the caught exception or otherwise, realize what class failed? A have pondered to make a wrapper of my own which stores a variable like gLastCreateAttemptUuid, but it feel cumbersome.

此外,假设 SomeClass 又尝试实例化其他未注册的内容.那么我们能找出根本问题吗?

Also, suppose that SomeClass in turn attempt to instanciate something else, which isn't registered. Can one then figure out the underlying issue?

推荐答案

CoCreateInstance() 调用者有责任提供关于它试图实例化的内容的足够信息 - ATL 和 Native COM Support 都没有内置功能

It's the duty of CoCreateInstance() caller to provide enough information about what it was trying to instantiate - both ATL and Native COM Support have no built-in features for that.

您可以调用其 CreateInstance() 方法,而不是调用使用类 id 参数化的智能指针构造函数 - 它具有完全相同的参数集,但不会引发异常.然后您可以检查 HRESULT 并处理错误并提供您刚刚用于错误处理程序的类 ID.

Instead of calling a smart pointer constructor parameterized with a class id you can call its CreateInstance() method - it has exactly the same set of parameters but doesn't throw exceptions. Then you could check the HRESULT and handle the error and provide the class id you just used to the error handler.

但是,如果问题发生在您无法控制的代码中,则对您没有帮助.在极端情况下,您可以使用 Process Monitor 来监控注册表查询并检测哪个类 ID 导致了问题.

However it will not help ypu if the problem happens in the code you don't control. In extreme cases you can use Process Monitor to monitor registry queries and detect which class id is causing the problem.

这篇关于“课程未注册"哪一堂课?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆