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.

227 lines
5.6 KiB

  1. #include "stdafx.h"
  2. #include "theapp.h"
  3. #include "comctlwrap.h"
  4. HINSTANCE g_hinst;
  5. EXTERN_C BOOL g_fRunningOnNT;
  6. UINT g_uWindowsBuild;
  7. // Local functions
  8. //
  9. void InitVersionInfo()
  10. {
  11. OSVERSIONINFOA osvi;
  12. osvi.dwOSVersionInfoSize = sizeof(osvi);
  13. GetVersionExA(&osvi);
  14. g_uWindowsBuild = LOWORD(osvi.dwBuildNumber);
  15. g_fRunningOnNT = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
  16. g_dwComCtlIEVersion = GetComCtlIEVersion();
  17. g_dwShlwapiVersion = GetShlwapiVersion();
  18. #ifdef _DEBUG
  19. // Debug code for simulating different OSes.
  20. CRegistry regDebug;
  21. if (regDebug.OpenKey(HKEY_LOCAL_MACHINE, c_szAppRegKey, KEY_READ))
  22. {
  23. DWORD dwSimulateWinBuild = g_uWindowsBuild;
  24. if (!regDebug.QueryDwordValue(c_szRegVal_WindowsBuild, &dwSimulateWinBuild))
  25. {
  26. TCHAR szBuildNum[10];
  27. if (regDebug.QueryStringValue(c_szRegVal_WindowsBuild, szBuildNum, _countof(szBuildNum)))
  28. dwSimulateWinBuild = MyAtoi(szBuildNum);
  29. }
  30. g_uWindowsBuild = (UINT)dwSimulateWinBuild;
  31. }
  32. #endif
  33. }
  34. BOOL WINAPI DllMain(
  35. HINSTANCE hinstDLL, // handle to the DLL module
  36. DWORD fdwReason, // reason for calling function
  37. LPVOID lpvReserved // reserved
  38. )
  39. {
  40. switch (fdwReason)
  41. {
  42. case DLL_PROCESS_ATTACH:
  43. DisableThreadLibraryCalls(hinstDLL);
  44. g_hinst = hinstDLL;
  45. InitVersionInfo();
  46. SHFusionInitializeFromModule(hinstDLL);
  47. break;
  48. case DLL_PROCESS_DETACH:
  49. SHFusionUninitialize();
  50. break;
  51. }
  52. return TRUE;
  53. }
  54. void APIENTRY HomeNetWizardRunDll(HWND hwndStub, HINSTANCE hAppInstance, LPSTR pszCmdLine, int nCmdShow)
  55. {
  56. if (S_OK == CoInitialize(NULL))
  57. {
  58. BOOL fReboot = FALSE;
  59. HomeNetworkWizard_ShowWizard(NULL, &fReboot);
  60. if (fReboot)
  61. {
  62. RestartDialog(NULL, NULL, EWX_REBOOT);
  63. }
  64. CoUninitialize();
  65. }
  66. return;
  67. }
  68. // Classfactory implementation
  69. LONG g_cRefThisDll = 0; // DLL global reference count
  70. STDAPI_(void) DllAddRef(void)
  71. {
  72. InterlockedIncrement(&g_cRefThisDll);
  73. }
  74. STDAPI_(void) DllRelease(void)
  75. {
  76. ASSERT( 0 != g_cRefThisDll );
  77. InterlockedDecrement(&g_cRefThisDll);
  78. }
  79. STDAPI DllCanUnloadNow(void)
  80. {
  81. return g_cRefThisDll ? S_FALSE : S_OK;
  82. }
  83. HRESULT CHomeNetworkWizard_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi);
  84. CF_TABLE_BEGIN( g_ObjectInfo )
  85. CF_TABLE_ENTRY( &CLSID_HomeNetworkWizard, CHomeNetworkWizard_CreateInstance, COCREATEONLY),
  86. CF_TABLE_END( g_ObjectInfo )
  87. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  88. {
  89. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  90. {
  91. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  92. DllAddRef();
  93. return NOERROR;
  94. }
  95. *ppvObj = NULL;
  96. return E_NOINTERFACE;
  97. }
  98. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  99. {
  100. DllAddRef();
  101. return 2;
  102. }
  103. STDMETHODIMP_(ULONG) CClassFactory::Release()
  104. {
  105. DllRelease();
  106. return 1;
  107. }
  108. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  109. {
  110. *ppv = NULL;
  111. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  112. {
  113. return CLASS_E_NOAGGREGATION;
  114. }
  115. else
  116. {
  117. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  118. if (punkOuter) // && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  119. return CLASS_E_NOAGGREGATION;
  120. IUnknown *punk;
  121. HRESULT hr = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  122. if (SUCCEEDED(hr))
  123. {
  124. hr = punk->QueryInterface(riid, ppv);
  125. punk->Release();
  126. }
  127. return hr;
  128. }
  129. }
  130. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  131. {
  132. if (fLock)
  133. DllAddRef();
  134. else
  135. DllRelease();
  136. return S_OK;
  137. }
  138. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  139. {
  140. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  141. {
  142. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  143. {
  144. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  145. {
  146. *ppv = (void*)pcls;
  147. DllAddRef(); // class factory holds DLL ref count
  148. return NOERROR;
  149. }
  150. }
  151. }
  152. *ppv = NULL;
  153. return CLASS_E_CLASSNOTAVAILABLE;
  154. }
  155. // Call ADVPACK for the given section of our resource based INF>
  156. // hInstance = resource instance to get REGINST section from
  157. // szSection = section name to invoke
  158. HRESULT CallRegInstall(HINSTANCE hInstance, LPCSTR szSection)
  159. {
  160. HRESULT hr = E_FAIL;
  161. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  162. if (hinstAdvPack)
  163. {
  164. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  165. if ( pfnri )
  166. {
  167. #ifdef WINNT
  168. STRENTRY seReg[] =
  169. {
  170. // These two NT-specific entries must be at the end
  171. { "25", "%SystemRoot%" },
  172. { "11", "%SystemRoot%\\system32" },
  173. };
  174. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  175. hr = pfnri(hInstance, szSection, &stReg);
  176. #else
  177. hr = pfnri(hInstance, szSection, NULL);
  178. #endif
  179. }
  180. FreeLibrary(hinstAdvPack);
  181. }
  182. return hr;
  183. }
  184. STDAPI DllRegisterServer(void)
  185. {
  186. CallRegInstall(g_hinst, "RegDll");
  187. return S_OK;
  188. }
  189. STDAPI DllUnregisterServer(void)
  190. {
  191. CallRegInstall(g_hinst, "UnregDll");
  192. return S_OK;
  193. }