I'm using VS 2005 and MFC, and I want to modify a system environment variable. So I looked up in the MSDN help and found that it is easy to set a user environment variable. However, for changing a system variable, the help says:
"Calling SetEnvironmentVariable has no effect on the system environment variables. The user can add or modify system environment variables using the Control Panel. To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message. This allows applications, such as the shell, to pick up your updates. Note that environment variables listed in this key are limited to 1024 characters."
I understand that, but find this way very error-prone and complicated. Is there really no easy, straightforward way to do such a simple thing as setting a system variable? No other methods availbale in MFC?
That works for all other processes, i.e. all the other processes that I start after I sent this message know the newly created system variable, and I do not have to restart my system.
However, the process that is currently running, i.e. the process that I used to set this variable is NOT aware of it, so if I make a call to GetEnvironmentVariable after setting it, I do NOT get it. I only get it if I restart the process.
is there a way to know that variable in the same process right after it has been created?
Can someone please help me. I am looking for a way to measure the speed of my program's execution. I am busy writing a simulation that needs to run as fast as possible and I want to make sure that the algorithms used are the fastest possible. Is there a way or a tool that can be used to measure the speed, like the amount of CPU clock cycles needed to complete an algorithm.
Not sure if this is what you want but you could use high resolution timer functions like QueryPerformanceCounter/QueryPerformanceFrequency before and after a piece of executing code and compare their values.
«_Superman_» I love work. It gives me something to do between weekends.
That counter macro seems to be counting the CPU cycles for a block of code. That does seem like the best way of determining the efficiency of a block of code, unlike time, that can vary greatly on different machines.