最新消息:想得多,做的少。一天到晚瞎鸡巴搞。

获取桌面快捷键指向的文件路径

Windows编程 阿虚 575浏览 0评论
#include <shlobj.h>  

bool ReadShortcut(LPWSTR lpwLnkFile, LPWSTR lpDescFile)
{
    bool bReturn = true;
    IShellLink *pShellLink;

    if (bReturn)
    {
        bReturn = (CoInitialize(NULL) == S_OK);
        if (bReturn)
        {
            bReturn = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                IID_IShellLink, (void **)&pShellLink) >= 0;
            if (bReturn)
            {
                IPersistFile *ppf;
                bReturn = pShellLink->QueryInterface(IID_IPersistFile, (void **)&ppf) >= 0;
                if (bReturn)
                {
                    bReturn = ppf->Load(lpwLnkFile, TRUE) >= 0;
                    if (bReturn)
                    {
                        pShellLink->GetPath(lpDescFile, MAX_PATH, NULL, 0);
                    }
                    ppf->Release();
                }
                pShellLink->Release();
            }
            CoUninitialize();
        }
    }
    return bReturn;
}

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    WCHAR sz[MAX_PATH * 2];
    ReadShortcut(L"C:\\Users\\Luck\\Desktop\\Autodesk 3ds Max 2009 32 位.lnk", sz);

   return 1;
}

转载请注明:虚无 » 获取桌面快捷键指向的文件路径

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址