代码之家  ›  专栏  ›  技术社区  ›  BullyWiiPlaza

Visual Studio加载库()“调试断言失败”

  •  0
  • BullyWiiPlaza  · 技术社区  · 6 年前

    我正在调试 64-bit C++ 应用于 Visual Studio 2017 Enterprise 但在排队的时候

    HMODULE dll = LoadLibrary(L"D:\\Cpp\\Program2\\x64\\Debug\\Program2.dll");
    

    我收到以下错误消息:

    Debug Assertion Failed!
    
    Program: D:\Cpp\Program\Debug\Program.exe
    File: minkernel\crts\ucrt\src\appcrt\stdio\output.cpp
    Line: 34
    
    Expression: stream != nullptr
    

    当我点击 Continue 我得到

    Program.exe has triggered a breakpoint.
    
    Unhandled exception at 0x0F35ED76 (ucrtbased.dll) in Program.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
    

    在里面 stdio.h :

    应用程序可以很好地构建/编译。整个代码是:

    #include "stdafx.h"
    #include <Windows.h>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
        /*
        * Load library in which we'll be hooking our functions.
        */
        HMODULE dll = LoadLibrary(L"D:\\Cpp\\Program2\\Debug\\Program2.dll");
        if (dll == NULL) {
            printf("The DLL could not be found.\n");
            getchar();
            return -1;
        }
    
        /*
        * Get the address of the function inside the DLL.
        */
        HOOKPROC addr = (HOOKPROC)GetProcAddress(dll, "meconnect");
        if (addr == NULL) {
            printf("The function was not found.\n");
            getchar();
            return -1;
        }
    
        /*
        * Hook the function.
        */
        HHOOK handle = SetWindowsHookEx(WH_KEYBOARD, addr, dll, 0);
        if (handle == NULL) {
            printf("The KEYBOARD could not be hooked.\n");
        }
    
        /*
        * Unhook the function.
        */
        printf("Program successfully hooked.\nPress enter to unhook the function and stop the program.\n");
        getchar();
        UnhookWindowsHookEx(handle);
    
        return 0;
    }
    

    怎么了?这个 DLL 文件系统中存在正在加载的文件。更改为 Release 建造或 Debug 没用。

    动态链接库 以及进程调用 LoadLibrary() 32-bit 64位 我明白了 Debug Assertion Failed 信息。如果位版本不匹配或文件不存在,则函数返回 NULL 没有 这个报错 信息。

    0 回复  |  直到 6 年前