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.

270 lines
7.7 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1995 **
  4. //*********************************************************************
  5. //
  6. // INIT.C - Initialization code for Internet control panel
  7. //
  8. // HISTORY:
  9. //
  10. // 4/3/95 jeremys Created.
  11. //
  12. #include "inetcplp.h"
  13. // external calls and defs
  14. #include <inetcpl.h>
  15. #define MLUI_INIT
  16. #include <mluisupp.h>
  17. //
  18. // Downlevel delay load support (we forward to shlwapi)
  19. //
  20. #include <delayimp.h>
  21. PfnDliHook __pfnDliFailureHook;
  22. HINSTANCE ghInstance=NULL;
  23. extern HMODULE hOLE32;
  24. DWORD g_dwtlsSecInitFlags;
  25. BOOL g_bMirroredOS = FALSE;
  26. HMODULE g_hOleAcc;
  27. BOOL g_fAttemptedOleAccLoad = FALSE;
  28. STDAPI_(BOOL) LaunchInternetControlPanelAtPage(HWND hDlg, UINT nStartPage);
  29. BOOL IsCompatModeProcess(void);
  30. void SetupDelayloadErrorHandler()
  31. {
  32. __pfnDliFailureHook = (PfnDliHook)GetProcAddress(GetModuleHandleA("shlwapi.dll"), "DelayLoadFailureHook");
  33. }
  34. /*******************************************************************
  35. NAME: DllEntryPoint
  36. SYNOPSIS: Entry point for DLL.
  37. ********************************************************************/
  38. STDAPI_(BOOL) DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpReserved)
  39. {
  40. if( fdwReason == DLL_PROCESS_ATTACH )
  41. {
  42. SHFusionInitializeFromModule(hInstDll);
  43. SetupDelayloadErrorHandler();
  44. if (IsCompatModeProcess())
  45. // Fail loading in compat mode process
  46. return 0;
  47. ghInstance = hInstDll;
  48. MLLoadResources(ghInstance, TEXT("inetcplc.dll"));
  49. #ifndef REPLACE_PROPSHEET_TEMPLATE
  50. InitMUILanguage(INETCPL_GetUILanguage());
  51. #endif
  52. #ifdef DEBUG
  53. CcshellGetDebugFlags();
  54. #endif
  55. // Thread local storage used in security.cpp
  56. g_dwtlsSecInitFlags = TlsAlloc();
  57. g_bMirroredOS = IS_MIRRORING_ENABLED();
  58. TlsSetValue(g_dwtlsSecInitFlags, (void *) new SECURITYINITFLAGS);
  59. }
  60. else if (fdwReason == DLL_PROCESS_DETACH)
  61. {
  62. MLFreeResources(ghInstance);
  63. if (g_hwndUpdate)
  64. {
  65. // we've got this subclassed.
  66. // if it's still valid as we leave, we need
  67. // to destroy it so that it doesn't fault trying to access our info
  68. DestroyWindow(g_hwndUpdate);
  69. }
  70. if(hOLE32)
  71. {
  72. FreeLibrary(hOLE32);
  73. hOLE32 = NULL;
  74. }
  75. if (g_hOleAcc)
  76. {
  77. FreeLibrary(g_hOleAcc);
  78. g_hOleAcc = NULL;
  79. g_fAttemptedOleAccLoad = FALSE;
  80. }
  81. // free tls used in security.cpp
  82. if(g_dwtlsSecInitFlags != (DWORD) -1)
  83. {
  84. SECURITYINITFLAGS * psif = NULL;
  85. psif = (SECURITYINITFLAGS *) TlsGetValue(g_dwtlsSecInitFlags);
  86. if(psif)
  87. {
  88. delete psif;
  89. psif = NULL;
  90. }
  91. TlsFree(g_dwtlsSecInitFlags);
  92. }
  93. SHFusionUninitialize();
  94. }
  95. return TRUE;
  96. }
  97. BOOL RunningOnNT()
  98. {
  99. return !(::GetVersion() & 0x80000000);
  100. }
  101. /*******************************************************************
  102. NAME: CPlApplet
  103. SYNOPSIS: Entry point for control panel.
  104. ********************************************************************/
  105. STDAPI_(LRESULT) CPlApplet // Control panel applet procedure
  106. (
  107. HWND hwndCpl, // Control panel parent window
  108. UINT uMsg, // message
  109. LPARAM lParam1, // value depends on message
  110. LPARAM lParam2 // value depends on message
  111. )
  112. {
  113. LPNEWCPLINFO lpNewCplInfo = (LPNEWCPLINFO) lParam2;
  114. LPCPLINFO lpCplInfo = (LPCPLINFO) lParam2;
  115. DWORD dwNIcons;
  116. switch (uMsg)
  117. {
  118. case CPL_INIT:
  119. // Initialization message from Control Panel
  120. return TRUE;
  121. case CPL_GETCOUNT:
  122. /* We always have the main internet CPL icon; on Win95 platforms,
  123. * we also have the Users icon if mslocusr.dll is present.
  124. */
  125. dwNIcons = 1;
  126. if (!RunningOnNT())
  127. {
  128. TCHAR szPath[MAX_PATH];
  129. // check if mslocusr.dll is present in the system dir
  130. if (GetSystemDirectory(szPath, ARRAYSIZE(szPath)))
  131. {
  132. PathAppend(szPath, TEXT("mslocusr.dll"));
  133. if (PathFileExists(szPath))
  134. dwNIcons++;
  135. }
  136. }
  137. return dwNIcons;
  138. case CPL_INQUIRE:
  139. /* CPL #0 is the main Internet CPL, #1 (the only other one we'll ever
  140. * be asked about) is the Users CPL.
  141. */
  142. if (!lParam1) {
  143. lpCplInfo->idIcon = IDI_INTERNET;
  144. lpCplInfo->idName = IDS_INTERNET;
  145. lpCplInfo->idInfo = IDS_DESCRIPTION;
  146. lpCplInfo->lData = 0;
  147. }
  148. else {
  149. lpCplInfo->idIcon = IDI_USERS;
  150. lpCplInfo->idName = IDS_USERS;
  151. lpCplInfo->idInfo = IDS_USERS_DESCRIPTION;
  152. lpCplInfo->lData = 0;
  153. }
  154. return FALSE;
  155. case CPL_NEWINQUIRE:
  156. // Return new-style info structure for Control Panel
  157. // By not responding to NEWINQUIRE, Win95 will not preload our
  158. // .cpl file; by extension, since we are statically linked to MSHTML's
  159. // import library, MSHTML will also not be loaded. If we respond to
  160. // this, then our cpl and MSHTML (>600k) are both loaded when the
  161. // control panel is just open. (IE, they will be loaded even if the
  162. // user has not selected to invoke our specific cpl applet.
  163. return TRUE; // TRUE == we are NOT responding to this
  164. break;
  165. case CPL_DBLCLK:
  166. //
  167. // This means the user did not specify a particular page
  168. //
  169. lParam2 = 0;
  170. // fall through
  171. case CPL_STARTWPARMSA:
  172. case CPL_STARTWPARMSW:
  173. /* CPL #0 is the main Internet CPL, #1 (the only other one we'll ever
  174. * be asked about) is the Users CPL. The Users CPL is loaded from
  175. * mslocusr.dll dynamically. The entrypoint is structured as a
  176. * rundll32 entrypoint.
  177. */
  178. if (!lParam1) {
  179. //
  180. // If lParam2!=NULL, then the user specified a page on the command line
  181. //
  182. if (lParam2)
  183. {
  184. UINT nPage;
  185. if (CPL_STARTWPARMSA == uMsg)
  186. nPage = StrToIntA((LPSTR)lParam2);
  187. else
  188. nPage = StrToIntW((LPWSTR)lParam2);
  189. LaunchInternetControlPanelAtPage(hwndCpl, nPage);
  190. }
  191. //
  192. // Otherwise request the default page
  193. //
  194. else
  195. LaunchInternetControlPanelAtPage(hwndCpl,DEFAULT_CPL_PAGE);
  196. }
  197. else {
  198. HINSTANCE hinstMSLU = LoadLibrary(TEXT("mslocusr.dll"));
  199. if (hinstMSLU != NULL) {
  200. typedef void (*PFNRUNDLL)(HWND hwndParent, HINSTANCE hinstEXE, LPSTR pszCmdLine, int nCmdShow);
  201. PFNRUNDLL pfn = (PFNRUNDLL)GetProcAddress(hinstMSLU, "UserCPL");
  202. if (pfn != NULL) {
  203. (*pfn)(hwndCpl, NULL, "", SW_SHOW);
  204. }
  205. FreeLibrary(hinstMSLU);
  206. }
  207. }
  208. return TRUE;
  209. case CPL_EXIT:
  210. // Control Panel is exiting
  211. break;
  212. default:
  213. break;
  214. }
  215. return 0L;
  216. }