I have the following code written in C:
#include <windows.h>
#include <stdio.h>
WCHAR* test(){
WCHAR var[256];
int nSize = GetEnvironmentVariableW(L"SystemRoot", NULL, 0);
GetEnvironmentVariableW(L"SystemRoot", &var, nSize);
wprintf(L"%s\n", var);
return var;
}
int main() {
WCHAR* var = test();
wprintf(L"%s\n", var);
return 0;
}
When I compile it in Visual Studio and run it it works as expected. It prints result two times - in main func and in test. Output is:
C:\Windows
C:\Windows
But when I compile it on linux with mingw compiler via command
i686-w64-mingw32-gcc -o test.exe -O3 -Os -static -s test.c
it gives this output after starting:
C:\Windows
(null)
Why do the test() func return NULL when I'm using mingw and what to do to make it work properly? Thanks.