Archived

This topic is now archived and is closed to further replies.

Dougie

Help with file access in XP, for .png files

Recommended Posts

Dougie    122
Hi there, I''m having a major problem with the ReadFile function in VC++ 6. When I run the code below, if I''m trying to read a .png file, it fills the buffer with a whole mess of crap. Code: char* filePath = new char[1024]; unsigned __int8 buf[36]; ... HANDLE hFile = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ReadFile(hFile, &buf[0], 36, &Read, NULL); CloseHandle(hFile); Ok, filePath is the entire file''s path, which I get from windows common dialog box. I''ve tried everything, and found that a .txt file or a .txt file renamed as a .png works fine. But for some reason it doesn''t like proper .png''s. Previously, I used a char buffer, and somehow the values ended up negative. Anyway, I''m using Windows XP home edition. Can anyone suggest code fixes?

Share this post


Link to post
Share on other sites
Mastaba    761
I''ll guarantee that it is the same. The Win32 API does not discriminate based upon a file''s extension. You are simply misreading what has been read in.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Consider using memory-mapped files. Basically that will give you a memory-pointer to read from and the OS will read from file as needed. Less pain for you and likely faster as you don''t need to copy any data.

A search for "memory-mapped" on http://codeproject.com/ will give you something to start with.

Share this post


Link to post
Share on other sites