VS2010中 C++创建DLL图解.
来源:互联网 发布:义乌淘宝培训机构 编辑:程序博客网 时间:2024/05/14 04:42
转自:http://hi.baidu.com/lipeiyi2006/item/df1d035734472d9509be17c0
VS2010中 C++创建DLL图解.
一、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
- 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图解
- VS2010中 C++创建DLL图解
- VS2010中 C++创建DLL图解
- VS2010中创建DLL
- VS2010 C++创建、调用DLL图解
- Ubuntu13.10几分钟自动断网问题(已解决)
- 批量提取文件名bat doc命令
- 【Google Calendar API v3】get events list with OAuth 2.0 & Rest
- SCTP_window7
- 养成6个习惯 预防并克服拖拉,摆脱工作状态不佳的妙方 自我激励法则
- VS2010中 C++创建DLL图解.
- Documentation/usb/bulk-streams.txt
- [备忘]解决apache配置mod_passenger.so permission denied
- 模板技术
- tcp ip状态详解
- HDU 1599 find the mincost route Floyd求最小环
- php与mysql基础 第二章 form
- stack与heap的关系与区别
- 判断CPU模式是大端还是小段(big-Endian和little-Endian)