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.

113 lines
2.4 KiB

  1. // LoggingTest.cpp : Defines the entry point for the console application.
  2. //
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <dbgtrace.h>
  6. #include "CEventLogger.h"
  7. #ifdef THIS_FILE
  8. #undef THIS_FILE
  9. #endif
  10. static char __szTraceSourceFile[] = __FILE__;
  11. #define THIS_FILE __szTraceSourceFile
  12. #define TRACE_FILEID 0
  13. DWORD WINAPI LoggingTestThread(LPVOID lpvThreadParam)
  14. {
  15. CEventLogger log;
  16. char szBuf[500];
  17. int nLoop;
  18. TraceFunctEnter("LoggingTestThread");
  19. if( log.Init("logfile") != ERROR_SUCCESS)
  20. {
  21. printf("Erorr!\n");
  22. goto cleanup;
  23. }
  24. //printf("Enter in something to log: ");
  25. //gets(szBuf);
  26. for(nLoop = 0;nLoop < 2000;nLoop++)
  27. {
  28. sprintf(szBuf, "%s %d", (LPSTR) lpvThreadParam,nLoop);
  29. if(log.LogEvent(1, szBuf, FALSE) != ERROR_SUCCESS )
  30. printf("ERROR\n");
  31. // wait 1 ms
  32. Sleep(1);
  33. }
  34. sprintf(szBuf,"Graphical Log Test, Thread: %s", (LPSTR) lpvThreadParam);
  35. log.LogEvent(1, szBuf, TRUE);
  36. TraceFunctLeave();
  37. return 1;
  38. cleanup:
  39. TraceFunctLeave();
  40. return(0);
  41. }
  42. int _cdecl main(int argc, char* argv[])
  43. {
  44. HANDLE ahThreads[4];
  45. DWORD dwId;
  46. CEventLogger log;
  47. char szBuf[4][256];
  48. int nLoop;
  49. #if !NOTRACE
  50. InitAsyncTrace();
  51. #endif
  52. if( argc < 2 )
  53. {
  54. printf("need some arguments, eh?\n");
  55. return 0;
  56. }
  57. for(nLoop = 1;nLoop <=4;nLoop++)
  58. sprintf(szBuf[nLoop-1], "%s - (Thread %d)", argv[1], nLoop);
  59. log.Init("LogFile.tmp");
  60. log.LogEvent(1, "Hello, I'm a PopUp", TRUE );
  61. log.LogEvent(1, "Hello, I'm a PopUp1", TRUE );
  62. log.LogEvent(1, "Hello, I'm a PopUp2", TRUE );
  63. ahThreads[0] = CreateThread(NULL,0,LoggingTestThread,(LPVOID) szBuf[0], CREATE_SUSPENDED, &dwId);
  64. ahThreads[1] = CreateThread(NULL,0,LoggingTestThread,(LPVOID) szBuf[1], CREATE_SUSPENDED, &dwId);
  65. ahThreads[2] = CreateThread(NULL,0,LoggingTestThread,(LPVOID) szBuf[2], CREATE_SUSPENDED, &dwId);
  66. ahThreads[3] = CreateThread(NULL,0,LoggingTestThread,(LPVOID) szBuf[3], CREATE_SUSPENDED, &dwId);
  67. ResumeThread(ahThreads[0]);
  68. ResumeThread(ahThreads[1]);
  69. ResumeThread(ahThreads[2]);
  70. ResumeThread(ahThreads[3]);
  71. WaitForMultipleObjects(4,ahThreads,TRUE,INFINITE);
  72. TermAsyncTrace();
  73. return 0;
  74. }