I am using COM functions of Autocad in my program. One functions keeps giving me the error 80070057 which means apparently
"One or more parameters or arguments are incorrect." This is what the documentation (written for VBA) says about this

AddItems Method
Adds one or more objects to the specified selection set.

object.AddItems Items

The object or objects this method applies to.

An array of objects to add to the selection set.

Objects currently in the specified selection set remain in the selection set. To replace the objects in the selection set, clear the selection set using the Clear method, then add the objects.
To remove individual objects from a selection set, use the RemoveItems method.

Below is the code, it seems to be working otherwise, but the last call just before the ret returns the 80070057.
Of course this proc is not ready yet, because of this error.

ListAllEntities proc uses ebx edi pIAcDoc:ptr IAcadDocument,pEntName:dword,pTargetDir:dword
;lists in a file all acad entities of selected type (using list command)
LOCAL pIModSp:ptr IAcadModelSpace
LOCAL TotCount:sdword
LOCAL pSelsets:dword
LOCAL pSelset:dword
LOCAL Ent:dword
LOCAL ObjName:dword
LOCAL SetName:dword
LOCAL pSetArr:dword
LOCAL FoundCount:dword
LOCAL Counter:dword

invoke vf(pIAcDoc,IAcadDocument,get_ModelSpace),addr pIModSp
invoke vf(pIModSp,IAcadModelSpace,get_Count),addr TotCount
invoke vf(pIAcDoc,IAcadDocument,get_SelectionSets),addr pSelsets
invoke SysAllocString,CStr(L("ListSet"))
mov SetName,eax
invoke vf(pSelsets,IAcadSelectionSets,Add_),SetName,addr pSelset
mov ebx,TotCount
dec ebx;first item is #0

mov ItemVar.vt,VT_I4
mov ItemVar.wReserved1,0
mov ItemVar.wReserved2,0
mov ItemVar.wReserved3,0
mov ItemVar.lVal,ebx

mov edi,esp

.while ebx!=-1
mov ItemVar.lVal,ebx
invoke vf(pIModSp,IAcadModelSpace,Item),ItemVar,addr Ent
invoke vf(Ent,IAcadEntity,get_ObjectName),addr ObjName
invoke WideCharToMultiByte,CP_ACP, 0 ,ObjName,-1, addr MsgBuffer, 256, NULL, NULL
invoke lstrcmpi,addr MsgBuffer,pEntName
.if eax==0;if its a kind of object we are looking for
push Ent
invoke SysFreeString,ObjName
dec ebx

mov eax,edi
sub eax,esp
shr eax,2;get the number of found objects in eax
mov FoundCount,eax
invoke SafeArrayCreateVector,VT_I4,0,FoundCount
mov pSetArr,eax

mov ebx,FoundCount
mov Counter,0
.while ebx>Counter
invoke SafeArrayPutElement,pSetArr,addr Counter,esp
add esp,sizeof dword
inc Counter

mov SetVariant.vt,VT_I4 or VT_ARRAY
mov SetVariant.wReserved1,0
mov SetVariant.wReserved2,0
mov SetVariant.wReserved3,0
m2m SetVariant.parray,pSetArr

invoke vf(pSelset,IAcadSelectionSet,AddItems),SetVariant

ListAllEntities endp

I guess i have something wrong with the VARIANT and/or SAFEARRAY, but i don't know what, so i'd appreciate any ideas.
Posted on 2004-05-18 15:41:39 by Janne
Hi Janne,

its a guess, but instead of

mov SetVariant.vt,VT_I4 or VT_ARRAY

I would try

mov SetVariant.vt, VT_ARRAY

The array "knows" the type of its elements, so I doubt it is
necessary to set VT_I4 as variant type

Posted on 2004-05-18 16:51:08 by japheth
Japheth, thanks for the guess, but the error is still the same.
Posted on 2004-05-18 21:51:02 by Janne
The correct types in this case were
VT_DISPATCH for the safearray
(VT_ARRAY or VT_DISPATCH) for the variant.
Posted on 2004-06-11 11:32:32 by Janne
Arnt variant a bugger... i remember dealing with simular things... Its like fishing really :rolleyes:

Posted on 2004-06-11 16:19:28 by NaN