Hello, Raw Material People.
This is only peripherally a Juce question (except why doesn’t Juce have a correct crossplatform “get environment variables” function? If this one worked, it would be useful in Juce, hint hint…)
I’ve been using getenv up until now, which usually works everywhere, but on Windows, this unfortunately does not read environment variables that are set after the program has started, and this is the only way that our copy protection program communicates with our main executable…
In the code below, GetEnvironmentVariable should be defined by windows.h (which, indeed, I shouldn’t even need to include because Juce always includes it…)
But when I actually try to compile it, I get an error: GetEnvironmentVariable: identifier not found.
(And I get a similar error if I try to call ::GetEnvironmentVariable.)
My Windows skills are still only basic, and this seems so obvious I’m not sure how to debug it…
Thanks in advance!
[code]#if JUCE_WINDOWS
#include <windows.h>
#endif
#include “rec/util/GetEnv.h”
namespace rec {
namespace util {
String getEnv(const char* name, const String& dflt) {
#if JUCE_WINDOWS
static const int MAX_ENV = 1024;
char buffer[MAX_ENV];
if (int len = GetEnvironmentVariable(name, buffer, MAX_ENV))
return str(string(buffer, buffer + len));
#else
const char* res = getenv(name);
if (res && *res)
return String(res);
#endif
return dflt;
}
} // namespace util
} // namespace rec
[/code]
