Source code of Windows XP (NT5)
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.

93 lines
2.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dputils.c
  6. * Content: common support routines
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 3/17/97 kipo created it
  11. ***************************************************************************/
  12. #include <windows.h>
  13. #include "dpf.h"
  14. #include "dputils.h"
  15. /*
  16. ** WideToAnsi
  17. *
  18. * CALLED BY: everywhere
  19. *
  20. * PARAMETERS: lpStr - destination string
  21. * lpWStr - string to convert
  22. * cchStr - size of dest buffer
  23. *
  24. * DESCRIPTION:
  25. * converts unicode lpWStr to ansi lpStr.
  26. * fills in unconvertable chars w/ DPLAY_DEFAULT_CHAR "-"
  27. *
  28. *
  29. * RETURNS: if cchStr is 0, returns the size required to hold the string
  30. * otherwise, returns the number of chars converted
  31. *
  32. */
  33. int WideToAnsi(LPSTR lpStr,LPWSTR lpWStr,int cchStr)
  34. {
  35. int rval;
  36. BOOL bDefault;
  37. if (!lpWStr && cchStr)
  38. {
  39. // can't call us w/ null pointer & non-zero cch
  40. DDASSERT(FALSE);
  41. return 0;
  42. }
  43. // use the default code page (CP_ACP)
  44. // -1 indicates WStr must be null terminated
  45. rval = WideCharToMultiByte(CP_ACP,0,lpWStr,-1,lpStr,cchStr,
  46. DPLAY_DEFAULT_CHAR,&bDefault);
  47. if (bDefault)
  48. {
  49. DPF(0,"!!! WARNING - used default string in WideToAnsi conversion.!!!");
  50. DPF(0,"!!! Possible bad unicode string - (you're not hiding ansi in there are you?) !!! ");
  51. }
  52. return rval;
  53. } // WideToAnsi
  54. /*
  55. ** AnsiToWide
  56. *
  57. * CALLED BY: everywhere
  58. *
  59. * PARAMETERS: lpWStr - dest string
  60. * lpStr - string to convert
  61. * cchWstr - size of dest buffer
  62. *
  63. * DESCRIPTION: converts Ansi lpStr to Unicode lpWstr
  64. *
  65. *
  66. * RETURNS: if cchStr is 0, returns the size required to hold the string
  67. * otherwise, returns the number of chars converted
  68. *
  69. */
  70. int AnsiToWide(LPWSTR lpWStr,LPSTR lpStr,int cchWStr)
  71. {
  72. int rval;
  73. if (!lpStr && cchWStr)
  74. {
  75. // can't call us w/ null pointer & non-zero cch
  76. DDASSERT(FALSE);
  77. return 0;
  78. }
  79. rval = MultiByteToWideChar(CP_ACP,0,lpStr,-1,lpWStr,cchWStr);
  80. return rval;
  81. } // AnsiToWide