添加一个快捷方式

  1. 阅读原文
阅读原文
HRESULT   CreateLink(LPCSTR   lpszPathObj,   
        LPCSTR   lpszPathLink,   LPCSTR   lpszDesc)   
{   
        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;   

                //   Set   the   path   to   the   shortcut   target   and   add   the   
                //   description.   
                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);   

                        //   Save   the   link   by   calling   IPersistFile::Save.   
                        hres   =   ppf-> Save(wsz,   TRUE);   
                        ppf-> Release();   
                }   
                psl-> Release();   
        }   
        return   hres;   
}

=========================================================


//   CreateLink   -   uses   the   Shell 's   IShellLink   and   IPersistFile   interfaces   
//       to   create   and   store   a   shortcut   to   the   specified   object.   
//   Returns   the   result   of   calling   the   member   functions   of   the   interfaces.   
//   lpszPathObj   -   address   of   a   buffer   containing   the   path   of   the   object.   
//   lpszPathLink   -   address   of   a   buffer   containing   the   path   where   the   
//       Shell   link   is   to   be   stored.   
//   lpszDesc   -   address   of   a   buffer   containing   the   description   of   the   
//       Shell   link.   

HRESULT   CreateLink(LPCSTR   lpszPathObj,   
        LPCSTR   lpszPathLink,   LPCSTR   lpszDesc)   
{   
        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;   

                //   Set   the   path   to   the   shortcut   target   and   add   the   
                //   description.   
                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);   

                        //   Save   the   link   by   calling   IPersistFile::Save.   
                        hres   =   ppf-> Save(wsz,   TRUE);   
                        ppf-> Release();   
                }   
                psl-> Release();   
        }   
        return   hres;   
}

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 Web@Cool02.com

文章标题:添加一个快捷方式

文章字数:302

本文作者:零贰

发布时间:2018-08-02, 07:23:22

最后更新:2020-03-26, 16:28:11

原始链接:/html/20180802072322.html

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
零址导航 Gitee