Register OCX and ActiveX with VC ++

Source: Internet
Author: User

Register ocxname. ocx


Example:

Regsvr32 netshare. ocx // register the netshare. ocx control.

Regsvr32/u netshare. ocx // unregister the netshare. ocx control


If the netshare. ocx file is not in the system directory, you must add the complete path before the file name. In addition to the regsvr32 application, Microsoft also published a program called regclean.exe on its web site. It can check the registry and remove the entries of the lost components in the registry. In addition to deleting "hanging" entries, regclean.exe also provides an "undo" file to help you restore the deletion of errors.


Registering ActiveX controls with regsvr32.exe is simple, but you need to manually register them. You need to manually unregister them when not using regsvr32.exe.

Method 2: Use Install Shield and select "self-registered" in it. The installer will automatically register;


Method 3: register an API Function

The design idea of this method is: first load the ActiveX control into the memory, then verify its validity, and then directly execute its registration function (dllregisterserver, dllunregisterserver) in the memory address ).

The programming method is as follows:


1. Use the Windows API function loadlibrary to load ActiveX controls;

2. Use the getprocaddress function to obtain the dllregisterserver (the deregistering function is dllunregisterserver) pointer in the ActiveX control;

3. Use the callwindowproc function to execute ActiveX Control registration functions (dllregisterserver and dllunregisterserver) that have been loaded into the memory ).


Example:


Typedef int (callback * myfunction) (void );

Myfunction = NULL;

Hinstance handle = NULL;

Handle = loadlibrary ("trdragdroptreectrl. ocx ");


If (handle! = NULL)

{

Myfunction = getprocaddress (handle, "dllregisterserver ");

If (myfunction! = NULL)

{

Myfunction ();

}

}

Method 4:Code to call regsvr32.exe

// Write in VB

Shell "regsvr32.exe control. ocx/S"

// VC Writing Method

: ShellExecute (null, null, "regsvr32.exe", "/s d: \ create Folder \ test \ release \ test. reg ", null, null );

// Add the reg file to enter the Registry

: ShellExecute (null, null, "regedit.exe", "/s d :\\ create Folder \ test \ release \ test. reg ", null, null );

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


Little Experience:

1. Sometimes the OCX control is invalid in the program. Check whether afxoleinit () is executed between calls (). If a container is used, make sure that afxenablecontrolcontainer () is executed ()

2. Use ActiveX control test container to conveniently test the created OCX control (from the Start Menu-Program-> Microsoft Visual Studio 6.0-> Microsoft Visual Studio 6.0 tools, you can see this tool)

3. Sometimes there is no problem with the control production, and the registration method is correct, but the registration fails, and The dll version may be incorrect, use dependencies to check whether the OCX control depends on the dll version.

Regsvr32.exe command instructions and Parameters

"Regsvr32 [/S] [/n] [/I (: using line)] dllname ". The dllname is the ActiveX control file name. We recommend that you copy it to the system folder before installation.

Parameters have the following meanings:

/U -- anti-Register Control

/S -- no matter whether the registration is successful or not, the prompt box is not displayed

/C -- console output

/I -- skip the control option for installation (different from registration)

/N -- do not register the control. This option must be used with the/I option.

Method for executing this command:

1. You can call up the running dialog box in "start"-"run", or use the win + R hotkey, and then enter it directly in the input column.

2. Run CMD at start to bring up the 'COMMAND prompt 'window, and then run the regsvr32 command.

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.