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.

131 lines
2.5 KiB

  1. //
  2. // dll.cpp
  3. //
  4. #include <iostream.h>
  5. #include <objbase.h>
  6. #include <shlwapi.h>
  7. #include <shlwapip.h>
  8. #include <shlobj.h>
  9. #include "cowsite.h"
  10. #include "Iface.h" // Interface declarations
  11. #include "Registry.h" // Registry helper functions
  12. #include "migutil.h"
  13. #include "migeng.h"
  14. #include "migfact.h"
  15. #include "migtask.h"
  16. #include "migoobe.h"
  17. ///////////////////////////////////////////////////////////
  18. //
  19. // Global variables
  20. //
  21. HMODULE g_hModule = NULL; // DLL module handle
  22. static long g_cComponents = 0; // Count of active components
  23. // Friendly name of component
  24. const char g_szFriendlyName[] = "Migration Wizard Engine";
  25. // Version-independent ProgID
  26. const char g_szVerIndProgID[] = "MigWiz";
  27. // ProgID
  28. const char g_szProgID[] = "MigWiz.1";
  29. ///////////////////////////////////////////////////////////
  30. //
  31. // Exported functions
  32. //
  33. STDAPI DllAddRef()
  34. {
  35. InterlockedIncrement(&g_cComponents);
  36. return S_OK;
  37. }
  38. STDAPI DllRelease()
  39. {
  40. InterlockedDecrement(&g_cComponents);
  41. return S_OK;
  42. }
  43. //
  44. // Can DLL unload now?
  45. //
  46. STDAPI DllCanUnloadNow()
  47. {
  48. if (g_cComponents == 0)
  49. {
  50. return S_OK;
  51. }
  52. else
  53. {
  54. return S_FALSE;
  55. }
  56. }
  57. //
  58. // Get class factory
  59. //
  60. STDAPI DllGetClassObject(const CLSID& clsid,
  61. const IID& iid,
  62. void** ppv)
  63. {
  64. HRESULT hres;
  65. DllAddRef();
  66. if (IsEqualIID(clsid, CLSID_MigWizEngine))
  67. {
  68. hres = CMigFactory_Create(clsid, iid, ppv);
  69. }
  70. else
  71. {
  72. *ppv = NULL;
  73. hres = CLASS_E_CLASSNOTAVAILABLE;
  74. }
  75. DllRelease();
  76. return hres;
  77. }
  78. //
  79. // Server registration
  80. //
  81. STDAPI DllRegisterServer()
  82. {
  83. return RegisterServer(g_hModule,
  84. CLSID_MigWizEngine,
  85. g_szFriendlyName,
  86. g_szVerIndProgID,
  87. g_szProgID);
  88. }
  89. //
  90. // Server unregistration
  91. //
  92. STDAPI DllUnregisterServer()
  93. {
  94. return UnregisterServer(CLSID_MigWizEngine,
  95. g_szVerIndProgID,
  96. g_szProgID);
  97. }
  98. ///////////////////////////////////////////////////////////
  99. //
  100. // DLL module information
  101. //
  102. BOOL APIENTRY DllMain(HANDLE hModule,
  103. DWORD dwReason,
  104. void* lpReserved)
  105. {
  106. if (dwReason == DLL_PROCESS_ATTACH)
  107. {
  108. g_hModule = (HMODULE)hModule;
  109. DisableThreadLibraryCalls((HMODULE)hModule); // PERF: makes faster because we don't get thread msgs
  110. }
  111. return TRUE;
  112. }