ShFileOperation fails with error 2 (file not found), then error 87 (invalid parameter). Filename and pathname is correct. Sometimes it works, sometimes, it doesn’t. Can’t see the pattern. Juggling all the flags doesn’t work… WTF!?
Reading the documentation again… oh…
SourceFileName := SourceFileName + #0;
TargetPath := TargetPath + #0;
I guess they really meant it when they said to double 0 terminate the strings… problem solved.

It’s a skill test. 🙂 Double zero terminate? Blech!
wasn’t this the thingy with “UniqueString” or something like that? I remember being forced to do that for some “ShellApi” command, I believe ShellExecute…
Bill Meyer It’s rather natural, you pass it a list of strings, terminated by an empty string.
Though I must admit I wonder why they didn’t go with array-of-pointers for this, as they do in so many other cases.
Dorin Duminica That’s something else. UniqueString just makes sure the string instance you get back has a reference count of one. But yes I do remember using it for some shell api stuff, but not why…
Asbjørn Heid I see. The context for the double termination was not apparent in Lars’ code.
Bill Meyer True, it’s one of those devils hiding in the details.
Here’s a link with some background as to why it’s used (which answers my earlier question): http://blogs.msdn.com/b/oldnewthing/archive/2011/05/11/10163169.aspx
Sadly the declaration in ShellAPI.pas hides this fact. If you look at the MSDN documentation[1] you’ll see that the to/from types are PCZZTSTR, a good clue that they’re not your average zero terminated strings.
However in Delphi the same members are declared as just another LPCSTR, which is just a regular zero terminated string[2]. Unicode versions share the same issue.
While of course both the PCZZTSTR type and the LPCSTR type looks the same to the compiler, they have different semantics (if that’s the right word, it’s late) which is lost in the Delphi conversion.
[1]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb759795
[2]: https://msdn.microsoft.com/en-us/library/cc230350.aspx
Asbjørn Heid I confused it… thank you for the oldnewthing link, interesting link.