Visual Studio LoadLibrary () "Ошибка отладки" - PullRequest
0 голосов
/ 23 июня 2018

Я отлаживаю приложение 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.

in 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 build или Debug не помогает.

Когда DLL и процесс, вызывающий LoadLibrary(), равны 32-bit или 64-bit, я получаю сообщение Debug Assertion Failed.Если битовые версии не совпадают или файл не существует, функция возвращает сообщение NULL и сообщение Debug Assertion Failed отсутствует.

...