VS2010中 C++创建DLL图解.
来源:互联网 发布:数据库常考面试题 编辑:程序博客网 时间:2024/05/21 22:49
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图解
- 重构-改善既有代码的设计
- windows shell里的文件系统<用delphi写的>
- 跟踪百度竞价推广的效果2种方法
- Python与Ruby
- Oracle之监视和解决锁定冲突(认证考试指南)
- VS2010中 C++创建DLL图解.
- Asterisk PBX 快速安装向导
- AFNetworking从百度云存储下载(判断网络状态)
- 正则表达式实例应用
- iOS开发 修改工程名
- 从hello world理解Linux的编译系统
- oracle数据库导入导出命令!
- 让人死去活来的cocos2d-x安卓开发环境搭建(windows+eclipse+ndk 不用cygwin)【上图】
- steiner tree的几道题目