fayifu 发表于 2007-8-24 17:31:00

利用COM在ARX中下面代码AutoCAD2008中始终创建空白文件失败?

<p>AutoCAD2008中始终创建空白文件失败。谁能知诉我错在哪里?</p><p>// 创建一张新图纸<br/>&nbsp;LPDISPATCH pDispatch = acedGetAcadWinApp()-&gt;GetIDispatch(TRUE);<br/>&nbsp;IAcadApplication *acadApp = NULL;<br/>&nbsp;HRESULT hr = S_OK;<br/>&nbsp;hr = pDispatch-&gt;QueryInterface(IID_IAcadApplication, (LPVOID*)&amp;acadApp);<br/>&nbsp;if (FAILED(hr))<br/>&nbsp;&nbsp;return;<br/>&nbsp;IAcadDocuments* pDocs;<br/>&nbsp;acadApp-&gt;get_Documents(&amp;pDocs);<br/>&nbsp;IAcadDocument* pacadDoc;</p><p>&nbsp;VARIANT varTemplate;<br/>&nbsp;::VariantInit(&amp;varTemplate); <br/>&nbsp;varTemplate.vt = VT_BSTR;<br/>&nbsp;varTemplate.bstrVal = _bstr_t(g_sPath/*Arx文件路径*/) + _bstr_t("Template\\acadiso.dwt");<br/>&nbsp;ads_printf(varTemplate.bstrVal);<br/>&nbsp;hr = pDocs-&gt;Add(varTemplate, &amp;pacadDoc); // ???这句代码执行返回结果失败,不能创建空白的图形文件</p><p>/* pDocs-&gt;Add(vtMissing, &amp;pacadDoc); // 在AutoCAD2000中正常执行代码*/</p><p>&nbsp;if (FAILED(hr))<br/>&nbsp;{<br/>&nbsp;&nbsp;ads_printf(_T("创建空白的图形文件失败。\n"));<br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p>

netthree 发表于 2009-3-16 09:38:00

参考如下:<br/>void OpenDwg( void *pData)<br/>{<br/> AcApDocument* pDoc = acDocManager-&gt;curDocument();<br/> if (acDocManager-&gt;isApplicationContext()) <br/> acDocManager-&gt;appContextOpenDocument((const TCHAR *)pData);<br/> else<br/> acutPrintf(L"\nUNABLE TO FIND NEW.DWG!\n");<br/>}<br/><br/>// This is command 'OpenTemplate'<br/>void OpenTemplate()<br/>{<br/> // 直接打开系统中存在的某个模板,如c:\\Template\\new.dwg<br/>static TCHAR pData[] = _T("c:\\Template\\new.dw");<br/>acDocManager-&gt;executeInApplicationContext(OpenDwg, (void *)pData);<br/>}
页: [1]
查看完整版本: 利用COM在ARX中下面代码AutoCAD2008中始终创建空白文件失败?