Article View: borland.public.cppbuilder.nativeapi
Article #12406Failed to resolve explorer lnk from the taskbar
From: Angus
Date: Sun, 07 Dec 2003 03:04
Date: Sun, 07 Dec 2003 03:04
131 lines
6188 bytes
6188 bytes
Hi, the following function ordinarily happily resolves a link to give
filename etc. But when applied to certain taskbar icons, such as explorer,
PathName comes out as NULL. Is there something obvious that i'm not doing?
many thanks, Angus.
bool MXMAPI::ResolveDeskTopIcon(HWND hwnd, LPCSTR
pszShortcutFile,AnsiString& FileName,AnsiString& PathName,AnsiString&
Arguments,AnsiString& Description, WORD& Hotkey,AnsiString&
IconPath,AnsiString& GetWorkingDirectory,int& IconIndex,int&
GetShowCommand){
try{
WORD HK;
WORD* Hotkeyptr = &HK;
int GSCmd;
int* GetShowCommandptr = &GSCmd;
int IconI;
int* IconIndexptr = &IconI;
HRESULT hres;
char szGotPath[MAX_PATH];
char szDescription[MAX_PATH];
char szArguments[MAX_PATH];
char szIconPath[MAX_PATH];
char szGetWorkingDirectory[MAX_PATH];
WIN32_FIND_DATA wfd; //file data.. size..when.. name.. extension etc.
//Before creating our CoCreatInstance, we first must initialise the com
library!
if(SUCCEEDED(CoInitialize(NULL))){
IShellLink* psl;// Shell Link Interface
IPersistFile *ppf; // Interface to Shortcut
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,IID_IShellLink,(void**) &psl);
if(SUCCEEDED(hres)){
// Get a pointer to the IPersistFile interface.
hres = psl->QueryInterface(IID_IPersistFile,(void**) &ppf);
wchar_t wsz[MAX_PATH];// Ensure string is Unicode.
if(SUCCEEDED(hres)){
AnsiString FilePath(pszShortcutFile);
wchar_t wFilePath[MAX_PATH];
FilePath.WideChar(wFilePath, MAX_PATH);
// use the IPersistFile::Load function to load the shortcut
if(SUCCEEDED(ppf->Load(wFilePath, STGM_READ))){
// use the IShellLink::Resolve function to resolve the link
if(SUCCEEDED(psl->Resolve(NULL,SLR_INVOKE_MSI|SLR_NOUPDATE|SLR_NO_UI))){//
SLR_ANY_MATCH))){
// if (SUCCEEDED(psl->Resolve(NULL,SLR_INVOKE_MSI))){//
SLR_ANY_MATCH))){
// get the path of the link's target
WIN32_FIND_DATA wfd;
char filename[MAX_PATH];
if(SUCCEEDED(psl->GetPath(filename, MAX_PATH,&wfd,
SLGP_UNCPRIORITY))){
char newpathname[MAX_PATH];
LPITEMIDLIST pidl;
psl->GetIDList(&pidl); //Getidlist creates this
object..i free it
SHGetPathFromIDList(pidl, newpathname);
if(pidl){
delete pidl;
pidl = NULL;
}
PathName = AnsiString(newpathname);
FileName = ExtractFileName(PathName);
if(FileName.IsEmpty()){
Application->MessageBox("Unable to Resolve
Desktop Icon.\n.","Messenger",MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
return false;
}
}//end succeeded
else throw Exception("Unable to resolve lnk filename");
char description[MAX_PATH*2];
if(SUCCEEDED(psl->GetDescription(description,
MAX_PATH*2)))//SLGP_SHORTPATH
Description = description;
else throw Exception("Unable to resolve lnk
description");
char arguments[MAX_PATH];
if(SUCCEEDED(psl->GetArguments(arguments,
MAX_PATH)))//SLGP_SHORTPATH
Arguments = arguments;
else throw Exception("Unable to resolve lnk Arguments");
if(SUCCEEDED(psl->GetHotkey(Hotkeyptr)))//SLGP_SHORTPATH
Hotkey = HK;
else throw Exception("Error:Unable to resolve lnk
Hotkey");
char iconlocation[MAX_PATH];
if(SUCCEEDED(psl->GetIconLocation(iconlocation,MAX_PATH,IconIndexptr))){//SL
GP_SHORTPATH
IconPath = AnsiString(iconlocation);
IconIndex = IconI;
}
else throw Exception("Unable to resolve lnk
IconLocation");
char workingdir[MAX_PATH];
if(SUCCEEDED(psl->GetArguments(workingdir,
MAX_PATH)))//SLGP_SHORTPATH
GetWorkingDirectory = workingdir;
else throw Exception("Unable to resolve lnk
IconLocation");
if(SUCCEEDED(psl->GetShowCmd(GetShowCommandptr)))//SLGP_SHORTPATH
GetShowCommand=GSCmd;
else throw Exception("Unable to resolve lnk
IconLocation");
}
else throw Exception("Failed IShell Link- level 1");
}
else throw Exception("Failed IShell Link - Level 2");
}
ppf->Release(); // Release pointer to IPersistFile interface.
psl->Release(); // Release pointer to IShellLink interface.
}
else
throw Exception("IShellLink Failed");
CoUninitialize();
}
else
throw Exception("IShellLink Failed");
}catch(Exception &e){
e.Message += "Error: -(ResolveIt) mxm";
Application->ShowException(&e);
return false;
}
return true;
}
Technical Details
Message-ID:
<3fd298ae@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ebe7a1f15ea83f48,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-12-06 19:09:15 PST Reply-To: "Angus" <anguspickton@yahoo.com> From: "Angus" <aguspickton@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Failed to resolve explorer lnk from the taskbar Date: Sun, 7 Dec 2003 16:04:26 +1300 Lines: 133 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 203.173.216.225 Message-ID: <3fd298ae@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1070766254 203.173.216.225 (6 Dec 2003 19:04:14 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail