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?
The first answer you linked to is the correct way. And it does not rely on
WebBrowserat all. It will probably help to define some of theNO_XXXmacros before includingwindows.h.In my version of
ShlGuid.hwhich is slightly older than yours, I seeso you can use
NO_SHDOCVW_GUIDSto 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>afterShlGuid.h, as shown e.g. here: https://stackoverflow.com/a/73422757/103167Links 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.