Why does this crash?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
VoidLogic

Why does this crash?

Post by VoidLogic »

Mode: Real
OS: DOS
Comp: Borland C++ 5.02
Platform: DOS standard

EXE B Crashes if:

1. EXE A is set as TSR and loaded more then once. (this should not happen?)
2. EXE A is not a TSR,a and another program uses its (old) memory ( i understand this)

EXE A:
--------------------------------------------------------------------------------
#include <Iostream.h>
#include <Fstream.h>
#include <StdLib.h>
#include <DOS.h>

void huge (*HelloPtr)(void);
void Hello(void);

void main(void)
{
HelloPtr = &Hello;
(*HelloPtr)();

  system("if exist C:\\TempPtr.dat del C:\\TempPtr.dat ");
  ofstream Stream;
  Stream.open("C:\\TempPtr.dat");
  Stream<<HelloPtr;
  Stream.close();
// _dos_keep(0, (_SS + (_SP+32/16) - _psp)); //Makes it TSR
}

void huge Hello(void)
{
cout<<"Hello World";
}
EXE B (the one that is run to test this external function calling)
-------------------------------------------------------------------------------

void huge (*HelloPtr)(void);

void main(void)
{
  unsigned long Temp;
  system("codesh~1.exe");
  ifstream Stream;
  Stream.open("C:\\TempPtr.dat");
  Stream>>Temp;
  Stream.close();
  HelloPtr = (void huge(*)())Temp;
(*HelloPtr)();
  getch(); //Also it crashes if this line is removed?!#$% wtf
}

Notes:

I have tried far, and _loadds also, no to avail.
Help Please!
Thanks

VoidLogic
Post Reply