Note 74: In the sample code for the SHGetFolderPath function, after the call I've reset the string length by re-casting it to PChar. This apparently useless line of code causes Delphi to reset the “Pascal string length” from the “C string length”, so that if you append another string to it you'll get the expected result. Do this operation every time you pass a string buffer to a Windows API function for it to be written.

This blog post is part of my "113 Delphi 2007 Handbook Notes" blogging project, to promote my new Delphi book.