View Single Post
  #5  
Old 02-14-2012, 05:23
*RemedY* *RemedY* is offline
Family
 
Join Date: Sep 2003
Posts: 115
Rept. Given: 18
Rept. Rcvd 72 Times in 30 Posts
Thanks Given: 0
Thanks Rcvd at 3 Times in 3 Posts
*RemedY* Reputation: 72
Here is something which I hope it helps:

First, the program that writes to stdout. Since you've written that you don't have access to the source, this one is exchangeable:

Code:
#include <windows.h>

int main()
{
    char c[] = "";
    unsigned long count;
    HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    for(int i = 0; i < 10; i++)
    {
        c[0] = i + 0x30;
        WriteFile(stdout, c, 1, &count, NULL);
        Sleep(1000);
    }
    c[0] = 0x0;
    WriteFile(stdout, c, 1, &count, NULL);
    CloseHandle(stdout);
    return 0;
}
Now the one that reads from stdin and writes through at once:

Code:
#include <windows.h>

int main()
{
    char c[] = " ";
    unsigned long incount, outcount, foutcount;
    HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE File;
    
    File = CreateFile("test.txt", 
                       GENERIC_WRITE, 
                       0, 
                       NULL, 
                       CREATE_NEW, 
                       FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH, 
                       NULL);
    while(c[0])
    {
        ReadFile(stdin, &c[0], 1, &incount, NULL);
        FlushFileBuffers(stdin);
        WriteConsole(stdout, c, 1, &outcount, NULL);
        WriteFile(File, c, 1, &foutcount, NULL);
        FlushFileBuffers(File);
    }
    CloseHandle(File);
    CloseHandle(stdout);
    CloseHandle(stdin);
    return 0;
}
I'm pretty sure you can adjust it to your needs.
If that doesn't help you, I'm wrong and I didn't get you right.
I'm sorry then.

Best regards
*RemedY*
Reply With Quote