Yes, it IS possible!
Buried under stdlib.h, I found the function _wfreopen, and used it…
here’s the resulting code block for redirection:
/********************************/
#ifndef NO_STDIO_REDIRECT
#ifdef _WIN32_WCE
//Serial connection can go both ways
_wfreopen(TEXT(STDOUT_FILE),L"w+",stdout);
_wfreopen(TEXT(STDERR_FILE),L"w",stderr);
#else
/ Redirect standard input and standard output /
newfp = freopen(STDOUT_FILE, “w”, stdout);
if ( newfp == NULL ) { / This happens on NT */
#if !defined(stdout)
stdout = fopen(STDOUT_FILE, “w”);
#else
newfp = fopen(STDOUT_FILE, “w”);
if ( newfp ) {
*stdout = newfp;
}
#endif
}
newfp = freopen(STDERR_FILE, “w”, stderr);
if ( newfp == NULL ) { / This happens on NT */
#if !defined(stderr)
stderr = fopen(STDERR_FILE, “w”);
#else
newfp = fopen(STDERR_FILE, “w”);
if ( newfp ) {
*stderr = newfp;
}
#endif
}
#ifndef _WIN32_WCE
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); / Line buffered /
setbuf(stderr, NULL); / No buffering */
#endif
#endif
#endif /* !NO_STDIO_REDIRECT /
/********************************/
And here’s an even neater trick:
/********************/
//Get rid of 2 errors
#ifdef _WIN32_WCE
#define remove(x) DeleteFile(x)
#endif
/* The standard output files */
#ifdef REDIRECT_SERIAL
#define STDOUT_FILE “COM1:”
#define STDERR_FILE “stderr.txt”
#else
#define STDOUT_FILE “stdout.txt”
#define STDERR_FILE “stderr.txt”
#endif
/********************/
When you reroute to COM1, the iPaq conveniently defaults to 9600 N 8 1
. Using the docking cradle, you can hook the serial up to your base
comp, and get console output through your favorite terminal emulator.