Control Safety Registration Method 3 Select

xiaoxiao2021-03-06  14

#include

#include

#include

...

/

// DLLREGISTERSERVER - Adds Entries to the system registry

/ * Original code (annotated)

StDAPI DLLREGISTERSERVER (VOID)

{

// Registers Object, Typelib and All Interfaces in Typelib

Return_Module.RegisterServer (TRUE);

}

/

// DllunregisterServer - Removes Entries from the system registry

StDAPI DllunregisterServer (Void)

{

Return_Module.unregisterServer (TRUE);

}

* /

// Uses: Registration Components Classification

// Description: Component security type is to set the security of components through the registration of component classification

HRESULT CREATECMOMPONENTCATEGORY (CATID CACID, WCHAR * CATDESCRIPTION) {

// Initialize ICATREGISTER object instance pointer

IcatRegister * pcr = null;

HRESULT HR = S_OK;

// Get an instance of IcatRegister objects

// Description: This interface originally registered component classification

HR = CocreateInstance (CLSID_STDComponentcategoriesmgr,

NULL, CLSCTX_INPROC_SERVER, IID_ICATREGISTER, (VOID **) & PCR);

IF (Failed (HR))

Return HR;

// Initialization classification information

// Description: Make sure to register HKCR / Component Categories / {.. catid ...}

CategoryInfo Catinfo;

Catinfo.catid = CATID;

Catinfo.lcid = 0x0409; // 中文 h

// Description: Ensure that the description provided will not be long, only 127 characters before copying

INT LEN = WCSLEN (CATDESCRIPTION);

IF (len> 127)

Len = 127;

WCSNCPY (Catinfo.szdescription, CATDESCRIPTION, LEN);

/ / Ensure that the description uses "/ 0" to end

Catinfo.szdescription [len] = '/ 0';

HR = PCR-> Registercategories (1, & Catinfo);

PCR-> Release ();

Return HR;

}

// Uses: Registration of interface classes in the existing component classification

HRESULT RegisterClsidIncategory (refclsid CLSID, CACID Catid) {

IcatRegister * pcr = null;

HRESULT HR = S_OK;

// Get CCM's IcatRegister interface

HR = CocreateInstance (CLSID_STDComponentcategoriesmgr,

NULL, CLSCTX_INPROC_SERVER, IID_ICATREGISTER, (VOID **) & PCR);

En (ac))

{

/ / Register the interface class in the component classification

Catid Rgcatid [1];

Rgcatid [0] = CACID;

HR = PCR-> RegisterClassImplcategories (CLSID, 1, RGCATID);

IF (PCR! ​​= NULL)

PCR-> Release ();

Return HR;

}

// Uses: Anti-registration existing interface class in component classification

HRESULT UnregisterClsidIncategory (refclsid clsid, catid catid) {

IcatRegister * pcr = null;

HRESULT HR = S_OK;

// Get CCM's IcatRegister interface

HR = CocreateInstance (CLSID_STDComponentcategoriesmgr,

NULL, CLSCTX_INPROC_SERVER, IID_ICATREGISTER, (VOID **) & PCR);

En (ac))

{

/ / Log out of the interface class in the existing component classification

Catid Rgcatid [1];

Rgcatid [0] = CACID;

HR = PCR-> UnregisterClassImplcategories (CLSID, 1, RGCATID);

}

IF (PCR! ​​= NULL)

PCR-> Release ();

Return HR;

}

// Register the server

Stdapi DllRegisterServer (void) {

HRESULT HR; // Return for Safety functions

AFX_MANAGE_STATE (_AFXModuleAdDRTHIS);

/ * The original code

IF (! AfxoleRegisterTypelib (AfxgetInstanceHandle (), _tlid))

Return Resultfromscode (Selfreg_e_typelib);

IF (! ColeObjectFactoryex :: UpdateRegistryll (True))

Return Resultfromscode (Selfreg_e_class);

* /

IF ("_Module.RegisterServer (TRUE)) {

AFXMessageBox ("Registration Type Library Failed");

}

// Create an initialization security component classification

HR = CreateComponentcategory (Catid_safeForInitializing,

L "Controls Safely Initializable from Persistent Data!");

IF (Failed (HR))

Return HR;

// Registration interface class in the above packet

HR = registerclsidincategory (CLSID_PSSUB, CACID_SAFEFORINIALIZING);

IF (Failed (HR))

Return HR;

// Create a script programming security component classification

HR = CREATECMOMPONENTCATEGORY (CACID_SAFEFORScripting,

L "Controls Safely Scriptable!");

IF (Failed (HR))

Return HR;

// Registration interface class in the above packet

HR = registerclsidincategory (CLSID_PSSUB, CATID_SAFEFORScripting);

IF (Failed (HR))

Return HR;

Return noerror;

}

// Uses: Anti-registration server

Stdapi DllunregisterServer (void) {

HRESULT HR; // HRESULT Used by Safety functions

AFX_MANAGE_STATE (_AFXModuleAdDRTHIS); / * The original code

IF (! AfxoleunregisterTypelib (_tlid))

Return Resultfromscode (Selfreg_e_typelib);

IF (! ColeObjectFactoryex :: UpdateRegistryLL (False))

Return Resultfromscode (Selfreg_e_class);

* /

IF ("_Module.RegisterServer (TRUE)) {

AFXMessageBox ("Anti-Registration Type Bank Failed");

}

// Delete the registry entry

HR = UnregisterClsidIndincategory (CLSID_PSSUB, CACID_SAFEFORINIALIZING);

IF (Failed (HR))

Return HR;

HR = UnregisterClsidIncategory (CLSID_PSSUB, CACID_SAFEFORSCRIPTIN);

IF (Failed (HR))

Return HR;

Return noerror;

}

or

Class ....

Public IOBJECTSAFETYIMPL ,

...

...

Begin_COM_MAP (CAGENT)

...

COM_Interface_entry (IOBJECTSAFETY)

...

END_COM_MAP ()

or

//2001.12.07 - Safety registration support

const catid catid_safeforscripting =

{0x7DD95801, 0x9882, 0x11cf, {0x9F, 0xA9, 0x00, 0XAA, 0x00, 0X6C, 0X42, 0XC4}}

Const catid car_safeforinitializing =

{0x7DD95802, 0x9882, 0x11cf, {0x9F, 0xA9, 0x00, 0XAA, 0x00, 0X6C, 0X42, 0XC4}};

....

//2001.12.07 - Safety registration support

Begin_category_map (CSUBAgent)

Implement_category (catid_safeforinitializing)

Implement_category (catid_safeforscripting)

END_CATEGORY_MAP ()

Pick yourself.

转载请注明原文地址:https://www.9cbs.com/read-48801.html

New Post(0)