I have two DLL files, A and B.
A needs B for setWindowsHookEx().
I use:
LoadLibrary(L"C:\\Sources\\TestDLL.dll") and GetProcAddress(hDll, "GetMsgProc")
When I try to run my program on Windows 7, GetProcAddress(hDll, "GetMsgProc")
returns an error.
GetLastError()
returns 122, but I think it not a good error code.
When I run my program on Windows 8 everything works.
When I change the function call in GetProcAddress(hDll, "foo")
typedef void(*foo)();
just creates message box
Everything works on Windows 7 and Windows 8.
I think my problem is __stdcal
l, but I don't find the solution.
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;
}
}
//============================================================================
I run my program on Windows 8 64 bit and Windows 7 32 bit.
I run Dependency Walker and I found the name GetProcAddress(hDll, "_GetMsgProc@12");
, but my program won't work.
这样,代码或编译器必须具有Windows 8和与Windows 7或更早版本不兼容的最新代码。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.