ReadFile() and Binary data

I have two programs: program A (in FORTRAN) and program B (in C++). They are connected through anonymous pipe with each other. Program B should read binary data directly from console of program A but for some reason I can not do that:

Following is the reading part of program B:

1
2
3
4
5
6
7
BOOL bSuccess = FALSE;
LPBYTE File_Data;
DWORD dwFileSize;
wFileSize = GetFileSize(V_hChildStd_OUT_Rd, NULL);
File_Data = new BYTE[dwFileSize+1];
bSuccess = ReadFile( V_hChildStd_OUT_Rd, File_Data, dwFileSize, &dwRead, NULL);
delete [] File_Data; 


Note: V_hChildStd_OUT_Rd is a handle to the output of program A.

If I pass one, two or three digit(s) integer number (say 1 or 10 or 100) the program works and I can get the number in File_Data array. But for higher integer numbers and all double numbers File_Data gives meaning less value. Note that for all numbers my bSuccess is TRUE! which means it can read the file. Can you please help me to solve the problem. Thanks!
Where are you displaying the output? It looks like you delete the read data as soon as you read it.
I watch the content of File_Data() in debug mode before deleting it.
Last edited on
Do you expect the data to be in string format or binary format? I think your debugger is showing you the binary representation of a double, which is nothing like the human-readable string format.
The documentation for GetFileSize() sais:
You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device.



As for getting lower values for ReadFile, you should call it in a loop, not only once. Read here for a complete example:
http://www.installsetupconfig.com/win32programming/windowsthreadsprocessapis7_18.html
@ L B: Is there any way to specify the debugger mode of data (Binary or string)?
@ modoran: That is a good point. I tried to use PeekNamedPipe() to get the number of bytes. It gives me exactly the same size as GetFileSize() which is interesting. But still I can not read the binary data!
I don't know anything about your debugger ;)

Also, you should read modoran's post.
Topic archived. No new replies allowed.