Problems raised by referencing third-party OCX controls in C # and workarounds

Source: Internet
Author: User

To invoke the OCX control:
1, register the OCX control in the System, command: Regsvr32.exe control location (plus/u parameter is unregistered)
2. Add the control to the. NET Toolbox and drag it to the form.

Without the toolbox, you manually add, you need to pay attention to a problem, is to use Aximp.exe to wrap the OCX control class, and then reference the generated DLL in the program can be.
aximp [Options]{file.dll | file.ocx}
The following command generates MediaPlayer.dll and AxMediaPlayer.dll for the Media Player control msdxm.ocx.
AxImp C:/systemroot/system32/msdxm.ocx

The ActiveX Control importer converts the type definition in the COM type library of an ActiveX control to a Windows forms control.
Windows Forms can host only Windows Forms controls, that is, classes that derive from control. Aximp.exe generates a wrapper class that can be hosted on an ActiveX control on a Windows form. This enables you to use the same design-time support and programming methodology that you can apply to other Windows forms controls. To host an ActiveX control, you must generate a wrapper control that derives from AxHost. This wrapper control contains an instance of the underlying ActiveX control. It knows how to communicate with an ActiveX control, but it is displayed as a Windows forms control. This generated control hosts the ActiveX control and exposes its properties, methods, and events as properties, methods, and events for the generated control.

If you do not wrap it directly, a catastrophic error will occur. The reason is explained above.

In the project, reference the generated DLL at the beginning of Microsoft Dynamics AX, and add in the form code:
Declare a public control object:
Public Axispicreclib.axispicrec Axispicrec;
Initialize the control within the InitializeComponent () method:
Axispicrec = new Axispicreclib.axispicrec ();//Must be a new object, otherwise the form designer has problems
((System.ComponentModel.ISupportInitialize) (this.) AXISPICREC)). BeginInit ();//Initialize Start
This. Controls.Add (this. AXISPICREC);//Add controls
((System.ComponentModel.ISupportInitialize) (this.) AXISPICREC)). EndInit ();

If you do not do this, an exception that throws a type of "System.windows.forms.axhost+invalidactivexstateexception" appears.

This. Axispicrec.ocxstate = ((System.Windows.Forms.AxHost.State) (resources. GetObject ("Axispicrec.ocxstate")));//Design control state

If you encounter the error "attempting to execute managed code within the OS loader lock," set debug--"Exception"
"----" Managed Debugging Assistants "to tick off the" LoaderLock "on it.

Problems raised by referencing third-party OCX controls in C # and workarounds

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.