I'm using some old COM code from EDGAR at access WMI for my TOP SECRET project,...and I cannot find a definition of the Coinvoke macro.
Here is the example code section that I'm high-jacking:
GetManufacturer FRAME pManufacturer, pModel
LOCAL hres :%HANDLE
LOCAL bstrNameSpace :%PTR
LOCAL variant :%PTR
// Connect to the desired namespace
invoke SysAllocString,L"\\.\root\cimv2"
mov [bstrNameSpace], eax
invoke CoInitializeSecurity, 0,-1,0,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE,0
mov [hres],eax
invoke CoCreateInstance,offset CLSID_WbemLocator,NULL,CLSCTX_INPROC_SERVER,offset IID_IWbemLocator, offset pWbemLocator
test eax,eax
jnz >>.EXIT
CoInvoke(pWbemLocator,IWbemLocator.ConnectServer,[bstrNameSpace],0,0,0,0,0,0,offset pNameSpace)
test eax,eax
jnz >>.EXIT1
CoInvoke(pNameSpace,IWbemServices.IUnknown.QueryInterface,offset IID_IUnknown,offset pUnk)
test eax,eax
// Set the security for our proxy
invoke CoSetProxyBlanket,[pNameSpace],RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE
invoke CoSetProxyBlanket,[pUnk],RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE
CoInvoke(pUnk,Unknown.Release)
// Execute the query, just pull all of the information
CoInvoke(pNameSpace,IWbemServices.ExecQuery,offset L"WQL", L'Select * from Win32_ComputerSystem',WBEM_FLAG_RETURN_IMMEDIATELY,NULL,offset pEnum)
test eax,eax
jnz >>.EXIT2
// Step the enumeration through the class object
CoInvoke(pEnum,IEnumWbemClassObject.Next,WBEM_INFINITE,1,offset pObj,offset hres)
test eax,eax
jnz >>.EXIT3
// Get the information we want
CoInvoke(pObj,IWbemClassObject.Get,L"Manufacturer",0,offset variant,0,0)
test eax,eax
jnz >.EXIT4
// The information is in UNICODE so convert it and display it
invoke WideCharToMultiByte,CP_ACP,NULL,[variant+8],-1,[pManufacturer],256,NULL,NULL
CoInvoke(pObj,IWbemClassObject.Get,L"Model",0,offset variant,0,0)
test eax,eax
jnz >.EXIT4
// The information is in UNICODE so convert it and display it
invoke WideCharToMultiByte,CP_ACP,NULL,[variant+8],-1,[pModel],256,NULL,NULL
.EXIT4
CoInvoke(pObj,IWbemClassObject.Release)
.EXIT3
CoInvoke(pEnum,IEnumWbemClassObject.Release)
.EXIT2
CoInvoke(pNameSpace,IWbemServices.Release)
.EXIT1
CoInvoke(pWbemLocator,IWbemLocator.Release)
.EXIT
invoke SysFreeString,[bstrNameSpace]
ret
endf
I haven't included all the WMI example code, but, here is the Start code section:
CODE SECTION
START:
invoke GetModuleHandle,0
mov rcx,eax
invoke CoInitialize,NULL
invoke GetManufacturer,offset szManufacturer,offset szModel
invoke MessageBox,NULL,offset szModel,offset szManufacturer,NULL
invoke CoUninitialize
invoke ExitProcess,0
EDGAR defines the Coinvoke macro in a file named: WMI.h
Here is the essence of it:
#DEFINE WINVER NTDDI_WIN7
#DEFINE FILTERAPI
#DEFINE LINKFILES
#include "WINDOWS.H"
#include "macros.h"
#include "wbemcli.h"
...No clue as to where either macros.h or wbemcli.h are,... :icon_eek:
coinvoke macro is defined in oaidl.inc (colib (http://masm32.com/board/index.php?topic=1821.msg31944#msg31944))
also read this post (http://masm32.com/board/index.php?topic=1821.msg18756#msg18756)
VERTOGRAD,
Thanks for the response, but, I have no file named: oaidl.inc in my masm/include directory,...
...But, the reference you supplied is good enough, thanks,...
Zen, did you try to download colib from the link provided in brackets?
Download colib archive , unzip it and navigate to include folder where oaidl.inc resides.
I suppose macros.h and wbemcli.h might be found in GoAsm headers.
VERTOGRAD,
Yeah,...thanks,...got it. I downloaded two different versions of the New COM Lib.
...ToutEnMasm (French comments) and, AsmAlmeria12,...
Thanks again,...this is a HUGE help. :biggrin:
For those of you who LOVE JUNK posts,...here is the Coinvoke macro, from the oaidl.inc file:
;---------------------------------------------------------------------
; coinvoke MACRO
;
; invokes an abritrary COM interface
;
; revised 2/22/01 added edx check in the pInterface (this is also a no-no)
; revised 12/29/00 to check for edx as a param and force compilation error
; (thanks to Andy Car for a how-to suggestion)
; revised 7/18/00 to pass pointer in edx not eax to aviod confusion with
; parmas passed with ADDR (Jeremy Collake's excellent suggestion)
; revised 5/4/00 for member function name decoration
; see http://ourworld.compuserve.com/homepages/ernies_world/coinvoke.htm
;
; pInterface pointer to a specific interface instance
; Interface the Interface's struct typedef
; Function which function or method of the interface to perform
; args all required arguments
; (type, kind and count determined by the function)
;
coinvoke MACRO pInterface:REQ, Interface:REQ, Function:REQ, args:VARARG
LOCAL istatement, arg
FOR arg, <args> ;; run thru args to see if edx is lurking in there
IFIDNI <&arg>, <edx>
.ERR <edx is not allowed as a coinvoke parameter>
ENDIF
ENDM
IFIDNI <&pInterface>, <edx>
.ERR <edx is not allowed as a coinvoke parameter>
ENDIF
istatement CATSTR <invoke (Interface PTR[edx]).&Interface>,<_>,<&Function, pInterface>
IFNB <args> ;; add the list of parameter arguments if any
istatement CATSTR istatement, <, >, <&args>
ENDIF
mov edx, pInterface
mov edx, [edx]
istatement
ENDM