ROT Marshal.GetActiveObject读取实例的问题?

大屏幕 2008-03-16 09:47:31
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using System.Runtime.InteropServices;

namespace SPMP.BomEditTool
{
public class AutoCADConnector : IDisposable
{
private AcadApplication _application;

private bool _initialized;

private bool _disposed;


public AutoCADConnector()
{
try
{
//Upon creation,attempt to retrieve running instance
_application = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
}
catch
{
try
{
//Create an instance and set flag to indicate this
_application = new AcadApplicationClass();

_application.Visible = true;

_initialized = true;
}
catch
{
throw;
}
}
}
//If the user doesn't call Dispose, the
//garbage collector will upon destruction

~AutoCADConnector()
{
Dispose(false);
}

public AcadApplication Application
{
get
{
//return our internal instance of autocad
return _application;
}
}

//This is the user-callable version of Dispose.
//It calls our internal version and removes the
//object from the garbage collector's queue.

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

//this version of Dispose gets called by our
//destructor

protected virtual void Dispose(bool disposing)
{
//if we create our Autocad instance, call its
//Quit method to avoid leaking memory.
if (!this._disposed && _initialized)
_application.Quit();

_disposed = true;
}


}

}

有没有人用过AutoCADConnector网上的这个程序,我用 (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17.1") 读取当前的autocad对象时,为什么当我同时打开多个autocad进程,只能读取第一个打开的autocad中的图形文件,而我想读取的是最后打开的 autocad中的图形文件。谁解决过这个问题?
...全文
538 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱的华尔兹 2011-10-20
  • 打赏
  • 举报
回复
同求啊!
大屏幕 2008-04-08
  • 打赏
  • 举报
回复
不太明白你说的,可以联系我。我的信箱是greatwelljing@163.com.这个问题我没解决。只好加个提示让用户只打开单个AutoCAD了。不开多进程不会出现这个问题。这段代码我试过了。无异常。如果你有,可以发我信箱里,我帮你调试下。
sumail123 2008-03-30
  • 打赏
  • 举报
回复
_application = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
我执行这里会有异常,操作不能完成.
在网上找了一下,据说是ROT方面的问题,但不是很明白.

GetActiveObject的参数在哪里可以查找相应控件的ID?

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧