Skip to content

Instantly share code, notes, and snippets.

@leafbird
Created June 25, 2013 14:11
Show Gist options
  • Save leafbird/5858750 to your computer and use it in GitHub Desktop.
Save leafbird/5858750 to your computer and use it in GitHub Desktop.
win32 프로그램에서 콘솔창 오픈하는 코드. from http://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
AllocConsole();
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
FILE* hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
FILE* hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
// use the console just like a normal one - printf(), getchar(), ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment