none
Referencing shell32.dll in Windows7 errors on XP RRS feed

  • Question

  • In my .NET 4.0 project, I've referenced shell32.dll (embed Interop Types) to get access to GetDetailsOf(). It works fine on Windows7 (64-bit) and Vista (32-bit), but on XP (clean install + security updates + .NET 4.0 Client Framework), it dies on

    Shell aShell = new Shell();

    I guess the problem has to do with the different version that XP has, but I don't really have a clue about how to solve this.

    I've searched for code to call the shell32.dll directly, but there's none using GetDetailsOf.

    Thanks in advance.

     

    BTW I've tried to WindowsAPICodePack, and it dies in the WPFExplorerBrowserDemo (compiled for .NET 4.0) on

    var sortedKnownFolders =
    from folder in KnownFolders.All
    where (folder.CanonicalName != null &&
    folder.CanonicalName.Length > 0 && 
    ((ShellObject)folder).Thumbnail.BitmapSource != null &&
    folder.CanonicalName.CompareTo("Network") != 0 &&
    folder.CanonicalName.CompareTo("NetHood") != 0)
    orderby folder.CanonicalName
    select folder;
    Sunday, August 8, 2010 3:12 PM

Answers

  • The problem was that XP shell32.dll doesn't implement IShellDispatch5. I solved it by extracting the interface declarations from Interop.Shell32.dll, and including only the ones I need, directly into the software.

    Thanks a lot for your help JohnWein.

    • Marked as answer by _patrick_ Monday, August 9, 2010 11:07 AM
    Monday, August 9, 2010 11:07 AM

All replies

  • Compile your program for x86 and reference a 32 bit XP shell32.dll.  Ensure that CopyLocal is checked.
    Sunday, August 8, 2010 3:53 PM
  • Thanks that worked, but I'm looking for a solution that doesn't require to ship additional assemblies. I expected CopyLocal and Embed to be equivalent, but as I see, this isn't the case.

    Any solution to use shell32 that doesn't require to ship additional assemblies?

    Sunday, August 8, 2010 4:31 PM
  • Thanks that worked, but I'm looking for a solution that doesn't require to ship additional assemblies. I expected CopyLocal and Embed to be equivalent, but as I see, this isn't the case.

    Any solution to use shell32 that doesn't require to ship additional assemblies?


    Uncheck CopyLocal and try it.
    Sunday, August 8, 2010 5:43 PM
  • I tried, but that doesn't work. It dies just like when referencing the Windows7 library.

    Sunday, August 8, 2010 7:04 PM
  • Then you can either CopyLocal, use WindowScriptHost to access the shell functions, or pinvoke. 
    Sunday, August 8, 2010 7:18 PM
  • I tried, but the program dies just like when referencing the Windows 7 library.

    One correction though, the program doesn't die on Shell aShell = new Shell(); but on the next command, because aShell is null.

    Sunday, August 8, 2010 7:23 PM
  • "Compile your program for x86 and reference a 32 bit XP shell32.dll.  Ensure that CopyLocal is checked."

    "Thanks that worked"

    "Then you can either CopyLocal, use WindowScriptHost to access the shell functions, or pinvoke"

    "I tried, but the program dies just like when referencing the Windows 7 library."

    What works and what doesn't?

    Sunday, August 8, 2010 7:40 PM
  • My previous message "I tried, but that doesn't work" didn't show up, that's why I replied twice. Your response in-between didn't showup either.

    Resume:
    Referencing + Embedding, doesn't work
    Reference XP + local copy, does work
    Reference XP, without local copy, doesn't work

    I've tried to find a sample of pinvoke with GetDetailsOf, but haven't been able, except for the WindowsAPICodePack, but that has exactly the same problem.

    I've just looked at the WindowScriptHost, but that doesn't contain the function GetDetailsOf.

    Sunday, August 8, 2010 8:17 PM
  • I've just looked at the WindowScriptHost, but that doesn't contain the function GetDetailsOf.
    This method is a little obscure.  You use WSH to use the Shell scripting methods.  CopyLocal for COM interop avoids a lot of incompatabilities.  You reference the earliest version you want to interop with.  It will work with all later versions.  You just can't use any of the features unique to the later versions
    Sunday, August 8, 2010 10:11 PM
  • The problem was that XP shell32.dll doesn't implement IShellDispatch5. I solved it by extracting the interface declarations from Interop.Shell32.dll, and including only the ones I need, directly into the software.

    Thanks a lot for your help JohnWein.

    • Marked as answer by _patrick_ Monday, August 9, 2010 11:07 AM
    Monday, August 9, 2010 11:07 AM