Windows程序中打开控制台
时间:2010-07-28 来源:ielnaf
//在Windows程序中打开控制台的程序
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h> bool CreateConsole(void)
{
FreeConsole();
if ( AllocConsole() )
{
int hCrt = _open_osfhandle((long)
GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
*stdout = *(::_fdopen(hCrt, "w"));
::setvbuf(stdout, NULL, _IONBF, 0);
*stderr = *(::_fdopen(hCrt, "w"));
::setvbuf(stderr, NULL, _IONBF, 0);
return TRUE;
}return FALSE;
}
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h> bool CreateConsole(void)
{
FreeConsole();
if ( AllocConsole() )
{
int hCrt = _open_osfhandle((long)
GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
*stdout = *(::_fdopen(hCrt, "w"));
::setvbuf(stdout, NULL, _IONBF, 0);
*stderr = *(::_fdopen(hCrt, "w"));
::setvbuf(stderr, NULL, _IONBF, 0);
return TRUE;
}return FALSE;
}
相关阅读 更多 +