I'm unable to create a console output under chrome.exe
when replacing the chrome.exe
's DLLs with my own.
Here's the code when I replace dxcompiler.dll
:
#include <iostream>
#include <windows.h>
#include <filesystem>
DWORD WINAPI Main(LPVOID LPAram) {
// Try to free the console first, if one exists
FreeConsole();
// Allocate a new console window
if (AllocConsole()) {
FILE* pConsole = nullptr;
freopen_s(&pConsole, "CONOUT$", "w", stdout); // Redirect stdout to console
std::cout << "Console allocated successfully!" << std::endl;
// Keep the console open by running an infinite loop
while (true) {
// You can add any code here to keep the console alive, for example:
Sleep(1000); // Pause the thread for a second to keep the console open
}
}
else {
MessageBox(NULL, L"Failed to allocate console.", L"Error", MB_OK);
}
return 69;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, Main, NULL, 0, NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
The response I get:
Failed to allocated console.