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.

226 lines
5.4 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. InterlockedDecrement(&g_cRefThisDll);
  77. }
  78. STDAPI DllCanUnloadNow(void)
  79. {
  80. return g_cRefThisDll ? S_FALSE : S_OK;
  81. }
  82. HRESULT CHomeNetworkWizard_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi);
  83. CF_TABLE_BEGIN( g_ObjectInfo )
  84. CF_TABLE_ENTRY( &CLSID_HomeNetworkWizard, CHomeNetworkWizard_CreateInstance, COCREATEONLY),
  85. CF_TABLE_END( g_ObjectInfo )
  86. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  87. {
  88. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  89. {
  90. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  91. DllAddRef();
  92. return NOERROR;
  93. }
  94. *ppvObj = NULL;
  95. return E_NOINTERFACE;
  96. }
  97. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  98. {
  99. DllAddRef();
  100. return 2;
  101. }
  102. STDMETHODIMP_(ULONG) CClassFactory::Release()
  103. {
  104. DllRelease();
  105. return 1;
  106. }
  107. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  108. {
  109. *ppv = NULL;
  110. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  111. {
  112. return CLASS_E_NOAGGREGATION;
  113. }
  114. else
  115. {
  116. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  117. if (punkOuter) // && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  118. return CLASS_E_NOAGGREGATION;
  119. IUnknown *punk;
  120. HRESULT hr = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  121. if (SUCCEEDED(hr))
  122. {
  123. hr = punk->QueryInterface(riid, ppv);
  124. punk->Release();
  125. }
  126. return hr;
  127. }
  128. }
  129. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  130. {
  131. if (fLock)
  132. DllAddRef();
  133. else
  134. DllRelease();
  135. return S_OK;
  136. }
  137. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  138. {
  139. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  140. {
  141. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  142. {
  143. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  144. {
  145. *ppv = (void*)pcls;
  146. DllAddRef(); // class factory holds DLL ref count
  147. return NOERROR;
  148. }
  149. }
  150. }
  151. *ppv = NULL;
  152. return CLASS_E_CLASSNOTAVAILABLE;
  153. }
  154. // Call ADVPACK for the given section of our resource based INF>
  155. // hInstance = resource instance to get REGINST section from
  156. // szSection = section name to invoke
  157. HRESULT CallRegInstall(HINSTANCE hInstance, LPCSTR szSection)
  158. {
  159. HRESULT hr = E_FAIL;
  160. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  161. if (hinstAdvPack)
  162. {
  163. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  164. if ( pfnri )
  165. {
  166. #ifdef WINNT
  167. STRENTRY seReg[] =
  168. {
  169. // These two NT-specific entries must be at the end
  170. { "25", "%SystemRoot%" },
  171. { "11", "%SystemRoot%\\system32" },
  172. };
  173. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  174. hr = pfnri(hInstance, szSection, &stReg);
  175. #else
  176. hr = pfnri(hInstance, szSection, NULL);
  177. #endif
  178. }
  179. FreeLibrary(hinstAdvPack);
  180. }
  181. return hr;
  182. }
  183. STDAPI DllRegisterServer(void)
  184. {
  185. CallRegInstall(g_hinst, "RegDll");
  186. return S_OK;
  187. }
  188. STDAPI DllUnregisterServer(void)
  189. {
  190. CallRegInstall(g_hinst, "UnregDll");
  191. return S_OK;
  192. }