Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AllocConsole() not displaying cout

Tags:

c++

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?

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.

like image 352
madziikoy Avatar asked Mar 21 '13 09:03

madziikoy


1 Answers

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; 
like image 135
Vladimir Sinenko Avatar answered Oct 27 '22 00:10

Vladimir Sinenko