summaryrefslogtreecommitdiff
path: root/print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp
diff options
context:
space:
mode:
authorLuke <[email protected]>2017-11-28 00:22:11 -0800
committerGitHub <[email protected]>2017-11-28 00:22:11 -0800
commit79bbbca2f6e37d94fbbbd60d12c5c1e7dde650da (patch)
tree793ff943b8b641f95d05401156badd42da4a0f12 /print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp
parented1df9a8b80b154b71b79635e40af75f4f19001c (diff)
parent2817004092cee784d4aaf36c045fdb5b0bc09f7e (diff)
Merge pull request #1 from Microsoft/master
Updating Local
Diffstat (limited to 'print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp')
-rw-r--r--print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp b/print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp
new file mode 100644
index 00000000..7845d5c1
--- /dev/null
+++ b/print/OEM Printer Customization Plug-in Samples/C++/bitmap/devmode.cpp
@@ -0,0 +1,132 @@
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//
+// Copyright 1998 - 2003 Microsoft Corporation. All Rights Reserved.
+//
+// FILE: Devmode.cpp
+//
+//
+// PURPOSE: Helper functions for manipulating the DEVMODE. These are commonly
+// shared by UI & rendering modules
+//
+
+
+#include "precomp.h"
+#include "bitmap.h"
+#include "debug.h"
+#include "devmode.h"
+
+// This indicates to Prefast that this is a usermode driver file.
+_Analysis_mode_(_Analysis_code_type_user_driver_);
+
+
+BOOL bConvertOEMDevmode(
+ PCOEMDEV pOEMDevIn,
+ POEMDEV pOEMDevOut
+ )
+
+/*++
+
+Routine Description:
+
+ Converts private DEVMODE members to the
+ current version.
+
+Arguments:
+
+ pOEMDevIn - pointer to OEM private devmode
+ pOEMDevOut - pointer to OEM private devmode
+
+Return Value:
+
+ TRUE if successful, FALSE if there is an error
+
+--*/
+
+{
+ if( (NULL == pOEMDevIn)
+ ||
+ (NULL == pOEMDevOut)
+ )
+ {
+ ERR("ConvertOEMDevmode() invalid parameters.\r\n");
+ return FALSE;
+ }
+
+ // Check OEM Signature, if it doesn't match ours,
+ // then just assume DMIn is bad and use defaults.
+ if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature)
+ {
+ // Set the devmode defaults so that anything the isn't copied over will
+ // be set to the default value.
+ pOEMDevOut->dwDriverData = 0;
+
+ // Copy the old structure in to the new using which ever size is the smaller.
+ // Devmode maybe from newer Devmode (not likely since there is only one), or
+ // Devmode maybe a newer Devmode, in which case it maybe larger,
+ // but the first part of the structure should be the same.
+
+ // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to;
+ // the fields that are in the DEVMODE never change only new fields get added to the end.
+
+ memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize));
+
+ // Re-fill in the size and version fields to indicated
+ // that the DEVMODE is the current private DEVMODE version.
+ pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
+ pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
+ }
+ else
+ {
+ // Don't know what the input DEVMODE is, so just use defaults.
+ pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
+ pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
+ pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
+ pOEMDevOut->dwDriverData = 0;
+ }
+
+ return TRUE;
+}
+
+
+BOOL bMakeOEMDevmodeValid(
+ POEMDEV pOEMDevmode
+ )
+
+/*++
+
+Routine Description:
+
+ Ensures that private OEM devmode members are valid.
+
+Arguments:
+
+ pOEMDevmode - pointer to OEM private devmode
+
+Return Value:
+
+ TRUE if successful, FALSE if there is an error
+
+--*/
+
+{
+ if(NULL == pOEMDevmode)
+ {
+ return FALSE;
+ }
+
+ // ASSUMPTION: pOEMDevmode is large enough to contain OEMDEV structure.
+
+ // Make sure that dmOEMExtra indicates the current OEMDEV structure.
+ pOEMDevmode->dmOEMExtra.dwSize = sizeof(OEMDEV);
+ pOEMDevmode->dmOEMExtra.dwSignature = OEM_SIGNATURE;
+ pOEMDevmode->dmOEMExtra.dwVersion = OEM_VERSION;
+
+ // Set driver data.
+ pOEMDevmode->dwDriverData = 0;
+
+ return TRUE;
+}
+