/*主要是通过GetEnvironmentVariable实现的。其函数原型如下:DWORD GetEnvironmentVariable( PCTSTR pszName, //记录要获取的参数名。 PTSTR pszValue, //标记要获取的参数名对应的参数值 DWORD cchValue);//表示pszValue能容纳最大字符数。Note:如果cchValue为0,则函数返回值为pszName对应的参数值加上'\0'的字符数 一个正确获取参数值的用法如下: */void PrintEnvironmentVariable(PCTSTR pszVariableName){ PTSTR pszValue = NULL; // Get the size of the buffer that is required to store the value DWORD dwResult = GetEnvironmentVariable(pszVariableName, pszValue, 0); if (dwResult != 0) { // Allocate the buffer to store the environment variable value DWORD size = dwResult * sizeof(TCHAR); pszValue = (PTSTR)malloc(size); GetEnvironmentVariable(pszVariableName, pszValue, size); _tprintf(TEXT("%s=%s\n"), pszVariableName, pszValue); free(pszValue); } else { _tprintf(TEXT("'%s'=\n"), pszVariableName); }}