HRESULT:0x80040154带有CLSID {}的COM对象无效或未注册 [英] HRESULT:0x80040154 COM object with CLSID {} is either not valid or not registered

查看:72
本文介绍了HRESULT:0x80040154带有CLSID {}的COM对象无效或未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#.NET 1.1应用程序中使用COM对象.当COM对象未在客户端计算机上注册时,出现异常:

I am using COM Object in my C# .NET 1.1 application. When the COM object is not registered on client machine, I get the exception:

带有CLSID {}的COM对象是无效或未注册."(HRESULT:0x80040154)

"COM object with CLSID {} is either not valid or not registered." (HRESULT:0x80040154)

我知道如何使用regsvr32注册COM对象.我们的要求是识别未注册的COM对象.我们不想对COM对象的名称进行硬编码,而是使用COM Exception/HResult动态标识它.有什么想法吗?

I know how to register the COM object using regsvr32. Our requirement is to identify the COM object which is not registered. We don't want to hardcode the name of the COM Object, rather identify it dynamically using the COM Exception/HResult. Any ideas?

推荐答案

鉴于本杰明·波兹松(Benjamin Podszun)的回答在评论中提到的情况,您的方法可能是:

Given the situation mentioned in the comment to Benjamin Podszun's answer, your approach could be:

  • 在注册表中查找CLSID( HKEY_CLASSES_ROOT \ CLSID \ {...} )
  • 如果找不到,则抛出该错误,以便显示一般错误消息
  • 根据对象的类型查找适当的子项(例如,用于In-proc本地COM DLL/OCX的InProcServer32).默认值将是DLL/OCX的路径.
  • 检查此路径是否存在,并使用文件名制作一条合适的消息.

这使您可以在OCX/DLL已移动的情况下显示不同的消息,但是如果未注册OCX/DLL,则当然无济于事.

This enables you to display a different message if the OCX/DLL has been moved, but of course won't help if it is not registered.

您还可能想花一些时间来理解原因(甚至五个原因!)在某些客户端计算机上正在移动/取消注册组件,这可能会建议一种防止这种情况的方法.例如,一种可能的情况是用户安装版本1,然后安装版本2,然后卸载版本1.根据安装程序的实现方式,卸载版本1可能会注销或删除版本2所需的组件.

You also might want to spend some time trying to understand why (or even five whys!) the components are being moved / unregistered on some client machines, which may suggest a way to prevent it . For example, one possible scenario is that the user installs version 1, then installs version 2, then uninstalls version 1. Depending on how your installer is implemented, uninstalling version 1 may deregister or remove the components needed for version 2.

另一种方法可能是查看安装程序是普通用户还是管理员的行为.

Another approach might be to see how the installer behaves as a normal user vs an administrator.

要确定发生故障的客户端计算机上的事件的确切顺序可能会有些困难,但值得尝试.

Identifying the exact sequence of events on failing client machines may be a bit of a challenge, but it's worth trying.

这篇关于HRESULT:0x80040154带有CLSID {}的COM对象无效或未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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