C++创建win32 DLL图解 (VS2010)
来源:互联网 发布:ubuntu安装到u盘 编辑:程序博客网 时间:2024/05/24 06:38
一、DLL的创建
创建项目: Win32->Win32项目,名称:MyDLL
选择DLL (D) ->完成.
1、新建头文件testdll.h
testdll.h代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef TestDll_H_
#define TestDll_H_
#ifdef MYLIBDLL
#define MYLIBDLL extern "C" _declspec(dllimport)
#else
#define MYLIBDLL extern "C" _declspec(dllexport)
#endif
MYLIBDLL
int
Add(
int
plus1,
int
plus2);
//You can also write like this:
//extern "C" {
//_declspec(dllexport) int Add(int plus1, int plus2);
//};
#endif
2、新建源文件testdll.cpp
testdll.cpp代码如下:
1
2
3
4
5
6
7
8
9
#include "stdafx.h"
#include "testdll.h"
#include <iostream>
using
namespace
std;
int
Add(
int
plus1,
int
plus2)
{
int
add_result = plus1 + plus2;
return
add_result;
}
3、新建模块定义文件mydll.def
mydll.def代码如下:
1
2
3
LIBRARY
"MyDLL"
EXPORTS
Add @1
4、vs2010自动创建dllmain.cpp文件,它定义了DLL 应用程序的入口点。
dllmain.cpp代码如下:
// dllmain.cpp : 定义 DLL 应用程序的入口点。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"
BOOL
APIENTRY DllMain(
HMODULE
hModule,
DWORD
ul_reason_for_call,
LPVOID
lpReserved
)
{
switch
(ul_reason_for_call)
{
case
DLL_PROCESS_ATTACH:
case
DLL_THREAD_ATTACH:
case
DLL_THREAD_DETACH:
case
DLL_PROCESS_DETACH:
break
;
}
return
TRUE;
}
最后,编译生成MyDLL.dll文件和MyDLL.lib文件。
1>------ 已启动生成: 项目: MyDLL, 配置: Debug Win32 ------
1> dllmain.cpp
========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========
1>------ 已启动生成: 项目: MyDLL, 配置: Debug Win32 ------
1> stdafx.cpp
1> testdll.cpp
1> MyDLL.cpp
1> 正在生成代码...
1> 正在创建库 D:\Visual C++\工程\Libaray\MyDLL\Debug\MyDLL.lib 和对象 D:\Visual C++\工程\Libaray\MyDLL\Debug
- C++创建win32 DLL图解 (VS2010)
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010 C++创建、调用DLL图解
- VS2010中 C++创建DLL图解
- VS2010 C++创建、调用DLL图解
- VS2010 C++创建、调用DLL图解
- VS2010中 C++创建DLL图解.
- VS2010中 C++创建DLL图解.
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- C++ VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中C++创建DLL图解
- fragement的生命周期
- mssql分页原理及效率分析
- linux 启动ftp 两台服务器挂载同一目录
- 性能调优之:Linux下高并发socket最大连接数【转】
- 程序员不应该再犯的五大编程错误
- C++创建win32 DLL图解 (VS2010)
- Highcharts 使用
- awk 个别运算符详解
- 创建索引
- 【Linux基础】面向连接的套接字通信(TCP)之函数说明
- 关于struts 2为什么会有代码执行漏洞的小帖子
- Kconfig
- 【转】C#调用C++DLL 数据类型转换
- 【异常解决】android.content.ActivityNotFoundException: Unable to find explicit activity class