1、dll生成
-
创建项目,选择动态链接库DLL
-
.h文件(函数的声明)
#pragma once //只编译一次
#ifndef ADD_H_ //如果未定义处理
#define ADD_H_
extern "C" _declspec(dllimport) int add(int x, int y);
// extern "C" 和 extern "C++" 按C或C++语言编译
//_declspec declarespecific 输出dll的lib
#endif
- .cpp文件 (函数的实现)
#include "stdafx.h" //预编译文件头
#include "add.h" //必须加头文件
int add(int x, int y)
{
return x+y;
}
- 生成->重新生成解决方案->.dll .lib .h 三个文件
2、dll调用
- 隐式调用1
包含目录x64 库目录lib 链接器.lib
#include " "
- 隐式调用2
1.复制.dll .h .lib 到项目(main.cpp)
2.添加资源文件.lib
3.#include " "