winapivisual-c++-2015

Replacement for __wgetmainargs in VS2015


Right now I'm using __wgetmainargs in order retrieve the array of strings that represent the variables set in the user's environment.

Using VS2013 everything works, however, using VS2015 I get error LNK2019: unresolved external symbol __wgetmainargs errors.

I found that this was removed and that CommandLineToArgvW is a replacement, but I don't need the command line arguments, I need the environment array (for some reason I cannot use _wenviron, I just get garbage there).

Which library do I have to add to the linker or which alternative API can I use?


Solution

  • A way for solving this is to use GetEnvironmentStrings which returns a pointer to a wchar_t sequence of all environment variables which are separated by \0 and end with \0\0 which can then be used directly or separated manually for a transformation into the format needed (GPLv2).