Thursday, June 12, 2008

SHFileOperation / Vista and oh boy ...

Yesterday I reported problems using SHFileOperation on Vista in a multi threading application. I experienced problems overwriting files when running Vista. The problems didn't occur running XP or Windows 2003 server.

For starters: it has nothing to do with multi threading applications - that was a false assessment on my part. I should stop working so late :-(

Comments from other programmers made me look again and create a small program that demonstrated the problem. I could not reproduce it using the small demo. So what gives?

It turned out the problems were cause by the specification of the file paths. The program I'm working on synchronizes folders, having the source on the web or on a local file system.

It turned out I was feeding paths using a '/' as a folder delimiter instead of a '\'. XP and Windows 2003 don't have a problem with that, Vista does...

In this case, changing the forward slashes to backslashes solved the problem. Still, kind of weird, but a smaller problem than SHFileOperation not being thread safe.

Bye,
Bart

Wednesday, June 11, 2008

SHFileOperation not thread safe under Vista

I found the 'cause' of the problems with the SHFileOperation function in Vista I reported earlier. It turns out that this function is not thread safe under Vista. It works fine with earlier operating systems when used in a multi threading application.

For now, the problem in my situation was (somewhat) easy to fix. I now execute the ShFileOperation in the main thread (using Synchronize) and that solved the problem with the utilities that I was working on. I can imagine that for larger application a bit more work would be involved. But maybe this little piece of information helps others.

I will implement the IFileOperation interface for Vista later on, but for now it can wait...

Bye,
Bart

IFileOperation replaces SHFileOperation on Vista

Today I got some reports from users that part of our file handling functions gave irregular results. On my development machine (a Windows 2003 Server) all was well and I could not replicate the problems.


After some digging into these issues I found a couple of postings (this one in de MSDN amongst others) about a new interface (IFileOperation) in Vista that replaces the SHFileOperation function.


Now, most of my code works just fine, but I have some specific problems with overwriting files that already exist. Some get overwritten, others don't. I suspect the SHFileOperation functions that (apparently) are still availble under Vista aren't quite backwards compatible.


Luckily I have created some wrapper functions in my code around the SHFileOperation functions, so it will be fairly easy to implement the IFileOperation method of Vista. But, being under pressure as always, this wasn't what I was waiting for right now :-o.



If I encounter any special issues I will let you know.



Bye,

Bart