Hi all,
I'm fairly new to programming as a whole and so I would be grateful if you can help me out.
I'm trying to write a program in VC++ or C++ that would intercept print jobs from another program and save this information in another file(to be formatted later). My idea was to read all the data being sent to LPT1 and save it in a text file.
I've tried writing a program which, according to my limited programming experience, should work(but doesn't). I just ran the program while printing from another text file and the program didn't do anything. It just ran forever.
Can any of you please help me locate and perhaps correct the faults in my program? I'd be very grateful for any help whatsoever.
Below is my code. Thanks.
void main(void)
{
DWORD rread=0, written=0;
//create a handle to LPT1
HANDLE handle = CreateFile( L"LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
//Check if handle was created
if (handle == INVALID_HANDLE_VALUE)
{
cout << "Invalid handle" << endl;
}
//open file to store data read from LPT1 to
ofstream file_op("D:\\myStreamBuffer.txt", ios:ut);
//Read data(exactly 8.192 bytes) from LPT1 (I specified 8.192 because I know how big the file to be printed is)
ReadFile(handle, file_op, 8.192, &rread, NULL);
//close the file. (I suspect this could potentially be the source of the //problem. perhaps I have to do a special command in order for //what was read to be stored into the file?)
file_op.close();
//close handle to LPT1
CloseHandle(handle);
}
I did a few tests and noticed that the program gets stuck on the following line
ReadFile(handle, file_op, 8.192, &rread, NULL);