编写DLL程序方法(二)
2014-05-27 21:01
169 查看
第一步:创建一个动态链接库程序 第二步:编写一个测试程序 #include "stdafx.h" int add(int a,int b) { return a+b; } int sub(int a,int b) { return a-b; } BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } 第三步:定义一个def文件(比如EXPORTS.def) EXPORTS add sub 第四步:直接编译DLL文件 第五步:编写测试程序,把编译目录下的xxx.dll 和xxx.lib 拷到你要调用此DLL的程序中 xxx.lib放到工程目录下,xxx.dll放到编译目录下 第六步:测试程序例如 // testDLL.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> typedef int (*addFunction)(int,int); typedef int (*subFunction)(int,int); int main(int argc, char* argv[]) { int a=5,b=1,c=0; addFunction add; subFunction sub; add=(addFunction)GetProcAddress(LoadLibrary("myDLL.dll"),"add"); sub=(addFunction)GetProcAddress(LoadLibrary("myDLL.dll"),"sub"); c=add(a,b); printf("%d\n",c); c=sub(a,b); printf("%d\n",c); return 0; } 第七步:直接运行即可
相关文章推荐
- VC++ 6.0下编写COM客户程序的三种方法(转载)
- 由云台协议DLL浅谈插件程序的编写(下)【原创】
- 用CodeGear C++ Builder 2007编写dll程序(二)
- 把Qt程序做成dll的方法
- VC编写DLL几种方法的简介
- 微软软件项目开发方法--如何编写优秀的程序( 主讲:林斌 )视频笔记
- 在VS2003中编写控制台程序的方法,以及自动缩进快捷键: CTRL+K+F
- 如何编写从M中选N的组合数程序,一个不用递归方法设计,一个用递归方法设计
- 用CodeGear C++ Builder 2007编写dll程序(一)
- VC编写DLL几种方法的简介
- Delphi环境中编写调用DLL的方法和技巧
- MFC中使用C#编写的Dll的方法
- 提供程序 DLL 未能正确初始化的解决方法(最简洁有效的方法)
- 导出.net编写的exe/dll文件中Resource的方法
- 用Delphi7编写代码时出现"dcc70.dll"调用失败的处理方法
- 用hibernate编写程序遇到的问题及解决方法
- VC编写DLL几种方法的简介.
- 由云台协议DLL浅谈插件程序的编写(上)【原创】
- 编写Linux系统下Daemon程序的方法步骤
- 的引用(请使用 TLBIMP 实用工具来引用 COM DLL): 提供程序 DLL 未能正确初始化。----------解决方法