I have just written this code:
hFile = CreateFile("c:\\file.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
if(GetFileType(hFile) == FILE_TYPE_DISK)
dwSize = GetFileSize(hFile, NULL);
wsprintf(szMsg, "File Size = %ld", dwSize);
MessageBox(hWnd, szMsg, "File Size In Bytes", NULL);
ReadFile(hFile, szBuf, dwSize, &dwRead, NULL);
szBuf[dwRead] = 0;
MessageBox(hWnd, szBuf, "File Contense", NULL);
Is is meant to get the file size of c:\file.txt and then using Read file read in the number of bytes returned by GetFileSize(). At the moment GetFileSize() returns 3114 as the number of bytes of file.txt which is correct. Then when i try to read it in my second message box is empty......
So the first message box dispays the number of bytes which it does and the second is meant to display the files contense, which it dosnt.
If i change dwsize in ReadFile() to somthing like 200 then it reads in some of the file, not all obviosly as it needs to read 3114 bytes. But if i put 3114 in rather that dwSize then the msgbox is empty again, as when using dwSize.
Does anyone know what im doing wrong here?