Hi, I need a function like GetOpenFileName that returns the full path along with the name of the file of the file that user the selected. The one that I am using only returns the file name and the extension.
Posted on 2003-04-10 13:54:25 by x86asm
set lpstrFile member of OPENFILENAME struct to point at some
char array in your program, and GetOpenFileName will return the full path of the
choosen file, to that array.

win32 api guide also says about 'lpstrFile'-member

'Pointer to a buffer that contains a filename used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, filename, and extension of the selected file.
'

I always zero-out the first byte of the buf pointer to by lpstrFile-member, and
it works ok.
Posted on 2003-04-10 14:48:10 by david
and indeed you have to make sure the first char is zero before calling that api (well, that or have it be a valid path+filename).
Posted on 2003-04-10 15:38:02 by f0dder
And definitely make sure that the size of that buffer will be large enough for any of the path/filename the user may choose.

If your program is strictly for your own use, you can determine yourself how your system is structured and reserve space accordingly. If your program is for "general consumption", you may want to include some error checking code unless you are very generous with the memory allocation.

(This very afternoon, I was trying to back-up some data on a CD and I was advised that some of the file names would have to be altered because they were too long!!!)

Raymond
Posted on 2003-04-10 21:46:20 by Raymond

And definitely make sure that the size of that buffer will be large enough for any of the path/filename the user may choose.

Use the MAX_PATH constant - defined as 260 in WinDef.h . Remember to add 1 for the trailing zero. In some very special cases this might not be enough, see Platform SDK: File Storage: File Systems: File Name Conventions. Quote:

The Unicode versions of several functions permit paths that exceed the MAX_PATH length if the path has the "\?\" prefix.


Humm.

If your program is strictly for your own use, you can determine yourself how your system is structured and reserve space accordingly. If your program is for "general consumption", you may want to include some error checking code unless you are very generous with the memory allocation.

For something as tiny as path buffers, you don't want to conserve this few bytes in expense of possible program limitations. And even for own-use-only, you ought to do a little error checking, so you get the swing of it for when you do "public" programs.


(This very afternoon, I was trying to back-up some data on a CD and I was advised that some of the file names would have to be altered because they were too long!!!)

Yeah. Stupid ISO limitations.
Posted on 2003-04-11 02:02:54 by f0dder