Get Environment Variable?

BlitzMax Forums/BlitzMax Programming/Get Environment Variable?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I've got a feeling that it was originally written in bb anyway as it's a tad 'convoluted' for native BMax code...
Strict

Extern "Win32"
	Function GetEnvironmentVariable(lpName$z, lpBuffer:Byte Ptr, nSize) = "GetEnvironmentVariableA@12"
End Extern

Print GetEnv("USERPROFILE")

End

Function GetEnv$(envVar$)
		Local buff@[64]
		
		Local rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		If rtn > buff.length
			buff@ = buff@[..rtn]
			rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		EndIf
		
		Return string.FromBytes(buff@, rtn)
End Function