Subj : Re: Run an external binary code To : borland.public.cpp.borlandcpp From : "Tim Jackson" Date : Mon Aug 18 2003 12:30 am You have a chunk of machine code you want to invoke in your program? (as opposed to running an .EXE file from within your program.) 1. Load your binary code into a char array. 2. Cast a (pointer to the char array) to a (pointer to function) 3. Call through the pointer. for example -------------- // declare a pointer to function taking no parameters and returning nothing void (fp*)(void); char buf[2000]; // Somewhere to put your code void *p; // a general purpose pointer // ... load the buffer, then ... p = buf; // Point at the data fp = p; // you can implicitly cast a void* to any * fp(); // Call your code - compiler dereferences the pointer -------------- It is shorter but a bit opaque to use an explicit cast instead of the void*, like -------------- fp = (void(*)())buf; fp(); -------------- or even forget both pointers and just directly cast and call the buffer, -------------- ((void(*)(void))buf)(); -------------- (I think) and you do need ALL those brackets. If you want to use parameters and returns then your external code will have to understand the compiler's parameter passing sequence. Tim Jackson "Henry" wrote in message news:3f3f5ab1@newsgroups.borland.com... > Hi! Please tell me how can I run an external binary code (from file and from > memory) through my C++ program. > > Thanks > (Henry) > > .