The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

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 [WayBackSetString 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.