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.

77 lines
1.9 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. Author:
  14. Ahsan S. Kabir
  15. Revision History:
  16. 18Nov97 akabir
  17. Created
  18. */
  19. //
  20. // ---- Macros to simplify recovering values from memory packets -------------
  21. #define REASSIGN_ALLOC(mp,ps,dw) \
  22. ps = mp.psStr; \
  23. dw = mp.dwAlloc;
  24. #define REASSIGN_SIZE(mp,ps,dw) \
  25. ps = mp.psStr; \
  26. dw = mp.dwSize;
  27. // -- (MAYBE_)ALLOC_MB ------------
  28. // Macros to allocate enough memory for an ansi-equivalent string
  29. #define ALLOC_MB(URLW,DWW,MPMP) { \
  30. MPMP.dwAlloc = ((DWW ? DWW : lstrlenW(URLW))+ 1)*sizeof(WCHAR); \
  31. ALLOC_BYTES(MPMP.psStr, MPMP.dwAlloc*sizeof(CHAR)); }
  32. // -- UNICODE_TO_ANSI -----
  33. // Base case macro to convert from unicode to ansi
  34. // We're subtracting 1 because we're converting the nullchar in dwAlloc.
  35. #define UNICODE_TO_ANSI(pszW, mpA) \
  36. mpA.dwSize = \
  37. WideCharToMultiByte(CP_ACP,0,pszW,(mpA.dwAlloc/sizeof(*pszW))-1,mpA.psStr,mpA.dwAlloc,NULL,NULL); \
  38. mpA.psStr[mpA.dwSize]= '\0';
  39. #define UNICODE_TO_ANSI_CHECKED(pszW, mpA, pfNotSafe) \
  40. mpA.dwSize = \
  41. WideCharToMultiByte(CP_ACP,0,pszW,(mpA.dwAlloc/sizeof(*pszW))-1,mpA.psStr,mpA.dwAlloc,NULL,pfNotSafe); \
  42. mpA.psStr[mpA.dwSize]= '\0';
  43. // -- ZERO_MEMORY_ALLOC -----
  44. // Zeroes out the memory alloc.
  45. // To protect sensitive information from showing up in the heap unexpectedly.
  46. #define ZERO_MEMORY_ALLOC(mpA) \
  47. if (mpA.psStr) \
  48. { \
  49. memset (mpA.psStr, 0, mpA.dwAlloc); \
  50. }
  51. #endif