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

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

问题描述

我为 Microsoft Office Word 构建了一个加载项.当 Word 以管理员身份运行时,使用加载项没有问题,但当它不是以管理员身份运行时,访问功能区元素有两个常见的异常.

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.

第一个异常:

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");

第二个例外:

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?

推荐答案

问题解决!

我之前安装过Office 2010,所以Windows Registry有一些不一致的地方.要修复它们,请打开 regedit 并从错误中查找 CLSID.

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_ROOTInterface{00020970-0000-0000-C000-000000000046}

使用子键:

  • ProxyStubClsid
  • ProxyStubClsid32
  • 类型库

查看 TypeLib 中的 (Default)Version 值.

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

现在找到下面的节点,使用 (Default) 值作为 .

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

HKEY_CLASSES_ROOTTypeLib

作为该元素的子元素,您会发现多个元素,其中之一是第一个注册表的Version.如果您检查其他元素,您会发现它们指向任何内容.除掉其他!!!解决了!

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天全站免登陆