'GetFileAttributes with environment variables

I am trying to have a file exist or not in a path using vc++.

if (INVALID_FILE_ATTRIBUTES != GetFileAttributes(L"%windir%\Myfile.exe"))
        printf("\n %ws", sPath);

I've put Myfile.exe in windows directory. Still it is not giving me right output.

Please help me.



Solution 1:[1]

I've found that

CString GetEnvironmentVarValue(CString strEnvVarName)
{
    TCHAR szVarValue[MAX_PATH] = "" ;
    GetEnvironmentVariable(strEnvVarName.GetBuffer(0), szVarValue, sizeof(szVarValue)) ;
    GetLongPathName(szVarValue, szVarValue, sizeof(szVarValue)) ;
    return CString(szVarValue) ;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 phuclv