Jerry
Jerry

Reputation: 1812

SHGetFolderPath returns garbage string in distribute version

    char desktopPath[MAX_PATH];
    HRESULT r = SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath);
    if (r != S_OK) {
        throw XArch(new XArchEvalWindows());
    }
    m_desktopPath = CString(desktopPath);

It is so weird. This piece of code works in VS2010 under both the release and debug modes. After I distribute it and run the application, I would get an error saying "The system cannot find the file specified". The more strange thing is my colleague runs the same application on his machine and it works.

In MSDN it says SHGetFolderPath is deprecated, so I tried to use SHGetKnownFolderPath. It is the same situation.

    PWSTR desktopPathW = 0;

    HRESULT hr = SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &desktopPathW);
    if (!SUCCEEDED(hr)) {
        throw XArch(new XArchEvalWindows());
    }
    CoTaskMemFree(static_cast<void*>(desktopPathW));

Any idea about what is going on? Or how am I suppose to debug this?

Thanks in advance. Jerry

Upvotes: 0

Views: 300

Answers (1)

MSalters
MSalters

Reputation: 179991

The comments explicitly state that S_OK is the only success result, and the error codes include S_FALSE, E_FAIL and E_INVALIDARG. You incorrectly assume that these 3 are the only error codes.

Upvotes: 2

Related Questions