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.

138 lines
3.2 KiB

  1. // AddIn.cpp
  2. // DLL server exported functions, global ATL module stuff.
  3. #include <initguid.h>
  4. #include "precomp.h"
  5. #include "resource.h"
  6. #include "AddIn.h"
  7. #include "Connect.h"
  8. #include "TestSettingsCtrl.h"
  9. #include "logviewer.h"
  10. #include "avoptions.h"
  11. #include "viewlog.h"
  12. #include <assert.h>
  13. extern CSessionLogEntryArray g_arrSessionLog;
  14. // Global heap so we don't corrupt VS's heap (or vice-versa)
  15. HANDLE g_hHeap = NULL;
  16. // Global ATL module
  17. CComModule _Module;
  18. // All the class objects this server exports.
  19. BEGIN_OBJECT_MAP(g_ObjectMap)
  20. OBJECT_ENTRY(CLSID_Connect, CConnect)
  21. OBJECT_ENTRY(CLSID_LogViewer, CLogViewer)
  22. OBJECT_ENTRY(CLSID_TestSettingsCtrl, CTestSettingsCtrl)
  23. OBJECT_ENTRY(CLSID_AVOptions, CAppVerifierOptions)
  24. END_OBJECT_MAP()
  25. // DLL Entry Point
  26. extern "C" BOOL WINAPI
  27. DllMain(
  28. HINSTANCE hInstance,
  29. DWORD dwReason,
  30. LPVOID /*lpReserved*/)
  31. {
  32. switch(dwReason)
  33. {
  34. case DLL_PROCESS_ATTACH:
  35. g_hInstance = hInstance;
  36. // Create our heap
  37. g_hHeap = HeapCreate(0,0,0);
  38. if (g_hHeap == NULL)
  39. {
  40. return FALSE;
  41. }
  42. // Initialize the ATL module
  43. _Module.Init(g_ObjectMap, hInstance, &LIBID_AppVerifierLib);
  44. g_psTests = new std::set<CTestInfo*, CompareTests>;
  45. // Prevent thread attach/detach messages
  46. DisableThreadLibraryCalls(hInstance);
  47. break;
  48. case DLL_PROCESS_DETACH:
  49. g_aAppInfo.clear();
  50. g_aAppInfo.resize(0);
  51. // Ugly, force call to destructor.
  52. // This is because we delete the heap here, but the C Run-time destroys
  53. // all the objects after this point, which uses the heap.
  54. g_aAppInfo.CAVAppInfoArray::~CAVAppInfoArray();
  55. g_aTestInfo.clear();
  56. g_aTestInfo.resize(0);
  57. g_aTestInfo.CTestInfoArray::~CTestInfoArray();
  58. g_arrSessionLog.clear();
  59. g_arrSessionLog.resize(0);
  60. g_arrSessionLog.CSessionLogEntryArray::~CSessionLogEntryArray();
  61. delete g_psTests;
  62. // Shutdown ATL module
  63. _Module.Term();
  64. // Delete our heap.
  65. if (g_hHeap)
  66. {
  67. HeapDestroy(g_hHeap);
  68. }
  69. break;
  70. }
  71. return TRUE;
  72. }
  73. // Used to determine whether the DLL can be unloaded by OLE
  74. STDAPI
  75. DllCanUnloadNow()
  76. {
  77. return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE;
  78. }
  79. // Returns a class factory to create an object of the requested type
  80. STDAPI
  81. DllGetClassObject(
  82. REFCLSID rclsid,
  83. REFIID riid,
  84. LPVOID* ppv)
  85. {
  86. return _Module.GetClassObject(rclsid, riid, ppv );
  87. }
  88. // DllRegisterServer - Adds entries to the system registry
  89. STDAPI
  90. DllRegisterServer()
  91. {
  92. return _Module.RegisterServer(TRUE);
  93. }
  94. // DllUnregisterServer - Removes entries from the system registry
  95. STDAPI
  96. DllUnregisterServer()
  97. {
  98. return _Module.UnregisterServer();
  99. }
  100. // Overloaded new and deletes to go through our allocator.
  101. void* __cdecl
  102. operator new(
  103. size_t size)
  104. {
  105. assert(g_hHeap);
  106. return HeapAlloc(g_hHeap, 0, size);
  107. }
  108. void __cdecl
  109. operator delete(
  110. void* pv)
  111. {
  112. assert(g_hHeap);
  113. HeapFree(g_hHeap, 0, pv);
  114. }