CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    3

    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)?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    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

  3. #3
    Join Date
    Dec 2008
    Posts
    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!

  4. #4
    Join Date
    Nov 2003
    Posts
    1,902

    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

  5. #5
    Join Date
    Dec 2008
    Posts
    3

    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.

  6. #6
    Join Date
    Nov 2003
    Posts
    1,902

    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
  •  





Click Here to Expand Forum to Full Width

Featured