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.

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