Tuesday, July 31, 2007

.Net, IronPython and the shell

One step forwards, two steps back, trying to get a uniformly applicable method to get the displayed icon for a file-name that doesn't drag in attributed code at some point.

We can P/Invoke to get file icons through SHGetFileInfo -- but that involves attribute decorated methods in a C# shim.

We might be able to get at IExtractIcon via COM Interop starting from the Shell like this:

though that route doesn't yet work on Mono (GetTypeFromProgID isn't yet implemented -- and the type being of type System.__ComObject, that's probably not there either). And in any case we still need to either P/Invoke DestroyIcon or read the icon resources directly from PE format, and manage the object ourselves, even if all the other argument passing works.

We could use Icon.ExtractAssociatedIcon if only it didn't restrict itself to just files that exist (in particular, unlike SHGetFileInfo, it does not do folders, or drives, let alone abstract allusions to files by their extension).

*sigh*

No comments :