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.

424 lines
10 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dllinit.c
  3. *
  4. * MCD library initialization routine(s).
  5. *
  6. * Created: 02-Apr-1996 21:25:47
  7. * Author: Gilman Wong [gilmanw]
  8. *
  9. * Copyright (c) 1996 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. #include <stddef.h>
  13. #include <windows.h>
  14. #include <wtypes.h>
  15. #include <windef.h>
  16. #include <wingdi.h>
  17. #include <winddi.h>
  18. #include <mcdesc.h>
  19. #include "mcdrv.h"
  20. #include <mcd2hack.h>
  21. #include "mcd.h"
  22. #include "mcdint.h"
  23. #include "debug.h"
  24. //
  25. // Global flags read from the registry.
  26. //
  27. ULONG McdFlags = 0;
  28. ULONG McdPrivateFlags = MCDPRIVATE_MCD_ENABLED;
  29. #if DBG
  30. ULONG McdDebugFlags = 0;
  31. #endif
  32. long GetMcdRegValue(HKEY hkMcd, REGSAM samAccess, LPSTR lpstrValueName,
  33. long lDefaultData);
  34. void GetMcdFlags(void);
  35. #ifdef MCD95
  36. //
  37. // Local driver semaphore.
  38. //
  39. CRITICAL_SECTION gsemMcd;
  40. extern MCDENGESCFILTERFUNC pMCDEngEscFilter;
  41. #endif
  42. /******************************Public*Routine******************************\
  43. * McdDllInitialize
  44. *
  45. * This is the entry point for MCD32.DLL, which is called each time
  46. * a process or thread that is linked to it is created or terminated.
  47. *
  48. \**************************************************************************/
  49. BOOL McdDllInitialize(HMODULE hModule, ULONG Reason, PVOID Reserved)
  50. {
  51. //
  52. // Suppress compiler warnings.
  53. //
  54. hModule;
  55. Reserved;
  56. //
  57. // Do appropriate attach/detach processing.
  58. //
  59. switch (Reason)
  60. {
  61. case DLL_PROCESS_ATTACH:
  62. #ifdef MCD95
  63. //
  64. // Initialize local driver semaphore.
  65. //
  66. __try
  67. {
  68. InitializeCriticalSection(&gsemMcd);
  69. }
  70. __except(EXCEPTION_EXECUTE_HANDLER)
  71. {
  72. return FALSE;
  73. }
  74. #endif
  75. //
  76. // On process attach, read setup information from registry.
  77. //
  78. GetMcdFlags();
  79. #ifdef WINNT
  80. //
  81. // Quick hack to work around multimon problems.
  82. // If there's more than one monitor, completely disable
  83. // MCD.
  84. //
  85. if (GetSystemMetrics(SM_CMONITORS) > 1)
  86. {
  87. McdPrivateFlags &= ~MCDPRIVATE_MCD_ENABLED;
  88. }
  89. #endif
  90. break;
  91. case DLL_PROCESS_DETACH:
  92. #ifdef MCD95
  93. //
  94. // MCD is now closed!
  95. //
  96. pMCDEngEscFilter = (MCDENGESCFILTERFUNC) NULL;
  97. //
  98. // Delete local driver sempahore.
  99. //
  100. DeleteCriticalSection((LPCRITICAL_SECTION) &gsemMcd);
  101. #endif
  102. break;
  103. case DLL_THREAD_ATTACH:
  104. case DLL_THREAD_DETACH:
  105. //
  106. // Nothing to do yet for thread attach/detach.
  107. //
  108. break;
  109. default:
  110. break;
  111. }
  112. return(TRUE);
  113. }
  114. /******************************Public*Routine******************************\
  115. * MCDGetMcdCritSect__priv
  116. *
  117. * MCD95 ONLY
  118. *
  119. * Return pointer to local MCD semaphore. Used to synchronize MCD32.DLL and
  120. * MCDSRV32.DLL.
  121. *
  122. * Returns:
  123. * Pointer to semaphore. Returns NULL on non-MCD95 builds.
  124. *
  125. * History:
  126. * 18-Mar-1997 -by- Gilman Wong [gilmanw]
  127. * Wrote it.
  128. \**************************************************************************/
  129. LPCRITICAL_SECTION APIENTRY MCDGetMcdCritSect__priv()
  130. {
  131. #ifdef MCD95
  132. return &gsemMcd;
  133. #else
  134. return (LPCRITICAL_SECTION) NULL;
  135. #endif
  136. }
  137. /******************************Public*Routine******************************\
  138. * GetMcdRegValue
  139. *
  140. * Get the data for the specified value. If the value cannot be found in
  141. * the specified registry key or is of a type other than REG_DWORD, then
  142. * the value is created (or recreated) with the supplied default data.
  143. *
  144. * History:
  145. * 02-Apr-1996 -by- Gilman Wong [gilmanw]
  146. * Wrote it.
  147. \**************************************************************************/
  148. long GetMcdRegValue(HKEY hkMcd, REGSAM samAccess, LPSTR lpstrValueName,
  149. long lDefaultData)
  150. {
  151. DWORD dwDataType;
  152. DWORD cjSize;
  153. long lData;
  154. //
  155. // For specified value, attempt to fetch the data.
  156. //
  157. cjSize = sizeof(long);
  158. if ( (RegQueryValueExA(hkMcd,
  159. lpstrValueName,
  160. (LPDWORD) NULL,
  161. &dwDataType,
  162. (LPBYTE) &lData,
  163. &cjSize) != ERROR_SUCCESS)
  164. || (dwDataType != REG_DWORD) )
  165. {
  166. //
  167. // Since we couldn't get the data, create the value using the
  168. // specified default data.
  169. //
  170. if (samAccess & KEY_WRITE)
  171. {
  172. cjSize = sizeof(long);
  173. if ( (RegSetValueExA(hkMcd,
  174. lpstrValueName,
  175. 0, // Reserved
  176. REG_DWORD,
  177. (BYTE *) &lDefaultData,
  178. cjSize) != ERROR_SUCCESS) )
  179. {
  180. DBGPRINT1("GetMcdRegValue: RegSetValueExA(%s) failed",
  181. lpstrValueName);
  182. }
  183. }
  184. //
  185. // Whether or not the value was created in the registry key, return
  186. // the default data.
  187. //
  188. lData = lDefaultData;
  189. }
  190. return lData;
  191. }
  192. /******************************Public*Routine******************************\
  193. * GetMcdFlags
  194. *
  195. * Fetch the MCD flags from the registry.
  196. * If the registry entries do not exist, create them.
  197. *
  198. * History:
  199. * 02-Apr-1996 -by- Gilman Wong [gilmanw]
  200. * Wrote it.
  201. \**************************************************************************/
  202. #define STR_MCDKEY (PCSTR)"Software\\Microsoft\\Windows\\CurrentVersion\\MCD"
  203. #define STR_ENABLE (LPSTR)"Enable"
  204. #define STR_SWAPSYNC (LPSTR)"SwapSync"
  205. #define STR_8BPP (LPSTR)"Palettized Formats"
  206. #define STR_IOPRIORITY (LPSTR)"IO Priority"
  207. #define STR_GENSTENCIL (LPSTR)"Use Generic Stencil"
  208. #define STR_EMULATEICD (LPSTR)"Enumerate as ICD"
  209. #define STR_DEBUG (LPSTR)"Debug"
  210. void GetMcdFlags()
  211. {
  212. HKEY hkMcd;
  213. DWORD dwAction;
  214. REGSAM samAccess;
  215. ULONG ulDefMcdFlags;
  216. ULONG ulDefMcdFlagsPriv;
  217. long lTmp;
  218. //
  219. // Default values for McdFlags and McdPrivateFlags.
  220. // If you want to change the defaults, change them here!
  221. //
  222. ulDefMcdFlags = MCDCONTEXT_SWAPSYNC;
  223. ulDefMcdFlagsPriv = MCDPRIVATE_MCD_ENABLED |
  224. MCDPRIVATE_PALETTEFORMATS |
  225. MCDPRIVATE_USEGENERICSTENCIL;
  226. //
  227. // Set initial values.
  228. //
  229. McdFlags = 0;
  230. #if DBG
  231. McdDebugFlags = 0;
  232. #endif
  233. //
  234. // First try for read/write access. Create the key
  235. // if necessary.
  236. //
  237. if ( RegCreateKeyExA(HKEY_LOCAL_MACHINE,
  238. STR_MCDKEY,
  239. 0, // Reserved
  240. (LPSTR) NULL,
  241. REG_OPTION_NON_VOLATILE,
  242. KEY_READ | KEY_WRITE,
  243. (LPSECURITY_ATTRIBUTES) NULL,
  244. &hkMcd,
  245. &dwAction) == ERROR_SUCCESS )
  246. {
  247. samAccess = KEY_READ | KEY_WRITE;
  248. }
  249. //
  250. // Next try read-only access. Do not try to create
  251. // key. Write permission is required to create and
  252. // we do not have that permission.
  253. //
  254. else if ( RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  255. STR_MCDKEY,
  256. 0, // Reserved
  257. KEY_READ,
  258. &hkMcd) == ERROR_SUCCESS )
  259. {
  260. samAccess = KEY_READ;
  261. }
  262. //
  263. // Finally, the key does not exist and we do not have
  264. // write access. Fall back on the defaults and return.
  265. //
  266. else
  267. {
  268. McdFlags = ulDefMcdFlags;
  269. McdPrivateFlags = ulDefMcdFlagsPriv;
  270. return;
  271. }
  272. //
  273. // "Enable" value. Default is 1 (enabled).
  274. //
  275. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_MCD_ENABLED) ? 1:0;
  276. if (GetMcdRegValue(hkMcd, samAccess, STR_ENABLE, lTmp))
  277. McdPrivateFlags |= MCDPRIVATE_MCD_ENABLED;
  278. else
  279. McdPrivateFlags &= (~MCDPRIVATE_MCD_ENABLED);
  280. //
  281. // "SwapSync" value. Default is 1 (enabled).
  282. //
  283. lTmp = (ulDefMcdFlags & MCDCONTEXT_SWAPSYNC) ? 1:0;
  284. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_SWAPSYNC, lTmp);
  285. if (lTmp != 0)
  286. {
  287. McdFlags |= MCDCONTEXT_SWAPSYNC;
  288. }
  289. //
  290. // "Palettized Formats" value. Default is 1 (enabled).
  291. //
  292. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_PALETTEFORMATS) ? 1:0;
  293. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_8BPP, lTmp);
  294. if (lTmp != 0)
  295. {
  296. McdPrivateFlags |= MCDPRIVATE_PALETTEFORMATS;
  297. }
  298. //
  299. // "IO Priority" value. Default is 0 (disabled).
  300. //
  301. lTmp = (ulDefMcdFlags & MCDCONTEXT_IO_PRIORITY) ? 1:0;
  302. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_IOPRIORITY, lTmp);
  303. if (lTmp != 0)
  304. {
  305. McdFlags |= MCDCONTEXT_IO_PRIORITY;
  306. }
  307. //
  308. // "Use Generic Stencil" value. Default is 1 (enabled).
  309. //
  310. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_USEGENERICSTENCIL) ? 1:0;
  311. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_GENSTENCIL, lTmp);
  312. if (lTmp != 0)
  313. {
  314. McdPrivateFlags |= MCDPRIVATE_USEGENERICSTENCIL;
  315. }
  316. //
  317. // "Enumerate as ICD" value. Default is 0 (disabled).
  318. //
  319. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_EMULATEICD) ? 1:0;
  320. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_EMULATEICD, lTmp);
  321. if (lTmp != 0)
  322. {
  323. McdPrivateFlags |= MCDPRIVATE_EMULATEICD;
  324. }
  325. #if DBG
  326. //
  327. // "Debug" value.
  328. //
  329. // Unlike the other settings, we do not create the Debug value if
  330. // it does not exist.
  331. //
  332. {
  333. DWORD dwDataType;
  334. DWORD cjSize;
  335. cjSize = sizeof(long);
  336. if ( (RegQueryValueExA(hkMcd,
  337. STR_DEBUG,
  338. (LPDWORD) NULL,
  339. &dwDataType,
  340. (LPBYTE) &lTmp,
  341. &cjSize) == ERROR_SUCCESS)
  342. && (dwDataType == REG_DWORD) )
  343. {
  344. McdDebugFlags = lTmp;
  345. }
  346. }
  347. #endif
  348. //
  349. // We're done, so close the registry key.
  350. //
  351. RegCloseKey(hkMcd);
  352. }