Windows NT 4.0 source code leak
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.

340 lines
8.2 KiB

4 years ago
  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 <rx.h>
  19. #include "mcdrv.h"
  20. #include "mcd.h"
  21. #include "mcdint.h"
  22. #include "debug.h"
  23. //
  24. // Global flags read from the registry.
  25. //
  26. ULONG McdFlags = 0;
  27. ULONG McdPrivateFlags = MCDPRIVATE_MCD_ENABLED;
  28. #if DBG
  29. ULONG McdDebugFlags = 0;
  30. #endif
  31. long GetMcdRegValue(HKEY hkMcd, REGSAM samAccess, LPSTR lpstrValueName,
  32. long lDefaultData);
  33. void GetMcdFlags(void);
  34. /******************************Public*Routine******************************\
  35. * McdDllInitialize
  36. *
  37. * This is the entry point for MCD32.DLL, which is called each time
  38. * a process or thread that is linked to it is created or terminated.
  39. *
  40. \**************************************************************************/
  41. BOOL McdDllInitialize(HMODULE hModule, ULONG Reason, PVOID Reserved)
  42. {
  43. //
  44. // Suppress compiler warnings.
  45. //
  46. hModule;
  47. Reserved;
  48. //
  49. // Do appropriate attach/detach processing.
  50. //
  51. switch (Reason)
  52. {
  53. case DLL_PROCESS_ATTACH:
  54. //
  55. // On process attach, read setup information from registry.
  56. //
  57. GetMcdFlags();
  58. break;
  59. case DLL_PROCESS_DETACH:
  60. //
  61. // Nothing to do yet for process detach.
  62. //
  63. break;
  64. case DLL_THREAD_ATTACH:
  65. case DLL_THREAD_DETACH:
  66. //
  67. // Nothing to do yet for thread attach/detach.
  68. //
  69. break;
  70. default:
  71. break;
  72. }
  73. return(TRUE);
  74. }
  75. /******************************Public*Routine******************************\
  76. * GetMcdRegValue
  77. *
  78. * Get the data for the specified value. If the value cannot be found in
  79. * the specified registry key or is of a type other than REG_DWORD, then
  80. * the value is created (or recreated) with the supplied default data.
  81. *
  82. * History:
  83. * 02-Apr-1996 -by- Gilman Wong [gilmanw]
  84. * Wrote it.
  85. \**************************************************************************/
  86. long GetMcdRegValue(HKEY hkMcd, REGSAM samAccess, LPSTR lpstrValueName,
  87. long lDefaultData)
  88. {
  89. DWORD dwDataType;
  90. DWORD cjSize;
  91. long lData;
  92. //
  93. // For specified value, attempt to fetch the data.
  94. //
  95. cjSize = sizeof(long);
  96. if ( (RegQueryValueExA(hkMcd,
  97. lpstrValueName,
  98. (LPDWORD) NULL,
  99. &dwDataType,
  100. (LPBYTE) &lData,
  101. &cjSize) != ERROR_SUCCESS)
  102. || (dwDataType != REG_DWORD) )
  103. {
  104. //
  105. // Since we couldn't get the data, create the value using the
  106. // specified default data.
  107. //
  108. if (samAccess & KEY_WRITE)
  109. {
  110. cjSize = sizeof(long);
  111. if ( (RegSetValueExA(hkMcd,
  112. lpstrValueName,
  113. 0, // Reserved
  114. REG_DWORD,
  115. (BYTE *) &lDefaultData,
  116. cjSize) != ERROR_SUCCESS) )
  117. {
  118. DBGPRINT1("GetMcdRegValue: RegSetValueExA(%s) failed",
  119. lpstrValueName);
  120. }
  121. }
  122. //
  123. // Whether or not the value was created in the registry key, return
  124. // the default data.
  125. //
  126. lData = lDefaultData;
  127. }
  128. return lData;
  129. }
  130. /******************************Public*Routine******************************\
  131. * GetMcdFlags
  132. *
  133. * Fetch the MCD flags from the registry.
  134. * If the registry entries do not exist, create them.
  135. *
  136. * History:
  137. * 02-Apr-1996 -by- Gilman Wong [gilmanw]
  138. * Wrote it.
  139. \**************************************************************************/
  140. #define STR_MCDKEY (PCSTR)"Software\\Microsoft\\Windows\\CurrentVersion\\MCD"
  141. #define STR_ENABLE (LPSTR)"Enable"
  142. #define STR_SWAPSYNC (LPSTR)"SwapSync"
  143. #define STR_8BPP (LPSTR)"Palettized Formats"
  144. #define STR_IOPRIORITY (LPSTR)"IO Priority"
  145. #define STR_GENSTENCIL (LPSTR)"Use Generic Stencil"
  146. #define STR_DEBUG (LPSTR)"Debug"
  147. void GetMcdFlags()
  148. {
  149. HKEY hkMcd;
  150. DWORD dwAction;
  151. REGSAM samAccess;
  152. ULONG ulDefMcdFlags;
  153. ULONG ulDefMcdFlagsPriv;
  154. long lTmp;
  155. //
  156. // Default values for McdFlags and McdPrivateFlags.
  157. // If you want to change the defaults, change them here!
  158. //
  159. ulDefMcdFlags = MCDCONTEXT_SWAPSYNC;
  160. ulDefMcdFlagsPriv = MCDPRIVATE_MCD_ENABLED |
  161. MCDPRIVATE_PALETTEFORMATS |
  162. MCDPRIVATE_USEGENERICSTENCIL;
  163. //
  164. // Set initial values.
  165. //
  166. McdFlags = 0;
  167. #if DBG
  168. McdDebugFlags = 0;
  169. #endif
  170. //
  171. // First try for read/write access. Create the key
  172. // if necessary.
  173. //
  174. if ( RegCreateKeyExA(HKEY_LOCAL_MACHINE,
  175. STR_MCDKEY,
  176. 0, // Reserved
  177. (LPSTR) NULL,
  178. REG_OPTION_NON_VOLATILE,
  179. KEY_READ | KEY_WRITE,
  180. (LPSECURITY_ATTRIBUTES) NULL,
  181. &hkMcd,
  182. &dwAction) == ERROR_SUCCESS )
  183. {
  184. samAccess = KEY_READ | KEY_WRITE;
  185. }
  186. //
  187. // Next try read-only access. Do not try to create
  188. // key. Write permission is required to create and
  189. // we do not have that permission.
  190. //
  191. else if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  192. STR_MCDKEY,
  193. 0, // Reserved
  194. KEY_READ,
  195. &hkMcd) == ERROR_SUCCESS )
  196. {
  197. samAccess = KEY_READ;
  198. }
  199. //
  200. // Finally, the key does not exist and we do not have
  201. // write access. Fall back on the defaults and return.
  202. //
  203. else
  204. {
  205. McdFlags = ulDefMcdFlags;
  206. McdPrivateFlags = ulDefMcdFlagsPriv;
  207. return;
  208. }
  209. //
  210. // "Enable" value. Default is 1 (enabled).
  211. //
  212. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_MCD_ENABLED) ? 1:0;
  213. if (GetMcdRegValue(hkMcd, samAccess, STR_ENABLE, lTmp))
  214. McdPrivateFlags |= MCDPRIVATE_MCD_ENABLED;
  215. else
  216. McdPrivateFlags &= (~MCDPRIVATE_MCD_ENABLED);
  217. //
  218. // "SwapSync" value. Default is 1 (enabled).
  219. //
  220. lTmp = (ulDefMcdFlags & MCDCONTEXT_SWAPSYNC) ? 1:0;
  221. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_SWAPSYNC, lTmp);
  222. if (lTmp != 0)
  223. {
  224. McdFlags |= MCDCONTEXT_SWAPSYNC;
  225. }
  226. //
  227. // "Palettized Formats" value. Default is 1 (enabled).
  228. //
  229. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_PALETTEFORMATS) ? 1:0;
  230. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_8BPP, lTmp);
  231. if (lTmp != 0)
  232. {
  233. McdPrivateFlags |= MCDPRIVATE_PALETTEFORMATS;
  234. }
  235. //
  236. // "IO Priority" value. Default is 0 (disabled).
  237. //
  238. lTmp = (ulDefMcdFlags & MCDCONTEXT_IO_PRIORITY) ? 1:0;
  239. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_IOPRIORITY, lTmp);
  240. if (lTmp != 0)
  241. {
  242. McdFlags |= MCDCONTEXT_IO_PRIORITY;
  243. }
  244. //
  245. // "Use Generic Stencil" value. Default is 1 (enabled).
  246. //
  247. lTmp = (ulDefMcdFlagsPriv & MCDPRIVATE_USEGENERICSTENCIL) ? 1:0;
  248. lTmp = GetMcdRegValue(hkMcd, samAccess, STR_GENSTENCIL, lTmp);
  249. if (lTmp != 0)
  250. {
  251. McdPrivateFlags |= MCDPRIVATE_USEGENERICSTENCIL;
  252. }
  253. #if DBG
  254. //
  255. // "Debug" value.
  256. //
  257. // Unlike the other settings, we do not create the Debug value if
  258. // it does not exist.
  259. //
  260. {
  261. DWORD dwDataType;
  262. DWORD cjSize;
  263. cjSize = sizeof(long);
  264. if ( (RegQueryValueExA(hkMcd,
  265. STR_DEBUG,
  266. (LPDWORD) NULL,
  267. &dwDataType,
  268. (LPBYTE) &lTmp,
  269. &cjSize) == ERROR_SUCCESS)
  270. && (dwDataType == REG_DWORD) )
  271. {
  272. McdDebugFlags = lTmp;
  273. }
  274. }
  275. #endif
  276. //
  277. // We're done, so close the registry key.
  278. //
  279. RegCloseKey(hkMcd);
  280. }