As the problem is with ReadFile, then the format of data stored in the file must be correct as fread works. The following test program (with no error checking as just a quick test) writes a double to a file using fwrite then reads it from the file using both fread and ReadFile and in both cases produces the correct output.
Code:#include <stdio.h> #include <windows.h> int main () { double val = 12.54; double x, rfx; FILE* pFile; DWORD dwRead; HANDLE fh; pFile = fopen("double", "wb"); fwrite(&val, sizeof(double), 1, pFile); fclose(pFile); x = 0; pFile = fopen("double", "rb"); fread((char*)&x, sizeof(double), 1, pFile); printf("read : %f\n", x); fclose(pFile); rfx = 0; fh = CreateFile("double", FILE_READ_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ReadFile(fh, (char*)&rfx, sizeof(double), &dwRead, NULL); printf("ReadFile : %f\n", rfx); return (0); }


Reply With Quote
