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.

138 lines
3.2 KiB

  1. // IUCtl.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f IUCtlps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include <initguid.h>
  8. #include "IUCtl.h"
  9. #include "IUCtl_i.c"
  10. #include "Update.h"
  11. #include "ProgressListener.h"
  12. #include "Detection.h"
  13. #include "UpdateCompleteListener.h"
  14. #include <UrlAgent.h>
  15. #include <FreeLog.h>
  16. #include <wusafefn.h>
  17. CComModule _Module;
  18. HANDLE g_hEngineLoadQuit;
  19. CIUUrlAgent *g_pIUUrlAgent;
  20. CRITICAL_SECTION g_csUrlAgent; // used to serialize access to CIUUrlAgent::Populate()
  21. BOOL g_fInitCS;
  22. //extern "C" const CLSID CLSID_Update2 = {0x32BF9AC1,0xB122,0x4fed,{0xB3,0xC7,0x2D,0xA5,0x20,0xDF,0x2B,0x4E}};
  23. BEGIN_OBJECT_MAP(ObjectMap)
  24. OBJECT_ENTRY(CLSID_Update, CUpdate)
  25. //OBJECT_ENTRY(CLSID_Update2, CUpdate)
  26. OBJECT_ENTRY(CLSID_ProgressListener, CProgressListener)
  27. OBJECT_ENTRY(CLSID_Detection, CDetection)
  28. OBJECT_ENTRY(CLSID_UpdateCompleteListener, CUpdateCompleteListener)
  29. END_OBJECT_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // DLL Entry Point
  32. extern "C"
  33. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  34. {
  35. if (dwReason == DLL_PROCESS_ATTACH)
  36. {
  37. //
  38. // create a global CIUUrlAgent object
  39. //
  40. g_pIUUrlAgent = new CIUUrlAgent;
  41. if (NULL == g_pIUUrlAgent)
  42. {
  43. return FALSE;
  44. }
  45. _Module.Init(ObjectMap, hInstance);
  46. DisableThreadLibraryCalls(hInstance);
  47. g_fInitCS = SafeInitializeCriticalSection(&g_csUrlAgent);
  48. //
  49. // Initialize free logging
  50. //
  51. InitFreeLogging(_T("IUCTL"));
  52. LogMessage("Starting");
  53. g_hEngineLoadQuit = CreateEvent(NULL, TRUE, FALSE, NULL);
  54. if (!g_fInitCS || NULL == g_hEngineLoadQuit)
  55. {
  56. LogError(E_FAIL, "InitializeCriticalSection or CreateEvent");
  57. return FALSE;
  58. }
  59. }
  60. else if (dwReason == DLL_PROCESS_DETACH)
  61. {
  62. if (g_fInitCS)
  63. {
  64. DeleteCriticalSection(&g_csUrlAgent);
  65. }
  66. //
  67. // Shutdown free logging
  68. //
  69. LogMessage("Shutting down");
  70. TermFreeLogging();
  71. if (NULL != g_hEngineLoadQuit)
  72. {
  73. CloseHandle(g_hEngineLoadQuit);
  74. }
  75. if (NULL != g_pIUUrlAgent)
  76. {
  77. delete g_pIUUrlAgent;
  78. }
  79. _Module.Term();
  80. }
  81. return TRUE; // ok
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Used to determine whether the DLL can be unloaded by OLE
  85. STDAPI DllCanUnloadNow(void)
  86. {
  87. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Returns a class factory to create an object of the requested type
  91. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  92. {
  93. return _Module.GetClassObject(rclsid, riid, ppv);
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DllRegisterServer - Adds entries to the system registry
  97. STDAPI DllRegisterServer(void)
  98. {
  99. // registers object, typelib and all interfaces in typelib
  100. return _Module.RegisterServer(TRUE);
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // DllUnregisterServer - Removes entries from the system registry
  104. STDAPI DllUnregisterServer(void)
  105. {
  106. return _Module.UnregisterServer(&CLSID_Update);
  107. }