AllocConsole()不显示cout [英] AllocConsole() not displaying cout
本文介绍了AllocConsole()不显示cout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以前工作正常,但是由于我将编译器(Visual Studio 2012)更新到最新的dll只是显示控制台,但不显示打印/焦距。
我不清楚为什么会发生这种情况。
任何想法?
我的一部分代码
__ declspec(dllexport)INT APIENTRY DllMain(HMODULE hDLL,DWORD原因,LPVOID保留)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
AllocConsole();
DisableThreadLibraryCalls(hDLL);
//
DeTurTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pSend,MySend);
if(DetourTransactionCommit()== NO_ERROR)
cout<<< [< MySend<< ]成功地绕过了。 << ENDL;
但没有显示。
解决方案
我模糊地记得你可能需要将stdout重定向到控制台。我可能错了(因为你的代码早期工作):
AllocConsole();
freopen(CONOUT $,w,stdout);
std :: cout<<< 这个工作<<的std :: ENDL;
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?
Part of my code
__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;
But nothing gets displayed.
解决方案
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屋!
查看全文