using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using System.Runtime.InteropServices; private void Form1_Load(object sender, EventArgs e) { double a; string strProgId = "AutoCAD.Application"; Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); //Autodesk.AutoCAD.ApplicationServices.Application acAppComObj; //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId); //Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen(); } 上述方法已经启动了CAD2009 但是下述方法则无法运行 private void Form1_Load(object sender, EventArgs e) { double a; string strProgId = "AutoCAD.Application"; Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); Autodesk.AutoCAD.ApplicationServices.Application acAppComObj; acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId); Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen(); } 而且只要定义了Autodesk.AutoCAD.ApplicationServices.Application acAppComObj就报错 未处理TypeInitializationException <Module>的类型初始值设定项发生异常 |