/*
记忆力越来越不中了,写个文章留待以后翻阅。
*/
dll 源码:
#include <windows.h>
extern "C" _declspec(dllexport) int Add(int x, int y)//申明函数为导出函数
{
int result = x + y;
return result;
}
extern "C" _declspec(dllexport) bool TestString(wchar_t* p)//申明函数为导出函数
{
bool bRet = true;
if( p )
{
if( wcscmp(p,L"熊风") == 0 )
{
bRet = true;
}
else
{
bRet = false;
}
}
else
{
bRet = false;
}
return bRet;
}
调用 dll源码:
typedef int (* DllAdd)(int,int);
typedef bool (*DllTestString)(wchar_t* );
int main(int argc,char** argv)
{
HMODULE hDll = LoadLibrary(L"TestDll.dll");//加载DLL文件
if (!hDll)
{
}
else
{
DllAdd dllAddFunc = (DllAdd)GetProcAddress(hDll,"Add");
int result = 0;
result = dllAddFunc(3,6);
DllTestString dllTestStringFunc = (DllTestString)GetProcAddress(hDll,"TestString");
bool bRet = dllTestStringFunc(L"熊风");
FreeLibrary(hDll);
}
return 0;
}