Search code examples
c++cwindowswinelnk

Wine linker error: trying to create .lnk


I'm trying to create an .lnk file programatically. I would prefer to use C, but C++ is fine (and is what all the MSDN stuff is in).

The relevant code sample is:

#include <windows.h>
#include <shobjidl.h>
#include <shlguid.h>

HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc) {
  HRESULT hres;
  IShellLink* psl;

  /* Get a pointer to the IShellLink interface. */
  hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                          IID_IShellLink, (LPVOID*)&psl);
  return hres;
}

I'm trying to comple with wineg++ using:

wineg++ -mno-cygwin -o t t2.cpp

And I'm getting the following errors:

t2-Tw9YPp.o: In function `CreateLink(char const*, char const*, char const*)':
t2.cpp:(.text+0x34): undefined reference to `IID_IShellLinkA'
/usr/bin/ld: t2-Tw9YPp.o: relocation R_386_GOTOFF against undefined hidden symbol `IID_IShellLinkA' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
winegcc: i486-linux-gnu-g++ failed

Any ideas?


Solution

  • The solution seems to be to change the includes section to:

    #define INITGUID
    #include <windows.h>
    #include <shobjidl.h>
    #include <shlguid.h>
    #include <initguid.h>
    

    ie, add #define INITGUID before everything and include #include <initguid.h>

    I have no idea why this works.

    I also had to add -lole32 to fix an error that came up after the cited one was resolved.

    The code compiles... now to see if I can make it do what I need.