From: Lennart Steinke Newsgroups: comp.os.msdos.djgpp Subject: Dynamic loading of functions Date: Fri, 14 Feb 1997 09:51:08 -0600 Organization: InterNetNews at News.BelWue.DE (Stuttgart, Germany) Lines: 60 Message-ID: NNTP-Posting-Host: zeus.adv-boeblingen.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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? 2) Are there already libs for djgpp which allow dynamic binding? 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