home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bc3.zip / REALPROC.H < prev    next >
C/C++ Source or Header  |  1992-02-14  |  2KB  |  72 lines

  1. //
  2. // (c) Copyright 1992, Qualitas, Inc. All Rights Reserved
  3. //
  4. // realproc.h - definitions for RealProcedure class
  5. //
  6. // The RealProcedure class provides a simple means of calling far functions
  7. // in real mode.  The class is based on DPMI function 0x301, Call Real
  8. // Procedure with Far Return.
  9. //
  10. // The constructor for the class accepts the procedure address and the count
  11. // of bytes to copy to the real mode stack.  Callers may then invoke the
  12. // the RealProcedure with normal function calling syntax.  
  13. //
  14. // This small model implementation makes some simplifying assumptions.  The 
  15. // constructor assumes that the protected mode code and data segments 
  16. // are accessible from real mode (i.e., are below address 1 MB), and that 
  17. // the real procedure uses the same code and data segment.  All RealProcedures
  18. // are called on a statically allocated stack within the data segment. 
  19. // Therefore, there is no need to convert near pointers or copy data between
  20. // address spaces, as would be necessary in a generalized real procedure
  21. // calling facility.
  22. //
  23. // RealProcedures can return values.  The cast operator methods provide a
  24. // means to extract return values from the real mode call structure associated
  25. // with the RealProcedure object.  Casting the return value of a RealProcedure
  26. // call causes the appropriate cast operator to compute the return value
  27. // based on the return type and the register state recorded by the DPMI host
  28. // when the real call returned. Types in addition to those provided
  29. // may be implemented in derived classes if necessary.
  30. //
  31. // Example:
  32. //
  33. //    long theRealFunction(char *s, long l, short s)
  34. //    {
  35. //        return l+s+strlen(s);
  36. //    }
  37. //
  38. //    void test(void)
  39. //    {
  40. //        RealProcedure rFunc(theRealFunction, 
  41. //                sizeof(char*)+sizeof(long)+sizeof(short));
  42. //
  43. //        long result;
  44. //
  45. //        result = (long)rFunc("abcdefgh", 0x100L, 0x10);
  46. //
  47. //        ...
  48. //    }
  49. //
  50. #include "dpmi.h"
  51.  
  52. class RealProcedure
  53. {
  54. public:
  55.     RealProcedure(void far *procAddress, int nArgBytes=0);    
  56.     RealProcedure& operator()(...);
  57.  
  58.     operator char()
  59.       {return (char)(dRegs.drEAX.s & 0xff);};
  60.     operator int() 
  61.       {return (int)dRegs.drEAX.s;};
  62.     operator long()
  63.       {return (long)(dRegs.drEAX.s)|((uLong)dRegs.drEDX.s << 16);};
  64.  
  65. protected:
  66.     uShort argSize;
  67.     dpmiRegs_t dRegs;
  68. };
  69.  
  70.  
  71.  
  72.