Article View: borland.public.cppbuilder.nativeapi
Article #9451IPersistFile::Load
From: Sten Larsson
Date: Thu, 08 Jul 2004 06:55
Date: Thu, 08 Jul 2004 06:55
81 lines
2960 bytes
2960 bytes
I'm using IPersistFile::Load to find the target of a "lnk" file. My
code is as follows (full code at bottom):
IShellLink *psl;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl)))
{
LPPERSISTFILE lppf;
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile,
reinterpret_cast<void **>(&lppf))))
{
wchar_t wIconPath[MAX_PATH + 1];
StringToWString(linkPath, wIconPath);
if (SUCCEEDED(lppf->Load(wIconPath, STGM_READ)))
It works fine, unless the file the link points to does not exist...
anyone have any tip on how to catch the resulting error message. I run
the app as a console app, and following error message comes as a
dialog box:
"The drive or network connection that the shortcut 'xxx' refers
to referst to is unavailable" ....
Anyone knows how to prevent the error message from appearing?
Thanks!
/sten
=============
string GetLinkTarget(const char* linkPath, bool coinit)
{
string retVal;
if (coinit)
{
CoInitialize(NULL);
}
IShellLink *psl;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl)))
{
LPPERSISTFILE lppf;
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile,
reinterpret_cast<void **>(&lppf))))
{
wchar_t wIconPath[MAX_PATH + 1];
StringToWString(linkPath, wIconPath); // my own function
if (SUCCEEDED(lppf->Load(wIconPath, STGM_READ)))
{
if (SUCCEEDED(psl->Resolve(NULL, SLR_ANY_MATCH)))
{
WIN32_FIND_DATA wfd;
char filename[MAX_PATH];
if (SUCCEEDED(psl->GetPath(filename, MAX_PATH,
&wfd, SLGP_UNCPRIORITY)))
{
retVal = filename;
}
}
}
lppf->Release();
}
psl->Release();
}
if (coinit)
{
CoUninitialize();
}
return retVal;
}
===
For direct email, remove _ and X.
Technical Details
Message-ID:
<u0rpe0lih7pjjkpgoujrtpv2ijfha62liq@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,88e58d05f3abd366,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Sten Larsson <s_t_enX@Xs_ten_l.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: IPersistFile::Load Date: Wed, 07 Jul 2004 23:55:01 -0700 Message-ID: <u0rpe0lih7pjjkpgoujrtpv2ijfha62liq@4ax.com> X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 66.81.114.178 X-Trace: newsgroups.borland.com 1089269940 66.81.114.178 (7 Jul 2004 23:59:00 -0700) Lines: 81 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail