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:
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.
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.
Parent of the new process is its creator. In your particular case - your process.
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 withUNICODE
defined. Then you should setCREATE_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 setCREATE_UNICODE_ENVIRONMENT
according to how you constructed the environment block, not according to the compilation defines.As said already, both
CreateProcessA
andCreateProcessW
may work with either Ansi or Unicode environment block. This is exactly the reason why this flag is required.