动态链接库
来源:互联网 发布:做软件开发 编辑:程序博客网 时间:2024/05/21 00:15
Abstract: Includes a short explaination and simple example of using virtual base classes as interfaces across an exe and a run-time loaded dll.
Using a class from a dll is easy when the dll is statically (or load-time) linked to your executable. The compiler gets the information it needs from the dll's header and the linker gets all information it needs from the import library. Periodically, someone posts to our newsgroups asking how to newsgroups load a class from a dll completely at run-time. The following is a simple answer to this question, using some of the basic techniques behind COM and CORBA.
Create the class dll:
- Create a virtual base class that contains all of the methods you would need to call from the class. This will be the interface your dll class will support.
- Make the dll class derive from that interface.
- Include the interface definition in the executable that will use the dll class.
- Export a function from the dll that will create a new instance of the dll class and return it's address (I will call this function CreateClassInstance()).
To use the class in your executable:
- Call LoadLibrary() on the dll that contains the class.
- Call GetProcAddress() to gain access to the CreateClassInstance() function.
- Call CreateClassObject() and store the returned address in an interface pointer.
Make calls to the object using the interface pointer and these calls will foreward to the derived object. Don't forget to delete the pointer when done with the object.
Depending on the complexity of the applicaiton, you may have to deal with reference counting issues to determine when to delete the pointer you received from the dll. This example does not take these considerations into account.
- 动态链接库、静态链接库;动态链接、静态链接
- 动态链接,静态链接,动态链接库,静态链接库
- 应用程序链接动态链接库
- cmake 链接动态链接库
- 动态链接和动态链接库
- 动态链接库-原理
- 动态链接库-实现
- 创建动态链接库
- 动态链接库
- 动态链接库
- 动态链接库
- 动态链接库
- 动态链接库
- 动态链接库小结
- 动态链接库简介
- 什么是动态链接库
- 什么是动态链接库?
- 动态链接库
- 内存检测工具比较
- Linux命令助记
- DB2创建数据库时遇到数据库别名存在的情况处理
- 进度栏编程
- 请了2天假,进了一趟城
- 动态链接库
- 免费和开源引擎的游戏引擎,转载自维基
- Java SE 中java.util.Collection 的学习...
- C++对象模型(四)
- 为什么学Python,教材选择!
- jps命令
- 机器人圆形队列算法(待完成)
- 从字符串分离出数值
- POJ 1651动态规划