<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
It's best to think of these in two parts. The Windows API part and then the interfacing with Pascal part.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
SaveAsFileName.lpstrFile = long pointer to a (C) string filename buffer</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
This buffer isn't created for you, you provide it and tell Windows it's size.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
If you were to just do</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:rgb(32, 31, 30);font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important">StrPLCopy(
 SaveAsFileName.lpstrFile, DefaulSaveAsFileName, Max_Path+1);</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:rgb(32, 31, 30);font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;">there is no buffer there to receive DefaultSaveAsFileName. (or more correctly the lpstrFile pointer will point to random memory).</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;"><br>
</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;">So, you first create the buffer, StrPLCopy the default string into it, and then pass it to the Windows API.</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;"><br>
</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;">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).</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;"><br>
</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;">Afterwards you can take that buffer (a C-string) and convert it to something Pascal-like again.</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;"><br>
</span></font></div>
<div style=""><font color="#201f1e"><span style="font-size: 14.6667px;">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
<span id="🙂">🙂</span></span></font></div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
--</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Alexander Grotewohl</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
https://dcclost.com</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> on behalf of James Richters via fpc-pascal <fpc-pascal@lists.freepascal.org><br>
<b>Sent:</b> Monday, June 21, 2021 1:56 PM<br>
<b>To:</b> 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org><br>
<b>Cc:</b> James Richters <james.richters@productionautomation.net>; 'Jean SUZINEAU' <jean.suzineau@wanadoo.fr><br>
<b>Subject:</b> Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">>I would prefer to use <br>
> StrPLCopy( SaveAsFileNameBuffer, DefaulSaveAsFileName,<br>
SizeOf(SaveAsFileNameBuffer));<br>
>instead of <br>
>  SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);<br>
<br>
I'm curious what the difference is between StrPLCopy() and PChar()<br>
<br>
I wonder if PChar() was my problem.. maybe I don't need the buffer, maybe I<br>
just needed:<br>
StrPLCopy( SaveAsFileName.lpstrFile, DefaulSaveAsFileName, Max_Path+1);<br>
?<br>
<br>
James<br>
<br>
_______________________________________________<br>
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org<br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</div>
</span></font></div>
</body>
</html>