Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.5 KiB

  1. /***
  2. **
  3. ** Module: T1Instal
  4. **
  5. ** Description:
  6. ** This is a Win32 DLL specific module, that implements
  7. ** the error logging mechanism under Win32.
  8. **
  9. ** Author: Michael Jansson
  10. ** Created: 12/18/93
  11. **
  12. ***/
  13. /***** INCLUDES */
  14. #include <windows.h>
  15. #include "types.h"
  16. #include "t1local.h"
  17. #ifdef NOMSGBOX
  18. #include <stdio.h>
  19. #endif
  20. /***** CONSTANTS */
  21. /*-none-*/
  22. /***** GLOBALS */
  23. extern HANDLE hInst; /* Cached in the T1Instal module. */
  24. /***** PROTOTYPES */
  25. extern int __cdecl sprintf(char *, const char *, ...);
  26. /***
  27. ** Function: LogError
  28. **
  29. ** Description:
  30. ** Add another message to the error log.
  31. ***/
  32. void LogError(const long type, const long id, const char *arg)
  33. {
  34. char caption[256];
  35. char msg[256];
  36. WORD etype;
  37. HANDLE h;
  38. DWORD logit;
  39. DWORD size;
  40. HKEY key;
  41. /* Map the internal envent type to EventLog type. */
  42. if (type==MSG_INFO)
  43. etype = EVENTLOG_INFORMATION_TYPE;
  44. else if (type==MSG_WARNING)
  45. etype = EVENTLOG_WARNING_TYPE;
  46. else
  47. etype = EVENTLOG_ERROR_TYPE;
  48. /* Access the REG data base. */
  49. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY_TYPE1INSTAL, 0,
  50. KEY_QUERY_VALUE, &key)==ERROR_SUCCESS) {
  51. size = sizeof(logit);
  52. if (RegQueryValueEx(key, (LPTSTR)SUBKEY_LOGFILE, NULL,
  53. NULL, (LPVOID)&logit, &size)==ERROR_SUCCESS &&
  54. logit!=0) {
  55. h = RegisterEventSource(NULL, STR_APPNAME);
  56. if (h!=NULL) {
  57. ReportEvent(h, etype, 0, id, NULL, 1, 0, (LPSTR *)&arg, NULL);
  58. DeregisterEventSource(h);
  59. }
  60. if (etype==EVENTLOG_WARNING_TYPE) {
  61. LoadString(hInst, (UINT)id, caption, sizeof(caption));
  62. sprintf(msg, caption, arg);
  63. LoadString(hInst, IDS_CAPTION, caption, sizeof(caption));
  64. #if NOMSGBOX
  65. fputs("WARNING- ", stderr);
  66. fputs(msg, stderr);
  67. fputs("\n", stderr);
  68. #else
  69. MessageBox(NULL, msg, caption, INFO);
  70. #endif
  71. SetLastError(0); /* MessageBox(NULL,...) is broken */
  72. }
  73. }
  74. if (etype==EVENTLOG_ERROR_TYPE) {
  75. LoadString(hInst, (UINT)id, caption, sizeof(caption));
  76. sprintf(msg, caption, arg);
  77. LoadString(hInst, IDS_CAPTION, caption, sizeof(caption));
  78. #if NOMSGBOX
  79. fputs("ERROR - ", stderr);
  80. fputs(msg, stderr);
  81. fputs("\n", stderr);
  82. #else
  83. MessageBox(NULL, msg, caption, INFO);
  84. #endif
  85. SetLastError(0); /* MessageBox(NULL,...) is broken */
  86. }
  87. RegCloseKey(key);
  88. }
  89. }