- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为 WH_GETMESSAGE 编写一个全局钩子(Hook)。但是当从 dll 调用 GetProcAddress 函数时,我收到错误代码 127,即 ERROR_PROC_NOT_FOUND。它无法找到 GetMsgProc。知道为什么吗?
另外,我是这种编程的新手,对于任何意外的错误,我深表歉意。
动态链接库文件:
#include "windows.h"
#include <stdio.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
__declspec(dllexport) LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, TEXT("I am in"),TEXT("In a DLL"), MB_OK);
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
程序加载DLL文件:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
typedef LRESULT(CALLBACK *LPGetMsgProc)(int nCode, WPARAM wParam, LPARAM lParam);
int main()
{
HMODULE hDll = LoadLibrary(_T("../../dllTouchInputHook/x64/Debug/dllTouchInputHook.dll"));
LPGetMsgProc proc = (LPGetMsgProc)GetProcAddress(hDll, "GetMsgProc");
if (proc == NULL) {
printf("The error code is %d", GetLastError());
}
HHOOK hMsgHook = SetWindowsHookEx(WH_GETMESSAGE, proc, hDll, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hMsgHook);
return 0;
}
最佳答案
未找到该函数,因为它没有像您期望的那样导出为 "GetMsgProc"
。它实际上更像是 "_GetMsgProc@12"
(32 位)或 "_GetMsgProc@20"
(64 位)。如果您希望它导出为 "GetMsgProc"
,那么您需要在编译 DLL 时使用 .DEF
文件。
您一开始就不应该以这种方式实现 Hook 。您应该将调用移动到 DLL 本身内部的 SetWindowsHookEx()
,然后导出一个函数来调用它,例如:
#include "windows.h"
#include <stdio.h>
HINSTANCE hThisDLL;
HHOOK hMsgHook;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hThisDLL = hinstDLL;
return TRUE;
}
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, TEXT("I am in"), TEXT("In a DLL"), MB_OK);
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
__declspec(dllexport) BOOL WINAPI InstallHook()
{
if (!hMsgHook)
hMsgHook = SetWindowsHookEx(WH_GETMESSAGE, &GetMsgProc, hThisDll, 0);
return (hMsgHook != NULL);
}
__declspec(dllexport) VOID WINAPI UninstallHook()
{
if (hMsgHook)
{
UnhookWindowsHookEx(hMsgHook);
hMsgHook = NULL;
}
}
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
typedef BOOL (WINAPI *LPInstallHook)();
typedef VOID (WINAPI *LPUninstallHook)();
int main()
{
HMODULE hDll = LoadLibrary(_T("../../dllTouchInputHook/x64/Debug/dllTouchInputHook.dll"));
if (!hDll)
{
printf("The error code is %d", GetLastError());
return -1;
}
LPInstallHook installProc = (LPInstallHook) GetProcAddress(hDll, "InstallHook"); // or "_InstallHook"
LPUninstallHook uninstallProc = (installProc) ? (LPUninstallHook) GetProcAddress(hDll, "UninstallHook") : NULL; // or "_UninstallHook"
if (!(installProc && uninstallProc))
{
printf("The error code is %d", GetLastError());
FreeLibrary(hDll);
return -1;
}
if (!installProc())
{
printf("The error code is %d", GetLastError());
FreeLibrary(hDll);
return -1;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
uninstallProc();
FreeLibrary(hDll);
return 0;
}
关于windows - 调用 GetProcAddress 时出现错误 127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46777304/
当我通过 win32api 调用 GetProcAddress() 时,我成功获得了句柄,但 ctypes 没有。 代码是: from ctypes import windll import win3
我使用名为“render()”的函数创建了一个 DLL,我想将它动态加载到我的应用程序中,但 GetProcAddress 找不到它。这是 DLL .h: #ifdef D3D_API_EXPORTS
这个问题在这里已经有了答案: Exporting functions from a DLL with dllexport (4 个答案) 关闭 5 年前。 我在动态库中有一个函数,如下所示: nam
正如我们所知,我们可以使用 GetProcAddress 从 DLL 句柄获取函数指针,例如在 DLL 中定义的方法 foo: int foo(long) 对于 foo 函数,我们可以得到这样的函数指
我得到了 MyDll.dll 及其函数定义如下 void pascal Myfunction(BOOL); 当我试图在另一个项目中使用该函数时,我无法使用 GetProcAddress() 获取该函数
我需要在 C++ 中动态加载一个 dll。 我已遵循本教程 http://msdn.microsoft.com/en-us/library/ms235636.aspx创建 dll,一切正常。 然后我关
我有一个游戏的 DLL,我正在导入到 Windows32 应用程序中,我已经成功加载它并调用了很多函数。但是我遇到了一个问题,我需要使用的某个函数需要传递给它的结构。 当我反汇编 DLL 时,我似乎可
这个问题在这里已经有了答案: GetProcAddress cannot find my functions (2 个答案) 关闭 9 年前。 我尝试使用 LoadLibrary 和 GetProc
有人解释下为什么下一段代码会在 ntdll.dll 中返回一个指针吗? GetProcAddress(LoadLibraryA("kernel32.dll"), "EncodePointer"); G
我尝试使用 getprocaddress 查找变量地址。但是我在这方面遇到了问题。问题是我将变量名称一个一个地存储在 char buff[100] 中,就像在循环中一样。那个时候我不知道变量的类型。那
我正在学习如何在 Windows 7 上使用 ctypes 在 python 中创建一个简单的调试器。我的问题是下面给出的代码似乎返回了一个无效地址(这是我对问题的猜测),但我可以弄清楚为什么。我想这
出于某种原因,每当我的 C# .NET 2.0 应用程序调用 GetProcAddress 时,它总是返回零。 public class MyClass { internal static c
使用 dlopen,您可以提供 NULL 作为库名称,并获得一个句柄,允许您在 任何 加载的库中找到一个符号库: If filename is a NULL pointer, then the ret
我正在尝试通过 Firemonkey 框架使用 Delphi XE2 来制作一个插件系统。问题是我收到错误 GetProcAddress 是未声明的标识符。当我尝试在 VCL 项目中使用 GetPro
我必须使用 DLL 中的一个简单函数;我能够加载库,但 GetProcAddress 返回 NULL。我想我了解名称修改,但也许我做错了什么。谢谢(代码如下,我会尽快添加所需的其他信息): mydll
我正在尝试使用 LoadLibrary 和 GetProcAddress 加载 dll。 LoadLibrary 返回一个有效的句柄,但我对 GetProcAddress 的调用返回 NULL。调用
这是我的代码。这看起来很简单,但不知何故它就是行不通。对该函数的最终调用总是因访问错误而失败。 extern "C" { typedef const char* (*Init_fptr_t)(
这个问题几乎可以归结为“我可以安全地将函数指针转换为参数可转换为这些类型的函数指针吗?”,但如果没有实际示例,这听起来非常可疑。 我制作了一个小的实用函数来从 DLL 中调用某些东西,给定 DLL 名
在我的例子中,我通过有效导出函数名称的 GetProcAddress 获得了一个函数指针,一旦我的应用程序调用导出函数,它就会在显示输出后崩溃。如果我从函数和 typdef 中删除参数并直接将 193
我目前在访问 dll 文件中的方法时遇到问题。我尝试访问的方法属于该类型。 int dstoch (float,float,float,float,float,float,float,float,fl
我是一名优秀的程序员,十分优秀!