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.

114 lines
2.9 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLCONV_H__
  11. #define __ATLCONV_H__
  12. #pragma once
  13. #ifndef _ATL_NO_PRAGMA_WARNINGS
  14. #pragma warning (push)
  15. #pragma warning(disable: 4127) // unreachable code
  16. #endif //!_ATL_NO_PRAGMA_WARNINGS
  17. #ifndef __cplusplus
  18. #error ATL requires C++ compilation (use a .cpp suffix)
  19. #endif
  20. #include <atldef.h>
  21. #include <objbase.h>
  22. namespace ATL
  23. {
  24. inline UINT _AtlGetConversionACP()
  25. {
  26. return( CP_ACP );
  27. }
  28. }; // namespace ATL
  29. #pragma pack(push,8)
  30. #ifndef _DEBUG
  31. #define USES_CONVERSION int _convert; _convert; UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; _acp; LPCWSTR _lpw; _lpw; LPCSTR _lpa; _lpa
  32. #else
  33. #define USES_CONVERSION int _convert = 0; _convert; UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; _acp; LPCWSTR _lpw = NULL; _lpw; LPCSTR _lpa = NULL; _lpa
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Global UNICODE<>ANSI translation helpers
  37. inline LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars, UINT acp)
  38. {
  39. ATLASSERT(lpa != NULL);
  40. ATLASSERT(lpw != NULL);
  41. if (lpw == NULL)
  42. return NULL;
  43. // verify that no illegal character present
  44. // since lpw was allocated based on the size of lpa
  45. // don't worry about the number of chars
  46. lpw[0] = '\0';
  47. MultiByteToWideChar(acp, 0, lpa, -1, lpw, nChars);
  48. return lpw;
  49. }
  50. inline LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT acp)
  51. {
  52. ATLASSERT(lpw != NULL);
  53. ATLASSERT(lpa != NULL);
  54. if (lpa == NULL)
  55. return NULL;
  56. // verify that no illegal character present
  57. // since lpa was allocated based on the size of lpw
  58. // don't worry about the number of chars
  59. lpa[0] = '\0';
  60. WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);
  61. return lpa;
  62. }
  63. #ifndef ATLA2WHELPER
  64. #define ATLA2WHELPER AtlA2WHelper
  65. #define ATLW2AHELPER AtlW2AHelper
  66. #endif
  67. #define A2W(lpa) (\
  68. ((_lpa = lpa) == NULL) ? NULL : (\
  69. _convert = (lstrlenA(_lpa)+1),\
  70. ATLA2WHELPER((LPWSTR) alloca(_convert*2), _lpa, _convert, _acp)))
  71. #define W2A(lpw) (\
  72. ((_lpw = lpw) == NULL) ? NULL : (\
  73. _convert = (lstrlenW(_lpw)+1)*2,\
  74. ATLW2AHELPER((LPSTR) alloca(_convert), _lpw, _convert, _acp)))
  75. #pragma pack(pop)
  76. #ifndef _ATL_DLL_IMPL
  77. #ifndef _ATL_DLL
  78. #define _ATLCONV_IMPL
  79. #endif
  80. #endif
  81. #endif // __ATLCONV_H__
  82. /////////////////////////////////////////////////////////////////////////////
  83. #ifdef _ATLCONV_IMPL
  84. //Prevent pulling in second time
  85. #undef _ATLCONV_IMPL
  86. #ifndef _ATL_NO_PRAGMA_WARNINGS
  87. #pragma warning (pop)
  88. #endif //!_ATL_NO_PRAGMA_WARNINGS
  89. #endif // _ATLCONV_IMPL