tags:

views:

590

answers:

2

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?

+2  A: 

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.

Rob Kennedy
Adding -luuid doesn't change the error messages. It doesn't error about not finding the library, just the error is not changed.
singpolyma
I don't have Wine, so I can't say for certain what library it IS defined in. You can see what a Unix library file contains with elfdump. Maybe that works for Wine libs, too, so you could search your lib folder for the file you need.
Rob Kennedy
I downloaded Wine. I find the string "IID_IShellLinkA" in shell32.dll.so.
Rob Kennedy
A: 

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.

singpolyma