I'm debugging a 64-bit C++ application in Visual Studio 2017 Enterprise but at the line
HMODULE dll = LoadLibrary(L"D:\\Cpp\\Program2\\x64\\Debug\\Program2.dll");
I'm getting the following error message:
Debug Assertion Failed!
Program: D:\Cpp\Program\Debug\Program.exe
File: minkernel\crts\ucrt\src\appcrt\stdio\output.cpp
Line: 34
Expression: stream != nullptr
When I click Continue I get
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:
The application can be built/compiled just fine. The whole code is:
#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;
}
What is wrong? The DLL file being loaded exists in the file system. Changing to Release build or Debug doesn't help.
When the DLL and the process calling LoadLibrary() are 32-bit or 64-bit I get the Debug Assertion Failed message. If the bit versions mismatch or the file doesn't exist, the function returns NULL and no Debug Assertion Failed message.

