[shell-coding] Re: CPP variable storage question

How long do you need the variable to live?

If you only need it to last as long as the module is loaded, just use a
global or static variable, or allocate some space (with malloc or
whatever) and keep the pointer in a global or static variable.

If you want it to last as long as litestep is loaded (eg, if your module
gets !reloaded), there are window messages to store and retrieve data,
look in the source of ckvwm or something, it saves the current desktop
number that way.  (it'll be in quitModule and initModuleEx, I believe)

If it needs to last across reboots/reloads, I would suggest using
modules.ini (with a config option to let people choose someplace else)  A
lot of people seem to look down on this file (it has issues with themes,
i believe), but I think it's better than using the registry and if you
allow a different file to be specified there shouldn't be any problems. 
Use Read/WriteProfileString/Int to access stuff there.  (actually, I
think these can even be remapped to the registry...)

-rabidcow


On Thu, 11 Jul 2002 21:00:59 +0200 "e-sushi" <e-sushi@xxxxxxx> writes:
> Hey there...
> I've got a tactical question (meaning I ask before I try to code 
> something
> that won't work anyway).
> 
> Problem:
> I want to have a variable in a module that acts like an internat 
> counter, if
> the module does something special, I want it to do var=var+1 and 
> store it
> until the module gets active again and might need the current var 
> value.
> 
> Now to what I'm not sure about:
> what's the safest way to do the job in cpp without losing the data 
> somewhere
> in space and without having any heavy module load just to keep that 
> one var
> allive. Stupid me thinks another textfile would be stupid... and I 
> hate
> reg-tuning, even if that's a nice possebility... but hey, all 
> coding
> languages support var storing in several cool ways... Anyone feeling 
> like he
> should become my personal hero of the day and tell me what's up with 
> vars in
> cpp? Any pitfalls? Any hints?  A short answer like: "memcopy will 
> not get
> lost when..." or "just don't try to..." would be enough, I'll sort 
> out the
> rest  and stop bugging you right away - thanks!
> 
> Mike
> *feeling like a bonsai wanting to grow*
> 
> e-sushi | e-sushi@xxxxxxx | [EOF]
> 
> 
> __________________________________________________
> Subscription options and archive:
> http://www.freelists.org/list/shell-coding
> 
> 

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.

__________________________________________________
Subscription options and archive:
http://www.freelists.org/list/shell-coding

Other related posts: