2013-03-21 19 views
22

Ben AllocConsole() kullandığım ve hata ayıklama amacıyla verileri görüntülemek için cout bir DLL var.
Eskiden çalışıyordum ama derleyicimi (Visual Studio 2012) en son dll'de güncellediğimden beri yalnızca konsolu değil, baskıları/kozaları gösteriyor.
Bunun neden olduğu konusunda fikrim yok.
Herhangi bir fikrin var mı? Benim kodAllocConsole() göstermiyor cout

__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; 

Ama hiçbir şey içinde

Bölüm görüntülenen alır.

cevap

48

Stdout'u konsola yeniden yönlendirmeniz gerekebileceğini hatırlıyorum. Ben (daha önce çalışan kodunuzu vardı beri) olsa yanlış olabilir:

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

ile vs2015 kullanarak çalışır. Garip. Ama çalıştı. – madziikoy

+7

'freopen (" CONIN $ "," r ", stdin);' beklendiği gibi çalışır. –

+1

'' freopen'' güvensiz olduğundan (güvenlik sorunları için), '' freopen_s (& new_stdout, 'CONOUT $', 'w', stdout); '' new_stdout'' '' 'FILE'' kullanılmalıdır. işaretçi. – ub3rst4r

2

Bu Biz Aslında çalıştı edeceğiz hattı std::cout.clear()

if (!AllocConsole()) 
    MessageBox(NULL, L"The console window was not created", NULL, MB_ICONEXCLAMATION); 

FILE* fp; 

freopen_s(&fp, "CONOUT$", "w", stdout); 

printf("Hello console on\n"); 

std::cout.clear(); 

std::cout << "Cout line one." << std::endl; 

cout << "Cout line two." << std::endl; 

MessageBox(NULL, (L"Pause to see console output."), (L"Pause Here"), MB_OK | MB_SYSTEMMODAL | MB_ICONEXCLAMATION); 

fclose(fp); 

if (!FreeConsole()) 
    MessageBox(NULL, L"Failed to free the console!", NULL, MB_ICONEXCLAMATION); 
+0

Gerçekten çok teşekkür ederim. Visual Studio'da benim için başka hiçbir şey yoktu. Ve şimdi yaklaşık bir saat için 2 sözde ünlü çözümleri deniyorum. –