新建,選擇Win32 Dynamic Link Library,輸入工程名testdll
在建立的工程中新建頭文件“testdll.h”和源文件“testdll.cpp”,代碼如下
//testdll.h
#ifndef TESTDLL_H
#define TESTDLL_H
extern "C" _declspec(dllexport) int GetData(int a,int b); //定義導出函數
int Max(int a,int b); //定義內部函數
#endif
//testdll.cpp
#include "testdll.h"
int GetData(int a,int b)
{
return Max(a,b);
}
int Max(int a,int b)
{
if(a>=b) return a;
else return b;
}
編譯後即得到DLL文件——testdll.dll