c++ - VC++ doesn't detect newly created env variable using GetEnvironmentVariable -


I am using WinEngFrown GetEnvironmentVariable to get the value of a variable that I just created. I'm running Windows XP and VC ++ 2005. If I run the program from within Visual Studio, then this new variable can not be found. If I run it from the command prompt, then it does. I restarted VC ++, but the same result I have also restarted all the examples of Visual Studio, but still this is the problem. If I reboot the PC, but it can be solved, but I am curious why it is so. Here is the code I am using:

  #define BUFSIZE 4096 # defined VARNAME TEXT ("MY_ENV_NAME") int _tmain (int argc, _TCHAR * argv []) {TCHAR CNY NVU [BUFSIZE ]; DWORD dwEnv = :: GetEnvironmentVariable (VARNAME, chNewEnv, BUFSIZE); If (dwEnv == 0) {DWORD dwErr = GetLastError (); If (dwErr == ERROR_ENVVAR_NOT_FOUND) {printf ("Environment variable does not exist. \"); Return -1; }} And {printf (chNewEnv); } Return 0; }  

If I change MY_ENV_NAME with something such as TEMP, it works as expected, any thoughts? Thank you. What is what Anders and Martin said, environmental variables is one thing that has been inherited at the beginning. application. The new program basically At the beginning of that time, gets a copy of the environment while debugging, your XI is generally started by Visual Studio, so the view of your application The studio will have the same environment. Visual Studio is usually started by explorer, if you change the environment variable by going to System Properties-> Advanced-> Engagement Variables, then you have to restart the Visual Studio to see the changes.

If you are looking at Visual Studio, you can go to Tools (at least VS2005 / 2008) ...-> Options ...-> Projects and Solutions-> VC ++ Are there. Show the log environment for project settings and 'yes'. This build will print all the environment variables in the build environment (ctrl + click on the link in your build output) You will have to create this information, but this is the best way to see the VS environment.

If you really need to change the environment variable then running and debugging hard times, you can build your debug XEN and call anywhere near debugback (), from where you can get debugging Want to start Then you can set your environment, start exchanging with Explorer, or command prompt again (JIT debugging is enabled for you to handle) You will get a popup when your code goes to the debugback () call and you can call it VS Engage with and can debug normally from there.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -