It's best to think of these in two parts. The Windows API part and then the 
interfacing with Pascal part.

SaveAsFileName.lpstrFile = long pointer to a (C) string filename buffer

This buffer isn't created for you, you provide it and tell Windows it's size.

If you were to just do

StrPLCopy( SaveAsFileName.lpstrFile, DefaulSaveAsFileName, Max_Path+1);

there is no buffer there to receive DefaultSaveAsFileName. (or more correctly 
the lpstrFile pointer will point to random memory).

So, you first create the buffer, StrPLCopy the default string into it, and then 
pass it to the Windows API.

On return, it uses that same buffer (Windows doesn't have to create the buffer 
because you did) and knows the maximum it can place into the buffer (because 
you provided that information).

Afterwards you can take that buffer (a C-string) and convert it to something 
Pascal-like again.

This is important because almost everything you do with the Windows API will be 
some variant of this procedure and you need to be able to repeat this every 
time you use it without bugs 🙂

--
Alexander Grotewohl
https://dcclost.com
________________________________
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> on behalf of James 
Richters via fpc-pascal <fpc-pascal@lists.freepascal.org>
Sent: Monday, June 21, 2021 1:56 PM
To: 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org>
Cc: James Richters <james.richt...@productionautomation.net>; 'Jean SUZINEAU' 
<jean.suzin...@wanadoo.fr>
Subject: Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default 
name

>I would prefer to use
> StrPLCopy( SaveAsFileNameBuffer, DefaulSaveAsFileName,
SizeOf(SaveAsFileNameBuffer));
>instead of
>  SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);

I'm curious what the difference is between StrPLCopy() and PChar()

I wonder if PChar() was my problem.. maybe I don't need the buffer, maybe I
just needed:
StrPLCopy( SaveAsFileName.lpstrFile, DefaulSaveAsFileName, Max_Path+1);
?

James

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to