帮忙看看我的DLL,为什么不成功?

kuangjingbo kuangjingbo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
/////////////////////////////////////////////////////////////////
//我的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;



}
...全文

相关推荐

评论 21
收藏 已收藏
分享
返回顶部
kuangjingbo
进程/线程/DLL 15,466 成员 49,169 内容