FWindowsPlatformMisc::GetEnvironmentVariable does not work

Hello Community!

I’m trying to get a windows environment variable in C++, but it seems to be that I cannot get them.

FString _env = FWindowsPlatformMisc::GetEnvironmentVariable(*FString("SomeEnvironmentVariable"));

In the WindowsPlatformMisc.h file, It does state this

	UE_DEPRECATED(4.21, "void FPlatformMisc::GetEnvironmentVariable(Name, Result, Length) is deprecated. Use FString FPlatformMisc::GetEnvironmentVariable(Name) instead.")
	static void GetEnvironmentVariable(const TCHAR* VariableName, TCHAR* Result, int32 ResultLength);

However, trying to use the FPlatformMisc version, it doesn’t seem to work either. The compiler tells me this:

1> error C2039: 'GetEnvironmentVariableW': is not a member of 'FWindowsPlatformMisc'
1> : note: see declaration of 'FWindowsPlatformMisc'
1> error C2660: 'GetEnvironmentVariableW': function does not take 1 arguments
1>  C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\processenv.h(161): note: see declaration of 'GetEnvironmentVariableW'

Is GetEnvironmentVariable not possible anymore with UE4 C++? or is there something off I’m currently doing since it’s depreciation?

const FString EnvVariable = FPlatformMisc::GetEnvironmentVariable(TEXT(“windir”));
UE_LOG(LogTemp, Log, TEXT(“EnvVariable: %s”), *EnvVariable);

If any problem let me know. My discord Andrew Bindraw#9014

Unfortunately, I have tried this and still has the same errors.

 1> error C2039: 'GetEnvironmentVariableW': is not a member of 'FWindowsPlatformMisc'
 1> : note: see declaration of 'FWindowsPlatformMisc'
 1> error C2660: 'GetEnvironmentVariableW': function does not take 1 arguments
 1>  C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\processenv.h(161): note: see declaration of 'GetEnvironmentVariableW'

I’ve fixed it:

#include "GenericPlatform/GenericPlatformMisc.h"
#undef GetEnvironmentVariable // Fix unclosed macros in processenv for Win