Question

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?

Was it helpful?

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.

OTHER TIPS

The linker is complaining that it doesn't know where IID_IShellLinkA is defined. You have the declaration in a header, but you're probably missing a library. I think it's defined in libuuid, so include that in your linking command with -luuid. The linker is probably configured to include a certain set of libraries automatically, including kernel32 and user32, but uuid just might not be on that list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top