home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / cassert.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  2.2 KB  |  90 lines

  1. // -------------------------------
  2. //  $Source: C:\logical\store\classes/RCS/CASSERT.CPP,v $
  3. //  $Revision: 1.8 $
  4. //  $Date: 1993/12/04 23:24:52 $
  5. //  $Author: jason $
  6. //  Language:       C++
  7. //  Licence:        Public Domain
  8. //  Purpose:        assert() replacement which knows about PM apps.
  9. // -------------------------------
  10.  
  11. //static const char RCSid[] = "$Id: CASSERT.CPP,v 1.8 1993/12/04 23:24:52 jason Exp jason $";
  12.  
  13. #if defined(__OS2__)
  14.  
  15. #define INCL_PM
  16. #define INCL_DOS
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <os2.h>
  20.  
  21. #include <CAssert.h>
  22.  
  23. void CSExport
  24. CAssertHandler(const char* cond, const char* file, const int line)
  25. {
  26.   // If the calling application runs in a PM window, then
  27.   // create a message box to display the problem.
  28.  
  29.   PTIB ptib;
  30.   PPIB ppib;
  31.  
  32.   DosGetInfoBlocks(&ptib, &ppib);
  33.  
  34.   if ((ppib->pib_ultype & 7) == FAPPTYP_WINDOWAPI)
  35.     {
  36.       char buffer[1024];    // Can't use a CString since that
  37.                             // uses CAssert.  Sigh.
  38.  
  39.       sprintf(buffer,
  40.               "Assertion '%s' failed in '%s' at line %d.\n",
  41.               cond, file, line);
  42.  
  43.       // Make sure that there's an adequate environment for
  44.       // the message box to run in.  If WinCreateMsgQueue
  45.       // fails, then there's probably a queue created for
  46.       // the calling thread already...
  47.  
  48.       HAB hab = WinInitialize(0);
  49.       HMQ hmq = 0;
  50.  
  51.       if (hab)
  52.         {
  53.           hmq = WinCreateMsgQueue(hab, 0);
  54.  
  55.           //if (hmq == 0)
  56.           //  {
  57.           //    APIRET rc = WinGetLastError(hab);
  58.           //    if (rc != PMERR_MSG_QUEUE_ALREADY_EXISTS)
  59.           //      abort();
  60.           // }
  61.         }
  62.  
  63.       // Pop up a message box
  64.  
  65.       WinMessageBox(HWND_DESKTOP,
  66.                     HWND_DESKTOP,
  67.                     (PSZ)buffer,
  68.                     (PSZ)"Fatal Error:",
  69.                     0,
  70.                     MB_ERROR | MB_OK);
  71.  
  72.       // Tidy up.
  73.  
  74.       if (hmq)
  75.         WinDestroyMsgQueue(hmq);
  76.       if (hab)
  77.         WinTerminate(hab);
  78.     }
  79.   else
  80.     {
  81.       // Boring text error on command line.
  82.       fprintf(stderr,
  83.               "Assertion '%s' failed in '%s' at line %d.\n",
  84.               cond, file, line);
  85.     }
  86.   abort();
  87. }
  88.  
  89. #endif
  90.