博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[VC] 枚举ActiveX控件的 CLSID 和 implemented/required CATIDs 的小工具
阅读量:4549 次
发布时间:2019-06-08

本文共 4468 字,大约阅读时间需要 14 分钟。

作者:。

  这是一个小工具,枚举ActiveX控件的 CLSID 和 implemented/required CATIDs。可用来帮助分析ActiveX控件部署问题。

一、代码

  全部代码——

View Code
#include 
#include
#include
#include
#include
#include
#include
#include
void doenumactivex(void);int _show_catid = FALSE;// 获取程序位数(被编译为多少位的代码)int GetProgramBits(){ return sizeof(int*) * 8;}int _tmain(int argc, _TCHAR* argv[]){ setlocale(LC_ALL, ""); // 使用系统当前代码页. _tprintf(_T("enumactivex v1.00 (%dbit)\n\n"), GetProgramBits()); CoInitialize(NULL); _show_catid = (argc>1); // 当带有命令行参数时,显示 implemented/required CATIDs。 doenumactivex(); CoUninitialize(); return 0;}void fprint_GUID(FILE *stream, REFGUID refguid){ #define GUID_STRING_LEN 50 OLECHAR szGuid[GUID_STRING_LEN]; int nCount = ::StringFromGUID2(refguid, szGuid, GUID_STRING_LEN); if (nCount<=0 || nCount>=GUID_STRING_LEN) return; szGuid[nCount] = 0; _ftprintf(stream, _T("%ls"), szGuid); // 因OLECHAR实际上是UTF16编码的字符串.}// 枚举ActiveX控件.void doenumactivex(void){ // 参考了: http://hi.baidu.com/dakzjbwlqctuyzr/item/46d199e81f81f312595dd86c LCID lcid = GetSystemDefaultLCID(); // // 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 interested 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, ((ULONG)-1), NULL, &pEnumGUID); // 若cRequired为0,则仅列出没有“Required Categories”的类。只有将其设为-1,才是忽略“Required Categories”筛选。 // Enumerate as long as you get S_OK CLSID clsid; //控件的GUID while ((hr = pEnumGUID->Next(1, &clsid, NULL)) == S_OK) { BSTR bstrClassName; // Get the information of class // This is what MSDN says about the parameters /*----------------------------------------------- 1. USERCLASSTYPE_FULL The full type name of the class. 2. USERCLASSTYPE_SHORT A short name (maximum of 15 characters) that is used for popup menus and the Links dialog box. 3. 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_list.AddString(strControlName); // == main == CATID catid; IEnumCATID *pEnumCATID = NULL; fprint_GUID(stdout, clsid); _tprintf(_T("\t%ls"), bstrClassName); // 因BSTR变量指向UTF16编码的字符串. _tprintf(_T("\n")); // EnumImplCategoriesOfClass if (_show_catid) { _tprintf(_T("\tEnumImplCategoriesOfClass:\n")); if (S_OK == pCatInfo->EnumImplCategoriesOfClass(clsid, &pEnumCATID)) { while (S_OK == pEnumCATID->Next(1, &catid, NULL)) { _tprintf(_T("\t\t")); fprint_GUID(stdout, catid); PWCHAR pszDesc = NULL; pCatInfo->GetCategoryDesc(catid, lcid, &pszDesc); _tprintf(_T("\t%ls"), pszDesc); ::CoTaskMemFree(pszDesc); _tprintf(_T("\n")); } pEnumCATID->Release(); } } // EnumReqCategoriesOfClass if (_show_catid) { _tprintf(_T("\tEnumReqCategoriesOfClass:\n")); if (S_OK == pCatInfo->EnumReqCategoriesOfClass(clsid, &pEnumCATID)) { while (S_OK == pEnumCATID->Next(1, &catid, NULL)) { _tprintf(_T("\t\t")); fprint_GUID(stdout, catid); PWCHAR pszDesc = NULL; pCatInfo->GetCategoryDesc(catid, lcid, &pszDesc); _tprintf(_T("\t%ls"), pszDesc); ::CoTaskMemFree(pszDesc); _tprintf(_T("\n")); } pEnumCATID->Release(); } } } // we are done so now release the interface ptr pCatInfo->Release();}

 

  
二、测试

  在以下编译器中成功编译——

VC6:x86版。
VC2005:x86版。

2.1 仅列出ActiveX控件的CLSID与名称

  如果直接运行,即没有命令行参数时,就仅列出ActiveX控件的CLSID与名称。

  例如在命令提示符中输入“enumactivex”——

  或者运行“enumactivex_ui.exe”——

2.2 还列出 implemented/required CATIDs

  如果随便写上一个命令行参数,就还会列出 implemented/required CATIDs。

  例如在命令提示符中输入“enumactivex”——
  或者运行“enumactivex_ui.exe”,并在自定义文本框中随便输入一个参数——

参考文献——
《枚举系统的ActiveX控件并在视图中显示》. S0746.
《[C#] cmdarg_ui:“简单参数命令行程序”的通用图形界面》. 

源码下载——

转载于:https://www.cnblogs.com/zyl910/archive/2012/09/25/enumactivex.html

你可能感兴趣的文章
c++深/浅拷贝 && 构造函数析构函数调用顺序练习题
查看>>
java读取文件夹下所有文件并替换文件每一行中指定的字符串
查看>>
HTML5规范-相关资料链接(大多都是英文文档)
查看>>
[转]OData/WebApi
查看>>
[转]高颜值、好用、易扩展的微信小程序 UI 库,Powered by 有赞
查看>>
[转]SQL Server如何启用xp_cmdshell组件
查看>>
[转]微擎应用笔记3--manifest.xml文件使用说明
查看>>
Codeforces 1000C Covered Points Count 【前缀和优化】
查看>>
python高效读取文件、文件改写
查看>>
gulp
查看>>
pgsql查询优化之模糊查询
查看>>
[转]-Gradle使用手册(三):构建任务
查看>>
ExtJS下拉树
查看>>
android 调用系统相机录像并保存
查看>>
BW系统表的命名规则
查看>>
Asp.Net在IE10下出现_doPostBack未定义的解决办法 LinkButton
查看>>
《CLR via C#》Part2之Chapter5 基元类型、引用类型和值类型(一)
查看>>
接口和抽象类的对比,面向对象的三大特性和四大特性
查看>>
1-9 RHEL7-文件权限管理
查看>>
apache服务器安装
查看>>