Dynamically loading unmanaged OCX in C#
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#的更多相关文章
- Dynamically loading an external JavaScript or CSS file
原文: Dynamically loading an external JavaScript or CSS file 通过javascript动态加载css文件和javascript文件,主要是通 ...
- AngularJS: Dynamically loading directives
http://www.codelord.net/2015/05/19/angularjs-dynamically-loading-directives/ ----------------------- ...
- JavaScript Madness: Dynamic Script Loading
Introduction I've developed some pretty seriously Javascript intensive sites, where the sheer quanti ...
- Static, Shared Dynamic and Loadable Linux Libraries
转载:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html Why libraries are used: Th ...
- Android Lint Checks
Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...
- 2016年4月最佳的20款 jQuery 插件推荐
这个列表包括20个我们觉得是最有用的免费的 jQuery 插件,它们都是最具创新性和最省时省力的解决方案,很多都是现代化的设计和开发中碰到的问题的处理方案.如果你熟悉下面列出的任何插件,请与我们的读者 ...
- requerjs 合并 优化配置
/* * This is an example build file that demonstrates how to use the build system for * require.js. * ...
- [mobile开发碎碎念]手机页面上显示PDF文件
demo:http://mozilla.github.io/pdf.js/web/viewer.html 项目地址:https://github.com/mozilla/pdf.js <scri ...
- 【引】runtime全解析,P1:Programming Guide
h2.Overview Objective-C language defers as many decisions as it can from compile time and link time ...
随机推荐
- 好用的一个object c 宏
好用的一个object c 宏 from https://github.com/justzt/ios-helper/blob/master/Macro.h // // Macro.h // Photo ...
- 阿里云ubuntu 创建svn服务器
1.SubVersion服务安装 sudo apt-get install subversion sudo apt-get install libapache2-svn 2.服务器配置 2.1相关用户 ...
- 【转】Jmeter安装成功后的目录介绍
1.bin目录 Jmeter.bat 打开Jmeter主界面 Jmeter使用的日志文件名称被定义到Jmeter.properties中,默认在Jmeter.log可查看日志 2.dosc和prin ...
- zufeoj 分数线划定
分数线划定 时间限制: 1 Sec 内存限制: 128 MB提交: 13 解决: 7[提交][状态][讨论版] 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A ...
- 使用airmon-ng工具开启监听模式
使用ifconfig命令查看活动的网络接口 可以看出网卡已经激活了,然后将网卡设置为混杂模式 root@sch01ar:~# airmon-ng start wlan0 用ifconfig查看网卡是否 ...
- js操作window
js操作window 常用属性 window.closed // window是否关闭 window.length // iframe个数 window.name // 获取和设置window的名字 ...
- 浅谈 Python 的 with 语句 【转载】
引言 with 语句是从 Python 2.5 开始引入的一种与异常处理相关的功能(2.5 版本中要通过 from __future__ import with_statement 导入后才可以使用) ...
- SSD惊悚的跪了,找回数据
1.电脑出现小bug,例如显示乱码,开机变慢等,都是SSD跪的前兆,哭,我怎么就没看出来,而且没有备份过数据. 2.终于,PC死机了...OK,重启,纳尼?起不来... 3.大哭,所有代码,所有论文不 ...
- 判定元素是否刚插入到DOM树
上接<这篇博文>,其应用于avalon的if绑定.如果一个节点还没有插入DOM树,那么avalon将延时对它进行扫描渲染,直到它再次插入到DOM树为止.由于CSS3 keyframe动画的 ...
- 字节流之文件输出流FileOutputStream
文件拷贝: