Sign unloading OCX controls, as well as to determine whether or not registered

Method one: running under Windows or dos command line: regsvr32 ocxname.ocx Registration

Example:
regsvr32 netshare.ocx // registered netshare.ocx control
regsvr32 / u netshare.ocx // deregister netshare.ocx control

if netshare.ocx file when not in the system directory, the full path must be added before the file name. In addition regsvr32 applications, Microsoft on its web site also provides a program called regclean.exe, you can check the registry entry and remove the missing component in the registry. regclean.exe addition to remove the "suspension" of the entry, it provides a "undo" file to help recover erroneous deletion.

Although simple, but you need to manually register with regsvr32.exe registered activeX control, when not need to manually lift the registration.

Method two: with install shield, which is selected from the "self-registered", the installer will automatically register;


Method three: API function registered
design idea of this method is: first activeX control into memory, and then determine the validity of the final perform its functions directly registered in memory address (DllRegisterServer, DllUnregisterServer).
Its programming method:

1, using the Windows api function Loadlibrary load activeX control;
2, using GetProcAddress function to get a function DllRegisterServer in activeX control register (DllUnregisterServer in cancellation function) pointer;
3, performing the function using CallwindowProc loaded memory activeX control function register (DllRegisterServer, DllUnregisterServer).

Example:

typedef int (* myFunction the callback) (void);
myFunction myFunction = null;
hInstance handle = null;
handle = the LoadLibrary ( "trdragdroptreectrl.ocx");

IF (handle = null!)
{
MyFunction = the GetProcAddress (handle, "DllRegisterServer in ");
IF (myFunction = null)!
{
myFunction ();
}
}

Method four: code calls regsvr32.exe

// vb wording

shell "regsvr32.exe control. OCX  / S"

// vc wording

:: ShellExecute (NULL, NULL, "regsvr32.exe", "/ s D: \\ new folder \\ TEST \\ TEST \\ Release \\ TEST.reg", NULL, NULL);

// Add the REG file into the registry

:: ShellExecute (NULL, NULL, "regedit.exe", "/ s D: \\ new folder \\ TEST \\ TEST \\ Release \\ TEST.reg", NULL, NULL);

Notes: / s title does not pop up a message box.


 

Little experience:
1, sometimes using ocx control program fails, check whether the calls between afxoleinit (). If a container, you also need to ensure that the implementation of the AfxEnableControlContainer ()
2, using Activex Control Test Container can easily test produced the ocx control (from the Start menu - "Programs -" Microsoft Visual Studio 6.0 -> Microsoft Visual Studio 6.0 Tools you can see this tool)
3, sometimes making no control problems, the way also registered, but the registration time indeed fail, if possible wrong dll version, use the View Dependencies dependent dll ocx control whether to use with the current version of the dll consistent.

regsvr32.exe command and parameter description

"Regsvr32 [/ s] [/ n] [/ i (: cmdline)] dllname". Which is dllname activex control file name, it is recommended to copy the system folder before installing.

Parameters have the following meanings:

/ U-- anti-registration control

/ S-- regardless of the success of registration, shall not display the prompt box

/ C-- console output

/ I-- option to skip the control installation (with different registration)

/ N-- not register controls, this option must be used with the / i option

The method of executing the command:

1, in the "Start" - "Run" to bring up the dialog box operation, may be used Win + R hotkey, and direct input to the input field

2, the start - run type cmd, and bring up the 'Command Prompt "window, and then execute the command regsvr32.

 

Method three examples:

Register Control

BOOL CYourClass::RegistOcx()

{

    HINSTANCE hLib = LoadLibrary ( "NTGraph.ocx" ); // Specify the registered ocx file path and file name.
 
    IF (hLib == NULL)
    {
         the MessageBox ( "Could not load OCX files!");
         return;
    }

    // Get the address registration function DllRegisterServer
    FARPROC lpDllEntryPoint;
    lpDllEntryPoint = GetProcAddress (hLib, "DllRegisterServer");

    // Call registration function DllRegisterServer
    IF (! LpDllEntryPoint = NULL)
    {
        IF (FAILED ((* lpDllEntryPoint) ()))
        {
            // MessageBox (the Handle, "calling DllRegisterServer failed!", "Failed ing ..", MB_OK);
            MessageBox ( "OCX registration failed!");
            FreeLibrary (hLib);
            return;
        };
        // MessageBox (the Handle, "! registered successfully", "Reg", MB_OK);
        MessageBox ( "OCX successfully registered!");
    }
    the else
        MessageBox ( "OCX registration failed!");
        // MessageBox (the Handle, "calling DllRegisterServer failed!", "failed ing ..", MB_OK);

}

Uninstall Control

BOOL CYourClass::UnRegistOcx()

{

    HINSTANCE hLib = LoadLibrary ( "NTGraph.ocx" ); // Specify the path you want to uninstall ocx file and the file name.
    IF (hLib == NULL)
    {
        // the MessageBox (the Handle, "can not load Dll files!", "failure .. ING" MB_OK);
        the MessageBox ( "Could not load OCX files!");
        return;
    }

    // Get the address registration function DllRegisterServer
    FARPROC lpDllEntryPoint;
    lpDllEntryPoint = GetProcAddress (hLib, "DllUnregisterServer"); // Note that this is DllUnregisterServer.

    // Call registration function DllRegisterServer in
    IF (lpDllEntryPoint = NULL!)
    {
        IF (((* lpDllEntryPoint) ()))
        {
            // MessageBox (the Handle, "call DllUnRegisterServer failed!", "Failure .. ING", MB_OK);
            MessageBox ( "call DllUnRegisterServer failed !!!");
            FreeLibrary (hLib);
            return;
        };
        // MessageBox (the Handle, "logout success!", "Unreg.", MB_OK);
        MessageBox ( "OCX cancellation of success!");
    }
    the else
    // MessageBox (the Handle, "call DllUnRegisterServer failed !!!", "result", MB_OK);
        MessageBox ( "OCX call DllUnRegisterServer failure !!!");

}

Determine whether to register  

BOOL CYourClass::IsRegistOcx()

{
    HKEY hKey;     
    BOOL bPresent;     
    TCHAR szPath[_MAX_PATH];     
    DWORD dwRegType;     
    DWORD cbData   =   sizeof   szPath   *   sizeof   TCHAR;    

   (! RegOpenKeyEx (the HKEY_CLASSES_ROOT, "the Clsid ActiveX.ActiveXControl \\", 0, KEY_READ, & hKey) = ERROR_SUCCESS) IF
        return to false;
    the else
        return to true;
  //ActiveX.ActiveXControl name and the internal name of the control as "NTGRAPH.NTGraphCtrl. 1 \\ CLSID "

}

 

Guess you like

Origin www.cnblogs.com/aaronguo/p/11858019.html