分类:
2008-02-29 13:25:46
//code by kruglinski,2006-10-30
#include "atlbase.h"
#include "atlconv.h"
#include "shlobj.h"
#include "iostream"
using namespace std;
LPCTSTR GetLnkTarget(LPCTSTR lpszLnkFile)
{
static TCHAR chTarget[MAX_PATH];
memset(chTarget,0,sizeof(chTarget));
USES_CONVERSION;
IShellFolder *Folder=NULL;
SHGetDesktopFolder(&Folder);//取得Shell根文件夹
if(Folder)
{
ULONG uRet=0;
LPITEMIDLIST pIDL=NULL;
ULONG uAttr=0;
//得到文件IDL
if(SUCCEEDED(Folder->ParseDisplayName(GetDesktopWindow(),NULL,T2W(lpszLnkFile),&uRet,&pIDL,&uAttr)))
{
IShellLink *Link=NULL;
Folder->BindToObject(pIDL,NULL,__uuidof(IShellLink),(void**)&Link);//得到IShellLink接口
if(Link)
{
uRet=0;
WIN32_FIND_DATA wfd={0};
//得到指向的目标位置
Link->GetPath(chTarget,MAX_PATH,&wfd,SLGP_UNCPRIORITY);
Link->Release();
}
}
Folder->Release();
}
return chTarget;
}
int main(void)
{
CoInitialize(NULL);
LPCTSTR lpszTarget=GetLnkTarget("C:\\jjwang2.pgd.lnk");
if(lstrlen(lpszTarget))
cout<
CoUninitialize();
return 0;
}