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.

59 lines
4.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // cnvmacros.h
  6. //
  7. // Purpose: Converts ansi to wcs or wcs to ansi using stack
  8. //
  9. //
  10. // WARNING!
  11. //
  12. // Do not attempt to use these functions on strings longer than _MAX_PATH
  13. //
  14. //***************************************************************************
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18. #ifndef _CNVMACROS_H_
  19. #define _CNVMACROS_H_
  20. #include <assertbreak.h>
  21. #define WCSTOANSISTRING(x, y, conversionFailure ) \
  22. char t_##x[_MAX_PATH]; \
  23. { \
  24. conversionFailure = false ; \
  25. int nLen = ::WideCharToMultiByte(CP_ACP, 0, x, -1, t_##x, _MAX_PATH, NULL, NULL); \
  26. if (nLen != 0) \
  27. { \
  28. y = t_##x; \
  29. } \
  30. else \
  31. { \
  32. ASSERT_BREAK(0); \
  33. conversionFailure = true ; \
  34. y = NULL; \
  35. } \
  36. } \
  37. #define ANSISTRINGTOWCS(in, out, conversionFailure ) \
  38. WCHAR t_##x[_MAX_PATH]; \
  39. { \
  40. conversionFailure = false ; \
  41. int nLen = MultiByteToWideChar(CP_ACP, 0, in, -1, t_##x, sizeof(t_##x)/sizeof(WCHAR)); \
  42. if (nLen != 0) \
  43. { \
  44. out = t_##x; \
  45. } \
  46. else \
  47. { \
  48. ASSERT_BREAK(0); \
  49. conversionFailure = true ; \
  50. out = NULL; \
  51. } \
  52. } \
  53. #endif