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.

224 lines
6.7 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1998 - 2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: Devmode.cpp
  9. //
  10. //
  11. // PURPOSE: Implementation of Devmode functions shared with OEM UI and OEM rendering modules.
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. //
  19. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  20. //
  21. //
  22. #include "precomp.h"
  23. #include "oemui.h"
  24. #include "debug.h"
  25. #include "devmode.h"
  26. // StrSafe.h needs to be included last
  27. // to disallow bad string functions.
  28. #include <STRSAFE.H>
  29. //
  30. //Performs operation on UI Plugins Private DevMode Members.
  31. //Called via IOemUI::DevMode
  32. //
  33. HRESULT hrOEMDevMode(DWORD dwMode, POEMDMPARAM pOemDMParam)
  34. {
  35. POEMDEV pOEMDevIn;
  36. POEMDEV pOEMDevOut;
  37. // Verify parameters.
  38. if( (NULL == pOemDMParam)
  39. ||
  40. ( (OEMDM_SIZE != dwMode)
  41. &&
  42. (OEMDM_DEFAULT != dwMode)
  43. &&
  44. (OEMDM_CONVERT != dwMode)
  45. &&
  46. (OEMDM_MERGE != dwMode)
  47. )
  48. )
  49. {
  50. ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n"));
  51. VERBOSE(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam);
  52. SetLastError(ERROR_INVALID_PARAMETER);
  53. return E_FAIL;
  54. }
  55. // Cast generic (i.e. PVOID) to OEM private devomode pointer type.
  56. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn;
  57. pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut;
  58. switch(dwMode)
  59. {
  60. //
  61. //The Method should return the size of the memory allocation needed to store the UI plugin Private DEVMODE.
  62. //
  63. case OEMDM_SIZE:
  64. pOemDMParam->cbBufSize = sizeof(OEMDEV);
  65. break;
  66. //
  67. //Should fill the Private DEVMODE with the default values.
  68. //
  69. case OEMDM_DEFAULT:
  70. //
  71. //OEM_DMEXTRAHEADER Members
  72. //
  73. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  74. pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  75. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  76. //
  77. //Private members
  78. //
  79. pOEMDevOut->dwDriverData = 0;
  80. pOEMDevOut->dwAdvancedData = 0;
  81. VERBOSE(DLLTEXT("pOEMDevOut after setting default values:\r\n"));
  82. Dump(pOEMDevOut);
  83. break;
  84. //
  85. //The method should convert private DEVMODE members to the current version, if necessary.
  86. //
  87. case OEMDM_CONVERT:
  88. ConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
  89. break;
  90. //
  91. //The method should validate the information contained in private DEVMODE members and merge validated values into a private DEVMODE structure containing default values
  92. //
  93. case OEMDM_MERGE:
  94. ConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
  95. MakeOEMDevmodeValid(pOEMDevOut);
  96. break;
  97. }
  98. Dump(pOemDMParam);
  99. return S_OK;
  100. }
  101. BOOL ConvertOEMDevmode(PCOEMDEV pOEMDevIn, POEMDEV pOEMDevOut)
  102. {
  103. if( (NULL == pOEMDevIn)
  104. ||
  105. (NULL == pOEMDevOut)
  106. )
  107. {
  108. ERR(ERRORTEXT("ConvertOEMDevmode() invalid parameters.\r\n"));
  109. return FALSE;
  110. }
  111. // Check OEM Signature, if it doesn't match ours,
  112. // then just assume DMIn is bad and use defaults.
  113. if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature)
  114. {
  115. VERBOSE(DLLTEXT("Converting private OEM Devmode.\r\n"));
  116. VERBOSE(DLLTEXT("pOEMDevIn:\r\n"));
  117. Dump(pOEMDevIn);
  118. // Set the devmode defaults so that anything the isn't copied over will
  119. // be set to the default value.
  120. pOEMDevOut->dwDriverData = 0;
  121. pOEMDevOut->dwAdvancedData = 0;
  122. // Copy the old structure in to the new using which ever size is the smaller.
  123. // Devmode maybe from newer Devmode (not likely since there is only one), or
  124. // Devmode maybe a newer Devmode, in which case it maybe larger,
  125. // but the first part of the structure should be the same.
  126. // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to;
  127. // the fields that are in the DEVMODE never change only new fields get added to the end.
  128. memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize));
  129. // Re-fill in the size and version fields to indicated
  130. // that the DEVMODE is the current private DEVMODE version.
  131. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  132. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  133. }
  134. else
  135. {
  136. WARNING(DLLTEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n"));
  137. // Don't know what the input DEVMODE is, so just use defaults.
  138. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  139. pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  140. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  141. pOEMDevOut->dwDriverData = 0;
  142. pOEMDevOut->dwAdvancedData = 0;
  143. }
  144. return TRUE;
  145. }
  146. BOOL MakeOEMDevmodeValid(POEMDEV pOEMDevmode)
  147. {
  148. if(NULL == pOEMDevmode)
  149. {
  150. return FALSE;
  151. }
  152. // ASSUMPTION: pOEMDevmode is large enough to contain OEMDEV structure.
  153. // Make sure that dmOEMExtra indicates the current OEMDEV structure.
  154. pOEMDevmode->dmOEMExtra.dwSize = sizeof(OEMDEV);
  155. pOEMDevmode->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  156. pOEMDevmode->dmOEMExtra.dwVersion = OEM_VERSION;
  157. // Set driver data, if not valid.
  158. if(pOEMDevmode->dwDriverData > 100)
  159. {
  160. pOEMDevmode->dwDriverData = 0;
  161. }
  162. // Set Advanced driver data, if not valid.
  163. if(pOEMDevmode->dwAdvancedData > 100)
  164. {
  165. pOEMDevmode->dwAdvancedData = 0;
  166. }
  167. return TRUE;
  168. }
  169. void Dump(PCOEMDEV pOEMDevmode)
  170. {
  171. if( (NULL != pOEMDevmode)
  172. &&
  173. (pOEMDevmode->dmOEMExtra.dwSize >= sizeof(OEMDEV))
  174. &&
  175. (OEM_SIGNATURE == pOEMDevmode->dmOEMExtra.dwSignature)
  176. )
  177. {
  178. VERBOSE(TEXT("\tdmOEMExtra.dwSize = %d\r\n"), pOEMDevmode->dmOEMExtra.dwSize);
  179. VERBOSE(TEXT("\tdmOEMExtra.dwSignature = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwSignature);
  180. VERBOSE(TEXT("\tdmOEMExtra.dwVersion = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwVersion);
  181. VERBOSE(TEXT("\tdwDriverData = %#x\r\n"), pOEMDevmode->dwDriverData);
  182. VERBOSE(TEXT("\tdwAdvancedData = %#x\r\n"), pOEMDevmode->dwAdvancedData);
  183. }
  184. else
  185. {
  186. ERR(ERRORTEXT("Dump(POEMDEV) unknown private OEM DEVMODE.\r\n"));
  187. }
  188. }