阿虚
Hello World!
Hello World!
获取桌面快捷键指向的文件路径
#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;
}

阿虚

文章作者

发表评论

textsms
account_circle
email

Hello World!

获取桌面快捷键指向的文件路径
扫描二维码继续阅读
2015-10-30