AllocConsole() 不显示 cout [英] AllocConsole() not displaying cout

查看:24
本文介绍了AllocConsole() 不显示 cout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DLL,我在其中使用 AllocConsole() 和 cout 来显示用于调试目的的数据.
它曾经工作得很好,但自从我将编译器 (Visual Studio 2012) 更新到最新版本后,dll 只显示控制台,而不显示打印/输出.
我不知道为什么会这样.
有什么想法吗?

I have a DLL where I use AllocConsole() and cout to display data for debugging purposes.
It used to work fine but since I updated my compiler (Visual Studio 2012) to the latest the dll just shows the console but not the prints/couts.
I am out of idea's as to why this is happening.
Any idea's?

我的部分代码

__declspec(dllexport) INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
    switch(Reason)
    {
    case DLL_PROCESS_ATTACH:    
        AllocConsole();

        DisableThreadLibraryCalls(hDLL);

        //
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID&)pSend, MySend);
        if(DetourTransactionCommit() == NO_ERROR)
             cout << "[" << MySend << "] successfully detoured." << endl;

但没有显示任何内容.

推荐答案

我依稀记得您可能需要将标准输出重定向到控制台.不过我可能是错的(因为你的代码更早运行):

I vaguely recall that you might need to redirect the stdout to the console. I might be wrong though (since you had your code working earlier):

AllocConsole();
freopen("CONOUT$", "w", stdout);
std::cout << "This works" << std::endl;

这篇关于AllocConsole() 不显示 cout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆