home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / fontedit / typecvt.h < prev   
C/C++ Source or Header  |  1997-10-05  |  7KB  |  268 lines

  1. /*++
  2.  
  3. Copyright (c) 1993-1997 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     typecvt.h
  8.  
  9. Abstract:
  10.  
  11.     Header file for typecvt.c.  Contains any defines, structures and prototypes
  12.     which are needed by programs to call the typecvt routines.
  13.  
  14.  
  15. --*/
  16.  
  17.  
  18. // Make sure we are not already defined.
  19.  
  20. #ifndef _TYPECVT_
  21.  
  22. #define _TYPECVT_
  23.  
  24. //
  25. // The following preprocessor directives are used to control possible
  26. // differences between the way integers are stored on the machine and
  27. // how they are stored in the file.  Normally Intel and MIPS chips will
  28. // all be little endian so these should not be necessray.  Some time in
  29. // the future we may port to a machine which is only big endian.
  30. // If this is the case CVT_BIG_ENDIAN_SUPPORT should be defined.
  31. //
  32.  
  33. //
  34. // The following defines are used to set the type of source and destination
  35. // structures.  For those of us who are confused by little endian and big
  36. // endian formats, here is a breif recap.
  37. //
  38. // Little Endian:  (This is used on Intel chips.  The MIPS chip is switchable
  39. //      but for NT is will run in little endian format.)
  40. //    This is where the high order bytes of a short or long are stored higher
  41. //    in memory.  For example the number 0x80402010 is stored as follows.
  42. //      Address:        Value:
  43. //          00            10
  44. //          01            20
  45. //          02            40
  46. //          03            80
  47. //    This looks backwards when memory is dumped in order: 10 20 40 80
  48. //
  49. // Big Endian:  (This is not currently used on any NT systems but hey, this
  50. //      is supposed to be portable!!)
  51. //    This is where the high order bytes of a short or long are stored lower
  52. //    in memory.  For example the number 0x80402010 is stored as follows.
  53. //      Address:        Value:
  54. //          00            80
  55. //          01            40
  56. //          02            20
  57. //          03            10
  58. //    This looks correct when memory is dumped in order: 80 40 20 10
  59. //
  60.  
  61. #define   CVT_ENDIAN_UNKNOWN  0   // Endian type is unknown. (do not use).
  62. #define   CVT_LITTLE_ENDIAN   1   // Format is little endian.
  63. #define   CVT_BIG_ENDIAN      2   // Format is big endian.
  64.  
  65. //
  66. // Define the endian type of the file.  CVT_FILE_ENDIAN_DEFAULT defines how
  67. // most files are stored on disk.  The default is in little endian since most
  68. // Microsoft standards are set based on the Intel chip.
  69. //
  70.  
  71. #define         CVT_FILE_ENDIAN_DEFAULT        CVT_LITTLE_ENDIAN
  72.  
  73. //
  74. // The following variables are used to make "changeable defines."   They
  75. // allow the caller to specify a constant which changes from system to
  76. // system.
  77. //
  78.  
  79. extern INT vfFileEndianType;
  80. extern INT vfSysEndianType;
  81.  
  82. #define   CVT_ENDIAN_FILE     vfFileEndianType
  83. #define   CVT_ENDIAN_SYSTEM   vfSysEndianType
  84.  
  85. //
  86. // Fake structure used to determine system alignment type.
  87. //
  88.  
  89. struct tagAlignmentCheck
  90. {
  91.     char    chElem1;        // Note that this structure will be different
  92.     long      lElem2;            // sizes based on the system alignment scheme.
  93.                             // The different values follow.
  94. };
  95.  
  96. //
  97. // Note that the following defines must correspond to the size of the
  98. // preceeding structure in different packing schemes.
  99. //
  100.  
  101. #define   CVT_ALIGN_PACKED      5   // Packed = 1-byte boundry ...
  102. #define   CVT_ALIGN_WORD        6   // WORD = 2-byte boundry ...
  103. #define   CVT_ALIGN_DWORD       8   // DWORD = 4-byte boundry ...
  104.  
  105. //
  106. // The following will correspond to one of the above alignment methods and
  107. // will then reflect the system that this is compiled under.
  108. //
  109.  
  110. #define   CVT_ALIGN_SYSTEM      sizeof(struct tagAlignmentCheck)
  111.  
  112.  
  113. //
  114. // The next two structures are the heart of the conversion process.  The
  115. // goal here is to describe two structures individually.  Each element should
  116. // be defined in a SDI structure.  An array of these structures will make up
  117. // the complete definition.
  118. //
  119.  
  120. typedef struct tagStructDefineInfo
  121. {
  122.     INT     cTypeSize;          // Size of type. (ex. sizeof (int)).
  123.     INT     cActualSize;        // Actual size (ex. sizeof (cTypeSize)).
  124.     INT     oPackedAlign;          // Offset of element in PACKED alginment.
  125.     INT     oWordAlign;            // Offset of element in WORD alginment.
  126.     INT     oDWordAlign;           // Offset of element in DWORD alginment.
  127. } SDI, * PSDI;
  128.  
  129. //
  130. // Prototypes for base functions which user can call to perfom the conversion.
  131. //
  132.  
  133. LONG
  134. lCalculateStructOffsets (
  135.      PSDI    rgsdiStructDefine,
  136.      INT     fAlignmentType,
  137.       INT             cSizeOfStruct
  138.     );
  139.  
  140. VOID
  141. vPerformConversion (
  142.      PSDI    rgsdiStructDefine,
  143.      PBYTE   pjSrcBuffer,
  144.      INT        fSrcAlignment,
  145.      INT        fSrcEndianType,
  146.     PBYTE   pjDestBuffer,
  147.      INT        fDestAlignment,
  148.      INT        fDestEndianType
  149.     );
  150.  
  151. VOID
  152. vSetFileEndianType (
  153.     BOOL     fNewEndianType
  154.     );
  155.  
  156. INT
  157. fDetermineSysEndianType (
  158.     VOID
  159.     );
  160.  
  161. //
  162. // Prototypes for convertion functions available to external programs.
  163. // These functions are never actually used by
  164. //
  165.  
  166. VOID
  167. vCharToShort (
  168.           PBYTE  pjSrc,
  169.          PBYTE  pjDest
  170.          );
  171. VOID
  172. vCharToUShort (
  173.           PBYTE  pjSource,
  174.          PBYTE  pjDest
  175.          );
  176. VOID
  177. vCharToLong (
  178.           PBYTE  pjSource,
  179.          PBYTE  pjDest
  180.          );
  181. VOID
  182. vCharToULong (
  183.           PBYTE  pjSource,
  184.          PBYTE  pjDest
  185.          );
  186. VOID
  187. vShortToShort (
  188.           PBYTE  pjSource,
  189.          PBYTE  pjDest
  190.          );
  191. VOID
  192. vShortToLong (
  193.           PBYTE  pjSource,
  194.          PBYTE  pjDest
  195.          );
  196. VOID
  197. vShortToULong (
  198.           PBYTE  pjSource,
  199.          PBYTE  pjDest
  200.          );
  201. VOID
  202. vLongToLong (
  203.           PBYTE  pjSource,
  204.          PBYTE  pjDest
  205.          );
  206. VOID
  207. vLongToShort (
  208.           PBYTE  pjSource,
  209.          PBYTE  pjDest
  210.          );
  211. VOID
  212. vLongToChar (
  213.           PBYTE  pjSource,
  214.          PBYTE  pjDest
  215.          );
  216. VOID
  217. vShortToChar (
  218.           PBYTE  pjSource,
  219.          PBYTE  pjDest
  220.          );
  221.  
  222. //
  223. // The following functions are the ones called by the utility functions.
  224. // They could also be used in some other situations so I will make them
  225. // public.
  226. //
  227.  
  228. SHORT
  229. sSHORTFromSrcBuff (
  230.          PBYTE   pjSrc
  231.     );
  232. USHORT
  233. usUSHORTFromSrcBuff (
  234.          PBYTE   pjSrc
  235.     );
  236. LONG
  237. lLONGFromSrcBuff (
  238.          PBYTE   pjSrc
  239.     );
  240. ULONG
  241. ulULONGFromSrcBuff (
  242.          PBYTE   pjSrc
  243.     );
  244.  
  245.  
  246. VOID
  247. vDestBuffFromSHORT (
  248.          SHORT   sSource,
  249.         PBYTE   pjDest
  250.     );
  251. VOID
  252. vDestBuffFromUSHORT (
  253.          USHORT  usSource,
  254.         PBYTE   pjDest
  255.     );
  256. VOID
  257. vDestBuffFromLONG (
  258.          LONG    lSource,
  259.         PBYTE   pjDest
  260.     );
  261. VOID
  262. vDestBuffFromULONG (
  263.          ULONG   ulSource,
  264.         PBYTE   pjDest
  265.     );
  266.  
  267. #endif  // _TYPECVT_
  268.