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.

95 lines
2.5 KiB

  1. /*
  2. - Pop3perf.cpp
  3. -
  4. * Purpose:
  5. *
  6. * Copyright:
  7. *
  8. * History:
  9. *
  10. */
  11. #include <StdAfx.h>
  12. #include <winperf.h>
  13. #define PERF_DLL_ONCE
  14. #include <Pop3SvcPerf.h>
  15. #include <perfdll.h>
  16. #define SZ_POP3_SERVICE_NAME L"Pop3Svc"
  17. // Debugging registry key constant
  18. BOOL WINAPI DllMain(
  19. HINSTANCE hinstDLL, // handle to the DLL module
  20. DWORD fdwReason, // reason for calling function
  21. LPVOID lpvReserved) // reserved
  22. {
  23. if (DLL_PROCESS_ATTACH == fdwReason)
  24. {
  25. PERF_DATA_INFO pdi;
  26. // Configure Perfmon Counters
  27. // PERF_DATA_INFO have buffers of MAX_PATH characters
  28. pdi.cGlobalCounters = cntrMaxGlobalCntrs;
  29. pdi.rgdwGlobalCounterTypes = g_rgdwGlobalCntrType;
  30. pdi.rgdwGlobalCntrScale = g_rgdwGlobalCntrScale;
  31. wcsncpy(pdi.wszSvcName, SZ_POP3_SERVICE_NAME, MAX_PATH-1);
  32. wcsncpy(pdi.wszGlobalSMName, szPOP3PerfMem, MAX_PATH-1);
  33. pdi.wszSvcName[MAX_PATH-1]=0;
  34. pdi.wszGlobalSMName[MAX_PATH-1]=0;
  35. // NOTE: If your service does not require Instance
  36. // counters, you MUST set cInstCounters to zero!
  37. pdi.cInstCounters = cntrMaxInstCntrs;
  38. wcsncpy(pdi.wszInstSMName, szPOP3InstPerfMem, MAX_PATH-1);
  39. wcsncpy(pdi.wszInstMutexName, szPOP3InstPerfMutex, MAX_PATH-1);
  40. pdi.wszInstSMName[MAX_PATH-1]=0;
  41. pdi.wszInstMutexName[MAX_PATH-1]=0;
  42. pdi.rgdwInstCounterTypes = g_rgdwInstCntrType;
  43. if (FAILED(HrInitPerf(&pdi)))
  44. return FALSE;
  45. }
  46. if (DLL_PROCESS_DETACH == fdwReason)
  47. {
  48. HrShutdownPerf();
  49. }
  50. return TRUE;
  51. }
  52. // Must have wrapper functions, otherwise the lib functions don't get
  53. // pulled into the executable (smart linking "saves us" again...)
  54. DWORD APIENTRY
  55. Pop3SvcOpenPerfProc(LPWSTR sz)
  56. {
  57. return OpenPerformanceData(sz);
  58. }
  59. DWORD APIENTRY
  60. Pop3SvcCollectPerfProc(LPWSTR sz, LPVOID *ppv, LPDWORD pdw1, LPDWORD pdw2)
  61. {
  62. return CollectPerformanceData(sz, ppv, pdw1, pdw2);
  63. }
  64. DWORD APIENTRY
  65. Pop3SvcClosePerfProc(void)
  66. {
  67. return ClosePerformanceData();
  68. }
  69. HRESULT _stdcall DllRegisterServer(void)
  70. {
  71. return RegisterPerfDll( SZ_POP3_SERVICE_NAME,
  72. L"Pop3SvcOpenPerfProc",
  73. L"Pop3SvcCollectPerfProc",
  74. L"Pop3SvcClosePerfProc"
  75. ) ;
  76. }
  77. HRESULT _stdcall DllUnregisterServer(void)
  78. {
  79. return HrUninstallPerfDll( SZ_POP3_SERVICE_NAME );
  80. }