I'm debugging an 64-bit application where c# exe is using native c++ dll, on Windows 7. It seems environment variables are different for these two, even though they are both executing in the same process. How is it possible that calling System.Environment.SetEnvironmentVariable has no effect on values returned by getenv()?
There are two types of environment variables: user environment variables (set for each user) and system environment variables (set for everyone). By default, a child process inherits the environment variables of its parent process.
1) PATH and Path are the same since Windows environment variables are case insensitive (File paths in Windows environment not case sensitive?). 2) Windows use Path to locate executables that are not located in the "current folder".
The difference between the two is that variables values may change during execution, while constant values cannot be reassigned. An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice.
How environment variables work. According to POSIX standards environment variables are all null-terminated strings in the format name=value where name cannot contain the = character. Depending on implementation name may not start with a digit and only consist of uppercase letters, digits, and the underscore _ .
The environment variables are just a blob of data which gets passed by windows to the process when it starts. The runtime functions you are using (The BCL for System.Environment and the CRT for getenv) are probably making copies of the environment during startup, which means they are not operating on the same "environment" variables.
Conceptually they must do this because otherwise there would need to be some way to synchronize them accessing the environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With