zoukankan      html  css  js  c++  java
  • directX枚举系统设备类 分类: DirectX 2014-09-20 08:30 491人阅读 评论(0) 收藏

    void CSysEnumDlg::DisplayFullCategorySet(void)
    {
        USES_CONVERSION;


        HRESULT hr;
        IEnumMoniker *pEmCat = 0;
        ICreateDevEnum *pCreateDevEnum = NULL;
        int nClasses=0;


        // Create an enumerator
        hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
                              IID_ICreateDevEnum, (void**)&pCreateDevEnum);
        ASSERT(SUCCEEDED(hr));
        if (FAILED(hr))
            return;


        // Use the meta-category that contains a list of all categories.
        // This emulates the behavior of GraphEdit.
        hr = pCreateDevEnum->CreateClassEnumerator(
                             CLSID_ActiveMovieCategories, &pEmCat, 0);
        ASSERT(SUCCEEDED(hr));


        if(hr == S_OK)
        {
            IMoniker *pMCat;
            ULONG cFetched;


            // Enumerate over every category
            while(hr = pEmCat->Next(1, &pMCat, &cFetched),
                  hr == S_OK)
            {
                IPropertyBag *pPropBag;


                // Associate moniker with a file
                hr = pMCat->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
                if(SUCCEEDED(hr))
                {
                    VARIANT varCatClsid;
                    varCatClsid.vt = VT_BSTR;


                    // Read CLSID string from property bag
                    hr = pPropBag->Read(L"CLSID", &varCatClsid, 0);
                    if(SUCCEEDED(hr))
                    {
                        CLSID clsidCat;//枚举所有的设备类


                        if(CLSIDFromString(varCatClsid.bstrVal, &clsidCat) == S_OK)
                        {
                            // Use the guid if we can't get the name
                            WCHAR *wszCatName;
                            TCHAR szCatDesc[MAX_PATH];


                            VARIANT varCatName;
                            varCatName.vt = VT_BSTR;


                            // Read filter name
                            hr = pPropBag->Read(L"FriendlyName", &varCatName, 0);
                            if(SUCCEEDED(hr))
                                wszCatName = varCatName.bstrVal;
                            else
                                wszCatName = varCatClsid.bstrVal;


    #ifndef UNICODE
                            WideCharToMultiByte(
                                    CP_ACP, 0, wszCatName, -1,
                                    szCatDesc, sizeof(szCatDesc), 0, 0);
    #else
                            lstrcpy(szCatDesc, W2T(wszCatName));
    #endif


                            if(SUCCEEDED(hr))
                                SysFreeString(varCatName.bstrVal);


                            // Add category name and CLSID to list box
                            AddFilterCategory(szCatDesc, &clsidCat);
                            nClasses++;
                        }


                        SysFreeString(varCatClsid.bstrVal);
                    }


                    pPropBag->Release();
                }
                else
                {
                    break;
                }


                pMCat->Release();
            } // for loop


            pEmCat->Release();
        }


        pCreateDevEnum->Release();


        // Update listbox title with number of classes
        SetNumClasses(nClasses);
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Leetcode---2. Add Two Numbers
    Leetcode---1. Two Sum
    dpkg:处理 xxx (--configure)时出错解决方案
    ubuntu 14.04搭建tensorflow-gpu开发环境
    Leetcode---35. Search Insert Position
    Leetcode---21. Merge Two Sorted Lists
    Leetcode----26. Remove Duplicates from Sorted Array
    Leetcode---28. Implement strStr()
    Leetcode----27 Remove Element
    qemu 安装 ubuntu-server 虚拟机
  • 原文地址:https://www.cnblogs.com/mao0504/p/4706518.html
Copyright © 2011-2022 走看看