本文主要是介绍ocx 有安全提示的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在 *Ctrl.cp 中找到
/ 初始化类工厂和 guidIMPLEMENT_OLECREATE_EX(COcxCzyCtrl, "OCXCZY.OcxCzyCtrl.1",0x2a81cd33, 0xccf0, 0x4426, 0x9a, 0xe3, 0xa, 0xb, 0xba, 0xe5, 0xf4, 0x44)const GUID CDECL CLSID_SafeItem = {0x2a81cd33, 0xccf0, 0x4426, 0x9a, 0xe3, 0xa, 0xb, 0xba, 0xe5, 0xf4, 0x44};在*App 中添加int COcxCzyApp::ExitInstance()
{// TODO: 在此添加您自己的模块终止代码。HRESULT hr;hr=ICzyVPATL->Release();return COleControlModule::ExitInstance();
}// 创建组件种类
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{ICatRegister* pcr = NULL ;HRESULT hr = S_OK ;hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);if (FAILED(hr))return hr;// Make sure the HKCR\Component Categories\{..catid...}// key is registered.CATEGORYINFO catinfo;catinfo.catid = catid;catinfo.lcid = 0x0409 ; // english// Make sure the provided description is not too long.// Only copy the first 127 characters if it is.int len = wcslen(catDescription);if (len>127)len = 127;wcsncpy(catinfo.szDescription, catDescription, len);// Make sure the description is null terminated.catinfo.szDescription[len] = '\0';hr = pcr->RegisterCategories(1, &catinfo);pcr->Release();return hr;
}// 注册组件种类
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{// Register your component categories information.ICatRegister* pcr = NULL ;HRESULT hr = S_OK ;hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);if (SUCCEEDED(hr)){// Register this category as being "implemented" by the class.CATID rgcatid[1] ;rgcatid[0] = catid;hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);}if (pcr != NULL)pcr->Release();return hr;
}
// 卸载组件种类
HRESULT UnRegisterCLSIDInCategory(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)){// Unregister this category as being "implemented" by the class.CATID rgcatid[1] ;rgcatid[0] = catid;hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);}if (pcr != NULL)pcr->Release();return hr;
}/
// DllRegisterServer - Adds entries to the system registrySTDAPI DllRegisterServer(void)
{HRESULT hr;AFX_MANAGE_STATE(_afxModuleAddrThis);if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))return ResultFromScode(SELFREG_E_TYPELIB);if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))return ResultFromScode(SELFREG_E_CLASS);// 标记控件初始化安全.// 创建初始化安全组件种类hr = CreateComponentCategory(CATID_SafeForInitializing,L"Controls safely initializable from persistent data!");if (FAILED(hr))return hr;// 注册初始化安全hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);if (FAILED(hr))return hr;// 标记控件脚本安全// 创建脚本安全组件种类 hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");if (FAILED(hr))return hr;// 注册脚本安全组件种类hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);if (FAILED(hr))return hr;return NOERROR;
}/
// DllUnregisterServer - Removes entries from the system registrySTDAPI DllUnregisterServer(void)
{HRESULT hr;AFX_MANAGE_STATE(_afxModuleAddrThis);// 删除控件初始化安全入口.hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);if (FAILED(hr))return hr;// 删除控件脚本安全入口hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);if (FAILED(hr))return hr;if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))return ResultFromScode(SELFREG_E_TYPELIB);if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))return ResultFromScode(SELFREG_E_CLASS);return NOERROR;
}//
这篇关于ocx 有安全提示的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!