0

我编写了一个外部应用程序来驱动带有为 COM 注册的 dll 的 autocad。我已经按照这些代码编写了我的应用程序,但是我用 AddNumbers() 方法替换了以下代码:

public string OpenDWGFile(string MyDWGFilePath)
{
DocumentCollection dm = Application.DocumentManager;
Document doc = null;

if(File.Exists(MyDWGFilePath))
{
   doc = dm.Open(MyDWGFilePath, false);
   Application.DocumentManager.MdiActiveDocument = doc;
   return "This file is exists";
 }
else
   return "This file is not exist";
}

但是当我运行我的应用程序时,autocad 软件会立即打开然后关闭,并且会显示此错误消息:调用目标已引发异常。

但如果我评论我的代码的以下行,则应用程序可以正常工作:

doc = dm.Open(MyDWGFilePath, false);
Application.DocumentManager.MdiActiveDocument = doc;
4

1 回答 1

1

您正在创建第二个实例,DocumentManager并为其提供对从第一个实例中检索到的对象的引用。我想你想用

dm.MdiActiveDocument = doc;
于 2012-01-10T10:24:50.923 回答