1

I want to programmatically create a Windows shortcut (.lnk file) to a folder. To do this, I tried this code snippet. However, I get the compilation error C2371 'WebBrowser': redefinition; different basic types in C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\exdisp.h line 2367.

Is there a C++17 std::filesystem API for this? If not, how can I fix the compilation error from above? Even with cleaned up includes, the error persists:

#include <Windows.h>
#include <shlguid.h>
#include <shobjidl_core.h>

Using the mklink command yields:
The device does not support symbolic links.
So that doesn't work either, maybe because this is an external SSD.

What else could I try?

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • I suggest asking another question which is focused just on the includes. The error you are getting has nothing at all to do with the `IShellLink` interface or even COM. Do you get the error with nothing at all in your program except the three `#include` lines in your question? Might be time to repair-install your copy of the Windows SDK. – Ben Voigt Jan 10 '23 at 23:17
  • If you want to solve the question yourself, search for the identifier `WebBrowser` in the files you are including, and pay close attention to what `#if` guards are surrounding that code (you want to just skip over it, not needed for calling `IShellLink`) – Ben Voigt Jan 10 '23 at 23:20

1 Answers1

2

The first answer you linked to is the correct way. And it does not rely on WebBrowser at all. It will probably help to define some of the NO_XXX macros before including windows.h.

In my version of ShlGuid.h which is slightly older than yours, I see

#ifndef NO_SHDOCVW_GUIDS

#ifndef GUID_DEFS_ONLY
#include <exdisp.h>
#include <shldisp.h>
#endif

so you can use NO_SHDOCVW_GUIDS to excise the troublesome header that you weren't wanting anyway.

If you wanted support for WebBrowser and the kitchen sink, another fix might be moving #include <windows.h> after ShlGuid.h, as shown e.g. here: https://stackoverflow.com/a/73422757/103167


Links are something that differ a fair amount from filesystem to filesystem, so difficult to standardize. Shell links (.lnk files) are filesystem-independent, but only work on MS Windows (completely non-portable) which also is a strike against finding support in a standard API.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720