home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / AutoPC / apcsdk10.exe / data1.cab / Emulation_Include_Files / apcdebug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-13  |  8.3 KB  |  314 lines

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     ApcDebug.h
  8.  
  9. Abstract:
  10.  
  11.     Common debug header for all AutoPC applications
  12.     Relies on WinCE debug routines
  13.  
  14. Notes:
  15.  
  16.     In your CPP file containing your WinMain or DllMain function:
  17.  
  18.     #define APCDBG_INIT "App or DLL name"
  19.     #include <apcdebug.h>
  20.  
  21.     The APCDBG_INIT define should be a string of 31 or less chars
  22.  
  23.     In all your other CPP files:
  24.  
  25.     #include <ApcDebug.h>
  26.  
  27.  
  28.     To Assert that something is true you:
  29.  
  30.     DEBUGCHK(exp)
  31.  
  32.     This will display a debug output containing the module name
  33.     specified in APC_DBG_INIT, the file name and line number of the
  34.     failed condition.  It will then do a hard break into the
  35.     debugger.  You can use ASSERT(exp) but you won't get the module
  36.     name displayed (you'll get Unknown).
  37.  
  38.  
  39.     To display a debug message you:
  40.  
  41.     DEBUGMSG(zone, printf_exp)
  42.  
  43.     where zone is one of ZONE_ defines below.  Using our common
  44.     ZONE_ defines lets us consistantly turn on and off debug output.
  45.  
  46.     ZONE_FUNCTION   entry and exit of a function
  47.  
  48.     ZONE_WARNING        warning of something that may be a problem but
  49.                 isn't technically an error.
  50.             NOTE: Everyone will see this output by default
  51.     
  52.     ZONE_ERROR      details of an error condition that shouldn't
  53.             be happening.
  54.             NOTE: Everyone will see this output by default
  55.  
  56.     ZONE_VERBOSE    trace output that allows a human to follow
  57.             program flow.  Useful when single stepping is
  58.             prohibitive due to timing related bugs, etc.
  59.  
  60.     ZONE_SPEECH    speech related trace output.  NOT errors and
  61.             warnings (these should use ZONE_WARNING and
  62.             ZONE_ERROR).
  63.  
  64.     ZONE_SINK    message sink trace output.  NOT errors and
  65.             warnings (these should use ZONE_WARNING and
  66.             ZONE_ERROR).
  67.  
  68.     ZONE_AUDIO    audio related trace output.  NOT errors and
  69.             warnings (these should use ZONE_WARNING and
  70.             ZONE_ERROR).
  71.  
  72.     ZONE_CONTROLS    control related trace output.  NOT errors and
  73.             warnings (these should use ZONE_WARNING and
  74.             ZONE_ERROR).
  75.  
  76.  
  77.     By default the debug output for ZONE_WARNING and ZONE_ERROR is
  78.     turned on.  If you want to enable debug output for a different
  79.     set of zones at any time, you need to calculate the sum of
  80.     2^zone# for each zone# you want turned on.  Then pass your sum
  81.     to SETDBGZONE() like this:
  82.  
  83.     SETDBGZONE(0x6);
  84.  
  85.  
  86.     If you really, really need additional ZONE_XXXXs defined you
  87.     need to do the following in your WinMain module:
  88.  
  89.     #define APCDBG_15 "your zone name"
  90.     #define APCDBG_14 "your zone name"
  91.         :
  92.     #define APCDBG_8 "your zone name"
  93.  
  94.     #define APCDBG_INIT "App or DLL name"
  95.     #include <ApcDebug.h>
  96.  
  97.     Start with 15 and work backwards in case we add additional
  98.     common zones.  You will also need to add lines like the
  99.     following to your common header so you can use your new zones:
  100.  
  101.     #define ZONE_YOURZONE   DEBUGZONE(15)
  102.  
  103. -------------------------------------------------------------------*/
  104.  
  105.  
  106. #ifndef _APCDEBUG_H
  107. #define _APCDEBUG_H
  108.  
  109. /////////////////////////////////////////////////////////
  110. //Review: dbgapi.h doesn't get included on NT yet, remove when emulator work done
  111. //
  112. // The following is stolen and paraphrased in part from public\COMMON\sdk\inc\dbgapi.h
  113. #ifndef __DBGAPI_H__
  114. #define __DBGAPI_H__
  115.  
  116.     #ifdef __cplusplus
  117.     extern "C" {
  118.     #endif
  119.     
  120.     #ifdef DEBUG
  121.  
  122.         typedef struct _DBGPARAM {
  123.             WCHAR    lpszName[32];           // @field Name of module
  124.             WCHAR   rglpszZones[16][32];    // @field names of zones for first 16 bits
  125.             ULONG   ulZoneMask;             // @field Current zone Mask
  126.         } DBGPARAM, *LPDBGPARAM;
  127.  
  128.         void NKDbgPrintfW(LPWSTR lpszFmt, ...);
  129.  
  130.         #ifdef APCDBG_INIT    // since we only do this once per app, insert the code here
  131.             #include <stdlib.h>
  132.             void NKDbgPrintfW(LPWSTR lpszFmt, ...)
  133.             {
  134.             WCHAR szTmp[1024];
  135.             va_list ap;
  136.  
  137.             va_start(ap, lpszFmt);
  138.             vswprintf(szTmp, lpszFmt, ap);
  139.             va_end(ap);
  140.             OutputDebugStringW(szTmp);
  141.             }
  142.         #endif // APCDBG_INIT
  143.  
  144.         extern  DBGPARAM    dpCurSettings;
  145.  
  146.         #define DEBUGZONE(n)  (dpCurSettings.ulZoneMask&(0x00000001<<n))
  147.  
  148.         #ifdef UNDER_CE
  149.         #undef DEBUGMSG
  150.         #undef DEBUGCHK
  151.         #endif
  152.  
  153.         #define DEBUGCHK(exp)    \
  154.            ((void)((exp)?1:(    \
  155.                NKDbgPrintfW ( TEXT("%s: DEBUGCHK failed in file %s at line %d \r\n"),    \
  156.                          (LPWSTR)dpCurSettings.lpszName, TEXT(__FILE__) ,__LINE__ ),    \
  157.                DebugBreak(), 0 )))
  158.  
  159.         #define DEBUGMSG(cond,printf_exp)   \
  160.            ((void)((cond)?(NKDbgPrintfW printf_exp),1:0))
  161.  
  162.         #define ASSERT(exp) DEBUGCHK(exp)
  163.         #define VERIFY(exp) DEBUGCHK(exp)
  164.  
  165.         #define DEBUGREGISTER(hMod) ((void)0)
  166.  
  167.     #else // not DEBUG
  168.  
  169.         #define ASSERT(exp)    ((void)0)
  170.         #define VERIFY(exp)    (exp)
  171.         #define DEBUGMSG(cond,printf_exp) ((void)0)
  172.         #define DEBUGCHK(exp) ((void)0)
  173.         #define DEBUGREGISTER(hMod) ((void)0)
  174.  
  175.     #endif // DEBUG
  176.  
  177.     #ifdef __cplusplus
  178.     }
  179.     #endif
  180.  
  181. #endif // __DBGAPI_H__
  182. //
  183. // End of NT emulator hack
  184. /////////////////////////////////////////////////////////
  185.  
  186.  
  187. #ifdef DEBUG
  188.  
  189.     /////////////////////////////////////////////////////////
  190.     // Start of DEBUG mode defines
  191.  
  192.     #ifdef ZONE_FUNCTION
  193.     #undef ZONE_FUNCTION
  194.     #endif
  195.  
  196.     #ifdef ZONE_ERROR
  197.     #undef ZONE_ERROR
  198.     #endif
  199.  
  200.     #ifdef ZONE_SPEECH
  201.     #undef ZONE_SPEECH
  202.     #endif
  203.  
  204.     #define ZONE_FUNCTION   DEBUGZONE(0)
  205.     #define ZONE_WARNING    DEBUGZONE(1)
  206.     #define ZONE_ERROR      DEBUGZONE(2)
  207.     #define ZONE_VERBOSE    DEBUGZONE(3)
  208.     #define ZONE_SPEECH    DEBUGZONE(4)
  209.     #define ZONE_SINK    DEBUGZONE(5)
  210.     #define ZONE_AUDIO    DEBUGZONE(6)
  211.     #define ZONE_CONTROLS    DEBUGZONE(7)
  212.  
  213.  
  214.     #ifdef APCDBG_INIT
  215.  
  216.         #pragma message("APCDBG_INIT defined - initializing dpCurSettings")
  217.  
  218.         DBGPARAM dpCurSettings = {
  219.             TEXT(APCDBG_INIT),
  220.             TEXT("Function"),   // ZONE_FUNCTION
  221.             TEXT("Warning"),    // ZONE_WARNING
  222.             TEXT("Error"),        // ZONE_ERROR
  223.             TEXT("Verbose"),    // ZONE_VERBOSE
  224.             TEXT("Speech"),        // ZONE_SPEECH
  225.             TEXT("Sink"),        // ZONE_SINK
  226.             TEXT("Audio"),        // ZONE_AUDIO
  227.             TEXT("Controls"),   // ZONE_CONTROLS
  228.  
  229.         #ifdef APCDBG_8
  230.             TEXT(APCDBG_8),
  231.         #else
  232.             TEXT("?"),
  233.         #endif
  234.  
  235.         #ifdef APCDBG_9
  236.             TEXT(APCDBG_9),
  237.         #else
  238.             TEXT("?"),
  239.         #endif
  240.  
  241.         #ifdef APCDBG_10
  242.             TEXT(APCDBG_10),
  243.         #else
  244.             TEXT("?"),
  245.         #endif
  246.  
  247.         #ifdef APCDBG_11
  248.             TEXT(APCDBG_11),
  249.         #else
  250.             TEXT("?"),
  251.         #endif
  252.  
  253.         #ifdef APCDBG_12
  254.             TEXT(APCDBG_12),
  255.         #else
  256.             TEXT("?"),
  257.         #endif
  258.  
  259.         #ifdef APCDBG_13
  260.             TEXT(APCDBG_13),
  261.         #else
  262.             TEXT("?"),
  263.         #endif
  264.  
  265.         #ifdef APCDBG_14
  266.             TEXT(APCDBG_14),
  267.         #else
  268.             TEXT("?"),
  269.         #endif
  270.  
  271.         #ifdef APCDBG_15
  272.             TEXT(APCDBG_15),
  273.         #else
  274.             TEXT("?"),
  275.         #endif
  276.  
  277.  
  278.             0x00000006        // ZONE_WARNING | ZONE_ERROR
  279.         };
  280.  
  281.  
  282.     #endif // APCDEBUGINIT
  283.  
  284.  
  285.     #define SETDBGZONE(z)    (dpCurSettings.ulZoneMask = z)
  286.  
  287.     #define S2WS1(str)   WCHAR S2WS1[100]; if(-1 == mbstowcs(S2WS1, (const char *)str, 100)) S2WS1[0]=0
  288.     #define S2WS2(str)   WCHAR S2WS2[100]; if(-1 == mbstowcs(S2WS2, (const char *)str, 100)) S2WS2[0]=0
  289.     #define S2WS3(str)   WCHAR S2WS3[100]; if(-1 == mbstowcs(S2WS3, (const char *)str, 100)) S2WS3[0]=0
  290.     #define S2WS4(str)   WCHAR S2WS4[100]; if(-1 == mbstowcs(S2WS4, (const char *)str, 100)) S2WS4[0]=0
  291.  
  292.  
  293.     // End of DEBUG mode defines
  294.     /////////////////////////////////////////////////////////
  295.  
  296. #else // not DEBUG
  297.  
  298.     /////////////////////////////////////////////////////////
  299.     // Start of RETAIL mode defines
  300.  
  301.     #define SETDBGZONE(z)    (0)
  302.  
  303.     #define S2WS1(str)          (0)
  304.     #define S2WS2(str)          (0)
  305.     #define S2WS3(str)          (0)
  306.     #define S2WS4(str)          (0)
  307.  
  308.     // End of RETAIL mode defines
  309.     /////////////////////////////////////////////////////////
  310.  
  311. #endif // DEBUG
  312.  
  313. #endif // _APCDEBUG_H
  314.