02-06-2007 07:07 AM
02-06-2007 09:03 AM
It seems that the problem in your code is in the size of the buffer passed to the function: nSize> parameter must be passed with the lenght of the (already) allocated buffer to hold the string. According to SDK documentation, "If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in characters, required to hold the value string and its terminating null character. " which seems to be your case. Try this in the interactive execution window:
#include "windows.h"
#include <utility.h>
static int p;
static char path[1024];
// DWORD GetEnvironmentVariable (
// LPCTSTR lpName, // environment variable name
// LPTSTR lpBuffer, // buffer for variable value
// DWORD nSize // size of buffer
//);
p = GetEnvironmentVariable ("Path", path, 1024);
DebugPrintf ("Returned bytes: %d\n", p);
DebugPrintf ("Returned string: %s\n", path);
02-06-2007 09:12 AM