[fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

Jean SUZINEAU jean.suzineau at wanadoo.fr
Sat Jun 19 01:15:27 CEST 2021

I'm not familiar with GetSaveFileNameA, but usually for the size of a 
FileName  buffer I use the constant MAX_PATH which is defined in unit 

MAX_PATH itself seems to be an alias from system unit where it is 
defined accordingly to the operating system (260 on windows, 4096 on 
Linux, 1024 on BSD, Solaris and Darwin).

Did you have a look at Microsoft's documentation for GetSaveFileNameA 
and the OPENFILENAMEA structure it takes as parameter ?


Particularly, you need to put in |nMaxFile |the size of the buffer 
pointed to by lpstrFile.

The folowing code works with a 120 characters long filename :

program test_GetSaveFileName;
     SysUtils, CommDlg;
const DefaultFilename= 'Test';
    Buffer: array[0..MAX_PATH] of Char; //size MAX_PATH + 1 for 
terminating null char
      StrPLCopy( Buffer, DefaultFilename, MAX_PATH);
      ofn.lStructSize:= sizeof(ofn);
      ofn.hInstance:= 0;
      ofn.lpstrFilter:= nil;
      ofn.lpstrCustomFilter:= nil;
      ofn.nMaxCustFilter:= 0;
      ofn.nFilterIndex:= 0;
      ofn.lpstrFile:= Buffer;
      ofn.nMaxFile:= Sizeof( Buffer);
      ofn.lpstrFileTitle:= nil;
      ofn.nMaxFileTitle:= 0;
      ofn.lpstrInitialDir:= nil;
      ofn.lpstrTitle:= 'test GetSaveFileNameA';
      ofn.Flags:= 0;
      ofn.nFileOffset:= 0;
      ofn.nFileExtension:= 0;
      ofn.lpstrDefExt:= nil;
      ofn.lCustData:= 0;
      ofn.lpfnHook:= nil;
      ofn.lpTemplateName:= nil;
      ofn.pvReserved:= nil;
      ofn.dwReserved:= 0;
      ofn.FlagsEx:= 0;
      if GetSaveFileNameA( @ofn)
          WriteLn( ofn.lpstrFile);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210619/5c4662b8/attachment.htm>

More information about the fpc-pascal mailing list