You'll have to perform a number of steps that are normally taken of automatically when you use the toolbox.

First and foremost, you have 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 two assemblies, axinterop.foo.dll contains a wrapper class that's derived from AxHost and allows you to 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 program.

Next you have to ensure these DLLs are present in the build directory. Best thing to do 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 have to create an instance of the control, use Assembly.CreateInstance() and pass the type name of the AxHost wrapper class. If you have no idea what its name might be, it isn't obvious, then use ildasm.exe to look at the axinterop.foo.dll assembly. Cast the returned object to AxHost.

Next you have to add the control to the form's Controls collection so it is visible and usable. You cannot call any interface methods until the control instance is created, that doesn't happen until you've added the control and the form's Load event has fired.

Next you have to use reflection or the dynamic keyword to obtain a reference to the interfaces implemented by the control, in case you need to set properties or call methods. That's difficult to get right, you'll want to write that code first with the control added from the toolbox so you don't have to guess too hard at the proper names.

Dynamically loading unmanaged OCX in C#的更多相关文章

  1. Dynamically loading an external JavaScript or CSS file

    原文:   Dynamically loading an external JavaScript or CSS file 通过javascript动态加载css文件和javascript文件,主要是通 ...

  2. AngularJS: Dynamically loading directives

    http://www.codelord.net/2015/05/19/angularjs-dynamically-loading-directives/ ----------------------- ...

  3. JavaScript Madness: Dynamic Script Loading

    Introduction I've developed some pretty seriously Javascript intensive sites, where the sheer quanti ...

  4. Static, Shared Dynamic and Loadable Linux Libraries

    转载:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html Why libraries are used: Th ...

  5. Android Lint Checks

    Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...

  6. 2016年4月最佳的20款 jQuery 插件推荐

    这个列表包括20个我们觉得是最有用的免费的 jQuery 插件,它们都是最具创新性和最省时省力的解决方案,很多都是现代化的设计和开发中碰到的问题的处理方案.如果你熟悉下面列出的任何插件,请与我们的读者 ...

  7. requerjs 合并 优化配置

    /* * This is an example build file that demonstrates how to use the build system for * require.js. * ...

  8. [mobile开发碎碎念]手机页面上显示PDF文件

    demo:http://mozilla.github.io/pdf.js/web/viewer.html 项目地址:https://github.com/mozilla/pdf.js <scri ...

  9. 【引】runtime全解析,P1:Programming Guide

    h2.Overview Objective-C language defers as many decisions as it can from compile time and link time ...

随机推荐

  1. Oracle存储过程使用总结

    1.使用Oracle存储过程查询结果集: 网上写的都是他妈的扯淡!其实一句话就行了,你只要返回一个游标就OK了.具体代码如下: CREATE OR REPLACE PROCEDURE PR_ORDER ...

  2. 水仙花之java与c++的战争======

    总结:同样在C++里可以运行正常的水仙花,在java里不行 为什么??是运算符优先级的问题吗: package com.a; //水仙花数 一个三位数 324:426/195 public class ...

  3. ATM:模拟实现一个ATM + 购物商城程序

    额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 支持多账户登录 支持账户间转账 记录每月日常消费流水 提供还款接口 ATM记录操作日志 提供管理接 ...

  4. 微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈

    分享出去的内容,可以通过jssdk进行修改. 1.配置jssdk Wx_config.html <?php import("@.ORG.jssdk"); $jssdk = n ...

  5. mysql锁,事务

    什么是事务 事务定义了一个服务操作序列,由服务器保证这些操作序列在多个客户并发访问和服务器出现故障情况下的原子性事务的属性 A --redo&undo C --undo I --lock D ...

  6. html5移动开发的几大特性

    html5移动开发的出现让移动平台的竞争由系统平台转向了浏览器之间:移动端的IE.Chrome.FireFox.Safari,亦或是新出现的浏览器,谁能达到在移动端对HTML5更好的支持,谁就能在以后 ...

  7. cocoa 线程操作

    在Cocoa 中创建线程使用NSThread类的detachNewThreadSelector: toTarget:withObject:方法 NSPort *port1 = [NSPort port ...

  8. vue-cli中的babel配置文件.babelrc详解

    本文介绍vue-cli脚手架工具根目录的babelrc配置文件 介绍 es6特性浏览器还没有全部支持,但是使用es6是大势所趋,所以babel应运而生,用来将es6代码转换成浏览器能够识别的代码 ba ...

  9. phpStudy启动失败时的解决方法 提示缺vc9运行库

    问题描述: 问题产生原因分析: php5.3.5.4和apache都是用vc9编译,电脑必须安装vc9运行库才能运行. php5.5.5.6是vc11编译,如用php5.5.5.6必须安装vc11运行 ...

  10. 3.使用Maven构建Web项目

    转自:https://blog.csdn.net/m261030956/article/details/46481837 从网上查了一些资料,才算明白(也就是怎么操作吧),怎么使用Maven构建一个W ...