Discussion
Topics
Last Day
Last Week
Tree View

Search
New Messages
Keyword Search

Help
Getting Started
Formatting
Troubleshooting
Program Credits

Utilities
Edit Profile
Administration
Contact

 
forum - discussion board
- about - downloads - registration - forum - misc - home - © 1996-99 GWD Text Editor

Putenv problem

GWD Text Editor Forum: Technical Support: Putenv problem
Top of pagePrevious messageNext messageBottom of pageLink to this message  By Abdullah Bushnaq on Wednesday, April 4, 2001 - 04:53 pm:

It seems that everytime a macro tries to update an environment variable using putenv, the getenv cannot retrieve that environment variable.

I am running somethin like this :

putenv("CLNT=AYA");

now running getenv("CLNT") will simply return a NULL.

Why is that happening? It works fine if I don't try to set it using putenv.

Thanks.

-Abdullah


Top of pagePrevious messageNext messageBottom of pageLink to this message  By Abdullah Bushnaq on Tuesday, July 17, 2001 - 07:33 pm:

Anybody with thoughts on this?


Top of pagePrevious messageNext messageBottom of pageLink to this message  By Abdullah Bushnaq on Tuesday, February 19, 2002 - 11:59 pm:

Vedran, is this a bug in putenv/getenv?


Top of pagePrevious messageNext messageBottom of pageLink to this message  By Vedran Gaco (Vgaco) on Wednesday, February 20, 2002 - 11:59 am:

putenv/getenv works fine under Windows 2000. I check those functions with the following script, before uploading GWD Text Editor 3.2 beta 1:


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
   char *psz = NULL;

   putenv("CLNT=AYA");

   psz = getenv("CLNT");

   if(psz != NULL)
      printf(psz);
   printf("\n");

   printf("Hello, World!\n");
   system("pause");
   return 0;
}


Top of pagePrevious messageNext messageBottom of pageLink to this message  By Abdullah Bushnaq on Wednesday, February 20, 2002 - 09:26 pm:

Try the following to see the problem:

Save the code you posted as a macro. Run it and it will display AYA for the CLNT variable.

Now, edit the script and comment out the putenv line. Run the script again, and you won't get that variable back, even though it is still out there (I shell out to a command prompt and I can see it)

The putenv/getenv combo works together correctly in one macro, but once that macro is done executing and you try to run any other macros, they don't seem able to get the value back using getenv.

I am using Windows NT 4.0.

Thanks.


Top of pagePrevious messageNext messageBottom of pageLink to this message  By Vedran Gaco (Vgaco) on Thursday, February 21, 2002 - 09:44 am:

Instead of getenv, try to use this function. It should work with all versions of the GWD Text Editor. Note that __getenv reserves memory with malloc and you should call free to delete memory or you will have memory leaks (at the script end, GWD Text Editor automatically frees only last 20 block reserved with malloc).


#include <windows.h>
char * __getenv(const char *pszName);


char * __getenv(const char *pszName)
{
   char   szDummyBuf[4];
   char * pszVar;
   DWORD nSize;

   nSize = 4;
   nSize = (DWORD)CallDLLFunc(NULL, "kernel32.dll", "GetEnvironmentVariableA", "pp4", pszName, szDummyBuf, nSize);

   if(nSize == 0)
      return NULL;

   pszVar = (char*)malloc(nSize+1);
   if(pszVar != NULL)
   {
      *pszVar = 0;
      CallDLLFunc(NULL, "kernel32.dll", "GetEnvironmentVariableA", "pp4", pszName, pszVar, nSize+1);
      return pszVar;
   }
   return NULL;
}


Add a Message


This is a public posting area. If you do not have an account, enter your full name into the "Username" box and leave the "Password" box empty. Your e-mail address is optional.
Username:  
Password:
E-mail:


- about - downloads - registration - forum - misc - home - © 1996-99 GWD Text Editor