MFC DLL导出类
来源:互联网 发布:新还珠格格第三部知画 编辑:程序博客网 时间:2024/06/01 08:13
FROM:
http://blog.csdn.net/hgy413/article/details/6545617
方法1:
在VC上new一个名为dll的MFC DLL工程。
第一步,创建一个interface.h文件来定义接口,代码如下:
//file interface.h
#ifndef _INTERFACE_H_
#define _INTERFACE_H_
interface ITest
{
virtual int Print()=0;
virtual ~ITest(){};
};
ITest* DllCreateTest();
void DllDestroyTest(ITest *pTest);
#endif
第二步,定义一个继承自接口interface的类CTest,代码如下:
//file test.h
#ifndef _TEST_H_
#define _TEST_H_
#include "interface.h"
class CTest : public ITest
{
public:
CTest();
virtual ~CTest();
int Print();
}
#endif
//file test.cpp
#include "StdAfx.h" //注意这里需要包含这个头文件,否则会报fatal error C1010: unexpected end of file while
// looking for precompiled header directive
#include "test.h"
CTest::CTest()
{
}
CTest::~CTest()
{
}
int CTest::Print()
{
printf("ok!/n");
return 0;
}
第三步,在dll.cpp文件里,实现DllCreateTest和DllDestroyTest两个函数,代码如下:
//file dll.cpp
......
ITest* DllCreateTest()
{
return new CTest();
}
void DllDestroyTest(ITest *pTest)
{
if(pTest != NULL) delete pTest;
pTest = NULL;
}
第四步,也是最容易忽略的一步,等以上操作都完成之后,还要在dll.def文件里,把要导出的函数DllCreateTest和DllDestroyTest加进去,如下:
; dll.def : Declares the module parameters for the DLL.
LIBRARY "dll"
DESCRIPTION 'dll Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
DllCreateTest
DllDestroyTest
至此,MFC DLL的工程已经完成。那么如何在其他工程中调用生成的dll呢
DllCreateTest取得一个全局变量g_Test,之后用g_Test去调用各个虚函数.
ITest不一定非得为纯虚函数!
在接口函数中调用窗口资源时要
添加:AFX_MANAGE_STATE(AfxGetStaticModuleState());
其说明见:http://blog.csdn.net/optman/article/details/332277
- MFC DLL导出类
- MFC DLL导出类
- MFC DLL如何导出类笔记
- mfc扩展dll导出类的制作方法
- MFC扩展DLL导出类相关问题
- MFC扩展DLL导出对话框类
- MFC扩展DLL导出对话框类
- MFC导出对话框类DLL的实现
- 实现MFC扩展DLL中导出类和对话框
- 一步一步实现MFC扩展DLL中导出类和对话框
- 实现MFC扩展DLL中导出类和对话框
- 实现MFC扩展DLL中导出类和对话框
- 一步一步实现MFC扩展DLL中导出类和对话框
- 一步一步实现MFC扩展DLL中导出类和对话框
- 实现MFC扩展DLL中导出类和对话框
- 实现MFC扩展DLL中导出类和对话框 【转】
- 将MFC 中的类封装为一个Dll并导出
- 一步一步实现MFC扩展DLL中导出类和对话框
- cocos2d-x ClippingNode的使用 节点剪裁
- 组件接口(API)设计指南[5]-最后的思考
- 理解PHP内核
- 图的遍历
- mount过程分析之一(基于3.16.3内核)
- MFC DLL导出类
- 视频开发之外部音视频输入
- SDUTOJ 1480 -- 哈希表(链地址法)
- 最长递增子序列
- getHeight/getTop
- 转移线程的所有权
- hive使用python脚本导致java.io.IOException: Broken pipe异常退出
- 关于Visual Studio 2013 编译 multi-byte character set MFC程序出现 MSB8031 错误的解决办法
- 用ctags为linux系统头文件生成systags