Win32 CreateProcess: When is CREATE_UNICODE_ENVIRONMENT *really* needed? Win32 CreateProcess: When is CREATE_UNICODE_ENVIRONMENT *really* needed? windows windows

Win32 CreateProcess: When is CREATE_UNICODE_ENVIRONMENT *really* needed?


Note that in the declaration of the CreateProcess function the lpEnvironment parameter is declared is LPVOID.

What does this mean? It means that you may use Ansi/Unicode version of CreateProcess function and pass it Ansi/Unicode version environment block in any combination. In particular you may use Unicode version of CreateProcess and pass it Ansi environment block and vice versa.

So that setting the CREATE_UNICODE_ENVIRONMENT is required iff you actually use unicode environment block, because there's no other conventional way (apart from some ugly heuristics) the OS may realize it's unicode.

Now regarding your questions:

  1. If you don't pass the environment block explicitly - the newly created process will initially have the same environment variables as its creator. Unless you need to make some extra-configuration to the newly created process - nothing more than this is reqiured.

  2. If you pass the environment block to the newly created process - you must either manually construct it or get it from somewhere. In either way you must know if it's unicode.

  3. Parent of the new process is its creator. In your particular case - your process.

  4. This depends solely on how environment block is created. If you always pass what you get by calling GetEnvironmentStrings - then it's in unicode iff you're compiling with UNICODE defined. Then you should set CREATE_UNICODE_ENVIRONMENT iff you're compiling in unicode. On the other hand if you construct it manually - you may construct it in unicode even if you don't compiler in unicode. Hence - you should set CREATE_UNICODE_ENVIRONMENT according to how you constructed the environment block, not according to the compilation defines.

  5. As said already, both CreateProcessA and CreateProcessW may work with either Ansi or Unicode environment block. This is exactly the reason why this flag is required.