How to get shortcut target

前端 未结 1 1350
暖寄归人
暖寄归人 2021-01-27 02:40

I need to be able to read the target of a shortcut (a .lnk file).

I have Googled this and found numerous results that I have found to be helpful: http://cboard.cprogramm

相关标签:
1条回答
  • 2021-01-27 02:42

    All headers are fine, but you are using wide (wchar_t based) and 'normal' (char based) strings incorrectly: IPersistFile::Load takes a wide string while IShellLinkA::GetPath takes a normal string. Using this should compile:

    IShellLinkA* psl; //specify the ansi version explicitely
    CoInitialize( 0 ); //you forgot this, needed for all COM calls to work
    char* tempStr = new char[ MAX_PATH ];
    std::wstring path = L"E:\\shortcuts\\myshortcut.lnk";
    

    Also if you just want the path, you can just pass 0 instead of a pointer to a WIN32_FIND_DATA.

    0 讨论(0)
提交回复
热议问题