WINERR.C

[大目次 | 目次 | 型・クラス・構造体 | 関数 | マクロ]

大目次

目次

型・クラス・構造体一覧

関数一覧

マクロ一覧


   1|/**************************************************************************
   2|  1. <<< Windows API エラーコード (WinErr) >>> 
   3|***************************************************************************/
   4|
   5|#include "mixer_precomp.h"  /* Auto precompiled header, Look at mixer-... folder */
   6|// #pragma hdrstop
   7|
   8|#if defined(USES_MXP_AUTOINC)
   9| #include  "winerr.ah"  /* Auto include header, Look at mixer-... folder */
  10|#endif
  11|
  12|
  13|#include  <windows.h>
  14|// #include  <winerror.h>
  15|
  16|#ifdef  WINERR_USE_DDRAW
  17| #include <ddraw.h>
  18|#endif
  19|
  20| 
  21|/*---------------------------------------------------------------------*/
  22|/* 2. <<<<◆(WinErr) Windows API エラーコード >>>> */ 
  23|/*---------------------------------------------------------------------*/
  24|
  25| 
  26|/**************************************************************************
  27|  2-1. <<< [WinErr_Res] 検索結果コード >>> 
  28|***************************************************************************/
  29|typedef  enum _WinErr_Res {
  30|  WinErr_Hit, WinErr_NotHit,
  31|} WinErr_Res;
  32| 
  33|/**************************************************************************
  34|  2-2. <<< ファイルパス文字列 >>> 
  35|***************************************************************************/
  36|
  37|#ifdef  FOR_WINCE
  38| char*  WinErr_Path_winerror = "D:\\WINCE300\\PUBLIC\\Eagle_APC\\WINCE300\\cesysgen\\sdk\\inc\\WINERROR.H";
  39| char*  WinErr_Path_ddraw = "D:\\WINCE300\\PUBLIC\\Eagle_APC\\WINCE300\\cesysgen\\sdk\\inc\\ddraw.h";
  40|#else
  41| char*  WinErr_Path_winerror = "c:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\\WINERROR.H";
  42| char*  WinErr_Path_ddraw = "D:\\mssdk\\include\\ddraw.h or D:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\\DDRAW.H";
  43|#endif
  44| 
  45|/**************************************************************************
  46|  2-3. <<< ★[WinErr_data] データ >>> 
  47|***************************************************************************/
  48|
  49|typedef struct _WinErr_Data {
  50|  int    code;    /* エラーコード */
  51|  char*  symbol;  /* シンボル名 */
  52|  char*  msg;     /* エラーの説明(予備情報) */
  53|  char**  headPath;  /* エラーコードのあるヘッダファイルのパス名のアドレス */
  54|} WinErr_Data;
  55|
  56|#define  CODE( symbol, msg, ppath ) \
  57|  { symbol, #symbol, msg, &ppath }
  58|#define  WINERR_OTHER  -1
  59|
  60|WinErr_Data  WinErr_noErrorData = CODE( ERROR_SUCCESS, "", WinErr_Path_winerror );
  61|WinErr_Data  WinErr_otherData = CODE( WINERR_OTHER, "WinErr に登録されていないコードです", WinErr_Path_winerror );
  62|
  63|WinErr_Data  WinErr_data[] = {
  64|
  65|  CODE( ERROR_SUCCESS, "", WinErr_Path_winerror ),
  66|
  67|  /* 2-4. <<< Windows 一般関係 >>> c:\Program Files\Microsoft Visual Studio\VC98\Include\WINERROR.H */
  68|  CODE( ERROR_INVALID_HANDLE, "", WinErr_Path_winerror ),
  69|  CODE( ERROR_FILE_NOT_FOUND, "The system cannot find the file specified.", WinErr_Path_winerror ),
  70|  CODE( ERROR_PATH_NOT_FOUND, "The system cannot find the path specified.", WinErr_Path_winerror ),
  71|  CODE( ERROR_ACCESS_DENIED, "", WinErr_Path_winerror ),
  72|  CODE( ERROR_INVALID_PARAMETER, "dwSize をチェック", WinErr_Path_winerror ),
  73|  CODE( ERROR_NOT_SUPPORTED, "", WinErr_Path_winerror ),
  74|
  75|  /* 2-5. <<< Direct Draw 関係 >>> D:\mssdk\include\ddraw.h or D:\Program Files\Microsoft Visual Studio\VC98\Include\DDRAW.H */
  76|  #ifdef  WINERR_USE_DDRAW
  77|   CODE( DDERR_CANTCREATEDC, "2つ目や、Lock などで DC が取れない", WinErr_Path_ddraw ),
  78|   CODE( DDERR_DCALREADYCREATED, "2つ目の DC は取れない", WinErr_Path_ddraw ),
  79|   CODE( DDERR_INVALIDCAPS, "", WinErr_Path_ddraw ),
  80|   CODE( DDERR_INVALIDPIXELFORMAT, "指定したピクセル書式は対応していません", WinErr_Path_ddraw ),
  81|   CODE( DDERR_INVALIDRECT, "矩形の指定がおかしい", WinErr_Path_ddraw ),
  82|   CODE( DDERR_NOCOLORKEYHW, "", WinErr_Path_ddraw ),
  83|   CODE( DDERR_SURFACEBUSY, "サーフェスが BUSY (ReleaseDCをすること)", WinErr_Path_ddraw ),
  84|   CODE( DDERR_OUTOFVIDEOMEMORY, "", WinErr_Path_ddraw ),   /* 380, 0x17C */
  85|   CODE( DDERR_UNSUPPORTEDFORMAT, "", WinErr_Path_ddraw ),
  86|  #endif
  87|
  88|};
  89|
  90|
  91|#undef  CODE
  92| 
  93|/**************************************************************************
  94|  2-6. <<< [WinErr_getData] データを検索する >>> 
  95|【補足】
  96|・内部用です。
  97|【内部補足】
  98|・pResult が WinErr_NotHit のときでも、
  99|  同じカテゴリが見つかったときは、そのカテゴリの中の1つのデータを返します。
 100|  同じカテゴリさえ見つからなかったときは、WinErr_otherData を返します。
 101|***************************************************************************/
 102|WinErr_Data*  WinErr_getData( int code, WinErr_Res* pResult )
 103|{
 104|  static  int  prevCode = 0;
 105|  static  WinErr_Data*  prevData = &WinErr_noErrorData;
 106|
 107|  WinErr_Data*  data = WinErr_data;
 108|  WinErr_Data*  data_over = WinErr_data + ( sizeof(WinErr_data) / sizeof(WinErr_Data) );
 109|  WinErr_Data*  neibData = &WinErr_otherData;
 110|
 111|  if ( prevCode == code )  return  prevData;
 112|
 113|  for ( ; data < data_over; data++ ) {
 114|    if ( data->code == code )  break;
 115|    if ( (data->code & 0x0FFF0000) == (code & 0x0FFF0000) )
 116|      neibData = data;
 117|    if ( (code & 0x0FFF0000) == 0x00070000 ) {
 118|      if ( (code & 0x0000FFFF) == data->code )  break;
 119|    }
 120|  }
 121|  if ( data < data_over ) {
 122|    prevCode = code;
 123|    prevData = data;
 124|    *pResult = WinErr_Hit;
 125|  }
 126|  else {
 127|    data = neibData;
 128|    *pResult = WinErr_NotHit;
 129|  }
 130|
 131|  return  data;
 132|}
 133| 
 134|/**************************************************************************
 135|  2-7. <<< [WinErr_assert_imp] エラーなら ASSERT する >>> 
 136|***************************************************************************/
 137|void  WinErr_assert_imp( int code, char* file, int line )
 138|{
 139|  WinErr_Res    res;
 140|  WinErr_Data*  data;
 141|  DWORD  r;
 142|  char*  p;
 143|  char  msg[2048];
 144|
 145|  data = WinErr_getData( code, &res );
 146|
 147|  sprintf( msg, "Windows API Err\r\n  code = 0x%08X", code );
 148|  p = strchr( msg, '\0' );
 149|
 150|  if ( res == WinErr_Hit ) {
 151|    sprintf( p, "(%s)\r\n  info: %s\r\n  file: %s",
 152|      data->symbol, data->msg, *data->headPath );
 153|  }
 154|  else if ( data == &WinErr_otherData ) {
 155|    sprintf( p, "(??????????)  nearest: none" );
 156|  }
 157|  else {
 158|    sprintf( p, "(??????????)  nearest: 0x%08X(%s)  nearest file: %s",
 159|      data->code, data->symbol, *data->headPath );
 160|  }
 161|
 162|  r = FormatMessage(
 163|    FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
 164|    NULL, code,
 165|    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // デフォルト言語
 166|    (LPTSTR)p, sizeof(msg) - (msg - p), NULL );
 167|  StrX_trim( p );         p = strchr( msg, '\0' );
 168|  strcpy( p, "\r\n  " );  p = strchr( msg, '\0' );
 169|
 170|  Errors_error_imp( file, line, Errors_ASSERT, Errors_ea,
 171|    Errors_ps, msg );
 172|}
 173|
 174| 
 175|/**************************************************************************
 176|  2-8. <<< [WinErr_getSym] シンボル名を返す >>> 
 177|***************************************************************************/
 178|char*  WinErr_getSym( int code )
 179|{
 180|  WinErr_Res    res;
 181|  WinErr_Data*  data = WinErr_getData( code, &res );
 182|
 183|  return  data->symbol;
 184|}
 185|
 186| 
 187|/**************************************************************************
 188|  2-9. <<< [WinErr_getMsg] エラーの説明を返す >>> 
 189|***************************************************************************/
 190|char*  WinErr_getMsg( int code )
 191|{
 192|  WinErr_Res    res;
 193|  WinErr_Data*  data = WinErr_getData( code, &res );
 194|
 195|  return  data->msg;
 196|}
 197|
 198|
 199| 
 200|/*---------------------------------------------------------------------*/
 201|/* 3. <<<<◆基本型のデバッグ表示 >>>> */ 
 202|/*---------------------------------------------------------------------*/
 203|
 204| 
 205|/**************************************************************************
 206|  3-1. <<< [WinErr_RECT_print] RECT 型のデバッグ表示 >>> 
 207|***************************************************************************/
 208|#ifndef  ERRORS_CUT_DEBUG_TOOL
 209|void  WinErr_RECT_print( RECT* t, const char* title )
 210|{
 211|  Errors_printf( "%sRECT[%p] (%d, %d)-(%d, %d)",
 212|    title, t, t->left, t->top, t->right, t->left );
 213|}
 214|#endif
 215|
 216|
 217| 
 218|