//隐式链接,方便,全部加载到内存空间,时间代价高。
//dll1.h
#ifdef DLL1_API
#else
#define DLL1_API extern "C" _declspec(dllimport) // extern "C"不改函数名。
#endif
DLL1_API int _stdcall func(); // _stdcall:标准调用约定,有extern "C"也会改函数名。
//dll1.m
#define DLL1_API extern "C" _declspec(dllexport)
#include "dll1.h"
int _stdcall func()
{
}
//dll1.def
LIBRARY dll1
EXPORTS
func(func_alias)
// 动态加载,需要时加载
GetLibrary()
GetProcAddress(,)
HINSTANCE hInst;
hInst = LoadLibrary("Dll1.dll");
typedef int (*FUNCPROC)();
FUNCPROC func = (FUNCPROC)GetProcAddress(hInst, "func");
FUNCPROC func = (FUNCPROC)GetProcAddress(hInst, MAKEINTRESOURCE(1)); // 用序号
if (!func)
{
// no "func"
}
FreeLibrary(hInst);