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.

74 lines
2.1 KiB

  1. //
  2. // Wrapper for <atlconv.h> that redirects it to our C-callable
  3. // helper functions, and also creates the appropriate definitions
  4. // for C callers so everybody can use the A2W/W2A macros.
  5. //
  6. #ifndef _SHCONV_H
  7. #define _SHCONV_H
  8. //
  9. // Force these to EXTERN_C so we can use them from C code, too.
  10. //
  11. STDAPI_(LPWSTR) SHA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars);
  12. STDAPI_(LPSTR) SHW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars);
  13. #define ATLA2WHELPER SHA2WHelper
  14. #define ATLW2AHELPER SHW2AHelper
  15. #ifdef __cplusplus
  16. #ifndef offsetof
  17. #define offsetof(s,m) ((size_t)&(((s *)0)->m))
  18. #endif
  19. #ifndef ATLASSERT
  20. #define ATLASSERT(f) ASSERT(f)
  21. #endif
  22. #include <atlconv.h>
  23. #else
  24. #define USES_CONVERSION int _convert = 0
  25. //
  26. // This macro assumes that lstrlenW(UNICODE) <= lstrlenA(ANSI)
  27. //
  28. #define A2W(lpa) (\
  29. ((LPCSTR)lpa == NULL) ? NULL : (\
  30. _convert = (lstrlenA(lpa)+1),\
  31. ATLA2WHELPER((LPWSTR) alloca(_convert*2), (LPCSTR)lpa, _convert)))
  32. //
  33. // This macro assumes that lstrlenA(ANSI) <= lstrlenW(UNICODE) * 2
  34. //
  35. #define W2A(lpw) (\
  36. ((LPCWSTR)lpw == NULL) ? NULL : (\
  37. _convert = (lstrlenW(lpw)+1)*2,\
  38. ATLW2AHELPER((LPSTR) alloca(_convert), lpw, _convert)))
  39. #define A2CW(lpa) ((LPCWSTR)A2W(lpa))
  40. #define W2CA(lpw) ((LPCSTR)W2A(lpw))
  41. #ifdef UNICODE
  42. #define T2A W2A
  43. #define A2T A2W
  44. __inline LPWSTR T2W(LPTSTR lp) { return lp; }
  45. __inline LPTSTR W2T(LPWSTR lp) { return lp; }
  46. #define T2CA W2CA
  47. #define A2CT A2CW
  48. __inline LPCWSTR T2CW(LPCTSTR lp) { return lp; }
  49. __inline LPCTSTR W2CT(LPCWSTR lp) { return lp; }
  50. #else
  51. #define T2W A2W
  52. #define W2T W2A
  53. __inline LPSTR T2A(LPTSTR lp) { return lp; }
  54. __inline LPTSTR A2T(LPSTR lp) { return lp; }
  55. #define T2CW A2CW
  56. #define W2CT W2CA
  57. __inline LPCSTR T2CA(LPCTSTR lp) { return lp; }
  58. __inline LPCTSTR A2CT(LPCSTR lp) { return lp; }
  59. #endif
  60. #include <crt/malloc.h> // Get definition for alloca()
  61. #endif // !C++
  62. #endif // _SHCONV_H