Background: ActiveX controls need to be used in recent projects. The projects are developed on the. NET platform. Therefore, the reference to ActiveX control is directly added to the project, and the reference is successfully added. There is no problem with instantiating a class instance in the code, but an "unprocessed comexception" exception is always thrown when calling its method or attribute.
Method 1:
1. register the OCX control in the system, and run the following command: regsvr32.exe control location (adding/U parameters indicates canceling registration );
2. Add the control to the. NET toolbox and drag it to form.
Method 2:
1、use aximp.exe to wrap the OCX control class;
2. reference the generated DLL in the program.
Differences:
1. method 1 does not require manual packaging of OCX controls. method 2 does;
2. method 1 adds the control to the toolbox first. method 2 does not.
**************************************** ********************************
About aximp.exe packaging ock control in msdn related text, link: http://msdn.microsoft.com/zh-cn/library/8ccdh774 (vs.80). aspx
Link content:
Windows form ActiveX control import program (aximp.exe)
The ActiveX control import program converts the type definition in the com Type Library of the ActiveX control to a Windows form control. Windows Forms can only hold Windows Forms controls, that is, classes derived from control. Aximp.exe generates a packaging class for ActiveX controls that can be carried on Windows Forms. This allows you to use the same design-time support and programming methodology that can be applied to other Windows Forms controls. To host ActiveX controls, you must generate a packaging control derived from axhost. This wrapper control contains an instance of the Basic ActiveX control. It knows how to communicate with ActiveX controls, but it is displayed as a Windows form control. The generated control carries the ActiveX control and exposes its properties, methods, and events as the properties, methods, and events of the generated control. Aximp [Options] {file. dll | file. ocx}
RemarksParameter: description file: contains the source file name of the ActiveX control to be converted. File parameters must contain the. dll or OCX extension. Option: Description/delaysign: Specifies aximp.exe to sign the result control with a delayed signature operation. This option must be specified with/keycontainer:,/Keyfile:, or/publickey. For more information about the delayed signature process, see delay for assembly signature. /Help:
Displays the command syntax and options of the tool. /Keycontainer: containername:
Use the public key/private key pair found in the key container specified by containername to sign the result control with a strong name.
/Keyfile: Filename:
Use the official public key/private key pair of the issuer found in filename to sign the result control with a strong name.
/Nologo:
Undisplay Microsoft startup title.
/Out: Filename:
Specifies the name of the assembly to be created.
/Publickey: Filename:
Use the Public Key found in the file specified by filename to sign the result control with a strong name.
/Silent:
The message indicating successful cancellation is displayed.
/Source:
Generate C # source code for Windows form packaging.
/Verbose:
Specify the verbose mode. The additional progress information is displayed.
/? :
Displays the command syntax and options of the tool. Aximp.exe converts the entire ActiveX Control Type Library at a time and generates a group of assemblies that contain the metadata and control implementation of the Common Language Runtime Library of the type defined in the original type library. The generated file is named according to the following pattern: Com-type Common Language Runtime Library Proxy: Windows form proxy of progid. dllactivex control (where ax indicates ActiveX): axprogid. dll note
If the member name of the ActiveX control matches the name defined in. NET Framework, aximp.exe adds the prefix "CTL" before the member name when creating the axhost derived class ". For example, assume that the ActiveX control has a member named "layout". Since the layout event is defined in. NET Framework, the Member is renamed as "ctllayout" in the axhost derived class ". You can use tools such as msil disassembly program (ildasm.exe) to check these generated files. Note that running aximp.exe on the ActiveX control shdocvw. dll will always create another file named shdocvw. dll in the directory where the tool is running. If you place the generated file in the "Documents and Settings" directory, Microsoft Internet Explorer and Windows resource manager may experience problems. When you restart your computer, windows first checks the "Documents and Settings" directory before viewing the System32 directory to find a copy of shdocvw. dll. It uses copies found in the "Documents and Settings" directory and tries to load hosted packages. Because Internet Explorer and Windows resource manager depend on the rendering engine in the shdocvw. dll version in the System32 directory, they will not work properly. If this problem occurs, delete the copy of shdocvw. dll in the "Documents and Settings" directory and restart the computer.
Example
The following command generates mediaplayer. dll and axmediaplayer. DLL for the Media Player control msdxm. ocx. Aximp C:/SYSTEMROOT/system32/msdxm. ocx
**************************************** ********************************