views:

50

answers:

1

Is there any reliable API to Get Windows Folder in Windows in C++? I am using the following way, however it failed.

    BOOL CQUserInfoHelper::GetWindowsPath(CString& strWindowsPath)
    {
        TCHAR windowsPathTemp[MAX_PATH];
        int nSize = MAX_PATH;
        ::GetWindowsDirectory(
            windowsPathTemp,
            nSize);
        strWindowsPath = windowsPathTemp;
        return TRUE;
    }
+2  A: 

Try This -

const DWORD dwBufferLength = 65537; CStringW strBuffer;

if (!::GetCurrentDirectory(dwBufferLength, strBuffer.GetBuffer(dwBufferLength))) return L""; strBuffer.ReleaseBuffer();

Shrik