Dbgfunc.c
上传用户:chzmdj
上传日期:2007-01-22
资源大小:135k
文件大小:2k
源码类别:

源码/资料

开发平台:

C/C++

  1. /**************************************************************************
  2.     DbgFunc.C
  3.     Use to write debug message to a file.
  4.     Because some code in this dll is system code, it can not be debug.
  5.     so I write some message to file.  Use this message to debug dll.
  6.     (C) 1996.11 Inventec (TianJin) Co., Ltd.
  7.     Author: Gang Yan
  8.     Comments:  1. 97.5.30 is version 1.0.
  9. ***************************************************************************/
  10. #include "windows.h"
  11. #include "stdio.h"
  12. #include "stdarg.h"
  13. #include "string.h"
  14. #include "DbgFunc.h"
  15. BOOL bDebugBegin = TRUE;
  16. // This function is used to check whether file handle and the buffer is right.
  17. // right then return FALSE, Otherwise return FALSE;
  18. BOOL IsErrPara(FILE* fp, LPSTR szBuff)
  19. {
  20. // Check file handle.
  21. if (fp == NULL)
  22. {
  23. MessageBeep(MB_OK);
  24. return TRUE;
  25. }
  26. return FALSE;
  27. }
  28. // Because thunk program can not debug.
  29. // So this function use to write debug message to file.
  30. // And use for debug version.
  31. void DbgPrintf(LPSTR fmt, ...)
  32. {
  33. va_list marker;
  34. char szBuff[4096];
  35. FILE* fp;
  36. va_start(marker, fmt);
  37. wvsprintf(szBuff, fmt, marker);
  38. va_end(marker);
  39.     
  40. #ifdef _DBGFILE_OVERWRITE_
  41. if (bDebugBegin)
  42. {
  43. // Delete old debug file.
  44. bDebugBegin = FALSE;
  45. fp = fopen(_DEBUG_FILE_NAME_, "w");
  46. fprintf(fp, "Debug Message:n");
  47. fclose(fp);
  48. }
  49. #endif
  50. fp = fopen(_DEBUG_FILE_NAME_, "a");
  51. if (IsErrPara(fp, szBuff))
  52. {
  53. return;
  54. }
  55. fprintf(fp, "%sn", szBuff);
  56. fclose(fp); 
  57. }
  58. void DbgLPCSTR(LPSTR szPreWrite, LPSTR szBuff, int cbLen, BOOL bReturn)
  59. {
  60. char temp[4096];
  61. FILE*  fp;
  62. strncpy(temp, szBuff, cbLen);
  63. temp[cbLen] = 0x00;
  64. #ifdef _DBGFILE_OVERWRITE_
  65. if (bDebugBegin)
  66. {
  67. // Delete old debug file.
  68. bDebugBegin = FALSE;
  69. fp = fopen(_DEBUG_FILE_NAME_, "w");
  70. fprintf(fp, "Debug Message:n");
  71. fclose(fp);
  72. }
  73. #endif
  74. fp = fopen(_DEBUG_FILE_NAME_, "a");
  75. if (IsErrPara(fp, szBuff))
  76. {
  77. return;
  78. }
  79. fprintf(fp, "%s%s", szPreWrite, temp);
  80. if (bReturn)
  81. fprintf(fp, "n");
  82. fclose(fp); 
  83. }