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!?

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.

Comments

  1. It's a skill test. :)  Double zero terminate? Blech!

    ReplyDelete
  2. 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...

    ReplyDelete
  3. 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.

    ReplyDelete
  4. 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...

    ReplyDelete
  5. Asbjørn Heid I see. The context for the double termination was not apparent in Lars' code.

    ReplyDelete
  6. 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

    ReplyDelete
  7. Asbjørn Heid I confused it... thank you for the oldnewthing link, interesting link.

    ReplyDelete

Post a Comment