09-07-2026, 07:22 AM
I need to make the second parameter of qmq's built-in function GetEnvVar optional.
Below is ChatGPT's answer, but it always produces garbled text in actual use.
Is there a better solution?
Function getEnv
Function GetEnvVar
Below is ChatGPT's answer, but it always produces garbled text in actual use.
Is there a better solution?
Function getEnv
function$ $name [str&value]
str R
if(GetEnvVar(name R))
,if(&value)
,,value = R
,,value.expandpath
,,ret value
,else
,,_s=R.expandpath
,,ret _sFunction GetEnvVar
;/
function$ $name str&value
;Gets an environment variable.
;Returns value if successful, 0 if failed.
;value - variable for value.
;Added in: QM 2.3.0.
int n1(4) n2
;g1
BSTR b.alloc(n1)
n2=GetEnvironmentVariableW(@name b n1)
if(n2>n1) n1=n2; goto g1
if(n2) value.ansi(b); ret value
value.all
