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.

95 lines
2.2 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. bDefault = FALSE;
  38. if (!lpWStr && cchStr)
  39. {
  40. // can't call us w/ null pointer & non-zero cch
  41. DDASSERT(FALSE);
  42. return 0;
  43. }
  44. // use the default code page (CP_ACP)
  45. // -1 indicates WStr must be null terminated
  46. rval = WideCharToMultiByte(CP_ACP,0,lpWStr,-1,lpStr,cchStr,
  47. DPLAY_DEFAULT_CHAR,&bDefault);
  48. if (bDefault)
  49. {
  50. DPF(0,"!!! WARNING - used default string in WideToAnsi conversion.!!!");
  51. DPF(0,"!!! Possible bad unicode string - (you're not hiding ansi in there are you?) !!! ");
  52. }
  53. return rval;
  54. } // WideToAnsi
  55. /*
  56. ** AnsiToWide
  57. *
  58. * CALLED BY: everywhere
  59. *
  60. * PARAMETERS: lpWStr - dest string
  61. * lpStr - string to convert
  62. * cchWstr - size of dest buffer
  63. *
  64. * DESCRIPTION: converts Ansi lpStr to Unicode lpWstr
  65. *
  66. *
  67. * RETURNS: if cchStr is 0, returns the size required to hold the string
  68. * otherwise, returns the number of chars converted
  69. *
  70. */
  71. int AnsiToWide(LPWSTR lpWStr,LPSTR lpStr,int cchWStr)
  72. {
  73. int rval;
  74. if (!lpStr && cchWStr)
  75. {
  76. // can't call us w/ null pointer & non-zero cch
  77. DDASSERT(FALSE);
  78. return 0;
  79. }
  80. rval = MultiByteToWideChar(CP_ACP,0,lpStr,-1,lpWStr,cchWStr);
  81. return rval;
  82. } // AnsiToWide