Thread View: borland.public.cppbuilder.deployment
1 messages
1 total messages
Started by KLo
Tue, 25 Jan 2005 08:07
how to get the target of a shortcut
Author: KLo
Date: Tue, 25 Jan 2005 08:07
Date: Tue, 25 Jan 2005 08:07
47 lines
2720 bytes
2720 bytes
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?
void GetLinkTarget(LPCTSTR szLinkFullPath) {
/*
include <shlguid.h> and <shlobj.h>
and in "project\options\directories and conditionals\conditional defines"
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);
// "load" 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,"DEBUG",0);
// not much to do, so just show some information
// cout << "Pointed item: " << buf << endl;
// cout << "Type: " << ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
// "folder\n" : "file\n");
// Release all interface pointers (both belong to the same object)
ppf->Release();
psl->Release();
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads