News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

com and DISP_E_UNKNOWNNAME

Started by minor28, September 07, 2009, 07:18:01 PM

Previous topic - Next topic

minor28

I have this code in masm and get following error message.


invoke OleInvoke,pDispatch,IDispatch.GetIDsOfNames,5,offset IID_NULL,pName,1,800h,addr pMemid

OleInvoke proc c pInterface:dword,offs:dword,cArg:dword,Arg:vararg

mov ecx,cArg
.while ecx>=1
dec ecx
mov eax,dword ptr [Arg+ecx*4]
push eax
.endw

mov eax,pInterface
mov edx,[eax]
push pInterface
mov eax,offs
call dword ptr [edx+eax]
ret

OleInvoke endp


Return value is 80020006 => DISP_E_UNKNOWNNAME. The name is not recognized.

Same thing with vs6.0 c++ works fine.

hr = pDispatch->GetIDsOfNames(IID_NULL, &pName, 1, LOCALE_SYSTEM_DEFAULT, &pMemid);

Return value is 0 => S_OK

I have done a parallel debug and watched and compared each argument pushed before calling the method. No diference.

I have a vague recollection that I sometimes have read about a bug. Could it be the compiler? Any hint would be appreciated.

Best regards

dedndave


OleInvoke proc c pInterface:dword,offs:dword,cArg:dword,Arg:vararg

try this...


OleInvoke proc pInterface:dword,offs:dword,cArg:dword,Arg:vararg

japheth


MSDN:


HRESULT GetIDsOfNames(
  REFIID  riid,                 
  OLECHAR FAR* FAR*  rgszNames, 
  unsigned int  cNames,         
  LCID   lcid,                   
  DISPID FAR*  rgDispId         
);


the second parameter must be a pointer to a pointer. So try


invoke OleInvoke,pDispatch,IDispatch.GetIDsOfNames,5,offset IID_NULL,addr pName,1,800h,addr pMemid



minor28

I did simplify the posted code.

invoke OleInvoke,pDispatch,IDispatch.GetIDsOfNames,5,offset IID_NULL,CWStr(pName),1,800h,addr pMemid



pName is actuallly an ansi string. A macro CWStr convert it to unicode.

CWStr macro pAStr
;Convert ansi string to unicode
LOCAL ErrMsg
LOCAL szWStrError
LOCAL buffer

.data
szWStrError db "Insufficient buffer size for new string",0
.data?
buffer dd 512 dup (?)
ErrMsg dd 128 dup (?)
.code

push ecx
push edx
invoke lstrlen,&pAStr
mov edx,eax
invoke MultiByteToWideChar,CP_ACP,0,&pAStr,-1,addr buffer,0
.if edx <= eax
invoke MessageBox,0,addr szWStrError,0,MB_OK or MB_ICONERROR
.else
invoke MultiByteToWideChar,CP_ACP,0,&pAStr,-1,addr buffer,sizeof buffer
.if eax==0
invoke GetLastError
invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,0,0,0,addr ErrMsg,128,0
invoke MessageBox,0,addr ErrMsg,0,MB_OK or MB_ICONERROR
.endif
.endif
pop edx
pop ecx
exitm <offset buffer>

endm


It then turned out that it is not a pointer to a pointer so I had to load the pointer to a local variable and the push the address.


QueryInterface proc uses edi esi edx pUnknown:dword,pName:dword,pGuidDispatch:dword
LOCAL Pointer:dword

push CWStr(pName)
pop Pointer
invoke OleInvoke,pDispatch,IDispatch.GetIDsOfNames,5,offset IID_NULL,addr Pointer,1,800h,addr pMemid


Thanks japheth, now it works.