最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Unable to create ConsoleOutput under chrome.exe - Stack Overflow

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论