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.

187 lines
5.6 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 "oemps.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. HRESULT hrOEMDevMode(DWORD dwMode, POEMDMPARAM pOemDMParam)
  30. {
  31. POEMDEV pOEMDevIn;
  32. POEMDEV pOEMDevOut;
  33. // Verify parameters.
  34. if( (NULL == pOemDMParam)
  35. ||
  36. ( (OEMDM_SIZE != dwMode)
  37. &&
  38. (OEMDM_DEFAULT != dwMode)
  39. &&
  40. (OEMDM_CONVERT != dwMode)
  41. &&
  42. (OEMDM_MERGE != dwMode)
  43. )
  44. )
  45. {
  46. ERR(ERRORTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n"));
  47. VERBOSE(DLLTEXT("\tdwMode = %d, pOemDMParam = %#lx.\r\n"), dwMode, pOemDMParam);
  48. SetLastError(ERROR_INVALID_PARAMETER);
  49. return E_FAIL;
  50. }
  51. // Cast generic (i.e. PVOID) to OEM private devomode pointer type.
  52. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn;
  53. pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut;
  54. switch(dwMode)
  55. {
  56. case OEMDM_SIZE:
  57. pOemDMParam->cbBufSize = sizeof(OEMDEV);
  58. break;
  59. case OEMDM_DEFAULT:
  60. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  61. pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  62. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  63. pOEMDevOut->dwDriverData = 0;
  64. VERBOSE(DLLTEXT("pOEMDevOut after setting default values:\r\n"));
  65. Dump(pOEMDevOut);
  66. break;
  67. case OEMDM_CONVERT:
  68. ConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
  69. break;
  70. case OEMDM_MERGE:
  71. ConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
  72. MakeOEMDevmodeValid(pOEMDevOut);
  73. break;
  74. }
  75. Dump(pOemDMParam);
  76. return S_OK;
  77. }
  78. BOOL ConvertOEMDevmode(PCOEMDEV pOEMDevIn, POEMDEV pOEMDevOut)
  79. {
  80. if( (NULL == pOEMDevIn)
  81. ||
  82. (NULL == pOEMDevOut)
  83. )
  84. {
  85. ERR(ERRORTEXT("ConvertOEMDevmode() invalid parameters.\r\n"));
  86. return FALSE;
  87. }
  88. // Check OEM Signature, if it doesn't match ours,
  89. // then just assume DMIn is bad and use defaults.
  90. if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature)
  91. {
  92. VERBOSE(DLLTEXT("Converting private OEM Devmode.\r\n"));
  93. VERBOSE(DLLTEXT("pOEMDevIn:\r\n"));
  94. Dump(pOEMDevIn);
  95. // Set the devmode defaults so that anything the isn't copied over will
  96. // be set to the default value.
  97. pOEMDevOut->dwDriverData = 0;
  98. // Copy the old structure in to the new using which ever size is the smaller.
  99. // Devmode maybe from newer Devmode (not likely since there is only one), or
  100. // Devmode maybe a newer Devmode, in which case it maybe larger,
  101. // but the first part of the structure should be the same.
  102. // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to;
  103. // the fields that are in the DEVMODE never change only new fields get added to the end.
  104. memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize));
  105. // Re-fill in the size and version fields to indicated
  106. // that the DEVMODE is the current private DEVMODE version.
  107. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  108. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  109. }
  110. else
  111. {
  112. WARNING(DLLTEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n"));
  113. // Don't know what the input DEVMODE is, so just use defaults.
  114. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
  115. pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  116. pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
  117. pOEMDevOut->dwDriverData = 0;
  118. }
  119. return TRUE;
  120. }
  121. BOOL MakeOEMDevmodeValid(POEMDEV pOEMDevmode)
  122. {
  123. if(NULL == pOEMDevmode)
  124. {
  125. return FALSE;
  126. }
  127. // ASSUMPTION: pOEMDevmode is large enough to contain OEMDEV structure.
  128. // Make sure that dmOEMExtra indicates the current OEMDEV structure.
  129. pOEMDevmode->dmOEMExtra.dwSize = sizeof(OEMDEV);
  130. pOEMDevmode->dmOEMExtra.dwSignature = OEM_SIGNATURE;
  131. pOEMDevmode->dmOEMExtra.dwVersion = OEM_VERSION;
  132. // Set driver data.
  133. pOEMDevmode->dwDriverData = 0;
  134. return TRUE;
  135. }
  136. void Dump(PCOEMDEV pOEMDevmode)
  137. {
  138. if( (NULL != pOEMDevmode)
  139. &&
  140. (pOEMDevmode->dmOEMExtra.dwSize >= sizeof(OEMDEV))
  141. &&
  142. (OEM_SIGNATURE == pOEMDevmode->dmOEMExtra.dwSignature)
  143. )
  144. {
  145. VERBOSE(_TEXT("\tdmOEMExtra.dwSize = %d\r\n"), pOEMDevmode->dmOEMExtra.dwSize);
  146. VERBOSE(_TEXT("\tdmOEMExtra.dwSignature = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwSignature);
  147. VERBOSE(_TEXT("\tdmOEMExtra.dwVersion = %#x\r\n"), pOEMDevmode->dmOEMExtra.dwVersion);
  148. VERBOSE(_TEXT("\tdwDriverData = %#x\r\n"), pOEMDevmode->dwDriverData);
  149. }
  150. else
  151. {
  152. ERR(ERRORTEXT("Dump(POEMDEV) unknown private OEM DEVMODE.\r\n"));
  153. }
  154. }