Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the target of a shortcut

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
How can I get the target of a shortcut programmatically?
I found an example on the net that uses the IShellLink object, I cannot get it to work in Cbuilder.
Any ideas?
 
I could get it to work, after a while or two

void GetLinkTarget(LPCTSTR szLinkFullPath) {
/*
include <shlguid.h> and <shlobj.h>
and in &quot;project\options\directories and conditionals\conditional defines&quot;
add: NO_WIN32_LEAN_AND_MEAN;
*/
IShellLink* psl;
HRESULT hr = CoInitialize(NULL);

// create a link manager object and request its interface
hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if( SUCCEEDED(hr) ) {
// associate the manager object with the link file in hand
IPersistFile* ppf;
// Get a pointer to the IPersistFile interface.
hr = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);

// full path string must be in Unicode.
OLECHAR wsz[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, szLinkFullPath, -1, wsz, MAX_PATH);

// &quot;load&quot; the name
hr = ppf->Load(wsz, STGM_READ);
// and resolve the link
// hr = psl->Resolve(NULL, SLR_UPDATE);

// Get the path to the link target.
WIN32_FIND_DATA ffd; // we get those free of charge
TCHAR buf[MAX_PATH]; // could have simply reused 'wsz'...
hr = psl->GetPath(buf, MAX_PATH, &ffd, 0);
Application->MessageBoxA( buf,&quot;DEBUG&quot;,0);
// not much to do, so just show some information
// cout << &quot;Pointed item: &quot; << buf << endl;
// cout << &quot;Type: &quot; << ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
// &quot;folder\n&quot; : &quot;file\n&quot;);

// Release all interface pointers (both belong to the same object)
ppf->Release();
psl->Release();
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top