The registration of the OCX control is uninstalled, and the registration is judged

Source: Internet
Author: User

method One:Run under DOS or Windows command line: regsvr32 ocxname.ocx Register

Example:
regsvr32 netshare.ocx//Register Netshare.ocx controls
regsvr32/u netshare.ocx//de-Registration of Netshare.ocx controls

If the Netshare.ocx file is not in the system directory, you must also include the full path in front of the file name. In addition to the Regsvr32 application, Microsoft also provides a program called RegClean.exe on its web site that can examine the registry and remove entries from the missing components in the registry. RegClean.exe in addition to removing the "hanging" entry, it also provides an "undo" file to help restore the deletion of the error.

Registering ActiveX controls with Regsvr32.exe is simple, but requires manual registration by the user, and manual de-registration when not in use.

Method Two:With the install shield, in the inside select "Self-registered", the installation program will be automatically registered;


Method Three:API function Registration
This approach is designed by loading the ActiveX control into memory, verifying its validity, and finally executing its registration function (DllRegisterServer, DllUnregisterServer) directly in the memory address.
The programming method is:

1. Use Windows API function LoadLibrary to load ActiveX controls;
2. Use the GetProcAddress function to get the registration function DllRegisterServer (logoff function is DllUnregisterServer) pointer in the ActiveX control;
3. Use the CallWindowProc function to execute an ActiveX control registration function (DllRegisterServer, DllUnregisterServer) loaded into memory.

Example:

typedef int (callback* myfunction) (void);
MyFunction myfunction = null;
HINSTANCE handle = NULL;
Handle = LoadLibrary ("Trdragdroptreectrl.ocx");

if (handle! = NULL)
{
MyFunction = GetProcAddress (handle, "DllRegisterServer");
if (myfunction! = null)
{
MyFunction ();
}
}

method Four: code call regsvr32.exe

VB notation

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 a reg file into the registry

:: ShellExecute (Null,null, "Regedit.exe", "/s d:\\ new Folder \\TEST\\TEST\\Release\\TEST.reg", Null,null);

Note: the/s header does not pop up a message box.


Small experience:
1, sometimes in the program to use the OCX control failure, check whether the call between the execution of AfxOleInit (). If a container is used, you also need to ensure that AfxEnableControlContainer () is executed.
2. Using the ActiveX Control Test Container can easily test the produced OCX (from the Start menu-"program-" Microsoft Visual Studio 6.0, Microsoft Visual Studi o 6.0 tools to see the tool)
3, sometimes control production is not a problem, the registration method is correct, but the registration of the time did not fail, possibly the version of the DLL is incorrect, use dependencies to see if the OCX control depends on the DLL version of the DLL is the same as now used.

regsvr32.exe command Description and parameters

"regsvr32 [/s] [/n] [/I (: cmdline)] dllname". Where Dllname is the name of the ActiveX control, it is recommended that you copy it to the System folder before installation.

The parameters have the following meanings:

/u--Anti-registration controls

/s--does not display the prompt box regardless of the registration success or not

/c--Console output

/i--the option to skip the control to install (unlike registration)

/n--do not register controls, this option must be used with the/I option

How to execute the command:

1, can be "start"-"Run", call up the running dialog box, you can also use the Win+r hotkey, and then directly in the input field to enter

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

Method Three examples:

Registering controls

BOOL Cyourclass::registocx ()

{

HINSTANCE Hlib = LoadLibrary ("Ntgraph.ocx"); Specifies the path and file name of the OCX file to be registered.

if (hlib = = NULL)
{
MessageBox ("Cannot load OCX file!");
Return
}

Get Registration function DllRegisterServer address
Farproc Lpdllentrypoint;
Lpdllentrypoint = GetProcAddress (hlib, "DllRegisterServer");

Call the registration function DllRegisterServer
if (lpdllentrypoint!=null)
{
if (FAILED ((*lpdllentrypoint) ()))
{
MessageBox (Handle, "Call DllRegisterServer failed!", "failure ing:", MB_OK);
MessageBox ("OCX registration failed!");
FreeLibrary (hlib);
Return
};
MessageBox (Handle, "registered successfully!", "Reg", MB_OK);
MessageBox ("OCX registered successfully!");
}
Else
MessageBox ("OCX registration failed!");
MessageBox (Handle, "Call DllRegisterServer failed!", "failure ing:", MB_OK);

}

Uninstalling controls

BOOL Cyourclass::unregistocx ()

{

HINSTANCE Hlib = LoadLibrary ("Ntgraph.ocx"); Specifies the path and file name of the OCX file to unload.
if (hlib==null)
{
MessageBox (Handle, "Cannot load DLL file!", "failed ing ...", MB_OK);
MessageBox ("Cannot load OCX file!");
Return
}

Get Registration function DllRegisterServer address
Farproc Lpdllentrypoint;
Lpdllentrypoint = GetProcAddress (hlib, "DllUnregisterServer");//Note this is DllUnregisterServer.

Call the registration function DllRegisterServer
if (lpdllentrypoint!=null)
{
if (((*lpdllentrypoint) ()))
{
MessageBox (Handle, "Call DllUnregisterServer failed! "," failure ing: ", MB_OK);
MessageBox ("Call DllUnregisterServer failed!!!");
FreeLibrary (hlib);
Return
};
MessageBox (Handle, "Logoff succeeded! "," Unreg ", MB_OK);
MessageBox ("OCX logoff succeeded!") ");
}
Else
MessageBox (Handle, "Call DllUnregisterServer failed!!!", "result", MB_OK);
MessageBox ("OCX call DllUnregisterServer failed!!!");

}

determine whether to register

BOOL Cyourclass::isregistocx ()

{
HKEY HKEY;
BOOL bpresent;
TCHAR Szpath[_max_path];
DWORD Dwregtype;
DWORD cbdata = sizeof szpath * sizeof TCHAR;

if (RegOpenKeyEx (HKEY_CLASSES_ROOT, "Activex.activexcontrol\\clsid", 0,key_read,&hkey)!=ERROR_SUCCESS)
return false;
Else
return true;
Activex.activexcontrol is the name and internal name of the control, such as "Ntgraph." Ntgraphctrl.1\\clsid "

}

If the VC program recommends the use of a third, directly loading the control exposes the registration and unloading functions, efficient

The registration of the OCX control is uninstalled, and the registration is judged

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.