Leaked source code of windows server 2003
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.

120 lines
2.8 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. /***** PROTOTYPES */
  24. extern int __cdecl sprintf(char *, const char *, ...);
  25. /***
  26. ** Function: LogError
  27. **
  28. ** Description:
  29. ** Add another message to the error log.
  30. ***/
  31. void LogError(const long type, const long id, const char *arg)
  32. {
  33. char caption[256];
  34. char msg[256];
  35. WORD etype;
  36. HANDLE h;
  37. DWORD logit;
  38. DWORD size;
  39. HKEY key;
  40. HMODULE hInst = ModuleInstance();
  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. if (arg && (strlen(caption)+strlen(arg)<sizeof(msg)))
  63. sprintf(msg, caption, arg);
  64. else
  65. {
  66. strcpy(msg, caption); // No room for the argument.
  67. }
  68. LoadString(hInst, IDS_CAPTION, caption, sizeof(caption));
  69. #if NOMSGBOX
  70. fputs("WARNING- ", stderr);
  71. fputs(msg, stderr);
  72. fputs("\n", stderr);
  73. #else
  74. MessageBox(NULL, msg, caption, INFO);
  75. #endif
  76. SetLastError(0); /* MessageBox(NULL,...) is broken */
  77. }
  78. }
  79. if (etype==EVENTLOG_ERROR_TYPE) {
  80. LoadString(hInst, (UINT)id, caption, sizeof(caption));
  81. if (arg && (strlen(caption)+strlen(arg)<sizeof(msg)))
  82. sprintf(msg, caption, arg);
  83. else
  84. {
  85. strcpy(msg, caption);
  86. }
  87. LoadString(hInst, IDS_CAPTION, caption, sizeof(caption));
  88. #if NOMSGBOX
  89. fputs("ERROR - ", stderr);
  90. fputs(msg, stderr);
  91. fputs("\n", stderr);
  92. #else
  93. MessageBox(NULL, msg, caption, INFO);
  94. #endif
  95. SetLastError(0); /* MessageBox(NULL,...) is broken */
  96. }
  97. RegCloseKey(key);
  98. }
  99. }