403126zhux 发表于 2009-3-18 19:17:00

[求助]环形阵列函数问题

<p>下面是我的代码:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LPDISPATCH pAppDisp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pAppDisp = acedGetAcadWinApp()-&gt;GetIDispatch(TRUE);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARIANT pArrayObjs;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VariantInit(&amp;pArrayObjs);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; V_VT(&amp;pArrayObjs) = VT_ARRAY | VT_DISPATCH;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double val = {0,0,0};<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARIANT basePoint ;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CTransUtil::PointsToVariant (val,&amp;basePoint);//将double型数组转换为VARIANT型<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint3d ptCenter(100, 100, 0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId objId=CTransUtil::CreateCircle(ptCenter, 20);//创建一个以100,100为圆心以20为半径的圆<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (SUCCEEDED(AcAxArrayPolar(objId,pAppDisp,4,2*(CTransUtil::PI()),basePoint,&amp;pArrayObjs)))acutPrintf("\nsucceeded");</p><p>//将DOUBLE转换为VARIANT型<br/>void&nbsp; CTransUtil::PointsToVariant (double* pt,VARIANT *a)</p><p>{SAFEARRAYBOUND rgsaBound;<br/>&nbsp;rgsaBound.lLbound=0L;<br/>&nbsp;rgsaBound.cElements=3;</p><p>SAFEARRAY* psa=NULL;<br/>&nbsp;psa=SafeArrayCreate(VT_R8,1,&amp;rgsaBound);<br/>&nbsp;for(long i=0;i&lt;3;i++) <br/>&nbsp;{if( FAILED(SafeArrayPutElement(psa,&amp;i,&amp;pt)))<br/>&nbsp;acutPrintf("\nPutElement FAILED");<br/>&nbsp;}<br/>&nbsp;V_VT(a)=VT_ARRAY | VT_R8;<br/>&nbsp;V_ARRAY(a)=psa;}</p><p>调试时代码没有问题,可是在执行时却显示CAD内部命令出错,请问我哪里出了问题???</p><p>高手一定帮帮忙啊</p>

bluelight 发表于 2009-3-21 10:49:00

可能是内存释放问题。SafeArrayCreate创建出来内存直接传入了CAD,可能会有问题。查一下MSDN,用拷贝函数复制一份数据传入CAD,然后把SafeArrayCreate创建的释放掉。

unionsoft 发表于 2009-3-23 15:34:00

basePoint 有问题,因为它的parray所指的数组psa生命期已经结束了,parray所指的内容是不确定的。
页: [1]
查看完整版本: [求助]环形阵列函数问题