#include <windows.h> #include <stdio.h> #include <fcntl.h> #include <io.h> #include <iostream> #include <fstream> BOOL WINAPI WriteToConsole(char *input) { BOOL bConsole = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE; if (bConsole) { int fd = 0; long lStdOut; lStdOut = (long)GetStdHandle( STD_ERROR_HANDLE); // STD_OUTPUT_HANDLE); fd = _open_osfhandle(lStdOut, _O_TEXT); if (fd > 0) { *stdout = *_fdopen(fd, "w"); setvbuf(stdout, NULL, _IONBF, 0 ); } } printf(input); FreeConsole(); return TRUE; }Unfortunately the problem isn't writing output to *any* console, but writing output to the main console that VFP starts when the EXE starts.
>* Using Win32 Functions in Visual FoxPro >* example=119 >* Saying "Hello World!" with VFP and WinAPI > > >#DEFINE STD_OUTPUT_HANDLE -11 > >DECLARE INTEGER AllocConsole IN kernel32 >DECLARE INTEGER GetConsoleWindow IN kernel32 >DECLARE INTEGER GetStdHandle IN kernel32 LONG nStdHandle > >DECLARE INTEGER ShowWindow IN user32 AS ShowWindowA; > INTEGER hWindow, INTEGER nCmdShow > >DECLARE INTEGER WriteConsole IN kernel32; > INTEGER hConsoleOutput, STRING @lpBuffer,; > INTEGER nCharsToWrite, INTEGER lpCharsWritten,; > INTEGER lpReserved > >= AllocConsole() >= ShowWindowA(GetConsoleWindow(), 1) >= WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "Hello World!", 12,0,0) >