bool GetFileList(std::string path)
{
path += "\\*";
CFileFind finder;
BOOL working = finder.FindFile(path.c_str());
while (working)
{
working = finder.FindNextFile();
if (!finder.IsDirectory() && !finder.IsDots())
{
if(finder.GetFileName() == "test.lnk")
return true;
}
}
return false;
}
bool findLink()
{
char Path[MAX_PATH+1];
std::string strDestDir;
LPITEMIDLIST pidl;
LPMALLOC pShell;
if(SUCCEEDED(SHGetMalloc(&pShell)))
{
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOPDIRECTORY,&pidl)))
{
if(!SHGetPathFromIDList(pidl,Path))
{
pShell->Free(pidl);
}
pShell->Release();
strDestDir = Path;
return GetFileList(strDestDir);
}
}
return false;
}
bool CreateLink2Desktop()
{
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
IShellLink *pisl;
hr = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pisl);
if (SUCCEEDED(hr))
{
IPersistFile* pIPF;
TCHAR pszPeFileName[MAX_PATH+1] = {0};
GetModuleFileName(NULL, pszPeFileName, MAX_PATH);
pisl->SetPath(pszPeFileName);
hr = pisl->QueryInterface(IID_IPersistFile, (void**)&pIPF);
if (SUCCEEDED(hr))
{
WCHAR szStartPath[MAX_PATH] = {0};
SHGetSpecialFolderPathW(NULL,szStartPath, CSIDL_DESKTOP, 0);
PathAppendW(szStartPath,L"test.lnk");
USES_CONVERSION;
LPCOLESTR lpOleStr = szStartPath;
pIPF->Save(lpOleStr, FALSE);
pIPF->Release();
}
pisl->Release();
}
CoUninitialize();
}
return true;
}