首页 > 学院 > 开发设计 > 正文

Create Console for Logging in Win32 Application

2019-11-10 20:08:57
字体:
来源:转载
供稿:网友

1 Create Console for Logging in Win32 application

Win32 Application is created without Console, which is quite useful for debuging.

1.1 AllocConsole && Redirect stdout

void InitConsole() { ASSERT_TRUE(AllocConsole()); auto out = GetStdHandle(STD_OUTPUT_HANDLE); auto message = "Console Allocated/n"; WriteConsole(out, message, (DWord)strlen(message), nullptr, nullptr); // redirect stream stdout mStdout = freopen("CONOUT$", "w", stdout); ASSERT_NOT_NULL(mStdout); PRintf("stdout redirected/n");}void DestroyConsole() { SAFE_CLOSE(mStdout); ASSERT_TRUE(FreeConsole());}

1.2 TODO: REPL

1) Support REPL in Console

See Also: AllocConsole, FreeConsole, GetStdHandle


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表