Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Microsoft variables declarations and QM translation
#1
Hi Gintaras, hi all,

using some WMI interfaces, i face a problem in type portage to Qm, thus it seems OK

Example, I search to get network interfaces paramaters.

For instance, following the declatation from Microsoft site:

Win32_NetworkAdapter class



Syntax
Code:
Copy      Help
class Win32_NetworkAdapter : CIM_NetworkAdapter
{
 string   AdapterType;
  .......
 string   ProductName;
 .....
}

If I use this code:

def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
int IFlags = wbemFlagReturnImmediately|wbemFlagForwardOnly
IDispatch objWMIService._getfile("winmgmts:")
IDispatch colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",@,IFlags)
IDispatch objProcess

foreach objProcess colProcesses
_s=objProcess.AdapterType

out _s   <================== Error (RT) in <open ":171: /388">Macro17:  0x80020005, type mismatch.  

_s=objProcess.ProductName 

out _s        <=========================output correct 

Microsoft Kernel Debug Network Adapter
TAP-Windows Adapter V9
Intel® Dual Band Wireless-AC 7260
Microsoft Wi-Fi Direct Virtual Adapter
Bluetooth Device (Personal Area Network)
Microsoft Wi-Fi Direct Virtual Adapter
WAN Miniport (SSTP)
WAN Miniport (IKEv2)
WAN Miniport (L2TP)
WAN Miniport (PPTP)
WAN Miniport (PPPOE)
WAN Miniport (IP)
WAN Miniport (IPv6)
WAN Miniport (Network Monitor)
Microsoft Wi-Fi Direct Virtual Adapter
Microsoft Wi-Fi Direct Virtual Adapter

Both should be string as per declaration, but one is giving error, the other is OK.

I'm out of clues, i know you can help this weird behavior

Thanks!
#2
When calling functions through IDispatch, VARIANT is used as an intermediate type for parameters and the return value. In this case it is of type VT_NULL sometimes, and QM then cannot convert to string (although should).

Macro Macro319
Code:
Copy      Help
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
int IFlags = wbemFlagReturnImmediately|wbemFlagForwardOnly
IDispatch objWMIService._getfile("winmgmts:")
IDispatch colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",@,IFlags)
IDispatch objProcess

foreach objProcess colProcesses
,VARIANT v=objProcess.AdapterType
,;out v.vt
,sel(v.vt) case VT_BSTR _s=v; case VT_NULL _s="<null>"; case else end "error"
,out _s
,;_s=objProcess.ProductName
,;out _s
#3
So, if QM catches a VT_NULL, i can't get the paramter value?
#4
VT_NULL means there is no value. The same as a null string.
#5
Ok, last question to close the thread.


Is VT_NULL expressed by QM means WMI parameter is actually and really equal to NULL, or that QM can't find the paramater value even not NULL, or both?
Would be sure of the NULL cause to handle code correctly.
#6
The first.
#7
Perfect. Thanks, very helpful to code my program.


Forum Jump:


Users browsing this thread: 1 Guest(s)