|
-
December 11th, 2008, 09:48 AM
#1
Accessing "Win32_DeviceBus" properties
I'm using the MSDN sample code to get WMI Data from a local computer (http://msdn.microsoft.com/en-us/libr...23(VS.85).aspx), and everything works fine for Win32 classes with only scalar elements (like in Win32_Processor).
Now I want to access Win32_DeviceBus which is defined as
class Win32_DeviceBus : CIM_Dependency
{
Win32_Bus REF Antecedent;
CIM_LogicalDevice REF Dependent;
};
How do I access the Antecedent properties (like Antecedent.BusType)?
-
December 11th, 2008, 11:39 AM
#2
Re: Accessing "Win32_DeviceBus" properties
What's your end goal? Are you trying to determine the bus type of a particular device?
Win32_DeviceBus is an association class. Never used an association class myself, but you should be able to get the "Antecedent" property. The returned variant should be of type IUnknown - which is actually an IWbemClassObject interface.
gg
-
December 15th, 2008, 04:04 AM
#3
Re: Accessing "Win32_DeviceBus" properties
The goal is to get a list if PCI devices, including the Bus/Device (and possibly) Function numbers, and it looks like I can find this in "Win32_DeviceBus".
I get the "Antecedent" like this:
...
IWbemClassObject *pclsObj;
VARIANT vtProp;
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
hr = pclsObj->Get(L"Antecedent", 0, &vtProp, 0, 0);
If "Antecedent" were a string, I could access it with "vtProp.bstrVal". But since it is a Variant, I guess I need to cast it (to Win32_Bus or IWbemClassObject?) before I can access its properties, but I don't know how.
Thanks!
-
December 15th, 2008, 09:28 AM
#4
Re: Accessing "Win32_DeviceBus" properties
Code:
IWbemClassObject *pWin32BusObj;
hr = vtProp.punkVal->QueryInterface(__uuidof(IWbemClassObject), (void**)&pWin32BusObj);
Don't forget to check hr, Release() your objects when you're done with them, and call VariantClear() on vtProp.
gg
-
December 15th, 2008, 11:24 AM
#5
Re: Accessing "Win32_DeviceBus" properties
Still not quite there. The
hr = pclsObj->Get(L"Antecedent", 0, &vtProp, 0, 0);
call looks ok, hr = S_OK, and the debugger shows vtProp.BSTR set to seomething like
0x00170ebc "\\DOCKNB143\root\cimv2:Win32_Bus.DeviceID="PCI_BUS_0""
But the
hr = vtProp.punkVal->QueryInterface(__uuidof(IWbemClassObject), (void**)&pWin32BusObj);
call fails because of an access violation.
"vtProp" seems to be pointing to a valid address, so does "vtProp.punkVal". However, vtProp.punkVal._vfptr[0] = 0x00000000.
-
December 15th, 2008, 11:46 AM
#6
Re: Accessing "Win32_DeviceBus" properties
Sorry, looks like the "Antecedent" property is actually a string, not an IUnknown pointer.
So that string is an "object path", which describes a unique object instance. You use IWbemServices::GetObject() to get an object instance based on its path.
Code:
IWbemClassObject *pWin32BusObj;
hr = pSvc->GetObject(vtProp.bstrVal, WBEM_FLAG_RETURN_WBEM_COMPLETE, 0,
&pWin32BusObj, 0);
http://msdn.microsoft.com/en-us/libr...09(VS.85).aspx
http://msdn.microsoft.com/en-us/libr...50(VS.85).aspx
gg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|