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.

178 lines
4.4 KiB

  1. #include "precomp.hxx"
  2. #pragma hdrstop
  3. #include <advpub.h> // RegInstall stuff
  4. #include "twprop.h" // CTimeWarpProp::CreateInstance
  5. #include "twfldr.h" // CTimeWarpFolder::CreateInstance
  6. HINSTANCE g_hInstance = 0;
  7. LONG g_cRefThisDll = 0; // DLL global reference count
  8. CF_TABLE_BEGIN(g_ObjectInfo)
  9. CF_TABLE_ENTRY(&CLSID_TimeWarpProp, CTimeWarpProp::CreateInstance, COCREATEONLY),
  10. CF_TABLE_ENTRY(&CLSID_TimeWarpFolder, CTimeWarpRegFolder::CreateInstance, COCREATEONLY),
  11. CF_TABLE_END(g_ObjectInfo)
  12. STDAPI_(void) DllAddRef(void)
  13. {
  14. InterlockedIncrement(&g_cRefThisDll);
  15. }
  16. STDAPI_(void) DllRelease(void)
  17. {
  18. ASSERT( 0 != g_cRefThisDll );
  19. InterlockedDecrement(&g_cRefThisDll);
  20. }
  21. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  22. {
  23. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  24. {
  25. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  26. DllAddRef();
  27. return NOERROR;
  28. }
  29. *ppvObj = NULL;
  30. return E_NOINTERFACE;
  31. }
  32. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  33. {
  34. DllAddRef();
  35. return 2;
  36. }
  37. STDMETHODIMP_(ULONG) CClassFactory::Release()
  38. {
  39. DllRelease();
  40. return 1;
  41. }
  42. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  43. {
  44. *ppv = NULL;
  45. // No aggregation
  46. if (punkOuter) // && !IsEqualIID(riid, IID_IUnknown))
  47. {
  48. return CLASS_E_NOAGGREGATION;
  49. }
  50. else
  51. {
  52. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  53. //if (punkOuter && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  54. // return CLASS_E_NOAGGREGATION;
  55. IUnknown *punk;
  56. HRESULT hr = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  57. if (SUCCEEDED(hr))
  58. {
  59. hr = punk->QueryInterface(riid, ppv);
  60. punk->Release();
  61. }
  62. return hr;
  63. }
  64. }
  65. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  66. {
  67. if (fLock)
  68. DllAddRef();
  69. else
  70. DllRelease();
  71. return S_OK;
  72. }
  73. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  74. {
  75. // Time Warp is only available beginning with Windows XP.
  76. if (!IsOS(OS_WHISTLERORGREATER))
  77. {
  78. return CO_E_WRONGOSFORAPP;
  79. }
  80. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  81. {
  82. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  83. {
  84. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  85. {
  86. *ppv = (void*)pcls;
  87. DllAddRef(); // class factory holds DLL ref count
  88. return NOERROR;
  89. }
  90. }
  91. }
  92. *ppv = NULL;
  93. return CLASS_E_CLASSNOTAVAILABLE;
  94. }
  95. STDAPI DllCanUnloadNow(void)
  96. {
  97. return g_cRefThisDll ? S_FALSE : S_OK;
  98. }
  99. // Call ADVPACK for the given section of our resource based INF
  100. // hInstance = resource instance to get REGINST section from
  101. // szSection = section name to invoke
  102. HRESULT CallRegInstall(HINSTANCE hInstance, LPCSTR szSection)
  103. {
  104. HRESULT hr = E_FAIL;
  105. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  106. if (hinstAdvPack)
  107. {
  108. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  109. if (pfnri)
  110. {
  111. STRENTRY seReg[] =
  112. {
  113. // These two NT-specific entries must be at the end
  114. { "25", "%SystemRoot%" },
  115. { "11", "%SystemRoot%\\system32" },
  116. };
  117. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  118. hr = pfnri(hInstance, szSection, &stReg);
  119. }
  120. FreeLibrary(hinstAdvPack);
  121. }
  122. return hr;
  123. }
  124. STDAPI DllRegisterServer(void)
  125. {
  126. CallRegInstall(g_hInstance, "RegDll");
  127. return S_OK;
  128. }
  129. STDAPI DllUnregisterServer(void)
  130. {
  131. CallRegInstall(g_hInstance, "UnregDll");
  132. return S_OK;
  133. }
  134. STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void *pReserved)
  135. {
  136. switch (dwReason)
  137. {
  138. case DLL_PROCESS_ATTACH:
  139. g_hInstance = hInstance;
  140. DisableThreadLibraryCalls(hInstance);
  141. CcshellGetDebugFlags();
  142. SHFusionInitializeFromModule(hInstance);
  143. InitSnapCheckCache();
  144. break;
  145. case DLL_PROCESS_DETACH:
  146. DestroySnapCheckCache();
  147. SHFusionUninitialize();
  148. break;
  149. }
  150. return TRUE;
  151. }