Mail Archives: djgpp/2000/08/16/06:00:18
From: | "Rafał Maj" <r_maj AT poczta DOT onet DOT pl>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | calling functions
|
Date: | Wed, 16 Aug 2000 10:44:44 +0200
|
Organization: | Academic Computer Center CYFRONET AGH
|
Lines: | 56
|
Message-ID: | <8ndkeb$lt8$5@info.cyf-kr.edu.pl>
|
NNTP-Posting-Host: | d-22-55.cyfronet.krakow.pl
|
X-Trace: | info.cyf-kr.edu.pl 966415627 22440 149.156.1.232 (16 Aug 2000 08:47:07 GMT)
|
X-Complaints-To: | news AT cyf-kr DOT edu DOT pl
|
NNTP-Posting-Date: | 16 Aug 2000 08:47:07 GMT
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.00.2615.200
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2615.200
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
My small program is making a copy of code of some function. Program works
fine, until my function is trying to call
library functions.
================ THIS PROGRAM WORKS ====================
#include <iostream.h>
int globA, globB, globC;
void fun() { globC= globA + globB; }
void fun_end() {};
main() {
globA=10; globB=5;
long int size = ((long int)(void*)fun_end) - ((long int)(void*)fun);
char *ptr = new char[size];
memcpy(ptr,(void*)fun,size);
void (*function_ptr)() = (void (*)()) ptr;
(*function_ptr)(); // <------ CALL of function copy
cerr<<globC<<endl; // same as print()
}
================ THIS PROGRAM DOESN'T WORK ====================
#include <iostream.h>
#include <dos.h>
int globA, globB, globC;
void fun() { globC= globA + globB;
delay(10); // <-------------------------- library function
}
void fun_end() {};
main() {
globA=10; globB=5;
long int size = ((long int)(void*)fun_end) - ((long int)(void*)fun);
char *ptr = new char[size];
memcpy(ptr,(void*)fun,size);
void (*function_ptr)() = (void (*)()) ptr;
(*function_ptr)(); // <------ program crashes (with error code 255)
cerr<<globC<<endl; // same as print()
}
===============================================================
So, can You send me working example, how to call copy of functions ?
I know it's possible, because Allegro is using stuf like this.
Rafal
- Raw text -