技术开发 频道

步步学ACTIVEX网页控件开发:创建安全的ActiveX控件

  2.修改DllRegisterServer函数: 

STDAPI DllRegisterServer(void)
{
    HRESULT hr;    
// HResult used by Safety Functions
    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;
}

  3.修改 DllUnregisterServer函数: 

STDAPI DllUnregisterServer(void)
{
    HRESULT hr;    
// HResult used by Safety Functions
    AFX_MANAGE_STATE(_afxModuleAddrThis);
    
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
      
return ResultFromScode(SELFREG_E_TYPELIB);
    
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
      
return ResultFromScode(SELFREG_E_CLASS);
    hr
=UnRegisterCLSIDInCategory(CLSID_SafeItem,                      CATID_SafeForInitializing);
    
if (FAILED(hr))
      
return hr;
    hr
=UnRegisterCLSIDInCategory(CLSID_SafeItem,
                        CATID_SafeForScripting);
    
if (FAILED(hr))
      
return hr;
    
return NOERROR;
}
0
相关文章