You'll have an perform a number of steps that is normally taken of automatically when you use the toolbox.
First and foremost, you had to run the Aximp.exe utility to generate the. NET Interop Assemblies. Use the Visual Studio Command Prompt to run the tool. You'll get the assemblies, Axinterop.foo.dll contains a wrapper class that's derived from AxHost and allows you put the Control on a form. And Interop.foo.dll, the interop assembly that makes the COM interfaces implemented by the control callable from a. NET PR Ogram.
Next you has to ensure these DLLs is present in the build directory. Best thing to does is to add them to your project and set their copy to Output Directory to "copy if newer".
Now you can use Assembly.Load ("Axinterop.foo.dll") in your code to dynamically Load the interop Assembly.
Next you has to create a instance of the control, use Assembly.createinstance () and pass the type name of the AxHost WRA Pper class. If you had no idea about its name might is, it isn ' t obvious, then use Ildasm.exe to look at the Axinterop.foo.dll ASSEMBL Y. Cast the returned object to AxHost.
Next you had to add the control to the form's Controls collection so it was visible and usable. You cannot call any interface methods until the control instance are created, that doesn ' t happen until you ' ve added the CO Ntrol and the form ' s Load event has fired.
Next you has to use reflection or the dynamic keyword to obtain a reference to the interfaces implemented by the control, In the need to set properties or call methods. That's difficult to get right, and you'll want to write this code first with the control added from the toolbox so you don ' t h Ave to guess too hard at the proper names.
Dynamically loading unmanaged OCX in C #