文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>如何让ActiveX控件在IE中成为安全的控件

如何让ActiveX控件在IE中成为安全的控件

时间:2010-11-15  来源:wjh2005

 

1. 定义常量_ctlid.  ID的值跟xxxCtrl.cpp文件中的IMPLEMENT_OLECREATE_EX一致.

 

const GUID CDECL BASED_CODE _ctlid =
{
0x8d82db93, 0xf821, 0x4d85, {0x99, 0xcf, 0xe1, 0x84, 0xa5, 0x9e, 0xfd, 0xc6} };

 
2. 增加函数CreateComponentCategory, RegisterCLSIDInCategory和UnRegisterCLSIDInCategory.

代码
 1 // Helper function to create a component category and associated
2 // description
3 HRESULT CreateComponentCategory(CATID catid, WCHAR *catDescription)
4 {
5 ICatRegister *pcr = NULL ;
6 HRESULT hr = S_OK ;
7
8 hr = CoCreateInstance( CLSID_StdComponentCategoriesMgr,
9 NULL,
10 CLSCTX_INPROC_SERVER,
11 IID_ICatRegister,
12 (void**)&pcr );
13
14 if (FAILED(hr))
15 {
16 return hr;
17 }
18
19 // Make sure the HKCR\Component Categories\{..catid...}
20 // key is registered
21 CATEGORYINFO catinfo;
22 catinfo.catid = catid;
23 catinfo.lcid = 0x0409 ; // english
24
25 // Make sure the provided description is not too long.
26 // Only copy the first 127 characters if it is
27 int len = wcslen(catDescription);
28 if (len>127)
29 {
30 len = 127;
31 }
32
33 wcsncpy(catinfo.szDescription, catDescription, len);
34 // Make sure the description is null terminated
35 catinfo.szDescription[len ] = '\0';
36
37 hr = pcr->RegisterCategories(1, &catinfo);
38 pcr->Release();
39
40 return hr;
41 }
42
43
44 // Helper function to register a CLSID as belonging to a component
45 // category
46 HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
47 {
48 // Register your component categories information.
49 ICatRegister *pcr = NULL ;
50 HRESULT hr = S_OK ;
51
52 hr = CoCreateInstance( CLSID_StdComponentCategoriesMgr,
53 NULL,
54 CLSCTX_INPROC_SERVER,
55 IID_ICatRegister,
56 (void**)&pcr );
57
58 if (SUCCEEDED(hr))
59 {
60 // Register this category as being "implemented" by
61 // the class.
62 CATID rgcatid[1] ;
63 rgcatid[0] = catid;
64 hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
65 }
66
67 if (pcr != NULL)
68 pcr->Release();
69
70 return hr;
71 }
72
73 // HRESULT UnRegisterCLSIDInCategory
74
75 HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
76 {
77 ICatRegister *pcr = NULL ;
78 HRESULT hr = S_OK ;
79
80 hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
81 NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
82 if (SUCCEEDED(hr))
83 {
84 CATID rgcatid[1] ;
85 rgcatid[0] = catid;
86 hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
87 }
88
89 if (pcr != NULL)
90 pcr->Release();
91
92 return hr;
93 }

  

3. 修改DllRegisterServer和DllUnregisterServer.

代码
 1 /////////////////////////////////////////////////////////////////////////////
2 // DllRegisterServer - Adds entries to the system registry
3 STDAPI DllRegisterServer(void)
4 {
5 AFX_MANAGE_STATE(_afxModuleAddrThis);
6
7 if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
8 return ResultFromScode(SELFREG_E_TYPELIB);
9
10 if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
11 return ResultFromScode(SELFREG_E_CLASS);
12
13 HRESULT hr = S_OK; // HResult used by Safety Functions
14
15 if (FAILED( CreateComponentCategory(
16 CATID_SafeForScripting,
17 L"Controls that are safely scriptable") ))
18 {
19 return ResultFromScode(SELFREG_E_CLASS);
20 }
21
22 if (FAILED( CreateComponentCategory(
23 CATID_SafeForInitializing,
24 L"Controls safely initializable from persistent data") ))
25 {
26 return ResultFromScode(SELFREG_E_CLASS);
27 }
28
29 if (FAILED( RegisterCLSIDInCategory(
30 _ctlid, CATID_SafeForScripting) ))
31 {
32 return ResultFromScode(SELFREG_E_CLASS);
33 }
34
35 if (FAILED( RegisterCLSIDInCategory(
36 _ctlid, CATID_SafeForInitializing) ))
37 {
38 return ResultFromScode(SELFREG_E_CLASS);
39 }
40
41 return NOERROR;
42 }
43
44
45 /////////////////////////////////////////////////////////////////////////////
46 // DllUnregisterServer - Removes entries from the system registry
47 STDAPI DllUnregisterServer(void)
48 {
49 AFX_MANAGE_STATE(_afxModuleAddrThis);
50
51 HRESULT hr = UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
52 if (SUCCEEDED(hr))
53 {
54 hr = UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
55 }
56
57
58 if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
59 return ResultFromScode(SELFREG_E_TYPELIB);
60
61 if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
62 return ResultFromScode(SELFREG_E_CLASS);
63
64 return hr;
65 }

 

相关阅读 更多 +
排行榜 更多 +
梦幻甜心蛋糕店手游 v1.0 安卓版

梦幻甜心蛋糕店手游 v1.0 安卓版

休闲益智 下载
狙击手血战鬼子 v8081.23.10.7 安卓版

狙击手血战鬼子 v8081.23.10.7 安卓版

休闲益智 下载
狙击手血战鬼子 v8081.23.10.7 安卓版

狙击手血战鬼子 v8081.23.10.7 安卓版

休闲益智 下载