Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 不适用于Windows 7,但适用于Windows 8 dll_C++_Windows_Dll_Stdcall_Getprocaddress - Fatal编程技术网

C++ 不适用于Windows 7,但适用于Windows 8 dll

C++ 不适用于Windows 7,但适用于Windows 8 dll,c++,windows,dll,stdcall,getprocaddress,C++,Windows,Dll,Stdcall,Getprocaddress,我有两个DLL文件,A和B A需要B用于setWindowsHookEx 我使用: LoadLibrary(L"C:\\Sources\\TestDLL.dll") and GetProcAddress(hDll, "GetMsgProc") 当我尝试在Windows7上运行程序GetProcAddresshDll时,GetMsgProc返回一个错误 GetLastError返回122,但我认为这不是一个好的错误代码 当我在Windows8上运行我的程序时,一切都正常 当我更改GetProcA

我有两个DLL文件,A和B

A需要B用于setWindowsHookEx

我使用:

LoadLibrary(L"C:\\Sources\\TestDLL.dll") and GetProcAddress(hDll, "GetMsgProc")
当我尝试在Windows7上运行程序GetProcAddresshDll时,GetMsgProc返回一个错误

GetLastError返回122,但我认为这不是一个好的错误代码

当我在Windows8上运行我的程序时,一切都正常

当我更改GetProcAddressHdl中的函数调用时,foo

typedef void*foo;只创建消息框

一切都可以在Windows7和Windows8上运行

我想我的问题是,但是我没有找到解决办法

DLL文件A DLL文件B 我在Windows8 64位和Windows7 32位上运行我的程序


我运行并找到了名称GetProcAddresshDll_GetMsgProc@12;, 但是我的程序无法运行。

然后,代码或编译器必须具有与Windows7或更高版本不兼容的Windows 8及更高版本的代码。

如果您执行的任何操作涉及在失败的调用和对GetLastError的调用之间进行的系统调用,则GetLastError返回的值可能已无效。总是先调用GetLastError,然后再调用其他任何东西。另外,您是否重载了GetLastError?你真的在C++编程吗?没有编译器特定的扩展?否则,您将如何对返回的DWORD调用方法?如果必须强制转换,则说明您做得不对。删除对SetWindowsHookEx调用中的强制转换,编译器将愉快地输出诊断。同样,您的LPCTSTR在您的Maskbox调用中是一个bug。我在Unicode中编译,这个文件的一部分是C++ iFIFF。并不是说演员阵容不必要。演员阵容很糟糕。您正在调用MessageBoxW,它需要两个类型为const wchar_t*的参数,但您正在传递类型为const char[3]的参数。删除所有强制转换,并修复错误。
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;
    }
}
//============================================================================