菜鸟求助
本人刚学习c#对cad的ActiveX Automation技术开发!想通过wenjian.Utility.GetEntity(out ReturnObj, out pickPoint, pickPrompt);获得cad中的对象(wenjian是定义的ducoment对象),出现未处理 System.Runtime.InteropServices.COMException
Message="灾难性故障 (异常来自 HRESULT:0x8000FFFF (E_UNEXPECTED))"
Source="Autodesk.AutoCAD.Interop"
ErrorCode=-2147418113
StackTrace:
在 Autodesk.AutoCAD.Interop.AcadUtilityClass.GetEntity(Object& Object, Object& PickedPoint, Object Prompt)
在 cadjiaohu.Form1.查询ToolStripMenuItem1_Click(Object sender, EventArgs e) 位置 E:\vs\cadjiaohu\Form1.cs:行号 113
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 cadjiaohu.Program.Main() 位置 E:\vs\cadjiaohu\Program.cs:行号 18
InnerException:
错误!望高手解答啊!不胜感激啊!
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using System.Reflection;
using Microsoft.VisualBasic.ApplicationServices;
namespace cadjiaohu
{
public partial class Form1 : Form
{
AcadLine returnLine;
AcadPoint returnPointObj;
AcadBlockReference returnBlock;
AcadCircle returncircle;
AcadText returnTextObj;
AcadMText returnMTextObj;
AcadSpline returnSpline;
AcadLWPolyline returnPolyLine;
AcadSelectionSet mySelectionSet;
public Int16[] FilterType= new Int16[4]{0,0,0,0};
public object[] FilterData= new object[4]{"*","*","*","*"};
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
}
catch
{
chuangkou = new AcadApplication();
}
finally
{
wenjian = chuangkou.ActiveDocument;
chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
chuangkou.Visible = true;
Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
}
}
private void chuangkou_BeginQuit(ref bool Cancel)
{
chuangkou = null;
wenjian = null;
MessageBox.Show("结束了CAD程序");
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult jieguo;
jieguo = openFileDialog1.ShowDialog();
if (jieguo == DialogResult.OK)
{
if (openFileDialog1.FileName == null)
MessageBox.Show("请选择有效的文件");
else
{
try
{
chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
}
catch
{
chuangkou = new AcadApplication();
}
finally
{
chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
chuangkou.Visible = true;
Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
}
chuangkou.Application.Visible = true;
wenjian = chuangkou.Documents.Open(openFileDialog1.FileName, null, null);
chuangkou.BeginQuit+=new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
}
}
Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
}
private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
chuangkou.Quit();
wenjian.Close(null,null);
}
private void 查询ToolStripMenuItem1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
object ReturnObj=new object ();
object pickPoint=new object ();
string pickPrompt = "选取对象";
wenjian.Utility.GetEntity(out ReturnObj, out pickPoint, pickPrompt); --------------------编程问答-------------------- --------------------编程问答-------------------- 拜托了,急啊!我参照的是基于Visual C#的AutoCAD 开发
及其在工程中的应用,感觉和上面的例子一样的,代码成功的生成,就是无法调用com组件啊!
高手们请帮帮吧 --------------------编程问答-------------------- 是不是没添加com组件的引用啊?? --------------------编程问答-------------------- 已经加了!
错误帮助器指示是库函数的错误!
不知怎解决啊!
补充:.NET技术 , C#