C++创建lnk

发布时间:2017-2-21 8:45:47 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"C++创建lnk",主要涉及到C++创建lnk方面的内容,对于C++创建lnk感兴趣的同学可以参考一下。

#include <shobjidl.h> #include <shlguid.h> #include <locale.h> static HRESULT CreateLink(TCHAR *lpszPathObj, TCHAR *lpszPathLink) { HRESULT hres; IShellLink* psl; // Get a pointer to the IShellLink interface. It is assumed that CoInitialize // has already been called. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; // Set the path to the shortcut target and add the description. psl->SetPath(lpszPathObj); // Query IShellLink for the IPersistFile interface, used for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); if (SUCCEEDED(hres)) { // Add code here to check return value from MultiByteWideChar // for success. // Save the link by calling IPersistFile::Save. hres = ppf->Save(lpszPathLink, TRUE); ppf->Release(); } psl->Release(); } return hres; } int main() { setlocale(LC_ALL, "chs"); TCHAR szLinkFilePath[MAX_PATH] = L"C:\\Documents and Settings\\All Users\\桌面\\test.lnk"; TCHAR szThisFilePath[MAX_PATH]; CoInitialize(NULL); GetModuleFileName(NULL, szThisFilePath, MAX_PATH); CreateLink(szThisFilePath, szLinkFilePath); CoUninitialize(); return 0; }

上一篇:使用文件方式实现Java序列化
下一篇:B. Phone Numbers

相关文章

关键词: C++创建lnk

相关评论