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

  1. //
  2. // (c) Copyright 1992, Qualitas, Inc. All Rights Reserved
  3. //
  4. // callback.h - definitions for CallBack class
  5. //
  6.  
  7. #include "dpmi.h"
  8.  
  9. // The CallBack class provides a means for implementing real mode 
  10. // call backs in a DPMI environment.  A CallBack is a real mode
  11. // address (paragraph:offset) allocated by a DPMI host, which,
  12. // when called, transfers control to a specified entry point in
  13. // protected mode.
  14. //
  15. // The constructor for the class requires as an argument the
  16. // address of the call back handler, i.e., the protected mode function
  17. // to be called from real mode.  
  18. //
  19. // After creation, a program obtains the actual real mode call back
  20. // address via the getCallBackAddress member.  This address, when
  21. // called from real mode, invokes the call back handler.
  22. //
  23. // The class automatically dispatches to the call back handler such that
  24. // DS==SS, and normal small model operation is possible.
  25. //
  26. // The contents of the dpmiRegs structure on the handler's stack reflect
  27. // the real mode register state at the time of the callback.  Any 
  28. // modifications to this state are realized when the handler returns to
  29. // real mode.  The class automatically configures the return CS:IP and
  30. // SS:SP.
  31. //
  32. // CallBacks are not reentrant.
  33. //
  34. // Example:
  35. //
  36. //
  37. //    #include "callback.h"
  38. //    #include "realfunc.h"
  39. //
  40. //    CallBack* pCallBack;
  41. //
  42. //    void myCallBackHandler(dpmiRegs dRegs)
  43. //    {
  44. //
  45. //        . . .
  46. //    }
  47. //
  48. //    void far myRealFunction(void (far *cbAddress)())
  49. //    {
  50. //        . . .
  51. //
  52. //        (*cbAddress)();        // invoke call back handler
  53. //
  54. //    }
  55. //
  56. //    void main(void)
  57. //    {
  58. //        . . . normal enter protected mode code . . .
  59. //
  60. //        pCallBack = new CallBack(myCallBackHandler);
  61. //
  62. //
  63. //        RealProcedure rp(myRealFunction, sizeof(void far*));
  64. //
  65. //
  66. //        rp(pCallBack->getCallBackAddress());
  67. //
  68. //    }
  69.  
  70. class CallBack
  71. {
  72. public:
  73.     CallBack(void (*cbHandler)(dpmiRegs_t));
  74.     ~CallBack(void);
  75.     void far *getCallBackAddress() {return cbAddr;};
  76.     
  77. protected:
  78.     int cbNumber;
  79.     void far *cbAddr;
  80.     dpmiRegs_t cbRegs;
  81. };