获取快捷方式的文件路径

#include

bool ReadShortcut(LPWSTR lpwLnkFile, LPSTR 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;

}

// 测试代码: char szBuf[MAX_PATH]; ReadShortcut(L”C:\GLWorld.lnk”, szBuf); MessageBox(0, szBuf, “”, 0);

支持原创技术分享,据说打赏我的人,都找到了女朋友!