这是一个要列出本机上所有控件的vc程序,与com有关,我不太懂,请高手指点一下,我想把它转成c#,要怎样对应起来啊,请大家不吝赐教,谢谢//Initialise COM libraries
CoInitialize (NULL);//The Component Category Manager implemented by System implements
//this interface
ICatInformation *pCatInfo=NULL;//Create an instance of standard Component Category Manager
HRESULT hr=CoCreateInstance (CLSID_StdComponentCategoriesMgr ,
                             NULL,
                             CLSCTX_INPROC_SERVER,
                             IID_ICatInformation ,
                             (void **)&pCatInfo);//Increase ref count on interface
pCatInfo->AddRef ();//IEnumGUID interface provides enumerator for enumerating through
//the collection of COM objects
IEnumGUID *pEnumGUID=NULL;//We are intersted in finding out only controls so put CATID_Control
//in the array
CATID pcatidImpl[1];
CATID pcatidReqd[1];
pcatidImpl[0]=CATID_Control;//Now enumerate the classes i.e. COM objects of this type.
pCatInfo->EnumClassesOfCategories (1,
                                   pcatidImpl,
                                   0,
                                   pcatidReqd ,
                                   &pEnumGUID);//Enumerate as long as you get S_OK
CLSID clsid;while( (hr= pEnumGUID->Next( 1, &clsid, NULL ))==S_OK )
{
 BSTR bstrClassName;   //Get the information of class //This is what MSDN says about the parameters
 /*-----------------------------------------------
 USERCLASSTYPE_FULL     The full type name of the class.
 USERCLASSTYPE_SHORT    A short name (maximum of 15 characters) that
                        is used for popup menus and the Links dialog
                        box.
 USERCLASSTYPE_APPNAME  The name of the application servicing the class
                        and is used in the Result text in dialog boxes.
 -----------------------------------------------*/
 OleRegGetUserType (clsid,USERCLASSTYPE_FULL,&bstrClassName);
 CString strControlName(bstrClassName);
 //Add string in our listbox
 m_list1.AddString (strControlName);
}//we are done so now release the interface ptr
pCatInfo->Release ();CoUninitialize ();另外它引用了"comcat.h",这个文件是做什么用的啊

解决方案 »

  1.   

    http://www.codeproject.com/dotnet/RobinComCat.asp
      

  2.   

    jiangsheng(蒋晟.Net[MVP]) 
    那个代码怎么看不懂亚/
      

  3.   

    创建组件类别管理器,取得组件的枚举器接口,枚举组件,that's all。
    另外,引用计数不正确,“pCatInfo->AddRef();”语句不需要。
      

  4.   

    你把"comcat.h"引用去掉编译,看看哪些函数啊常量啥的没定义,你就知道它是干什么用的了。