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

    Finding how many PCI slots are on system

    Hi guys, I'm trying to create code to determine how many PCI slots are currently on a system...available and used.

    I have been trying to use the Win32_SystemSlot WMI class but it doesnt seem to be working properly.

    Code:
    //query systemslot
    IEnumWbemClassObject* pEnumerator = NULL;
        hres = pSvc->ExecQuery(
            bstr_t("WQL"), 
            bstr_t("SELECT * FROM Win32_SystemSlot"),
            WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
            NULL,
            &pEnumerator);
    //get class object
    	IWbemClassObject *pclsObj;
        ULONG uReturn = 0;
        	int noPCI = 0;
    		int noAGP = 0;
    		int noPCMIA = 0;
    //loop through system slots
        while (pEnumerator)
        {
            //next object
            HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
                &pclsObj, &uReturn);
    		
            VARIANT vtProp;
    		//get connecter type data (unsigned int16 array)
     		hr = pclsObj->Get(L"ConnectorType", 0, &vtProp, 0, 0);
                    
                    //create uint16 array to store data
    		unsigned short aShort[sizeof(vtProp)];
    		memcpy (aShort, (char*)(&vtProp), sizeof(aShort));
    		for(int i=0; i<sizeof(aShort); i++)
    		cout << aShort[i] << endl;
    
            VariantClear(&vtProp);
    instead of outputting useful shorts containing data according to this table http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx (scroll down to connector type) it gives me instead the output:

    8195 | -13364 | -13364 | -13364 | -5808 | 22 | -13364 | -13364 |
    8195 | -13364 | -13364 | -13364 | -5808 | 22 | -13364 | -13364 |
    8195 | -13364 | -13364 | -13364 | -5808 | 22 | -13364 | -13364 |

    Which is the output for each iteration through the three system slots it loops through.

    PCI slots should come up as 99. Any idea what i'm doing wrong?

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

    Re: Finding how many PCI slots are on system

    You access a variant array using the safe-array COM API.
    http://msdn.microsoft.com/en-us/library/ms221145.aspx

    Use "SAFEARRAY *psa = V_ARRAY(&vProp);" to get the handle to the safe-array.

    gg

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