🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.deployment
Article #212

how to get the target of a shortcut

#212
From: KLo
Date: Tue, 25 Jan 2005 08:07
47 lines
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();
    }
}
Technical Details
Message-ID: <20050125160657.5FCB.GETFUN@btamail.net.cn>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f8e54,9496033065fc0dd8,start
X-Google-Attributes: gidf8e54,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 25 Jan 2005 16:07:36 +0800
From: KLo <getfun@btamail.net.cn>
Newsgroups: borland.public.cppbuilder.deployment
Subject: how to get the target of a shortcut
Message-ID: <20050125160657.5FCB.GETFUN@btamail.net.cn>
MIME-Version: 1.0
X-Mailer: Becky! ver. 2.11.02 [CN] with BkNews Plug-In ver. 2.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 202.95.19.28
X-Trace: newsgroups.borland.com 1106640456 202.95.19.28 (25 Jan 2005 00:07:36 -0800)
Lines: 49
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail