I have added a CoInvoke macro to the
MasmBasic library, usage (for example, more below):
CoInvoke pInterface, IWebBrowserVtbl.
get_HWND, addr hWin
There is a somewhat "unfinished" thread
in the old forum, and I have a suspicion that the macro shown there might not work correctly. Below is my version (from MasmBasic.inc):
CoInvoke MACRO pInterface:REQ,Method:REQ,args:VARARG
LOCAL is, ct, ciPush$, tmp$, tmpAddr$, errEdx$
ct=0
ciPush$ equ <>
FOR arg, <args>
ct=ct+1
ciPush$ CATSTR <arg>, <#>, ciPush$
ENDM
ciPush$ CATSTR ciPush$, < >
WHILE ct
ct=ct-1
is INSTR ciPush$, <#>
tmp$ SUBSTR ciPush$, 1, is-1
tmpAddr$ CATSTR tmp$, <123>
; addr tmpAddr$ SUBSTR tmpAddr$, 1, 4
ifidni tmpAddr$, <addr>
% errEdx$ equ tmp$ tmp$ SUBSTR ciPush$, 5, is-5
lea edx, tmp$
push
edx else
ifidni tmp$, <edx>
ifdef errEdx$
% echo ### edx overwritten by errEdx$ ###
.err
endif endif push
tmp$ endif
ciPush$ SUBSTR ciPush$, is+1
ENDM
ifdifi <pInterface>, <eax>
mov eax, pInterface
endif push
eax mov eax, [eax]
mov edx, [eax+Method]
call dword ptr [eax+Method]
; Method=4, 8, ...ENDM
One question: In some very old posts by Ernie Murphy (e.g.
here) and Japheth, you can find statements like:
.ERR <edx is not allowed as a coinvoke parameter>Is there any good reason not to allow edx? My version throws an error if edx gets overwritten by an
addr xyz, but otherwise I just can't see why edx should not work with CoInvoke... ::)
Just for fun, below a short COM app that launches MSIE (will not assemble with JWasm 2.08):
include \masm32\MasmBasic\
MasmBasic.inc ;
download (version 8 Sept 2012 required)
.data?
WebInterface dd ?
; will be loaded by CoCreateInstance
.code
CLSID_InternetExplorer
GuidFromString("0002DF01-0000-0000-C000-00
0000
0000
46")
IID_IWebBrowser2
GuidFromString(D30C1661-CDAF-11D0-8A3E-00C04FC9E26E)
MyBrowser proc url
LOCAL vEmpty:VARIANT, hWin
ClearLocalVariables uses
edi mov
edi, offset WebInterface
.if !dword ptr [
edi]
invoke CoCreateInstance, addr CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, addr IID_IWebBrowser2,
edi cmp eax, S_OK
jne cci_failed
CoInvoke [
edi], IWebBrowserVtbl.
put_StatusBar, VARIANT_FALSE
; OK, now configure the browser CoInvoke [
edi], IWebBrowserVtbl.
put_MenuBar, VARIANT_FALSE
CoInvoke [
edi], IWebBrowserVtbl.
put_Visible, VARIANT_TRUE
CoInvoke [
edi], IWebBrowserVtbl.
get_HWND, addr hWin
invoke ShowWindow, hWin, SW_MINIMIZE
; MSIE has the bad habit of showing by default a restored window
invoke ShowWindow, hWin, SW_MAXIMIZE
; the author likes it maximised ;-) .endif
lea
edx, vEmpty
CoInvoke [
edi], IWebBrowserVtbl.
Navigate,
Ole$(url),
edx, edx, edx, edx ; COM needs a BSTR, so the ANSI URL needs to be converted
cci_failed:
PopUses
ret
MyBrowser endp
Init invoke OleInitialize, NULL
.if eax==S_OK
invoke MyBrowser,
Chr$("
http://masmforum.com/~masm32/board/index.php")
.endif
invoke OleUninitialize
Exitend start
Source & exe attached below.