home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / xtow.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  117 lines

  1. /***
  2. *xtow.c - convert integers/longs to wide char string
  3. *
  4. *       Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       The module has code to convert integers/longs to wide char strings.
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <windows.h>
  13. #include <stdlib.h>
  14.  
  15. #define INT_SIZE_LENGTH   20
  16. #define LONG_SIZE_LENGTH  40
  17.  
  18. #define I64_SIZE_LENGTH     80
  19.  
  20. /***
  21. *wchar_t *_itow, *_ltow, *_ultow(val, buf, radix) - convert binary int to wide
  22. *       char string
  23. *
  24. *Purpose:
  25. *       Converts an int to a wide character string.
  26. *
  27. *Entry:
  28. *       val - number to be converted (int, long or unsigned long)
  29. *       int radix - base to convert into
  30. *       wchar_t *buf - ptr to buffer to place result
  31. *
  32. *Exit:
  33. *       calls ASCII version to convert, converts ASCII to wide char into buf
  34. *       returns a pointer to this buffer
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. wchar_t * __cdecl _itow (
  41.         int val,
  42.         wchar_t *buf,
  43.         int radix
  44.         )
  45. {
  46.         char astring[INT_SIZE_LENGTH];
  47.  
  48.         _itoa (val, astring, radix);
  49.         MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, astring, -1,
  50.                             buf, INT_SIZE_LENGTH);
  51.  
  52.         return (buf);
  53. }
  54.  
  55. wchar_t * __cdecl _ltow (
  56.         long val,
  57.         wchar_t *buf,
  58.         int radix
  59.         )
  60. {
  61.         char astring[LONG_SIZE_LENGTH];
  62.  
  63.         _ltoa (val, astring, radix);
  64.         MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, astring, -1,
  65.                             buf, LONG_SIZE_LENGTH);
  66.  
  67.         return (buf);
  68. }
  69.  
  70. wchar_t * __cdecl _ultow (
  71.         unsigned long val,
  72.         wchar_t *buf,
  73.         int radix
  74.         )
  75. {
  76.         char astring[LONG_SIZE_LENGTH];
  77.  
  78.         _ultoa (val, astring, radix);
  79.         MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, astring, -1,
  80.                             buf, LONG_SIZE_LENGTH);
  81.  
  82.         return (buf);
  83. }
  84.  
  85. #ifndef _NO_INT64
  86.  
  87. wchar_t * __cdecl _i64tow (
  88.         __int64 val,
  89.         wchar_t *buf,
  90.         int radix
  91.         )
  92. {
  93.         char astring[I64_SIZE_LENGTH];
  94.  
  95.         _i64toa (val, astring, radix);
  96.         MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, astring, -1,
  97.                             buf, I64_SIZE_LENGTH);
  98.         return (buf);
  99. }
  100.  
  101. wchar_t * __cdecl _ui64tow (
  102.         unsigned __int64 val,
  103.         wchar_t *buf,
  104.         int radix
  105.         )
  106. {
  107.         char astring[I64_SIZE_LENGTH];
  108.  
  109.         _ui64toa (val, astring, radix);
  110.         MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, astring, -1,
  111.                             buf, I64_SIZE_LENGTH);
  112.         return (buf);
  113. }
  114.  
  115. #endif  /* _NO_INT64 */
  116.  
  117.