HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid) { //注册组件分组信息 ICatRegister* pcr = NULL; HRESULT hr = S_OK; hr=CoCreateInstance(CLSID_StdComponentCategoriesMgr,NULL,CLSCTX_INPROC_SERVER,IID_ICatRegister,(void**)&pcr); if(SUCCEEDED(hr)) { //注册已实现的类到分组 CATID rgcatid[1]; rgcatid[0] = catid; hr = pcr->RegisterClassImplCategories(clsid,1,rgcatid); } if(pcr != NULL) pcr->Release(); return hr; }
ActiveX的注册是在函数DLLRegisterServer中进行的,在组件中 DLLRegisterServer 函数调用了CreateComponentCategory和RegisterCLSIDInCategory函数来保证控件的安全性初始化和脚本操作。所以DLLRegisterServer应添加如下代码:
//注册控件是安全性初始化的 hr=CreateComponentCategory(CATID_SafeForInitializing,L"Controls safely initializable from persistent data!"); if(FAILED(hr))return hr; CLSID m_clsid;//本控件的的clsid CLSIDFromString(L"{0F968806-D214-11D5-9022-5254AB123A61}",&m_clsid); hr=RegisterCLSIDInCategory(m_clsid,CATID_SafeForInitializing); if(FAILED(hr))return hr; //注册控件是安全性脚本操作的 hr=CreateComponentCategory(CATID_SafeForScripting,L"Controls safely scriptable!"); if(FAILED(hr))return hr; hr=Regist |