我有两个DLL文件,A和B.
需要B来设置setWindowsHookEx()。
我用:
LoadLibrary(L"C:\\Sources\\TestDLL.dll") and GetProcAddress(hDll, "GetMsgProc")
当我尝试在Windows 7上运行我的程序时,GetProcAddress(hDll, "GetMsgProc")
会返回错误。
GetLastError()
返回122,但我认为这不是一个好的错误代码。
当我在Windows 8上运行程序时,一切正常。
当我在GetProcAddress(hDll, "foo")
typedef void(*foo)();
只创建消息框
一切都适用于Windows 7和Windows 8.
我认为我的问题是__stdcal
l,但我找不到解决方案。
typedef void(*foo)();
typedef LRESULT(_stdcall *LPGetMsgProc)(int nCode, WPARAM wParam, LPARAM lParam);
#define NOM_CLASSE_JAVA_TEST "Lcom/XXX/controller/fonctions/Fonctions;"
JNIEXPORT jboolean JNICALL Java_com_XXX_system_Jni_getVeille
(JNIEnv *env, jclass)
{
{
HINSTANCE hDll = (HINSTANCE)LoadLibrary(L"C:\\Sources\\TestDLL.dll");
CString str1("it ok");
if (!hDll)
{
CString str5("error1");
CString str4(GetLastError().ToString());
MessageBox(NULL, str4, str5, MB_ICONERROR);
return -1;
}
LPGetMsgProc pfnProc = (LPGetMsgProc)GetProcAddress(hDll, "GetMsgProc");
if (!pfnProc)
{
CString str5("error2");
CString str4(GetLastError().ToString());
MessageBox(NULL, str4, str5, MB_ICONERROR);
FreeLibrary(hDll);
return -1;
}
// Setup global hook
HHOOK hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)pfnProc, hDll, 0);
if (!hHook)
{
CString str5("hookeroor");
CString str4(GetLastError().ToString());
MessageBox(NULL, str4, str5, MB_ICONERROR);
FreeLibrary(hDll);
return -1;
}
while (TRUE)
{
// Check to see if any messages are waiting in the queue
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Translate the message and dispatch it to WindowProc()
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// If the message is WM_QUIT, exit the while loop
if (msg.message == WM_QUIT)
break;
}
return true;
}
}
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <string>
#include <conio.h>
#include <tchar.h>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
#include <fstream>
#include <cstddef>
#include <cstdio> //std::remove
#include <vector>
#pragma comment(lib, "user32.lib")
extern "C" _declspec(dllexport) void foo(void)
{
MessageBox(NULL, (LPCTSTR)"ok", (LPCTSTR)"ok", MB_ICONERROR);
}
//============================================================================
extern "C"
{
_declspec(dllexport) LRESULT _stdcall GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, (LPCTSTR)"ok", (LPCTSTR)"ok", MB_ICONERROR);
nCode = 0;
wParam = NULL;
lParam = NULL;
}
}
//============================================================================
我在Windows 8 64位和Windows 7 32位上运行我的程序。
我运行Dependency Walker,我找到了名称GetProcAddress(hDll, "_GetMsgProc@12");
,但我的程序无效。
答案 0 :(得分:-2)
然后,代码或编译器必须具有与Windows 7或更早版本不兼容的Windows 8和更新代码。