天天看点

win32 app里使用控制台打印调试信息

<span style="font-size:18px;">HANDLE hOutput;
void console_init(void)
{
    AllocConsole();   
    SetConsoleTitle("Debug Window");
    hOutput=GetStdHandle(STD_OUTPUT_HANDLE); 
    //FreeConsole();  
}

void DebugPrint(char *fmt, ...)
{
    DWORD uLen;
    char buffer[4096];
    int arg;

    arg = (int)&fmt + sizeof(int);
    vsprintf(buffer, fmt, (char *)arg);

    WriteConsole(hOutput, buffer, strlen(buffer), &uLen, NULL);</span>