It's not quite what you were after, but it may solve your problem.
I had a similar problem with stdio, so I redirected it to a file.
I hope the following helps.
Richard.
------
/* Declare a pointer to store the 'real' stdout /*
FILE * stdout_old;
/* Save the 'real' stdout so we can put it back later */
stdout_old = stdout;
/* Open a debug file, and point stdout to it */
stdout = fopen("c:\debug.txt", "w");
/* run some code */
printf("This should appear in the debug file \n");
/* Close our debug file */
fclose(stdout);
/* Return stdout to the 'real' stdout */
stdout = stdout_old;