To: djgpp AT delorie DOT com Subject: Re: Dynamic loading of functions Message-ID: <19970214.172521.7647.0.chambersb@juno.com> References: From: chambersb AT juno DOT com (Benjamin D Chambers) Date: Fri, 14 Feb 1997 20:23:29 EST On Fri, 14 Feb 1997 09:51:08 -0600 Lennart Steinke writes: >Hi! > >I'm currently playing with the idea of loading function dynamically >(for plug ins). It's working, but I've some questions: > >1) Do I have to lock the memory of the funtion after loading or > not? Don't know. >2) Are there already libs for djgpp which allow dynamic binding? Yes. They're called DLM's, you can do EVERYTHING in them that you can do in a normal object file. They're actually better, because you can overload function names in vanilla C (no C++), by unloading one set of commands and loading a different set. ...Chambers > >Here's the simple and short demo source: > >====Start >#include >#include > >static void __begin_func(void){}; > >int f1(int a) >{ > printf("\nTest %i\n",a); > return a*2; >} > >static void __end_func(void){}; > >int (*f2)(int a); > >void main(void) >{ > void *p_func; > FILE *f; > long int size; > int a=2; > > p_func= &__begin_func+ sizeof(int); > size = (long int) (&__end_func- &__begin_func); > > f=fopen("test.fnc","wb"); > fwrite(p_func, size, 1, f); > fclose(f); > > f=fopen("test.fnc","rb"); > (void *)f2 = malloc(size); > fread(f2,size,1, f); > fclose(f); > > a=f2(a); > printf("%i\n",a); > >} > >====End > > >Lenny >-- >Lennart Steinke (steinke AT adv-boeblingen DOT de) >http://mars.adv-boeblingen.de/~steinke > > >