新建項目——選擇空項目——選擇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下面