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.

88 lines
1.9 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. unihelpr.h
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #ifndef _UNIHELPR_H_
  9. #define _UNIHELPR_H_
  10. /*
  11. These macros are based on the MFC macros found in file afxconv.h. They have been modified
  12. slightly to delete references to the MFC helper functions AfxW2AHelper and AfxA2WHelper
  13. so that the MFC DLL is not required.
  14. */
  15. #include <malloc.h>
  16. #define _MbToWide(dst, src, cnt) \
  17. MultiByteToWideChar(CP_ACP, 0, src, (int)cnt, dst, (int)cnt)
  18. #define _WideToMb(dst, src, cnt) \
  19. WideCharToMultiByte(CP_ACP, 0, src, (int)cnt, dst, (int)(2 * cnt), NULL, NULL)
  20. #define A2CW(lpa) (\
  21. ((LPCSTR)lpa == NULL) ? NULL : ( \
  22. _convert = (lstrlenA(lpa)+1), \
  23. _convPtr = alloca(_convert*2), \
  24. _MbToWide((LPWSTR)_convPtr, lpa, _convert), \
  25. (LPCWSTR)_convPtr \
  26. ) \
  27. )
  28. #define A2W(lpa) (\
  29. ((LPCSTR)lpa == NULL) ? NULL : ( \
  30. _convert = (lstrlenA(lpa)+1), \
  31. _convPtr = alloca(_convert*2), \
  32. _MbToWide((LPWSTR)_convPtr, lpa, _convert),\
  33. (LPWSTR)_convPtr \
  34. ) \
  35. )
  36. #define W2CA(lpw) (\
  37. ((LPCWSTR)lpw == NULL) ? NULL : ( \
  38. _convert = (wcslen(lpw)+1), \
  39. _convPtr = alloca(_convert*2), \
  40. _WideToMb((LPSTR)_convPtr, lpw, _convert), \
  41. (LPCSTR)_convPtr \
  42. )\
  43. )
  44. #define W2A(lpw) (\
  45. ((LPCWSTR)lpw == NULL) ? NULL : (\
  46. _convert = (wcslen(lpw)+1),\
  47. _convPtr = alloca(_convert*2), \
  48. _WideToMb((LPSTR)_convPtr, lpw, _convert), \
  49. (LPSTR)_convPtr \
  50. )\
  51. )
  52. #ifndef _DEBUG
  53. #define USES_CONVERSION size_t _convert; void *_convPtr; _convPtr, _convert;
  54. #else
  55. #define USES_CONVERSION int _convert = 0; void *_convPtr = NULL; assert( 0 == _convert ); assert( NULL ==_convPtr );
  56. #endif
  57. #ifdef _UNICODE
  58. #define T2A W2A
  59. #define A2T A2W
  60. #define T2W(x) (x)
  61. #define W2T(x) (x)
  62. #else
  63. #define T2W A2W
  64. #define W2T W2A
  65. #define T2A(x) (x)
  66. #define A2T(x) (x)
  67. #endif
  68. #endif