帮看下这段代码错在哪?
这是一段打开CAD的代码,编译能通过,但运行到m_AcadDoc=m_AcadApp.GetActiveDocument();时出错CLSID clsid;
HRESULT h;
CString str;
h=::CLSIDFromProgID(L"AutoCAD.Application",&clsid);
if(FAILED(h))
{
MessageBox("No Acad");
return;
}
IUnknown *pUnknown=NULL;
h=::GetActiveObject(clsid,NULL,&pUnknown);
if(FAILED(h))
{
h=m_AcadApp.CreateDispatch(clsid);
if(FAILED(h))
MessageBox("Fail Acad");
MessageBox("Ok Acad");
}
m_AcadDoc=m_AcadApp.GetActiveDocument();
m_AcadMSpace=m_AcadDoc.GetModelSpace();
m_AcadApp.SetVisible(TRUE);
变量在头文件中的定义是
IAcadApplication m_AcadApp;
IAcadModelSpace m_AcadMSpace;
IAcadDocument m_AcadDoc;