Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables are different for dll than exe

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()?

like image 445
AareP Avatar asked Mar 01 '11 11:03

AareP


People also ask

What are the two types of environment variables?

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.

What is the difference between path and environment variable?

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".

What is the difference between variables and environment variables?

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.

Are environment variables all strings?

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 _ .


1 Answers

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.

like image 185
Stewart Avatar answered Sep 22 '22 02:09

Stewart