#include "stdafx.h"
#include <shlobj.h>
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
//创建2个接口
CComPtr<IShellLink> spShellLink;
HRESULT hr=spShellLink.CoCreateInstance(CLSID_ShellLink);
CComPtr<IPersistFile> spPersistFile;
//取得此EXE的文件名及路径
TCHAR FileName[MAX_PATH+1];
ZeroMemory(FileName, MAX_PATH+1);
GetModuleFileName(NULL, FileName, MAX_PATH);
hr=spShellLink->SetPath(FileName);
hr=spShellLink->SetDescription("备注:随便写点");
hr=spShellLink->QueryInterface(IID_IPersistFile, (void **)&spPersistFile);
//取得桌面的全路径
LPITEMIDLIST pidl;
hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl);
TCHAR szPath[MAX_PATH];
SHGetPathFromIDList(pidl, szPath);
//创建快捷方式
CComBSTR strLinkFilePath(szPath);
strLinkFilePath.Append(L"\\测试.lnk");
hr=spPersistFile->Save(strLinkFilePath, TRUE);
spPersistFile.Release();
spShellLink.Release();
::CoUninitialize();
return 0;
}