Are you trying to call IShellLink::GetPath? If so, it needs to be called on a valid IShellLink object. The code in the linked thread is for C++ and will not compile in C. When faced with C++ code and you are using C, you have two choices.
The first is to leave the code as C++ and include it in your project as a seperate .cpp file. You will have to prepend the C++ function definitions with extern "C" so that they can be called from C code:
Then you will have to create a prototype at the top of your C file:
extern "C" BOOL GetShortcutTarget(LPCTSTR szShortcutFile, LPTSTR szTarget, SIZE_T cchTarget)
With this done, you should be able to call the C++ functions from your .c files.
BOOL GetShortcutTarget(LPCTSTR szShortcutFile, LPTSTR szTarget, SIZE_T cchTarget);
The other option, which usually involves more work, is to convert the code from C++ to C. Here is the GetShortcutTarget function converted to C:
To compile this with Dev-C++, add -luuid -lole32 to the Linker box under Project->Project Options->Parameters tab.
#include <objidl.h> /* For IPersistFile */
#include <shlobj.h> /* For IShellLink */
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "uuid.lib")
* Retrieves the path that a shortcut file points to.
* szShortcutFile The path to the shortcut file.
* szTarget Pointer to a buffer that will receive the target path.
* The buffer length should be at least MAX_PATH characters.
* cchTarget The size of the szTarget buffer, in characters.
* A non-zero value is returned on success. If the function fails zero
* will be returned. GetLastError can NOT be called to get an additional error code.
* Runtime requirements:
* CoInitialize or CoInitializeEx must have been called before using this function.
* Compile requirements:
* C. Include <windows.h>, <objidl.h> & <shlobj.h>. Link "uuid.lib".
BOOL GetShortcutTarget(LPCTSTR szShortcutFile, LPTSTR szTarget, SIZE_T cchTarget)
IShellLink* psl = NULL;
IPersistFile* ppf = NULL;
BOOL bResult = FALSE;
# if !defined(UNICODE)
if (0 == MultiByteToWideChar(CP_ACP, 0, szShortcutFile, -1, wsz, MAX_PATH) )
LPCWSTR wsz = szShortcutFile;
if (FAILED( CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &psl) ))
if (FAILED( psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (void **) &ppf) ))
if (FAILED( ppf->lpVtbl->Load(ppf, wsz, STGM_READ) ))
if (NOERROR != psl->lpVtbl->GetPath(psl, szTarget, cchTarget, NULL, 0) )
bResult = TRUE;
if (ppf) ppf->lpVtbl->Release(ppf);
if (psl) psl->lpVtbl->Release(psl);
if (!bResult && cchTarget != 0) szTarget = TEXT('\0');
#if 1 /* Test code. */
TEXT("C:\\Documents and Settings\\All Users\\Start Menu\\")
_tprintf(TEXT("The shortcut target is '%s'.\n"), szTarget);