EDN Admin
Well-known member
I need to add an activeX control to a C# form. To do this, I added the control to the toolbox and after that I added the control to the form. It seems that the application was running fine, but after this, when I tried to open the project again and show
the form designer, Visual Studio (VS2010) was closed due an error.
After this I tried other way to add the component. Using the aximp aplication I generated the needed .dlls to load manually the control. Then, in the constructor of the form, I add this code (after InitializeComponent invokation) to load the control:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; this.SuspendLayout();
System.ComponentModel.ComponentResourceManager resources = <span style="color:Blue; new System.ComponentModel.ComponentResourceManager(<span style="color:Blue; typeof(FrmScada));
axIDEMainForm1 = <span style="color:Blue; new AxIDEScadaActiveX.AxIDEMainFrm();
((System.ComponentModel.ISupportInitialize)(<span style="color:Blue; this.axIDEMainForm1)).BeginInit();
<span style="color:Blue; this.axIDEMainForm1.Dock = System.Windows.Forms.DockStyle.Fill;
<span style="color:Blue; this.axIDEMainForm1.Location = <span style="color:Blue; new System.Drawing.Point(0, 0);
<span style="color:Blue; this.axIDEMainForm1.Name = <span style="color:#A31515; "axIDEMainForm1";
<span style="color:Blue; this.axIDEMainForm1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject(<span style="color:#A31515; "axIDEMainForm1.OcxState")));
<span style="color:Blue; this.axIDEMainForm1.Size = <span style="color:Blue; new System.Drawing.Size(615, 572);
<span style="color:Blue; this.axIDEMainForm1.TabIndex = 0;
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.axIDEMainForm1);
((System.ComponentModel.ISupportInitialize)(<span style="color:Blue; this.axIDEMainForm1)).EndInit();
<span style="color:Blue; this.ResumeLayout();
[/code]
<br/>
But when the line:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.axIDEMainForm1);
[/code]
is executed, LoaderLock shows the following message:
<pre>Managed Debugging Assistant LoaderLock has detected a problem in D:devGALILEO IVbranches4.5 8_BinDesignerRunTimeImageDesigner.vshost.exe.
Additional Information: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang[/code]
What can I do to solve this problem? (The activeX control is written in C++ and it is not calling any managed code)
View the full article
the form designer, Visual Studio (VS2010) was closed due an error.
After this I tried other way to add the component. Using the aximp aplication I generated the needed .dlls to load manually the control. Then, in the constructor of the form, I add this code (after InitializeComponent invokation) to load the control:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; this.SuspendLayout();
System.ComponentModel.ComponentResourceManager resources = <span style="color:Blue; new System.ComponentModel.ComponentResourceManager(<span style="color:Blue; typeof(FrmScada));
axIDEMainForm1 = <span style="color:Blue; new AxIDEScadaActiveX.AxIDEMainFrm();
((System.ComponentModel.ISupportInitialize)(<span style="color:Blue; this.axIDEMainForm1)).BeginInit();
<span style="color:Blue; this.axIDEMainForm1.Dock = System.Windows.Forms.DockStyle.Fill;
<span style="color:Blue; this.axIDEMainForm1.Location = <span style="color:Blue; new System.Drawing.Point(0, 0);
<span style="color:Blue; this.axIDEMainForm1.Name = <span style="color:#A31515; "axIDEMainForm1";
<span style="color:Blue; this.axIDEMainForm1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject(<span style="color:#A31515; "axIDEMainForm1.OcxState")));
<span style="color:Blue; this.axIDEMainForm1.Size = <span style="color:Blue; new System.Drawing.Size(615, 572);
<span style="color:Blue; this.axIDEMainForm1.TabIndex = 0;
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.axIDEMainForm1);
((System.ComponentModel.ISupportInitialize)(<span style="color:Blue; this.axIDEMainForm1)).EndInit();
<span style="color:Blue; this.ResumeLayout();
[/code]
<br/>
But when the line:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.axIDEMainForm1);
[/code]
is executed, LoaderLock shows the following message:
<pre>Managed Debugging Assistant LoaderLock has detected a problem in D:devGALILEO IVbranches4.5 8_BinDesignerRunTimeImageDesigner.vshost.exe.
Additional Information: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang[/code]
What can I do to solve this problem? (The activeX control is written in C++ and it is not calling any managed code)
View the full article