Here's the deal as far as I've determined: at least as of Windows 8.1, "Explorer.exe" appears to strip out all combining characters before looking for the file. You can test this either in c# or a console (do chcp 65001
first to get in unicode mode). If you try to open a target named ปู (thai for "crab") it won't work, but if you remove the vowel mark under so that you have just ป, it will work. Further, if you have a folder named ป and you as it to open ปู, it will open the ป folder!
This explains why some other devs had no problem; the problem is not non-ascii: rather, it is filenames with composable characters. Not all languages use them, and even in languages that do, not all file names have them.
The good news is, there's a different way to open these that doesn't have this problem, which is described by @bert-huijben in this answer.
For completeness, here's the version similar to what I ended up using:
[DllImport("shell32.dll", ExactSpelling = true)]
public static extern void ILFree(IntPtr pidlList);
[DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr ILCreateFromPathW(string pszPath);
[DllImport("shell32.dll", ExactSpelling = true)]
public static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);
public void SelectItemInExplorer(string path)
{
var pidlList = ILCreateFromPathW(path);
if(pidlList == IntPtr.Zero)
throw new Exception(string.Format("ILCreateFromPathW({0}) failed",path));
try
{
Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
}
finally
{
ILFree(pidlList);
}
}