c++ – How to create shortcuts using C ++, WinAPI

Question:

I am writing an installer, which, as is customary, should create a shortcut on the desktop and a group in the Start menu.

Found on the net many variations of the same shortcut creation function which is based on Shellapi. MinGW displays two errors when compiling code with this function:

  1. undefined reference to `CoCreateInstance @ 20 '

  2. undefined reference to `IID_IPersistFile '

At the same time, without underlining anything in red in the code. It doesn't understand simple SHCreateShortcut() either. Static compilation is very critical!

Actually the question: is it really possible to create a shortcut except through Shell? Is it not possible to simply WriteFile(..."Link.lnk"...) , having previously WriteFile(..."Link.lnk"...) necessary paths and names into the buffer variable of the file being created after a certain sequence of bytes, which is responsible for identifying the parameters of the shortcut? If so, please tell me these sequences (markers). Or maybe there are other ways to create shortcuts?

Answer:

You see, without Shell... probably you can – somehow MS do it :)? only it will be difficult and intolerable – theoretically, the format can change.

Your problem, it seems, is simply that the required library is not connected to the project (as far as I remember, Shell32.lib ).

Scroll to Top