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.

80 lines
2.0 KiB

  1. #ifndef INETCHAR_H
  2. #define INETCHAR_H
  3. /* Copyright (c) 1998 Microsoft Corporation
  4. Module Name:
  5. inetchar.h
  6. Abstract:
  7. macros for converting between Unicode and MultiByte characters.
  8. Contents:
  9. REASSIGN_ALLOC
  10. REASSIGN_SIZE
  11. ALLOC_MB
  12. UNICODE_TO_ANSI
  13. MAYBE_COPY_ANSI
  14. Author:
  15. Ahsan S. Kabir
  16. Revision History:
  17. 18Nov97 akabir
  18. Created
  19. */
  20. //
  21. // ---- Macros to simplify recovering values from memory packets -------------
  22. #define REASSIGN_ALLOC(mp,ps,dw) \
  23. ps = mp.psStr; \
  24. dw = mp.dwAlloc;
  25. #define REASSIGN_SIZE(mp,ps,dw) \
  26. ps = mp.psStr; \
  27. dw = mp.dwSize;
  28. // -- (MAYBE_)ALLOC_MB ------------
  29. // Macros to allocate enough memory for an ansi-equivalent string
  30. #define ALLOC_MB(URLW,DWW,MPMP) { \
  31. MPMP.dwAlloc = ((DWW ? DWW : lstrlenW(URLW))+ 1)*sizeof(WCHAR); \
  32. MPMP.psStr = (LPSTR)ALLOC_BYTES(MPMP.dwAlloc*sizeof(CHAR)); }
  33. // -- UNICODE_TO_ANSI -----
  34. // Base case macro to convert from unicode to ansi
  35. // We're subtracting 1 because we're converting the nullchar in dwAlloc.
  36. #define UNICODE_TO_ANSI(pszW, mpA) \
  37. mpA.dwSize = \
  38. WideCharToMultiByte(CP_ACP,0,pszW,(mpA.dwAlloc/sizeof(*pszW))-1,mpA.psStr,mpA.dwAlloc,NULL,NULL); \
  39. mpA.psStr[mpA.dwSize]= '\0';
  40. #define UNICODE_TO_ANSI_CHECKED(pszW, mpA, pfNotSafe) \
  41. mpA.dwSize = \
  42. WideCharToMultiByte(CP_ACP,0,pszW,(mpA.dwAlloc/sizeof(*pszW))-1,mpA.psStr,mpA.dwAlloc,NULL,pfNotSafe); \
  43. mpA.psStr[mpA.dwSize]= '\0';
  44. // -- (MAYBE_)COPY_ANSI ----
  45. // Given ansi source and widechar destination pointers, convert from the former to latter
  46. #define COPY_ANSI(mp,pszW,dwW) { dwW = MultiByteToWideChar(CP_ACP, 0, mp.psStr, mp.dwSize+1, pszW, dwW) - 1; }
  47. #define MAYBE_COPY_ANSI(mp,pszW,dwW) { if (pszW && mp.psStr) \
  48. { dwW = MultiByteToWideChar(CP_ACP, 0, mp.psStr, mp.dwSize+1, pszW, dwW) - 1; } }
  49. #endif