怎样读出快捷方式里的内容,用IShellLink。最好有源代码。

解决方案 »

  1.   

    void GetLinkPath(char* lpszLink, char* szPath)
    {
        HRESULT hres; 
        IShellLink* psl; 
        char szGotPath[MAX_PATH];
        WIN32_FIND_DATA wfd;    *szPath = 0; // assume failure
        CoInitialize(0);
        // Get a pointer to the IShellLink interface.
        hres = CoCreateInstance(CLSID_ShellLink, NULL,
            CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
        if (SUCCEEDED(hres)) {
            IPersistFile* ppf;        // Get a pointer to the IPersistFile interface.
            hres = psl->QueryInterface(IID_IPersistFile,
                (void**)&ppf);
            if (SUCCEEDED(hres)) {
                WCHAR wsz[MAX_PATH];            // Ensure that the string is Unicode.
                MultiByteToWideChar(CP_ACP, 0, lpszLink, -1, wsz,
                    MAX_PATH);            // Load the shortcut.
                hres = ppf->Load(wsz, STGM_READ);
                if (SUCCEEDED(hres)) {                // Resolve the link.
                    hres = psl->Resolve(0, 0);
                    if (SUCCEEDED(hres)) {                    // Get the path to the link target.
                        hres = psl->GetPath(szGotPath,
                            MAX_PATH, (WIN32_FIND_DATA *)&wfd,
                            SLGP_SHORTPATH );
                        if (SUCCEEDED(hres))
                            lstrcpy(szPath, szGotPath);
                    }
                }
            // Release the pointer to the IPersistFile interface.
            ppf->Release();
            }
        // Release the pointer to the IShellLink interface.
        psl->Release();
        }
        if(hres)
            strcpy(szPath, lpszLink);
        CoUninitialize();
    }
      

  2.   

    编译通过了,但是执行到hres = ppf->Load(wsz, STGM_READ)后,
                    if (SUCCEEDED(hres)) {
                    // Resolve the link.
                    hres = psl->Resolve(0, 0);
                    if (SUCCEEDED(hres)) {
                        // Get the path to the link target.
                        hres = psl->GetPath(szGotPath,
                            MAX_PATH, (WIN32_FIND_DATA *)&wfd,
                            SLGP_SHORTPATH );
                        if (SUCCEEDED(hres))
                            lstrcpy(szPath, szGotPath);
    这些并没有执行,为什么