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.

288 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1994-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. drvaplet.c
  5. Abstract:
  6. This module contains the driver routines for the project.
  7. Revision History:
  8. --*/
  9. //
  10. // Include Files.
  11. //
  12. #include "main.h"
  13. #include "drvaplet.h"
  14. //
  15. // Defines for Win16 builds.
  16. //
  17. #ifndef WIN32
  18. #define LoadLibrary16 LoadLibrary
  19. #define FreeLibrary16 FreeLibrary
  20. #define GetProcAddress16 GetProcAddress
  21. #endif
  22. //
  23. // Global Variables.
  24. //
  25. //
  26. // CplApplet.
  27. //
  28. const TCHAR *c_szCplApplet = TEXT("CPlApplet");
  29. const char *c_szCplAppletA = "CPlApplet";
  30. //
  31. // Typedef Declarations.
  32. //
  33. //
  34. // DRIVER_APPLET_INFO: the info we keep around about a driver applet.
  35. //
  36. typedef struct
  37. {
  38. HMODULE module;
  39. APPLET_PROC applet;
  40. HICON icon;
  41. } DRIVER_APPLET_INFO, *PDAI;
  42. //
  43. // GetDriverModule: gets the module.
  44. //
  45. ////////////////////////////////////////////////////////////////////////////
  46. //
  47. // GetDriverModule
  48. //
  49. // Gets the module.
  50. //
  51. ////////////////////////////////////////////////////////////////////////////
  52. HMODULE GetDriverModule(
  53. LPCTSTR name)
  54. {
  55. #ifdef WIN32
  56. #ifdef WINNT
  57. return (LoadLibrary(name));
  58. #else
  59. return (LoadLibrary16(name));
  60. #endif
  61. #else
  62. return (GetModuleHandle(name));
  63. #endif
  64. }
  65. ////////////////////////////////////////////////////////////////////////////
  66. //
  67. // ReleaseDriverModule
  68. //
  69. ////////////////////////////////////////////////////////////////////////////
  70. void ReleaseDriverModule(
  71. HMODULE module)
  72. {
  73. #ifdef WIN32
  74. #ifdef WINNT
  75. FreeLibrary(module);
  76. #else
  77. FreeLibrary16(module);
  78. #endif
  79. #else
  80. //
  81. // do nothing (got it with GetModuleHandle)
  82. //
  83. #endif
  84. }
  85. ////////////////////////////////////////////////////////////////////////////
  86. //
  87. // OpenDriverApplet
  88. //
  89. // Opens a handle to the named driver applet.
  90. //
  91. ////////////////////////////////////////////////////////////////////////////
  92. HDAP OpenDriverApplet(
  93. LPCTSTR name)
  94. {
  95. PDAI driver = (PDAI)LocalAlloc(LPTR, sizeof(DRIVER_APPLET_INFO));
  96. if (driver)
  97. {
  98. if ((driver->module = GetDriverModule(name)) != NULL)
  99. {
  100. if ((driver->applet = (APPLET_PROC)
  101. #ifdef WINNT
  102. GetProcAddress(driver->module, c_szCplAppletA)) != NULL)
  103. #else
  104. GetProcAddress16(driver->module, c_szCplApplet)) != NULL)
  105. #endif
  106. {
  107. union
  108. {
  109. NEWCPLINFO newform;
  110. CPLINFO oldform;
  111. } info = { 0 };
  112. CallDriverApplet( (HDAP) driver,
  113. NULL,
  114. CPL_NEWINQUIRE,
  115. 0,
  116. (LPARAM)&info.newform );
  117. if (info.newform.dwSize == sizeof(info.newform))
  118. {
  119. driver->icon = info.newform.hIcon;
  120. return ((HDAP)driver);
  121. }
  122. //
  123. // NOTE: If the driver doesn't handle CPL_NEWIQUIRE, we must use CPL_INQUIRE
  124. // and LoadIcon the icon ourselves. Win32 doesn't provide a LoadIcon16, so
  125. // in Win32 the 16 bit side of the thunk for CPL_NEWINQUIRE does this. In
  126. // Win16, we do it right here.
  127. //
  128. #ifndef WIN32
  129. info.oldform.idIcon = 0;
  130. CallDriverApplet( (HDAP)driver,
  131. NULL,
  132. CPL_INQUIRE,
  133. 0,
  134. (LPARAM)&info.oldform );
  135. if (info.oldform.idIcon)
  136. {
  137. driver->icon =
  138. LoadIcon( driver->module,
  139. MAKEINTRESOURCE(info.oldform.idIcon) );
  140. return ((HDAP)driver);
  141. }
  142. #endif
  143. }
  144. ReleaseDriverModule(driver->module);
  145. }
  146. LocalFree(driver);
  147. }
  148. return ((HDAP)0);
  149. }
  150. ////////////////////////////////////////////////////////////////////////////
  151. //
  152. // CloseDriverApplet
  153. //
  154. // Closes a handle to a driver applet.
  155. //
  156. ////////////////////////////////////////////////////////////////////////////
  157. void CloseDriverApplet(
  158. HDAP HDAP)
  159. {
  160. #define driver ((PDAI)HDAP)
  161. if (driver)
  162. {
  163. if (driver->icon)
  164. {
  165. DestroyIcon(driver->icon);
  166. }
  167. ReleaseDriverModule(driver->module);
  168. LocalFree(driver);
  169. }
  170. #undef driver
  171. }
  172. ////////////////////////////////////////////////////////////////////////////
  173. //
  174. // GetDriverAppletIcon
  175. //
  176. // Gets a driver applet's icon (if any).
  177. //
  178. ////////////////////////////////////////////////////////////////////////////
  179. HICON GetDriverAppletIcon(
  180. HDAP HDAP)
  181. {
  182. #define driver ((PDAI)HDAP)
  183. //
  184. // Must return a copy for the current process/task to own.
  185. //
  186. return ((driver && driver->icon) ? CopyIcon(driver->icon) : NULL);
  187. #undef driver
  188. }
  189. ////////////////////////////////////////////////////////////////////////////
  190. //
  191. // CallDriverApplet
  192. //
  193. // Calls the driver applet (same syntax as CplApplet).
  194. //
  195. ////////////////////////////////////////////////////////////////////////////
  196. LRESULT CallDriverApplet(
  197. HDAP HDAP,
  198. HWND wnd,
  199. UINT msg,
  200. LPARAM p1,
  201. LPARAM p2)
  202. {
  203. #define driver ((PDAI)HDAP)
  204. if (driver)
  205. {
  206. #ifdef WIN32
  207. return ( CallCPLEntry16( driver->module,
  208. (FARPROC16)driver->applet,
  209. wnd,
  210. msg,
  211. p1,
  212. p2 ) );
  213. #else
  214. return (driver->applet(wnd, msg, p1, p2));
  215. #endif
  216. }
  217. return (0L);
  218. #undef driver
  219. }