新建项目——选择空项目——选择dll
.h文件
#ifndef _XXX_H_
#define _XXX_H_
#ifdef WBFUNCTIONAPI_EXPORTS
# define MY_DLL_EXP __declspec(dllexport)//导出
#else
# define MY_DLL_EXP __declspec(dllimport)//导入
#endif
//__declspec(dllexport) int add(int a, int b);
class MY_DLL_EXP HelloDll {
public:
void myfunc();
};
#endif
.cpp文件
// MyDll.cpp
#include <iostream>
#include "myfucn.h"
void HelloDll::myfunc()
{
std::cout << "hello, this is my dll ^_^ " << std::endl;
}
//int add(int a, int b)
//{
// return a + b;
//}
注意在预定义中写上:WBFUNCTIONAPI_EXPORTS
出现如下错误表示:工程设置预处理与定义的不一致
1>d:\toothcode\mipnephroscope\nephroscopeproject\wbbasicapi\source.cpp(6): warning C4273: 'HelloDll::hello' : inconsistent dll linkage
1> d:\toothcode\mipnephroscope\nephroscopeproject\wbbasicapi\header.h(10) : see previous definition of 'hello'
遇到的问题:注意文件生成的目录位置,不要引用错误
win32和x64下面生成的位置不一样。win32直接在同级目录下面生成一个release和debug,而x64生成的在x64/release或者x64/debug下面