Pregunta

Estoy tratando de crear un archivo .lnk programáticamente. Preferiría usar C, pero C ++ está bien (y es en lo que están todas las cosas de MSDN).

El ejemplo de código relevante es:

#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;
}

Estoy tratando de completar con wineg ++ usando:

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

Y obtengo los siguientes errores:

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

¿Alguna idea?

¿Fue útil?

Solución

La solución parece ser cambiar la sección de inclusión a:

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

es decir, agregue #define INITGUID antes de todo e incluya #include <initguid.h>

No tengo idea de por qué esto funciona.

También tuve que agregar -lole32 para corregir un error que surgió después de que se resolvió el citado.

El código se compila ... ahora para ver si puedo hacer que haga lo que necesito.

Otros consejos

El vinculador se queja de que no sabe dónde se define IID_IShellLinkA. Tiene la declaración en un encabezado, pero probablemente le falta una biblioteca. Creo que está definido en libuuid , así que inclúyalo en su comando de enlace con -luuid. El vinculador probablemente esté configurado para incluir un cierto conjunto de bibliotecas automáticamente, incluidos kernel32 y user32, pero uuid podría no estar en esa lista.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top