Use SetString if your source memory reagion with characters is not null-terminated…
Posted by jpluimers on 2020/03/03
Too many people forget this (including myself) every now and then) so here is a reminder to use the [WayBack] SetString
method when assigning strings from memory regions having characters but no null terminator:
Anyway, assuming that you use a Unicode Delphi you want to use SetString in its place:
SetString(password, PWideChar(Credential.CredentialBlob), Credential.CredentialBlobSize div 2);
It was by David Heffernan commenting on [WayBack] I have this code sample on StackOverflow using a function WideCharToWideString… I can’t seem to find anything on this function… – Nils Guillermin – Google+.
Note that like the above Delphi 2009 link (where it is a WideChar function to Unicode string conversion function), it was also available in Delphi 2007 and earlier as [WayBack] SetString
.
–jeroen
Leave a comment