帮忙看看我的DLL,为什么不成功?
/////////////////////////////////////////////////////////////////
//我的DLL工程,生成TheDLL.dll文件
/////////////////////////////////////////////////////////////////
#include <windows.h>
#ifdef __cplusplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
int rtnValue=0;
EXPORT void CALLBACK Set(int n);//把n的值传给rtnValue
EXPORT int CALLBACK Get();//返回rtnValue的值
BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD dwReason,LPVOID lpvReserved)
{
return TRUE;
}
EXPORT void CALLBACK Set(int n)
{
rtnValue=n;
}
EXPORT int CALLBACK Get()
{
return rtnValue;
}
///////////////////////////////////////////////////////
//我的.exe文件,用来调用.DLL文件
///////////////////////////////////////////////////////
#include <windows.h>
typedef void (CALLBACK * PFNSET)(int);
typedef int (CALLBACK * PFNGET)();
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
TCHAR buffer[100];
HANDLE hLibrary;
PFNSET pfnSet;
PFNGET pfnGet;
unsigned long error;
if(NULL==(hLibrary=LoadLibrary(TEXT("TheDLL.dll"))))
{
error=GetLastError();
MessageBox(NULL,TEXT("LOAD DLL ERROR"),TEXT("ERROR"),MB_OK);
return 0;
}
if(NULL==(pfnSet=(PFNSET)GetProcAddress(hLibrary,TEXT("Set"))))
{
error=GetLastError();
MessageBox(NULL,TEXT("LOAD FUNCTION Set ERROR"),TEXT("ERROR"),MB_OK);
return 0;
}
if(NULL==(pfnGet= (PFNGET)GetProcAddress(hLibrary,TEXT("Get"))))
{
error=GetLastError();
MessageBox(NULL,TEXT("LOAD FUNCTION Get ERROR"),TEXT("ERROR"),MB_OK);
return 0;
}
(* pfnSet)(100);
wsprintf(buffer,TEXT("%d"),(int)(pfnGet)());
MessageBox(NULL,buffer,TEXT("TEST"),MB_OK);
if(hLibrary)
FreeLibrary(hLibrary);
return 0;
}