Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IShell GetPath results in Access Violation (on some machines infrequently)

8 views
Skip to first unread message

moh...@gmail.com

unread,
Feb 24, 2005, 12:07:03 PM2/24/05
to
Hi all,

I am trying to resolve a shortcut link (target.lnk) using
IShellLink/IPersistFile interfaces. Here is the code that does it. Is
there something wrong with this? The GetPath() functions throws access
vioaltion on some machines and results in a crash sometimes.

std::wstring fullPath //contains path to shortcut target.lnk
TCHAR buf[MAX_PATH];
IShellLink* psl;

HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,IID_IShellLink, (void**)&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);
if (SUCCEEDED(hr))
{
// "load" the name and resove the link
hr = ppf->Load(fullPath.c_str(), STGM_READ);
if (SUCCEEDED(hr))
{
hr = psl->Resolve(NULL, SLR_UPDATE|SLR_NO_UI);
if (SUCCEEDED(hr))
hr = psl->GetPath(buf, MAX_PATH, &ffd, 0);
}
// Release interface pointers
ppf->Release();
}

// Release interface pointers
psl->Release();
}

Any help would be appreciated. Any suggestions are welcome. I am
seeing it on two WIN 2000 machines.

Thanks
M

Severian

unread,
Feb 25, 2005, 10:08:46 PM2/25/05
to

In comparing my link resolution code (written in C for a non-Unicode
application), to yours, I do not call Resolve() at all:

BOOL ResolveLink(LPCSTR plink, LPSTR pname)
{
HRESULT hres;
IShellLink* psl;
char fullpath[MAX_PATH];
WIN32_FIND_DATA wfd;
IPersistFile* ppf;
WORD wsz[MAX_PATH];

if (pname != plink)
strcpy(pname, plink); /* In case no resolution */
hres = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
if (SUCCEEDED(hres)) {
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf);
if (SUCCEEDED(hres)) {
MultiByteToWideChar(CP_ACP, 0, plink, -1, wsz, MAX_PATH);
hres = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
if (SUCCEEDED(hres)) {
hres = psl->lpVtbl->GetPath(psl, fullpath, MAX_PATH, &wfd, 0);
if (SUCCEEDED(hres) && fullpath[0]) {
if (!SevGetLongPathName(fullpath, pname, MAX_PATH))
strcpy(pname, fullpath); /* Don't return DOS name */
}
}
ppf->lpVtbl->Release(ppf);
}
psl->lpVtbl->Release(psl);
}
return SUCCEEDED(hres)
}

Whether coded in C or C++, it is the ugliest and most ridiculous way
to handle links (shortcuts) I have ever seen!

--
Sev

0 new messages