- void EnumDesktopLnkPath()
- {
- WCHAR szPath[MAX_PATH] = {0};
- SHGetSpecialFolderPathW(NULL, szPath, CSIDL_DESKTOPDIRECTORY, 0);
-
- IShellFolder* pShell = NULL;
- if(FAILED(SHGetDesktopFolder(&pShell)))
- {
- return ;
- }
- IShellFolder* pFolder = NULL;
- ITEMIDLIST* pItem = NULL;
- if(FAILED(pShell->ParseDisplayName(NULL, NULL, szPath, NULL, &pItem, NULL)))
- {
- return ;
- }
- if(FAILED(pShell->BindToObject(pItem, NULL, IID_IShellFolder, (LPVOID*)&pFolder)))
- {
- return ;
- }
- pShell->Release();
-
- if(NULL == pFolder)
- {
- return ;
- }
-
- IEnumIDList* pEnum = NULL;
- if(FAILED(pFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &pEnum)))
- {
- return ;
- }
- pItem = NULL;
- ULONG ulFetched = 0;
-
- WCHAR szLnkPath[MAX_PATH] = {0};
- WCHAR szLnkName[MAX_PATH] = {0};
- LPCWSTR pszLnkName(L".lnk");
-
- WIN32_FIND_DATAW fd = {0};
- while(S_OK == pEnum->Next(1, &pItem, &ulFetched))
- {
-
- SHGetDataFromIDListW(pFolder, pItem, SHGDFIL_FINDDATA, &fd, sizeof(fd));
- swprintf(szLnkName, L"%s", fd.cFileName);
- if(0 == wcscmp(wcsrchr(szLnkName, L‘.‘), pszLnkName))
- {
- swprintf(szLnkPath, L"%s//%s", szPath, szLnkName);
- AfxMessageBox(CString(szLnkPath));
-
- }
- }
- pEnum->Release();
- pFolder->Release();
- }
-
- BOOL ParseLnk2Path(LPCWSTR pszLnkName)
- {
- ::CoInitialize(NULL);
- IShellLink* pShell = NULL;
- IPersistFile* pFile = NULL;
- if(S_OK == ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&pShell))
- {
- if(S_OK == pShell->QueryInterface(IID_IPersistFile, (LPVOID*)&pFile))
- {
- pFile->Load(pszLnkName, STGM_READWRITE);
- TCHAR szPath[MAX_PATH] = {0};
- pShell->GetPath(szPath, MAX_PATH, NULL, SLGP_UNCPRIORITY);
- AfxMessageBox(CString(szPath));
- }
-
- }
- pShell->Release();
- pFile->Release();
- ::CoUninitialize();
- return TRUE;
- }
http://blog.csdn.net/visualeleven/article/details/6433330