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.

80 lines
1.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpvxlib.cpp
  6. * Content: Useful char utility functions lib for sample apps
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/07/99 rodtoll Created It
  12. * 06/28/2000 rodtoll Prefix Bug #38033
  13. *
  14. ***************************************************************************/
  15. #include "dpvxlibpch.h"
  16. // Conversion Functions
  17. int DPVDX_WideToAnsi(LPSTR lpStr,LPWSTR lpWStr,int cchStr)
  18. {
  19. int rval;
  20. BOOL bDefault = FALSE;
  21. if (!lpWStr && cchStr)
  22. {
  23. DebugBreak();
  24. return 0;
  25. }
  26. // use the default code page (CP_ACP)
  27. // -1 indicates WStr must be null terminated
  28. rval = WideCharToMultiByte(CP_ACP,0,lpWStr,-1,lpStr,cchStr,
  29. "-",&bDefault);
  30. if (bDefault)
  31. {
  32. DebugBreak();
  33. }
  34. return rval;
  35. }
  36. HRESULT DPVDX_AllocAndConvertToANSI(LPSTR * ppszAnsi,LPWSTR lpszWide)
  37. {
  38. int iStrLen;
  39. if (!lpszWide)
  40. {
  41. *ppszAnsi = NULL;
  42. return S_OK;
  43. }
  44. // call wide to ansi to find out how big +1 for terminating NULL
  45. iStrLen = DPVDX_WideToAnsi(NULL,lpszWide,0) + 1;
  46. *ppszAnsi = new char[iStrLen];
  47. if (!*ppszAnsi)
  48. {
  49. return E_OUTOFMEMORY;
  50. }
  51. DPVDX_WideToAnsi(*ppszAnsi,lpszWide,iStrLen);
  52. return S_OK;
  53. }
  54. int DPVDX_AnsiToWide(LPWSTR lpWStr,LPSTR lpStr,int cchWStr)
  55. {
  56. int rval;
  57. if (!lpStr && cchWStr)
  58. {
  59. return 0;
  60. }
  61. rval = MultiByteToWideChar(CP_ACP,0,lpStr,-1,lpWStr,cchWStr);
  62. return rval;
  63. } // AnsiToWide