Quote:
I don't see how function pointers in DllCall can help us with COM. Example using mentioned WebBrowser control with imaginary DllCall would help.
My first example isn't enough?
As I said in the previous message I haven't tried IWebBrowser2 so I can't show the usage about it right now. Instead, I'll post about WMI which has been done already.
Actually there exist two ways to do it. Since MS thinks WMI is so important, MS provides both Interfaces to be used in C/C++ and in scripts. Although the interface for C/C++ is more natural in this approach, I'll use the one for scripts as it'd be the easier one to be adapted to the objects scripters are generally interested in.
It'll enumerate all the network adapters in the system.
(Sorry, I haven't commented it appropriately. Just take it as a showcase.)
Code:
sNamespace := "winmgmts:{impersonationLevel=impersonate}!\\.\" . "root\cimv2"
sClass := "SELECT * FROM " . "Win32_NetworkAdapter"
sQLang := "WQL"
VarSetCapacity(wNamespace, StrLen(sNamespace) * 2 + 2)
VarSetCapacity(wClass, StrLen(sClass) * 2 + 2)
VarSetCapacity(wQLang, 8)
Unicode(sNameSpace, wNameSpace, StrLen(sNamespace) + 1)
Unicode(sClass, wClass, StrLen(sClass) + 1)
Unicode(sQLang, wQLang, 4)
EncodeInteger(&IID_IDispatch , 0x00020400)
EncodeInteger(&IID_IDispatch + 4, 0)
EncodeInteger(&IID_IDispatch + 8, 0xC0)
EncodeInteger(&IID_IDispatch +12, 0x46 << 24)
hModule := DllCall("LoadLibrary", "str", "msjava.dll")
DllCall("ole32\CoInitialize", "Uint", 0)
DllCall("ole32\CoGetObject"
, "Uint", &wNamespace
, "Uint", 0
, "Uint", &IID_IDispatch
, "UintP", psvc)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(psvc) + 4*15)
, "Uint", psvc
, "Uint", &wClass
, "Uint", &wQLang
, "Uint", 48
, "Uint", 0
, "UintP", pset)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pset) + 4*7)
, "Uint", pset
, "UintP", penm)
VarSetCapacity(sText, 10240, 1)
VarSetCapacity(vt, 4 * 4)
Loop
{
hResult := DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(penm) + 4*3)
, "Uint", penm
, "Uint", 1
, "Uint", &vt
, "Uint", 0)
If hResult
break
pobj := DecodeInteger(&vt + 4*2)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pobj) + 4*22)
, "Uint", pobj
, "Uint", 0
, "UintP", ptr)
DllCall("WideCharToMultiByte"
, "Uint", 0
, "Uint", 0
, "Uint", ptr
, "int", -1
, "Uint", &sText
, "int", 10240
, "Uint", 0
, "Uint", 0)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pobj) + 4*2)
, "Unit", pobj)
MsgBox % sText
}
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pset) + 4*2)
, "Unit", penm)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pset) + 4*2)
, "Unit", pset)
DllCall("msjava\call"
, "Uint", DecodeInteger(DecodeInteger(pset) + 4*2)
, "Unit", psvc)
DllCall("ole32\CoUninitialize")
DllCall("FreeLibrary", "Uint", hModule)
Unicode(ByRef sString, ByRef wString, nLength)
{
DllCall("MultiByteToWideChar"
, "Uint", 0
, "Uint", 0
, "Uint", &sString
, "int", -1
, "Uint", &wString
, "int", nLength)
}
DecodeInteger(ptr)
{
DllCall("RtlMoveMemory", "UintP", deref, "Uint", ptr, "Uint", 4)
Return deref
}
EncodeInteger(ref, val)
{
DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", 4, "Uint", val)
}
BTW, is this a bug? I have to use VarSetCapacity(sText, 10240, 1) or non-zero byte for the last parameter.
If use VarSetCapacity(sText, 10240) or VarSetCapacity(sText, 10240, 0), then empty sText was returned.