Jump to content
  • Advertisement

Archived

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

Dougie

Help with file access in XP, for .png files

This topic is 5416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
It would make no difference. The data been read is not the same as in the file it''s been read from. I checked

Share this post


Link to post
Share on other sites
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
whoops... umm, I was reading the wrong section of bytes. I was reading 16 bytes off for what I wanted.

Share this post


Link to post
Share on other sites
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!