Opening Files: very weird error.

Started by
14 comments, last by Nacho 21 years, 7 months ago
Hi! I have modified the function included in TOTWGPG to load bitmap files and today I discovered a very weird erro while I was using this function in my app. Here´s the section that´s giving me a headache: int LoadBitmapFile(BITMAP_FILE_PTR Bitmap,char *lpFileName,DDPIXELFORMAT &ddPixel) { int iFileHandle, iCounter; UCHAR *lpTempBuffer = NULL; OFSTRUCT FileData; memset(&FileData,0,sizeof(OFSTRUCT)); if(-1==(iFileHandle = OpenFile(lpFileName,&FileData,OF_READ))) { DWORD d = GetLastError(); return BMP_FAILED; } // More code. } // End LoadBitmapFile(). One function call might look like this: LoadBitmapFile(&Bitmap,"cdabc.bmp",ddPixel); The weird thing is that if I write for the name "cdab.bmp" (assuming there´s such a BMP, of course), the iFileHandle var inside LoadBitmapFile gets a proper value (different from -1). But if I pass "cdabc.bmp" (or "bitmap24.bmp", a longer name), iFileHandle gets the value -1. GetLastError() returned the error code 111 which, according to MSDN, is 111 The file name is too long. ERROR_BUFFER_OVERFLOW Does somebody have a clue of what´s going on in here? If you need more pieces of the code just ask me. Thanks in advance!!
Advertisement
Try sticking with dos 8.3 format. Or write a new bmp loader.
#ifndef (Goldsword_was_here)#define (Goldsword_was_here)cout << "Goldsword was here" << endl;#endif
quote:Original post by goldsword
Try sticking with dos 8.3 format.


The book has examples with files with more characters than 8.

quote:Original post by goldsword
Or write a new bmp loader.


I don´t want to write another one, I´d like to know what´s going on here.

Anybody can help me? Thanks!

It seems like every day 10 people have trouble with the code in this book. I wouldn''t trust it too much. You might want to look into CreateFile, fopen, or fstream to open the file. Maybe they''ll solve the problem.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
No, I think the code is really trustable. I´m pretty sure it´s me who´s making a silly mistake. Anyway, I´ll try to make it work in another way. Is it possible that some other function in the program is causing this problem? Thanks!
From MSDN: "The OFSTRUCT structure contains a pathname string member whose length is limited to OFS_MAXPATHNAME characters. OFS_MAXPATHNAME is currently defined to be 128. Because of this, you cannot use the OpenFile function to open a file whose path length exceeds 128 characters. The CreateFile function does not have such a path length limitation."
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
quote:Original post by dalleboy
From MSDN: "The OFSTRUCT structure contains a pathname string member whose length is limited to OFS_MAXPATHNAME characters. OFS_MAXPATHNAME is currently defined to be 128. Because of this, you cannot use the OpenFile function to open a file whose path length exceeds 128 characters. The CreateFile function does not have such a path length limitation."


I don´t think "cdabc.bmp" exceeds 128 characters. The problem must be somewhere else.

I can't tell you why it's not working, but I can tell you to switch over to CreateFile. MSDN says OpenFile is there to support 16-bit versions of Windows, which not a lot of people use anymore

[edited by - Zipster on August 19, 2002 3:58:27 AM]
quote:Original post by Ignacio Liverotti
I don''t think "cdabc.bmp" exceeds 128 characters. The problem must be somewhere else.

Read my post again, MSDN said: "you cannot use the OpenFile function to open a file whose path length exceeds 128 characters". And with path I think they mean the full path to the file including the drive, subdirectories and the file itself.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Thanks for your posts! I´ll rewrite the function using CreateFile.

dalleboy: I think my path exceeded the 128 characters, because it is c:\archivos de programa\microsoft visual studio\... a lot more. When I read your first post I tought you referred to the file´s name.

Thanks for your answers again! During my next section (I have a dialup connection) I´ll tell you if CreateFile did the trick.

This topic is closed to new replies.

Advertisement