Chuyu-Team / YY-Thunks

Fix DecodePointer, EncodePointer,RegDeleteKeyEx etc. APIs not found in Windows XP RTM.
MIT License
496 stars 102 forks source link

SHGetKnownFolderPath 在 XP 上返回 E_INVALIDARG (0x80070057) #77

Closed CyanoHao closed 2 months ago

CyanoHao commented 2 months ago

YY-Thunks 版本:NuGet v1.0.9

代码:

#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h>

#include <stdio.h>

int main()
{
    wchar_t* p = nullptr;
    auto hr = SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, nullptr, &p);
    if (SUCCEEDED(hr))
    {
        MessageBoxW(nullptr, p, L"Documents", MB_OK);
        CoTaskMemFree(p);
    }
    else
    {
        wchar_t buf[256];
        swprintf(buf, 256, L"Error: %08X", hr);
        MessageBoxW(nullptr, buf, L"Error", MB_OK);
    }
    return 0;
}
CyanoHao commented 2 months ago

https://github.com/Chuyu-Team/YY-Thunks/blob/a8d9d31efbf7e007801670c4a25bfdb08dd9d940/src/Thunks/shell32.hpp#L458

根据 SHGetFolderPathW 的文档和示例,这里的参数应该是

    SHGetFolderPathW(nullptr, dwFlags | csidl, hToken, SHGFP_TYPE_CURRENT, pPathBuffer); 
mingkuang-Chuyu commented 2 months ago

感谢反馈,这是我的问题,你说的没有错。 CSIDL_FLAG_CREATE等相关参数应该合并到csidl中。另外我又对代码进行了排查并重新更新代码。请等待新版本发布。

mingkuang-Chuyu commented 2 months ago

https://github.com/Chuyu-Team/YY-Thunks/releases/tag/v1.0.10-Beta1 已经修复,请查收