转载原文
http://blog.csdn.net/jarvischu/article/details/5799930
- {
- //创建快捷方式
- CString lpszPathLink("C:/aaa.lnk");
- LPCSTR lpszPathObj="C:/aaa.txt";
- LPCSTR lpszDesc="link for a txt";
- CoInitialize(NULL);
- HRESULT hres;
- IShellLink* psl;
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
- IID_IShellLink, (LPVOID*)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
- //设置快捷方式的目标路径,添加描述
- psl->SetPath(lpszPathObj);
- psl->SetDescription(lpszDesc);
- // Query IShellLink for the IPersistFile interface for saving the
- // shortcut in persistent storage.
- hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
- if (SUCCEEDED(hres))
- {
- WCHAR wsz[MAX_PATH];
- // Ensure that the string is Unicode.
- MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
- // TODO: Check return value from MultiByteWideChar to ensure
- // Save the link by calling IPersistFile::Save.
- hres = ppf->Save(wsz, TRUE);
- ppf->Release();
- }
- psl->Release();
- }
- // return hres;
- CoUninitialize();
- }