Pregunta

I'm writing code that can update files (how uncommon and exciting !). When a file has been updated I need Windows Explorer to call the overlay extensions again, so that I always have the correct overlays over files. I figured I would do this with some p/invoke trickery (looking how TortoiseSVN is doing it), but I always get error 14007 and cant' find why. This is the code :

IntPtr ptr = Marshal.StringToHGlobalUni(FullName);
Shell.SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSH, ptr, IntPtr.Zero);
Win32Exception w = new Win32Exception(Marshal.GetLastWin32Error());
LOG.ErrorFormat("Error {0} calling SHChangeNotify : {1}", w.NativeErrorCode, w.Message);
Marshal.FreeHGlobal(ptr)

Fullname is the path of the file that's been updated. I get the following error :

Error 14007 calling SHChangeNotify : The requested lookup key was not found in any active activation context

What am I doing wrong here ?

FYI :

[DllImport("Shell32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern void SHChangeNotify(HChangeNotifyEventID wEventId, HChangeNotifyFlags uFlags, IntPtr dwItem1, IntPtr dwItem2);

SHCNE_UPDATEITEM = 0x00002000
SHCNF_PATH = SHCNF_PATHW = 0x0005
SHCNF_FLUSH = 0x1000
¿Fue útil?

Solución

The documentation for SHChangeNotify does not mention that the Win32 "last error" code is set on failure. Any value returned by GetLastError is meaningless.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top