Cannot compile under Win7 and run under XP with dll reference RRS feed

  • Question

  • I have a C#/WPF Application that is running on an XP Embedded product.  The project has a reference to shell32.dll, which is used to create desktop shortcuts.  When the project is compiled, an Interop.Shell32.dll is added to the compiler output.  This has been working well when compiled on a WinXP computer using Visual Studio 2008.  When I started compiling on a Windows 7 computer, using Visual Studio 2010.  the Application no longer runs on the XP Embedded product and gives this error:  "Could not create shortcut... Exception: Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch5'.  This operation failed because the QueryInterface call on the COM component for the interface with IID \{86673B89-6CF2-4DE8-8767-F794EBE74F4E}' failed due to the following error: No such interface supported {Exception from HRESULT: 0x80004002 {E_NOINTERFACE}}.  Is there a project setting that allows an XP compatible Interop.Shell32.dll to be created?
    • Moved by CoolDadTx Wednesday, February 9, 2011 3:04 PM Not IDE related (From:Visual C# IDE)
    Tuesday, February 8, 2011 8:32 PM

All replies

  • This is the expected behavior. There is no project setting that can generate interop for XP shell32.dll on Windows 7, distributing the dll from XP to 7 is against your Windows end user license agreement.

    When you write code that is expected to run on earlier versions of COM server, don't use features only available on later version of COM servers. Generally speaking you should not use classes in a interop dll except when creating the COM objects. You should only use interfaces that are known to work with your deployment environment (IShellDispatch4, for example) to access the properties and methods of the object.

    This forum is not a catch-all forum for the code you can write in the IDE, otherwise the forums under the Windows Forms category and forums.asp.net won't be created in the first place. If you need more help in programming the shell, I suggest you to visit the shell programming forum.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Tuesday, February 8, 2011 9:49 PM
  • I think we get this error for console programs because we need to use [STAThead] but that is the default for Windows Forms. If the WPF application is [MTAThread] then it needs [STAThead].

    Sam Hobbs

    Wednesday, March 14, 2018 5:13 PM