QString sPathTarget
= [MY_EXE_PATH
];
QString sLinkArguments
= "link arguments";
QString sLinkIcon
= [MY_ICON_PATH
];
// This icon will be the LNK icon, but also the icon my app has in the taskbar when launched from the LNK
WCHAR pathDesktop[MAX_PATH];
HRESULT result = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, pathDesktop);
if (SUCCEEDED(result)) {
CoInitialize(NULL);
IShellLinkW* shellLink = NULL;
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
if (SUCCEEDED(result)) {
shellLink->SetPath(sPathTarget.toStdWString().c_str());
shellLink->SetArguments(sLinkArguments.toStdWString().c_str());
shellLink->SetIconLocation(sLinkIcon.toStdWString().c_str(), 0);
IPersistFile* persistFile;
result = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);
if (SUCCEEDED(result)) {
result = persistFile->Save(linkPath.toStdWString().c_str(), TRUE);
persistFile->Release();
bRet = true;
}
shellLink->Release();
}
}
QString sPathTarget = [MY_EXE_PATH];
QString sLinkName = "link name";
QString sLinkArguments = "link arguments";
QString sLinkIcon = [MY_ICON_PATH]; // This icon will be the LNK icon, but also the icon my app has in the taskbar when launched from the LNK
WCHAR pathDesktop[MAX_PATH];
HRESULT result = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, pathDesktop);
if (SUCCEEDED(result)) {
QString linkPath = QDir(QString::fromWCharArray(pathDesktop)).absoluteFilePath(QString("%1.lnk").arg(sLinkName));
CoInitialize(NULL);
IShellLinkW* shellLink = NULL;
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
if (SUCCEEDED(result)) {
shellLink->SetPath(sPathTarget.toStdWString().c_str());
shellLink->SetArguments(sLinkArguments.toStdWString().c_str());
shellLink->SetIconLocation(sLinkIcon.toStdWString().c_str(), 0);
IPersistFile* persistFile;
result = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);
if (SUCCEEDED(result)) {
result = persistFile->Save(linkPath.toStdWString().c_str(), TRUE);
persistFile->Release();
bRet = true;
}
shellLink->Release();
}
}
To copy to clipboard, switch view to plain text mode
Thanks,
Bookmarks