none
GetEnvironmentVariable(TMP)在64位系统的结果 RRS feed

  • 问题

  • wchar_t tmpFolder[MAX_PATH] = L"";
    DWORD result = ::GetEnvironmentVariable(L"TMP", tmpFolder, sizeof(tmpFolder) - 1);
    
    在32位系统(xp)下,tmpFolder的结果是正确的;在64位系统(Windows server 2008r2)下,tmpFolder的结果是"C:\.....\Temp\2",为什么会多个"2"呢?
    2011年3月25日 9:24

答案

  • http://msdn.microsoft.com/en-us/library/ms683188(v=vs.85).aspx

    lpBuffer [out, optional]

    A pointer to a buffer that receives the contents of the specified environment variable as a null-terminated string. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character.

    返回的是没有结束符的字符串。所以你需要根据返回值,来决定实际环境变量字符串长度。


    麻烦把正确答案设为解答。
    2011年3月25日 9:46
    版主
  • wchar_t tmpFolder[MAX_PATH] = {L""};
     DWORD result = ::GetEnvironmentVariableW(L"TMP", tmpFolder, MAX_PATH-1);
     AfxMessageBox(CString(tmpFolder));
    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年3月28日 5:30
    版主
  • Hi Kakakakaka,

    您的问题很可能系统的环境变量设置有关,请您查看一下系统的环境变量设置.

     

    谢谢,

    Lucy

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年4月1日 9:44
    版主

全部回复

  • http://msdn.microsoft.com/en-us/library/ms683188(v=vs.85).aspx

    lpBuffer [out, optional]

    A pointer to a buffer that receives the contents of the specified environment variable as a null-terminated string. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character.

    返回的是没有结束符的字符串。所以你需要根据返回值,来决定实际环境变量字符串长度。


    麻烦把正确答案设为解答。
    2011年3月25日 9:46
    版主
  • wchar_t tmpFolder[MAX_PATH] = {L""};
     DWORD result = ::GetEnvironmentVariableW(L"TMP", tmpFolder, MAX_PATH-1);
     AfxMessageBox(CString(tmpFolder));
    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年3月28日 5:30
    版主
  • DWORD WINAPI GetEnvironmentVariable(
     __in_opt  LPCTSTR lpName,
     __out_opt LPTSTR lpBuffer,
     __in    DWORD nSize
    );
    

    Parameters

    lpName

    The name of the environment variable.

    lpBuffer

    A pointer to a buffer that receives the contents of the specified environment variable as a null-terminated string. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character.

    nSize

    The size of the buffer pointed to by the lpBuffer parameter, in characters.


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年3月28日 5:59
    版主
  • wchar_t tmpFolder[MAX_PATH] = {L""};
    DWORD result = ::GetEnvironmentVariableW(L"TMP", tmpFolder, MAX_PATH-1);

     

    结果依然是"C:\Users\ORCHES~1\AppData\Local\Temp\2", 而且result值为38,似乎也包含了"\2".

    2011年3月28日 7:47
  • Hi Kakakakaka,

    您的问题很可能系统的环境变量设置有关,请您查看一下系统的环境变量设置.

     

    谢谢,

    Lucy

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年4月1日 9:44
    版主