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中的图形文件。谁解决过这个问题?