Source code of Windows XP (NT5)
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.

221 lines
7.8 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1997 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. #ifndef __cplusplus
  13. #error ATL requires C++ compilation (use a .cpp suffix)
  14. #endif
  15. #ifndef _INC_MALLOC
  16. #include <malloc.h>
  17. #endif // _INC_MALLOC
  18. #pragma pack(push,8)
  19. // Make sure MFC's afxconv.h hasn't already been loaded to do this
  20. #ifndef USES_CONVERSION
  21. #ifndef _DEBUG
  22. #define USES_CONVERSION int _convert; _convert
  23. #else
  24. #define USES_CONVERSION int _convert = 0
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Global UNICODE<>ANSI translation helpers
  28. LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars);
  29. LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars);
  30. #ifndef ATLA2WHELPER
  31. #define ATLA2WHELPER AtlA2WHelper
  32. #define ATLW2AHELPER AtlW2AHelper
  33. #endif
  34. #define A2W(lpa) (\
  35. ((LPCSTR)lpa == NULL) ? NULL : (\
  36. _convert = (lstrlenA(lpa)+1),\
  37. ATLA2WHELPER((LPWSTR) alloca(_convert*2), (LPCSTR)lpa, _convert)))
  38. #define W2A(lpw) (\
  39. ((LPCWSTR)lpw == NULL) ? NULL : (\
  40. _convert = (lstrlenW(lpw)+1)*2,\
  41. ATLW2AHELPER((LPSTR) alloca(_convert), lpw, _convert)))
  42. #define A2CW(lpa) ((LPCWSTR)A2W(lpa))
  43. #define W2CA(lpw) ((LPCSTR)W2A(lpw))
  44. #if defined(_UNICODE)
  45. // in these cases the default (TCHAR) is the same as OLECHAR
  46. inline int ocslen(LPCOLESTR x) { return lstrlenW(x); }
  47. inline OLECHAR* ocscpy(LPOLESTR dest, LPCOLESTR src) { return lstrcpyW(dest, src); }
  48. inline LPCOLESTR T2COLE(LPCTSTR lp) { return lp; }
  49. inline LPCTSTR OLE2CT(LPCOLESTR lp) { return lp; }
  50. inline LPOLESTR T2OLE(LPTSTR lp) { return lp; }
  51. inline LPTSTR OLE2T(LPOLESTR lp) { return lp; }
  52. #elif defined(OLE2ANSI)
  53. // in these cases the default (TCHAR) is the same as OLECHAR
  54. inline int ocslen(LPCOLESTR x) { return lstrlen(x); }
  55. inline OLECHAR* ocscpy(LPOLESTR dest, LPCOLESTR src) { return lstrcpy(dest, src); }
  56. inline LPCOLESTR T2COLE(LPCTSTR lp) { return lp; }
  57. inline LPCTSTR OLE2CT(LPCOLESTR lp) { return lp; }
  58. inline LPOLESTR T2OLE(LPTSTR lp) { return lp; }
  59. inline LPTSTR OLE2T(LPOLESTR lp) { return lp; }
  60. #else
  61. inline int ocslen(LPCOLESTR x) { return lstrlenW(x); }
  62. //lstrcpyW doesn't work on Win95, so we do this
  63. inline OLECHAR* ocscpy(LPOLESTR dest, LPCOLESTR src)
  64. {return (LPOLESTR) memcpy(dest, src, (lstrlenW(src)+1)*sizeof(WCHAR));}
  65. //CharNextW doesn't work on Win95 so we use this
  66. #define T2COLE(lpa) A2CW(lpa)
  67. #define T2OLE(lpa) A2W(lpa)
  68. #define OLE2CT(lpo) W2CA(lpo)
  69. #define OLE2T(lpo) W2A(lpo)
  70. #endif
  71. #ifdef OLE2ANSI
  72. inline LPOLESTR A2OLE(LPSTR lp) { return lp;}
  73. inline LPSTR OLE2A(LPOLESTR lp) { return lp;}
  74. #define W2OLE W2A
  75. #define OLE2W A2W
  76. inline LPCOLESTR A2COLE(LPCSTR lp) { return lp;}
  77. inline LPCSTR OLE2CA(LPCOLESTR lp) { return lp;}
  78. #define W2COLE W2CA
  79. #define OLE2CW A2CW
  80. #else
  81. inline LPOLESTR W2OLE(LPWSTR lp) { return lp; }
  82. inline LPWSTR OLE2W(LPOLESTR lp) { return lp; }
  83. #define A2OLE A2W
  84. #define OLE2A W2A
  85. inline LPCOLESTR W2COLE(LPCWSTR lp) { return lp; }
  86. inline LPCWSTR OLE2CW(LPCOLESTR lp) { return lp; }
  87. #define A2COLE A2CW
  88. #define OLE2CA W2CA
  89. #endif
  90. #ifdef _UNICODE
  91. #define T2A W2A
  92. #define A2T A2W
  93. inline LPWSTR T2W(LPTSTR lp) { return lp; }
  94. inline LPTSTR W2T(LPWSTR lp) { return lp; }
  95. #define T2CA W2CA
  96. #define A2CT A2CW
  97. inline LPCWSTR T2CW(LPCTSTR lp) { return lp; }
  98. inline LPCTSTR W2CT(LPCWSTR lp) { return lp; }
  99. #else
  100. #define T2W A2W
  101. #define W2T W2A
  102. inline LPSTR T2A(LPTSTR lp) { return lp; }
  103. inline LPTSTR A2T(LPSTR lp) { return lp; }
  104. #define T2CW A2CW
  105. #define W2CT W2CA
  106. inline LPCSTR T2CA(LPCTSTR lp) { return lp; }
  107. inline LPCTSTR A2CT(LPCSTR lp) { return lp; }
  108. #endif
  109. inline BSTR OLE2BSTR(LPCOLESTR lp) {return ::SysAllocString(lp);}
  110. #if defined(_UNICODE)
  111. // in these cases the default (TCHAR) is the same as OLECHAR
  112. inline BSTR T2BSTR(LPCTSTR lp) {return ::SysAllocString(lp);}
  113. inline BSTR A2BSTR(LPCSTR lp) {USES_CONVERSION; return ::SysAllocString(A2COLE(lp));}
  114. inline BSTR W2BSTR(LPCWSTR lp) {return ::SysAllocString(lp);}
  115. #elif defined(OLE2ANSI)
  116. // in these cases the default (TCHAR) is the same as OLECHAR
  117. inline BSTR T2BSTR(LPCTSTR lp) {return ::SysAllocString(lp);}
  118. inline BSTR A2BSTR(LPCSTR lp) {return ::SysAllocString(lp);}
  119. inline BSTR W2BSTR(LPCWSTR lp) {USES_CONVERSION; return ::SysAllocString(W2COLE(lp));}
  120. #else
  121. inline BSTR T2BSTR(LPCTSTR lp) {USES_CONVERSION; return ::SysAllocString(T2COLE(lp));}
  122. inline BSTR A2BSTR(LPCSTR lp) {USES_CONVERSION; return ::SysAllocString(A2COLE(lp));}
  123. inline BSTR W2BSTR(LPCWSTR lp) {return ::SysAllocString(lp);}
  124. #endif
  125. #if defined(_WINGDI_) && !defined(NOGDI)
  126. /////////////////////////////////////////////////////////////////////////////
  127. // Global UNICODE<>ANSI translation helpers
  128. LPDEVMODEW AtlDevModeA2W(LPDEVMODEW lpDevModeW, LPDEVMODEA lpDevModeA);
  129. LPDEVMODEA AtlDevModeW2A(LPDEVMODEA lpDevModeA, LPDEVMODEW lpDevModeW);
  130. LPTEXTMETRICW AtlTextMetricA2W(LPTEXTMETRICW lptmW, LPTEXTMETRICA pltmA);
  131. LPTEXTMETRICA AtlTextMetricW2A(LPTEXTMETRICA lptmA, LPTEXTMETRICW pltmW);
  132. #ifndef ATLDEVMODEA2W
  133. #define ATLDEVMODEA2W AtlDevModeA2W
  134. #define ATLDEVMODEW2A AtlDevModeW2A
  135. #define ATLTEXTMETRICA2W AtlTextMetricA2W
  136. #define ATLTEXTMETRICW2A AtlTextMetricW2A
  137. #endif
  138. #define DEVMODEW2A(lpw)\
  139. ((lpw == NULL) ? NULL : ATLDEVMODEW2A((LPDEVMODEA)alloca(sizeof(DEVMODEA)+lpw->dmDriverExtra), lpw))
  140. #define DEVMODEA2W(lpa)\
  141. ((lpa == NULL) ? NULL : ATLDEVMODEA2W((LPDEVMODEW)alloca(sizeof(DEVMODEW)+lpa->dmDriverExtra), lpa))
  142. #define TEXTMETRICW2A(lptmw)\
  143. ((lptmw == NULL) ? NULL : ATLTEXTMETRICW2A((LPTEXTMETRICA)alloca(sizeof(TEXTMETRICA)), lptmw))
  144. #define TEXTMETRICA2W(lptma)\
  145. ((lptma == NULL) ? NULL : ATLTEXTMETRICA2W((LPTEXTMETRICW)alloca(sizeof(TEXTMETRICW)), lptma))
  146. #ifdef OLE2ANSI
  147. #define DEVMODEOLE DEVMODEA
  148. #define LPDEVMODEOLE LPDEVMODEA
  149. #define TEXTMETRICOLE TEXTMETRICA
  150. #define LPTEXTMETRICOLE LPTEXTMETRICA
  151. #else
  152. #define DEVMODEOLE DEVMODEW
  153. #define LPDEVMODEOLE LPDEVMODEW
  154. #define TEXTMETRICOLE TEXTMETRICW
  155. #define LPTEXTMETRICOLE LPTEXTMETRICW
  156. #endif
  157. #if defined(_UNICODE)
  158. // in these cases the default (TCHAR) is the same as OLECHAR
  159. inline LPDEVMODEW DEVMODEOLE2T(LPDEVMODEOLE lp) { return lp; }
  160. inline LPDEVMODEOLE DEVMODET2OLE(LPDEVMODEW lp) { return lp; }
  161. inline LPTEXTMETRICW TEXTMETRICOLE2T(LPTEXTMETRICOLE lp) { return lp; }
  162. inline LPTEXTMETRICOLE TEXTMETRICT2OLE(LPTEXTMETRICW lp) { return lp; }
  163. #elif defined(OLE2ANSI)
  164. // in these cases the default (TCHAR) is the same as OLECHAR
  165. inline LPDEVMODE DEVMODEOLE2T(LPDEVMODEOLE lp) { return lp; }
  166. inline LPDEVMODEOLE DEVMODET2OLE(LPDEVMODE lp) { return lp; }
  167. inline LPTEXTMETRIC TEXTMETRICOLE2T(LPTEXTMETRICOLE lp) { return lp; }
  168. inline LPTEXTMETRICOLE TEXTMETRICT2OLE(LPTEXTMETRIC lp) { return lp; }
  169. #else
  170. #define DEVMODEOLE2T(lpo) DEVMODEW2A(lpo)
  171. #define DEVMODET2OLE(lpa) DEVMODEA2W(lpa)
  172. #define TEXTMETRICOLE2T(lptmw) TEXTMETRICW2A(lptmw)
  173. #define TEXTMETRICT2OLE(lptma) TEXTMETRICA2W(lptma)
  174. #endif
  175. #endif //_WINGDI_
  176. #else //!USES_CONVERSION
  177. // if USES_CONVERSION already defined (i.e. MFC_VER < 4.21 )
  178. // flip this switch to avoid atlconv.cpp
  179. #define _ATL_NO_CONVERSIONS
  180. #endif //!USES_CONVERSION
  181. // Define these even if MFC already included
  182. #if defined(_UNICODE)
  183. // in these cases the default (TCHAR) is the same as OLECHAR
  184. inline LPOLESTR CharNextO(LPCOLESTR lp) {return CharNextW(lp);}
  185. #elif defined(OLE2ANSI)
  186. // in these cases the default (TCHAR) is the same as OLECHAR
  187. inline LPOLESTR CharNextO(LPCOLESTR lp) {return CharNext(lp);}
  188. #else
  189. inline LPOLESTR CharNextO(LPCOLESTR lp) {return (LPOLESTR)(lp+1);}
  190. #endif
  191. #pragma pack(pop)
  192. #endif // __ATLCONV_H__
  193. /////////////////////////////////////////////////////////////////////////////