编写了一个DLL文件,其中有函数
_declspec(dllexport) void FunctionName();
然后在程序中如下调用该函数:
typedef void (*MYFUNCTION)(void);
HINSTANCE hInstance;
MYFUNCTION func;
hInstance = ::LoadLibrary("dllname.dll");
func = (MYFUNCTION)GetProcAddress(hInstance, "FunctionName"); //获取函数的地址
(*func)(); //调用函数
::FreeLibrary();
但是在编译的时候提示出错,需要如下声明函数:
extenr "C" _declspec(dllexport) void FunctionName(void);
这样修改之后就可以正常调用函数了。