“未登记类别”哪一堂课? [英] "class not registered" which class?

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

问题描述

请考虑这个代码:

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

Ie我有一个代码块,用来描述我的对象。
有时(错误的安装)它失败,因为一些类没有正确注册。
(我没有特别的问题,这里一般的讨论。)

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.

而不是调用一个智能指针构造函数参数化的类id,你可以调用它的CreateInstance()方法 - 它具有完全相同的参数集,但不会抛出异常。然后你可以检查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.

但是它不会帮助ypu如果问题发生在代码你不控制。在极端情况下,您可以使用进程监视器监视注册表查询,并检测哪个类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天全站免登陆