when is environment variable created?

This topic is 4807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

the environmentvariable in vc is equal environmentvariable in windows?? for example path variable in windows and $(VSInstallDir) in vc can be access by GetEnvironmentVariable SetEnvironmentVariable? when was these environment variable created? where was thes environment variable created? are these global? what is different from variable created by programmer self. like int var1; float var2; Share this post Link to post Share on other sites Advertisement Quote:  Original post by derek7the environmentvariable in vc is equal environmentvariable in windows?? Yes Quote:  Original post by derek7for example path variable in windows and$(VSInstallDir) in vc can be accessby GetEnvironmentVariable SetEnvironmentVariable?
Yes

Quote:
 Original post by derek7when was these environment variable created?where was thes environment variable created?are these global?
They were created (registered) when the program that set them was installed. For instance, the \$(VSInstallDir) variable would be registered when you installed VS, and the PATH variable when you installed windows (And other applications might change it). They're system-wide, yes.

Quote:
 Original post by derek7what is different from variable created by programmer self.like int var1; float var2;
An environment variable is a variable that is global to Windows. Any application can read/write it. An environment variable is a key-value type, where both types are strings - I.e. you can't store an int in an environment variable (Well, you can store the string representation of it like "42").

Edit: You can use this code to list all the environment variables:
void* pEnvironmentStrings = GetEnvironmentStrings();char* psz = (char*)pEnvironmentStrings;do {	OutputDebugString(psz);	OutputDebugString("\n");	psz += strlen(psz)+1;} while(*psz);FreeEnvironmentStrings((LPSTR)pEnvironmentStrings);

Share on other sites
thank for your clear explanation.but one thing I don't know .

these environment variables are defined at system boot time?

when I setup windows or vc,every time system boot,these variables are defined at memory??
and which memory segment are these variable defined?
on heap? on stack? or .............

• 10
• 17
• 9
• 14
• 41