****************************************
Module:Mylib.h
****************************************
#ifdef MYLIBAPI
//MYLIBAPI应该在所有的DLL源文件包含Mylib.h之前定义
//此时所有的由MYLIBAPI前缀定义的函数、C++类或变量将定义为导出
#else
//使用该DLL的其它可执行模块包含Mylib.h时,由MYLIBAPI前缀定义的函数、C++类或变量将定义为导入,供执行模块调用
#define MYLIBAPI extern "C" __declspec(dllimport)
#endif
MYLIBAPI int g_nResult;
MYLIBAPI int Add(int nLeft , int nRight);
******************************************
Module:MyLibFile1.cpp
******************************************
#include <windows.h>
//在包含Mylib.h之前先定义MYLIBAPI ,Mylib.h文件中由MYLIBAPI前缀定义的函数、C++类或变量将定义为导出
#define MYLIBAPI extern "C" __declspec(dllexport)
#include "MyLib.h"
int g_nResult;
int Add(int nLeft , int nRight)
{
g_nResult = nLeft + nRight;
return ( g_nResult );
}