📄 demo.cpp
字号:
#include <stdio.h>
#include <windows.h>
//首先定义输出函数声明,定义函数调用规范
typedef UINT (CALLBACK* MessageBoxType)(UINT ,LPCTSTR,LPCTSTR,UINT);
typedef UINT (CALLBACK* MessageBoxProxyType)(UINT ,UINT ,LPCTSTR,LPCTSTR,UINT);
void main(void)
{
BOOL freeResult, runTimeLinkSuccess = FALSE;
HINSTANCE dllHandle = NULL;
HINSTANCE dllProxyHandle = NULL;
MessageBoxType MessageBoxPtr = NULL;
MessageBoxProxyType MessageBoxProxyPtr = NULL;
//加载动态链接库,保存返回的实例句柄
dllHandle = LoadLibrary("user32.dll");
// 如果返回句柄有效,尝试得到函数地址
if (NULL != dllHandle)
{
//通过调用GetProcAddress函数得到MessageBox函数指针。
MessageBoxPtr = (MessageBoxType)GetProcAddress(dllHandle,
"MessageBoxA");
// 通过返回的函数地址调用API函数
if (runTimeLinkSuccess = (NULL != MessageBoxPtr))
{
dllProxyHandle = LoadLibrary("invoke.dll");
// 如果返回句柄有效,尝试得到函数地址
if (NULL != dllProxyHandle)
{
MessageBoxProxyType MessageBoxProxyPtr = NULL;
MessageBoxProxyPtr= (MessageBoxProxyType)GetProcAddress(dllProxyHandle,
"InvokeFunc");
if (MessageBoxProxyPtr!=NULL) {
(*MessageBoxProxyPtr)((DWORD)MessageBoxPtr,NULL,"hi","Call Successfully!",MB_OK);
}
FreeLibrary(dllProxyHandle);
}
}
//释放加载的动态链接库
freeResult = FreeLibrary(dllHandle);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -