Lessons Learnt in C# ActiveX Control dev

132 views
Skip to first unread message

Balaji Kartikeyan

unread,
Apr 20, 2018, 2:03:08 PM4/20/18
to IADS
I am currently using Visual studio 2010 to develop various custom C# Activex Controls.Since I have learned a lot during the process with help of Symvionics Engineer Dale Jones and others, I have decided to create a thread just to maintain a copy of all the lessons learnt during this dev process to be available to all the developers:

1. One of the latest issues that I faced was that every ActiveX control dll that we created in Visual Studio 2010 was accompanied by "interop.IadsAutomationLib.dll" file. This unmanaged dll has to bed placed along with the managed dll inorder to successfully registeer the dll using Regasm.exe. But our current uploader is setup in such a way that it renames the files with the group name that is trying to upload the file.For example, if a person from group "XYZ" is trying to upload the "ABC.dll" and "interop.IadsAutomationLib.dll" then the uploader will rename the files to "XYZ.ABC.dll" and "XYZ.interop.IadsAutomationLib.dll" which created troubles when registering the new dll since the original "interop.IadsAutomationLib.dll" is now missing. In order to solve this issue and to reduce the number of dlls that need to uploaded , when creating the Activex control, under the "references" in "Solution explorer" select the "interop.IadsAutomationLib" , that should bring up "Properties" dialog box below the "Solutions Explorer". In the "property" dialog box , set "Copy Local"->"False" and "Embed Interop Type" -> "True" , this should pack the interop types used in the managed code into the final assembly which can then be loaded an registered on to system.

Balaji Kartikeyan

unread,
May 22, 2018, 11:54:56 AM5/22/18
to IADS
Update 2:
I have another update regarding developing controls in c#. I was able to attach a OpenGL object to our user control and deploy it in IADS. I used the in-built example from SharpGL (a wrapper for .NET framework) of a rotating pyramid and attached it to an user control. One of the primary challenge was to include the associated dlls (which hosts the OpenGL llibrary). I used the folllowing code to unwrap the dll and then zip it up with the assembly that we create. 
Inside the public Usercontrol1():
            string resource1 = "SampleAxControlCSharpDotNet.SharpGL.dll";
            string resource2 = "SampleAxControlCSharpDotNet.SharpGL.SceneGraph.dll";
            string resource3 = "SampleAxControlCSharpDotNet.SharpGL.WinForms.dll";
            EmbeddedAssembly.Load(resource1, "SharpGL.dll");
            EmbeddedAssembly.Load(resource2, "SharpGL.WinForms.dll");
            EmbeddedAssembly.Load(resource3, "SharpGL.SceneGraph.dll");
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            return EmbeddedAssembly.Get(args.Name);
        }
Inside the Initialize function add the following:
private void InitializeComponent()
        {
            this.openGLControl1 = new SharpGL.OpenGLControl();
            ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).BeginInit();
            this.SuspendLayout();
            // 
            // openGLControl1
            // 
            this.openGLControl1.BackColor = System.Drawing.SystemColors.Control;
            this.openGLControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.openGLControl1.DrawFPS = true;
            this.openGLControl1.FrameRate = 20;
            this.openGLControl1.Location = new System.Drawing.Point(0, 0);
            this.openGLControl1.Name = "openGLControl1";
            this.openGLControl1.OpenGLVersion = SharpGL.Version.OpenGLVersion.OpenGL2_1;
            this.openGLControl1.RenderContextType = SharpGL.RenderContextType.FBO;
            this.openGLControl1.RenderTrigger = SharpGL.RenderTrigger.TimerBased;
            this.openGLControl1.Size = new System.Drawing.Size(908, 695);
            this.openGLControl1.TabIndex = 0;
            this.openGLControl1.OpenGLInitialized += new System.EventHandler(this.openGLControl_OpenGLInitialized);
            this.openGLControl1.OpenGLDraw += new SharpGL.RenderEventHandler(this.openGLControl_OpenGLDraw);
            this.openGLControl1.Resized += new System.EventHandler(this.openGLControl_Resized);
            // 
            // UserControl1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.openGLControl1);
            this.Name = "UserControl1";
            this.Size = new System.Drawing.Size(908, 695);
            ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).EndInit();
            this.ResumeLayout(false);

        }
In case if you have any questions please feel free to message me. 
Reply all
Reply to author
Forward
0 new messages