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.

239 lines
5.2 KiB

  1. /*
  2. * inetcpl.c - Indirect calls to inetcpl.cpl.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.h"
  7. #pragma hdrstop
  8. #include "inetcpl.h"
  9. /* Types
  10. ********/
  11. /* Internet CPL vtable */
  12. typedef struct internetcplvtbl
  13. {
  14. HRESULT (WINAPI *AddInternetPropertySheets)(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lparam, PUINT pucRefCount, LPFNPSPCALLBACK pfnCallback);
  15. }
  16. INTERNETCPLVTBL;
  17. DECLARE_STANDARD_TYPES(INTERNETCPLVTBL);
  18. /* Module Constants
  19. *******************/
  20. #pragma data_seg(DATA_SEG_READ_ONLY)
  21. PRIVATE_DATA CCHAR s_cszInternetCPL[] = "inetcpl.cpl";
  22. PRIVATE_DATA CCHAR s_cszAddInternetPropertySheets[] = "AddInternetPropertySheets";
  23. #pragma data_seg()
  24. /* Module Variables
  25. *******************/
  26. /* Internet CPL reference count */
  27. PRIVATE_DATA UINT s_ucRef = 0;
  28. PRIVATE_DATA HINSTANCE s_hinstInternetCPL = NULL;
  29. /* Internet CPL vtable */
  30. PRIVATE_DATA PINTERNETCPLVTBL s_pinetcplvtbl = NULL;
  31. /***************************** Private Functions *****************************/
  32. #ifdef DEBUG
  33. PRIVATE_CODE BOOL IsValidPCINTERNETCPLVTBL(PCINTERNETCPLVTBL pcinetcplctbl)
  34. {
  35. return(IS_VALID_READ_PTR(pcinetcplctbl, CINTERNETCPLVTBL) &&
  36. IS_VALID_CODE_PTR(pcinetcplctbl->AddInternetPropertySheets, AddInternetPropertySheets));
  37. }
  38. PRIVATE_CODE BOOL InternetCPLNotLoadedStateOK(void)
  39. {
  40. return(! s_hinstInternetCPL &&
  41. ! s_pinetcplvtbl);
  42. }
  43. PRIVATE_CODE BOOL InternetCPLLoadedStateOK(void)
  44. {
  45. return(IS_VALID_HANDLE(s_hinstInternetCPL, INSTANCE) &&
  46. IS_VALID_STRUCT_PTR(s_pinetcplvtbl, CINTERNETCPLVTBL));
  47. }
  48. PRIVATE_CODE BOOL InternetCPLStateOK(void)
  49. {
  50. return(InternetCPLNotLoadedStateOK() ||
  51. InternetCPLLoadedStateOK());
  52. }
  53. #endif /* DEBUG */
  54. PRIVATE_CODE BOOL IsInternetCPLLoaded(void)
  55. {
  56. ASSERT(InternetCPLStateOK());
  57. return(s_hinstInternetCPL != NULL);
  58. }
  59. PRIVATE_CODE BOOL GetInternetCPLProc(PCSTR pcszProc, FARPROC *pfp)
  60. {
  61. ASSERT(IS_VALID_STRING_PTR(pcszProc, CSTR));
  62. ASSERT(IS_VALID_WRITE_PTR(pfp, FARPROC));
  63. ASSERT(IS_VALID_HANDLE(s_hinstInternetCPL, INSTANCE));
  64. *pfp = GetProcAddress(s_hinstInternetCPL, pcszProc);
  65. if (*pfp)
  66. TRACE_OUT(("GetInternetCPLProc(): Got address of %s!%s.",
  67. s_cszInternetCPL,
  68. pcszProc));
  69. else
  70. WARNING_OUT(("GetOLEProc(): Failed to get address of %s!%s.",
  71. s_cszInternetCPL,
  72. pcszProc));
  73. ASSERT(! *pfp ||
  74. IS_VALID_CODE_PTR(*pfp, FARPROC));
  75. return(*pfp != NULL);
  76. }
  77. PRIVATE_CODE BOOL FillInternetCPLVTable(void)
  78. {
  79. BOOL bResult;
  80. ASSERT(IS_VALID_HANDLE(s_hinstInternetCPL, INSTANCE));
  81. if (AllocateMemory(sizeof(*s_pinetcplvtbl), &s_pinetcplvtbl))
  82. {
  83. bResult = GetInternetCPLProc(s_cszAddInternetPropertySheets,
  84. &(FARPROC)(s_pinetcplvtbl->AddInternetPropertySheets));
  85. if (bResult)
  86. TRACE_OUT(("FillInternetCPLVTable(): Internet CPL vtable filled successfully."));
  87. else
  88. {
  89. FreeMemory(s_pinetcplvtbl);
  90. s_pinetcplvtbl = NULL;
  91. }
  92. }
  93. else
  94. bResult = FALSE;
  95. ASSERT(! bResult ||
  96. InternetCPLLoadedStateOK());
  97. return(bResult);
  98. }
  99. PRIVATE_CODE BOOL LoadInternetCPL(void)
  100. {
  101. BOOL bResult;
  102. bResult = IsInternetCPLLoaded();
  103. if (! bResult)
  104. {
  105. s_hinstInternetCPL = LoadLibrary(s_cszInternetCPL);
  106. if (s_hinstInternetCPL)
  107. {
  108. bResult = FillInternetCPLVTable();
  109. if (bResult)
  110. TRACE_OUT(("LoadInternetCPL(): %s loaded.",
  111. s_cszInternetCPL));
  112. }
  113. else
  114. WARNING_OUT(("LoadInternetCPL(): LoadLibrary(%s) failed.",
  115. s_cszInternetCPL));
  116. if (! bResult)
  117. UnloadInternetCPL();
  118. }
  119. ASSERT(InternetCPLStateOK());
  120. return(bResult);
  121. }
  122. /****************************** Public Functions *****************************/
  123. PUBLIC_CODE void UnloadInternetCPL(void)
  124. {
  125. if (s_pinetcplvtbl)
  126. {
  127. FreeMemory(s_pinetcplvtbl);
  128. s_pinetcplvtbl = NULL;
  129. TRACE_OUT(("UnloadInternetCPL(): Freed %s vtable.",
  130. s_cszInternetCPL));
  131. }
  132. if (s_hinstInternetCPL)
  133. {
  134. FreeLibrary(s_hinstInternetCPL);
  135. s_hinstInternetCPL = NULL;
  136. TRACE_OUT(("UnloadInternetCPL(): Freed %s.",
  137. s_cszInternetCPL));
  138. }
  139. return;
  140. }
  141. HRESULT InternetCPLCanUnloadNow(void)
  142. {
  143. return ((s_ucRef > 0) ? S_FALSE : S_OK);
  144. }
  145. #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  146. PUBLIC_CODE HRESULT WINAPI AddInternetPropertySheets(
  147. LPFNADDPROPSHEETPAGE pfnAddPage,
  148. LPARAM lparam, PUINT pucRefCount,
  149. LPFNPSPCALLBACK pfnCallback)
  150. {
  151. HRESULT hr;
  152. /*
  153. * Increment the Internet CPL's reference count around this call it so that
  154. * it is not unloaded during the call.
  155. */
  156. if (LoadInternetCPL())
  157. hr = s_pinetcplvtbl->AddInternetPropertySheets(pfnAddPage, lparam,
  158. &s_ucRef,
  159. pfnCallback);
  160. else
  161. hr = E_FAIL;
  162. return(hr);
  163. }
  164. #pragma warning(default:4100) /* "unreferenced formal parameter" warning */