giovedì 13 dicembre 2012

Windows application with console

se stai usando una windows application come entry point per l'applicazione e vuoi anche una console

#include <iostream>
#include <string>
#include <cstdio>
#include <windows.h>
#include <io.h>
#include <fcntl.h>

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (AllocConsole()) {
int ifd = _open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
int ofd = _open_osfhandle((intptr_t)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);

*stdin = *_fdopen(ifd, "r");
*stdout = *_fdopen(ofd, "w");

std::cout<<"I made a console window";
std::cin.get();

fclose(stdout);
fclose(stdin);
}
}

Reference:
http://www.daniweb.com/software-development/cpp/threads/347901/is-it-possible-to-use-a-console-app-and-windows-one-at-the-same-time

Nessun commento:

Posta un commento