Marshal.GetActiveObject从esri c #adginin抛出异常 [英] Marshal.GetActiveObject throws exception from esri c# addin

查看:274
本文介绍了Marshal.GetActiveObject从esri c #adginin抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的esri插件能够查找并使用现有的excel实例。代码:



I want my esri addin to look for and use an existing instance of excel. The code:

Microsoft.Office.Interop.Excel.Application exApp = null;
try
{
  exApp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (Exception err)
{MessageBox.Show(err.ToString()); }



GetActiveObject每次抛出异常:


GetActiveObject throws an exception every time:

引用:

来自marshal.getactiveobject的异常

System.Runtime.InteropServices.COMException(0x800401E3);操作不可用(HRESULT异常:0x800401E3(MK_E_UNAVAILABLE))

在System.Runtime.InteropServices.Marshal.GetActiveObject(bla bla bla)

exception from marshal.getactiveobject
System.Runtime.InteropServices.COMException (0x800401E3); Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
at System.Runtime.InteropServices.Marshal.GetActiveObject( bla bla bla)





我写了一个小测试应用程序(Windows应用程序)来做同样的事情,它按预期工作。如果excel正在运行,它将返回对excel实例的引用,否则返回null。它从不抛出异常。为什么插件每次抛出异常?关于esri addins的事情? (这是arcmap的附加内容)



现在已经好几天了,任何帮助都表示赞赏。谢谢!



I wrote a little test app (windows app) to do this same thing, it works as expected. It returns a reference to the instance of excel if excel is running, otherwise it returns null. It never throws the exception. Why is the addin throwing an exception every time? Something about esri addins? (It's an addin to arcmap)

Been banging on this for days now, any help is appreciated. thanks!

推荐答案

这篇关于Marshal.GetActiveObject从esri c #adginin抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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