News:

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

COM from MASM32

Started by axtens, June 18, 2007, 04:25:21 AM

Previous topic - Next topic

axtens

Okay, I'll keep it short this time.

I have a COM DLL that I wrote in Delphi. It exposes a function which accepts a WideString and returns a Boolean.

I'm using the COM plugin for RadASM.
The GUIDs are:

sIID_IConverters textequ <{08DD3E3E3h,05DF7h,04BA8h,{08Ch,000h,02Dh,022h,0DEh,0FFh,081h,090h}}>
IID_IConverters GUID sIID_IConverters
sCLSID_Converters textequ <{00CF7C6A0h,0981Dh,04C2Ch,{0A7h,04Ch,026h,0DDh,071h,03Ch,022h,0BEh}}>
CLSID_Converters GUID sCLSID_Converters


The following works:

invoke CoInitializeEx,0,0
MOV hResult, rv(CoCreateInstance,ADDR CLSID_Converters,NULL,CLSCTX_SERVER,ADDR IID_IConverters,ADDR pIConverters)


but I'm quite at a loss to figure out how to pass in the address of the returned boolean. I've tried putting it in .data? and as a LOCAL, as a WORD / DWORD / VARIANT / VARIANT_BOOL but to no effect. The RadASM plugin says that I should have code like this:
mov eax,pIConverters
mov edx,[eax]
push /VT_BOOL/
;Parameters ( sName )
push /VT_VARIANT/
push pIConverters
;call IConverters._IsEnc
call dword ptr [edx+30*4]


I'm fairly sure I'm doing the right thing with the push of the VT_VARIANT for the sName parameter: that's done as
mov pWideAllocStr,rv(SysAllocString,sEncoding)
where pWideAllocStr is defined as a LOCAL DWORD and the sEncoding is arriving as a pointer to a widestring. pWideAllocStr ends up pointing to a BSTR.

The chunk in question is
mov eax,pIConverters
mov edx,[eax]
push offset bIsEncoding ;defined in .data? as bIsEncoding DW ?
;Parameters ( sName )
push pWideAllocStr
push pIConverters
;call IConverters._IsEnc
call dword ptr [edx+30*4]


Running with a VB6 testing program, the program dies immediately after the call

Can anyone tell me what I'm doing wrong? Is there a better way?

Kind regards,
Bruce.

axtens

Hmm... seems  I hadn't done it right. Funny what stopping for lunch does, that and praying about it.

mov pWideAllocStr,rv(SysAllocString,sEncoding)
MOV var.vt, VT_BSTR
MOV EAX, pWideAllocStr
MOV var.bstrVal, EAX

mov eax,pIConverters
mov edx,[eax]
push bIsEncoding
;Parameters ( sName )
push var
push pIConverters
;call IConverters._IsEnc
call dword ptr [edx+30*4]

that gets past the call. So far so good.

Kind regards,
Bruce.

axtens

Grrrrrr

Okay, it's not crashing, but it's still not working. The string parameter is not being passed to the DLL. The DLL is being called, but nothing's getting passed.

IsEncoding PROC STDCALL uses EDI ESI EBX sEncoding:DWORD

;LOCAL bIsEncoding:WORD
;LOCAL pSTR:DWORD
;LOCAL lpWideCharStr[128]:BYTE
LOCAL pWideAllocStr:DWORD
LOCAL nLen:DWORD
LOCAL arg1:VARIANT
LOCAL res1:VARIANT

PUSH EDX
PUSH ECX

mov pWideAllocStr,rv(SysAllocString,sEncoding)

MOV arg1.vt, VT_BSTR
MOV EDX, pWideAllocStr
MOV arg1.bstrVal, EDX

DumpMem ADDR arg1, sizeof VARIANT

MOV res1.vt, VT_BOOL

mov eax,pIConverters
mov edx,[eax]
;push bIsEncoding
push res1
;Parameters ( sName )
push arg1
push pIConverters
;call IConverters._IsEnc
call dword ptr [edx+30*4]

PrintHex EAX
PrintLine
fn SysFreeString,pWideAllocStr
MOVZX EAX, bIsEncoding
POP ECX
POP EDX
ret

IsEncoding endp