klg0582@uxa.cso.uiuc.edu (Ken-Huang Lin) (08/09/90)
I would like to have some "global variables" remain alive even after the program ends so that the next program can access them. I tried to set environment variables inside the program using system("set v=..."); in Turbo C. Unfortunately, the effect is only local to that program. Is there any way to set the global environment variables in a program? Or is there a better way to serve the same purpose? Thank you in advance, Ken H. Lin lin@uiwpl.ece.uiuc.edu
jeffmu@microsoft.UUCP (Jeff MUZZY) (08/11/90)
>From: klg0582@uxa.cso.uiuc.edu (Ken-Huang Lin) | I would like to have some "global variables" remain alive even after the | program ends so that the next program can access them. I tried to set | environment variables inside the program using | system("set v=..."); | in Turbo C. Unfortunately, the effect is only local to that program. Is | there any way to set the global environment variables in a program? Or is | there a better way to serve the same purpose? Here is how I would solve the problem. This is like our config files for Windows and Lanman. I would create a file called GLOBAL.INI which is pointed to by an ENV variable called HOME or INIT. I would write generic routine to read and write from the tags in the file. The structure of the file would be like. [Program-1] var1=szTag var2=1 var3=Color Then when you run your program you can use your routine to access from init file. If you ever port your software to windows or PM your code won't have to change much. Look at the call GetProfileString() in a book about windows program to give you an idea. -- jeffmu@microsoft or uunet!microsoft!jeffmu MaBellNet: (206) 882-8080 <Insert your favorite disclaimer about opinions and companies here>
deadog@kk4fs.UUCP (Dead Dog) (08/17/90)
klg0582@uxa.cso.uiuc.edu (Ken-Huang Lin) writes: > I would like to have some "global variables" remain alive even after the > program ends so that the next program can access them. I tried to set > environment variables inside the program using > system("set v=..."); > in Turbo C. Unfortunately, the effect is only local to that program. Is > there any way to set the global environment variables in a program? Or is > there a better way to serve the same purpose? There is a way you can search backward through memory blocks and find the "real" environment table, but there is a much better way. Write the variables into a file... int write_vars() { FILE *f; f=fopen("globvar.dat","wb"); if (f==NULL) return 0; /* error creating file */ fprintf(f,"%d\n",v); fprintf(f,"%s\n",misc_string); /* ... */ fclose(f); } Then read them in with your second program. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "The laugh of the king was clear :Dead Dog (Robey) and strong, so out of fear the 4 @6555 (wwivnet) crowd laughed along." -Tony Banks ..!rti!tijc02!kk4fs!deadog
scp@cs.arizona.edu ( Purcell) (08/27/90)
In article <Za01N1w162w@kk4fs.UUCP> deadog@kk4fs.UUCP (Dead Dog) writes: >klg0582@uxa.cso.uiuc.edu (Ken-Huang Lin) writes: > >> I would like to have some "global variables" remain alive even after the >> program ends so that the next program can access them. I tried to set >> environment variables inside the program using >> system("set v=..."); >> in Turbo C. Unfortunately, the effect is only local to that program. Is >> there any way to set the global environment variables in a program? Or is >> there a better way to serve the same purpose? > >There is a way you can search backward through memory blocks and find the >"real" environment table, but there is a much better way. Write the >variables into a file... If you don't need to share a lot of variables, you might try the Intra-Application Communications Area, 16 bytes starting at 0040:00F0h. I've successfully used this area to return extended status info from child programs to their parent. See page 62 of Norton's Programmer's Guide for more info (not much more, though). Good Luck... Sean -------------------------------------------------------------------------------- Sean Purcell : scp@cs.arizona.edu : "Never underestimate the bandwidth of a station wagon..." --------------------------------------------------------------------------------