|
斑竹,请救!在VC环境下我用OLE自动化技术来读写的DWG文件,我完全按照别人文章的程序建立程序,但是出现AutoCAD无法启动的错误.请问这是什么原因?
其读写DWG文件的函数如下:
void CAcadRWDwgDoc::OnRwDwg()
{
// TODO: Add your command handler code here
VARIANT startPoint,endPoint;
SAFEARRAY* start = NULL;
SAFEARRAY* end = NULL;
IAcadApplication acad;
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOne((long)0),
covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
//启动Autocad应用软件
if(!acad.CreateDispatch("AutoCAD.Application.15"))
{
AfxMessageBox("Autocad 启动失败");
return;
}
acad.SetVisible(TRUE);
IAcadDocuments docs = acad.GetDocuments();
long total = docs.GetCount();
IAcadDocument doc = docs.Open("C:\\Documents and Settings\\Administrator\\MyDocuments\\Drawing1",covFalse);
IAcadModelSpace mSpace = doc.GetModelSpace();
long entitiesNum = mSpace.GetCount();
if(entitiesNum >= 1)
{
IAcadEntity entity = mSpace.Item(covOne);
CString name = entity.GetObjectName();
if(name == "AcDbLine"){
IAcadLine line = mSpace.Item(covOne);
startPoint = line.GetStartPoint();
endPoint = line.GetEndPoint();
}
}
start = PointToSafeArrayB(1,1,0);
startPoint.vt = VT_R8|VT_ARRAY;
startPoint.parray = start;
end = PointToSafeArrayA(100,200,0);
endPoint.vt = VT_R8|VT_ARRAY;
endPoint.parray = end;
mSpace.AddLine(startPoint,endPoint);
mSpace.AddCircle(endPoint,60);
mSpace.AddText("I LOVE YOU AUTOCAD",endPoint,100);
SafeArrayDestroy(start);
SafeArrayDestroy(end);
COleVariant name("C:\\Documents and Settings\\Administrator\\My Documents\\Drawing1");
doc.Close(covTrue,name);
acad.Quit();
}
其中当程序执行到
if(!acad.CreateDispatch("AutoCAD.Application.15"))
{
AfxMessageBox("Autocad 启动失败");
return;
}
这里时,编译指出不能找到指定的文件,另外,在注册表HKEY_CLASSES_ROOT中里找不到AutoCAD
组件的DLL文件名称。我想AutoCAD无法启动可能跟这个有关系? |
|