1.新建項(xiàng)目:
新建-->項(xiàng)目-->Win32控制臺(tái)-->選擇DLL、空項(xiàng)目。
2.創(chuàng)建.h文件
//MyDll.h
#ifndef _MYDLL_H_
#define _MYDLL_H_
extern "C"{
#ifdef _DLL_SAMPLE
#define DLL_SAMPLE_API __declspec(dllexport)
#else
#define DLL_SAMPLE_API __declspec(dllimport)
#endif
int a = 0;
DLL_SAMPLE_API void TestDll(int);
#undef DLL_SAMPLE_API
}
#endif
3.創(chuàng)建.cpp文件
//MyDll.cpp
#include <iostream>
#include "MyDll.h"
using namespace std;
void TestDll(int m)
{
cout<<"Test Dll "<<m<<" a="<<a<<endl;
}
4.點(diǎn)擊生成。
在Debug中會(huì)生成項(xiàng)目名.dll和.lib文件。