一、创建DLL 文件
1 vs2010下选择win32应用程序,创建DLL 工程
2 创建头文件testdll.h
#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
3 创建源文件
#include "stdafx.h"
#include "testdll.h"
#include
using namespace std;
int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}4 创建模块文件
LIBRARY "MyDLL"
EXPORTS
Add @15 选择release版本进行编译
二、调用DLL文件中的函数
#include "stdafx.h"
#include
#include
#pragma comment (lib , "MyDll.lib" )
extern "C"_declspec (dllimport) int Add(int plus1, int plus2);
int _tmain(int argc, _TCHAR* argv[])
{
printf("%d\n",Add(6,4));
return 0;
}
本文详细介绍了如何在Visual Studio 2010中创建DLL动态链接库文件,包括定义头文件、实现源文件、创建模块定义文件及编译设置。同时,还展示了如何在另一项目中导入并调用DLL文件中的Add函数,涉及到了dllimport和dllexport关键字的使用。

被折叠的 条评论
为什么被折叠?



