#include "stdafx.h" #include <atlcomcli.h> #import "D:\C++test\FirstCom\Release\FirstCom.dll" no_namespace #import "C:\Program Files\Common Files\Autodesk Shared\acax18chs.tlb" no_namespace int _tmain() { HRESULT hr; CoInitialize(NULL); CLSID clsid; hr=CLSIDFromString(OLESTR("AutoCAD.Application.18"), &clsid); CComPtr<IAcadApplication> pFir; pFir.CoCreateInstance(clsid); // pFir->Visible = TRUE; // pFir->WindowState = acMax; // HWND hw = (HWND)(pFir->HWND); // ::SetForegroundWindow(hw); IAcadDocumentPtr idoc; hr = pFir->get_ActiveDocument(&idoc); IAcadModelSpacePtr iMod; hr = idoc->get_ModelSpace(&iMod); double ptV[3]; ptV[0] = 10; ptV[1] = 10; ptV[2] = 0; VARIANT insertPT; VariantInit(&insertPT); insertPT.vt = VT_ARRAY | VT_R8; //类型(数组,双精度型) SAFEARRAYBOUND rgsabound[1]; rgsabound[0].cElements = 3; //数组所含元素数 rgsabound[0].lLbound = 0; //数组上界 insertPT.parray = SafeArrayCreate(VT_R8, 1, rgsabound); //创立一维数组 SafeArrayLock(insertPT.parray); insertPT.parray->pvData = ptV; SafeArrayUnlock(insertPT.parray); hr = iMod->AddCircle(insertPT, 10); hr = pFir->ZoomExtents(); CoUninitialize(); return 0; }