GetActiveObject()与GetObject()-MK_E_UNAVAILABLE错误 [英] GetActiveObject() vs. GetObject() -- MK_E_UNAVAILABLE Error

查看:82
本文介绍了GetActiveObject()与GetObject()-MK_E_UNAVAILABLE错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部:

我在将一些VBA代码转换为C#时遇到一些问题。

I am having some problems translating some VBA code to C#.

充当本地COM服务器的第三方应用程序。

We have a 3rd party app which acts as a local COM server.

在VBA代码中,我们使用 GetObject()来获取对现有对象的引用

In the VBA code we use GetObject() to get a reference to the existing object

例如

Set appHandle = GetObject("", ProgId)

这很好。

我在我们的C#代码中添加了对第三方应用程序的引用,并使用 Marshal.GetActiveObject()尝试获取对正在运行的实例的引用。

I added a reference to the 3rd party app in our c# code, and used Marshal.GetActiveObject() to try and get a reference to a running instance.

例如

var appModel = (IAppCoModel)Marshal.GetActiveObject(ProgId);

但我一直遇到 MK_E_UNAVAILABLE 错误。

在C#代码中创建新对象

Creating a new object works fine in the C# code

例如

var appModel = new AppCoModel()

这将启动第三方应用程序,并允许我与其进行通信。

this launches the 3rd party app and allows me to communicate with it. It is only grabbing a reference to a running instance that fails.

我尝试过的操作

不同的安全上下文

VS在管理员模式下运行,而第3方应用程序则不在。我尝试从命令行(非管理员)运行c#应用程序。仍然失败。

Different security contexts
VS is running in admin mode, the 3rd party app isn't. I tried running our c# app from the command line (non-admin). Still failing.

检查ROT内容
(由 Marshal.GetActiveObject()在C#中引发MK_E_UNAVAILABLE异常

第三方应用未显示在其中。

Check the ROT contents
(suggested by Marshal.GetActiveObject() throws MK_E_UNAVAILABLE exception in C#)
The 3rd party app doesn't appear in it. Don't know enough COM to be sure that it needs to.

检查了所有注册表项

看很好(据我所知),它们足以创建和创建第三方应用程序的实例,并且VBA可以找到它。

Checked all the Registry entries
Look good (as far as I can see) and they are good enough to create and instance of the 3rd party app and for the VBA to find it. Anything specific that I should check here?

人们可以提出的任何建议将不胜感激。

Any suggestions that people can make would be appreciated.

推荐答案

全部:

不太确定结束自己问题的礼节,但是由于我找到了答案,所以我想用某种方式标记

Not too sure what the etiquette for closing one's own question is but since I found the answer I would like to some way mark it as 'not needing an answer'.

GetActiveObject()返回MK_E_UNAVAILABLE的原因是第三方应用程序未注册为自动化服务器。无法获得对正在运行的实例的引用。

The reason that GetActiveObject() returns MK_E_UNAVAILABLE is that the 3rd party app is not registered as an automation server. It is not possible to get a reference to the running instance.

该代码未在VBA代码中显示,因为:

This didn't show in the VBA code because:


  1. GetObject(,ProgID)每次创建一个新实例( http://msdn.microsoft.com/en-us/library/gg251785.aspx

  1. GetObject("",ProgID) creates a new instance each time ( http://msdn.microsoft.com/en-us/library/gg251785.aspx )

如果第三方应用未运行,则COM暴露的功能会启动该应用。因此,在VBA中,我们正在创建多个对象,它们都指向同一运行的应用程序,而不是附加到运行的应用程序。

The COM exposed functionality in the 3rd party app launches the app if it is not running. So in the VBA we are creating multiple objects all pointing at the same running app rather than attaching to the running app.

这篇关于GetActiveObject()与GetObject()-MK_E_UNAVAILABLE错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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