错误访问COM组件 [英] Error accessing COM components

查看:1274
本文介绍了错误访问COM组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Microsoft Office Word中的加载项。没有使用外接当Word中跑了作为管理员的问题,但是当它不跑作为管理员,有访问带状元件两种常见的例外情况。

第一种例外情况:

 无法投型系统.__ ComObject的COM对象的接口类型Microsoft.Office.Core.IRibbonUI。此操作失败的原因是对IID{000C03A7-0000-0000-C000-000000000046}接口的COM组件调用QueryInterface失败,原因是以下错误:无法找到。 (从HRESULT异常:0x80030002(STG_E_FILENOTFOUND))。
   在Microsoft.Office.Core.IRibbonUI.InvalidateControl(字符串控件ID)

在控制由以下code失效会出现此错误:

  ribbon.InvalidateControl(控制ID);

和第二个例外:

 无法投类型的COM对象Microsoft.Office.Interop.Word.ApplicationClass接口类型Micr​​osoft.Office.Interop.Word._Application。此操作失败的原因是对IID{00020970-0000-0000-C000-000000000046}接口的COM组件调用QueryInterface失败,原因是以下错误:无法找到。 (从HRESULT异常:0x80030002(STG_E_FILENOTFOUND))。
   在Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()

在以下code的最后一行出现此错误:

 对象wdStory = Word.WdUnits.wdStory;
反对wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(REF wdStory,参考wdMove)

我怎样才能解决这个问题呢?


解决方案

问题解决了!

我有previously安装Office 2010,所以在Windows注册表中一些不会出现不一致。
为了解决这些问题,打开注册表编辑器并找到从错误的CLSID。

您会发现类似的东西的第二个错误:

  HKEY_CLASSES_ROOT \\接口\\ {00020970-0000-0000-C000-000000000046}

随着子项:


  • ProxyStubClsid

  • ProxyStubClsid32

  • 类型库

看看在(默认)版本里面的值类型库

现在找到节点下,使用(默认)<类型库ID>

HKEY_CLASSES_ROOT \\的TypeLib \\ <类型库ID> \\

由于这种元素的孩子,你会发现多个元素的再一个就是第一个注册的版本。如果你检查别人的元素,你会发现,它们指向什么。 删除他人!!! 它解决了!

I built an add-in for Microsoft Office Word. There isn't an issue using the add-in when Word is ran as Administrator, but when it's not ran as an Administrator, there are two common exceptions accessing Ribbon elements.

The first Exception:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.IRibbonUI'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000C03A7-0000-0000-C000-000000000046}' failed due to the following error:  could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
   at Microsoft.Office.Core.IRibbonUI.InvalidateControl(String ControlID)

This error occurs when the Control is invalidated by the following code:

ribbon.InvalidateControl("control-id");

And the second Exception:

Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error:  could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
   at Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()

This error occurs on the last line of the following code:

object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)

How can I fix this problem?

解决方案

Problem solved!

I have previously installed Office 2010, so there are some inconsistences in Windows Registry. To fix them, open the regedit and find for the CLSID from the error.

You will find something like that for the second error:

HKEY_CLASSES_ROOT\Interface\{00020970-0000-0000-C000-000000000046}

With the subkeys:

  • ProxyStubClsid
  • ProxyStubClsid32
  • TypeLib

Take a look at the (Default) and Version values inside of TypeLib.

Now find the node below, using the (Default) value as <TypeLib ID>.

HKEY_CLASSES_ROOT\TypeLib\ <TypeLib ID> \

As child of this elements you will find more than one element, one of then is the Version of the first registry. If you inspect the others elements, you will find that they point to nothing. Remove the others!!! It's solved!

这篇关于错误访问COM组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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