//封装的创建快捷方式API
// szStartAppPath : 点击后启动的程序
// szAddCmdLine : 传给main函数的lpCmdLine
// szDestLnkPath : 快捷方式的保存路径
// szIconPath : 快捷方式显示的图标
bool CreateLinkFile(LPCTSTR szStartAppPath, LPCTSTR szAddCmdLine, LPCOLESTR szDestLnkPath, LPCTSTR szIconPath)
{
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
IShellLink *pShellLink;
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pShellLink);
if (SUCCEEDED(hr))
{
pShellLink->SetPath(szStartAppPath);
tstring strTmp = szStartAppPath;
int nStart = strTmp.find_last_of(TEXT("/\\"));
pShellLink->SetWorkingDirectory(strTmp.substr(0, nStart).c_str());
pShellLink->SetArguments(szAddCmdLine);
if (szIconPath)
{
pShellLink->SetIconLocation(szIconPath, 0);
}
IPersistFile* pPersistFile;
hr = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
if (SUCCEEDED(hr))
{
hr = pPersistFile->Save((szDestLnkPath), FALSE);
if (SUCCEEDED(hr))
{
return true;
}
pPersistFile->Release();
}
pShellLink->Release();
}
CoUninitialize();
}
return false;
}
//百度的string转换wstring
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}