00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032
00033 #ifndef __ATLCONV_H__
00034 #define __ATLCONV_H__
00035
00036 #include <malloc.h>
00037
00038 namespace OW32
00039 {
00040
00041 #ifdef _CONVERSION_USES_THREAD_LOCALE
00042 #error "_CONVERSION_USES_THREAD_LOCALE is unsupported"
00043 #else
00044 #ifndef _DEBUG
00045 #define USES_CONVERSION int _convert; _convert; LPCWSTR _lpw; _lpw; LPCSTR _lpa; _lpa
00046 #else
00047 #define USES_CONVERSION int _convert = 0; _convert; LPCWSTR _lpw = NULL; _lpw; LPCSTR _lpa = NULL; _lpa
00048 #endif
00049 #endif
00050
00051
00052 inline LPWSTR WINAPI A2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
00053 {
00054 lpw[0] = '\0';
00055 MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars);
00056 return lpw;
00057 }
00058
00059 inline LPSTR WINAPI W2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
00060 {
00061 lpa[0] = '\0';
00062 WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL);
00063 return lpa;
00064 }
00065
00066 #define A2W(lpa) (\
00067 ((_lpa = lpa) == NULL) ? NULL : (\
00068 _convert = (lstrlenA(_lpa)+1),\
00069 OW32::A2WHelper((LPWSTR) _alloca(_convert*2), _lpa, _convert)))
00070
00071 #define W2A(lpw) (\
00072 ((_lpw = lpw) == NULL) ? NULL : (\
00073 _convert = (lstrlenW(_lpw)+1)*2,\
00074 OW32::W2AHelper((LPSTR) _alloca(_convert), _lpw, _convert)))
00075
00076 #define A2CW(lpa) ((LPCWSTR)A2W(lpa))
00077 #define W2CA(lpw) ((LPCSTR)W2A(lpw))
00078
00079 #ifdef _UNICODE
00080 #define T2A W2A
00081 #define A2T A2W
00082 inline LPWSTR T2W(LPTSTR lp) { return lp; }
00083 #define T2W OW32::T2W
00084 inline LPTSTR W2T(LPWSTR lp) { return lp; }
00085 #define W2T OW32::W2T
00086 #define T2CA W2CA
00087 #define A2CT A2CW
00088 inline LPCWSTR T2CW(LPCTSTR lp) { return lp; }
00089 inline LPCTSTR W2CT(LPCWSTR lp) { return lp; }
00090 #else
00091 #define T2W A2W
00092 #define W2T W2A
00093 inline LPSTR T2A(LPTSTR lp) { return lp; }
00094 #define T2A OW32::T2A
00095 inline LPTSTR A2T(LPSTR lp) { return lp; }
00096 #define A2T OW32::A2T
00097 #define T2CW A2CW
00098 #define W2CT W2CA
00099 inline LPCSTR T2CA(LPCTSTR lp) { return lp; }
00100 #define T2CA OW32::T2CA
00101 inline LPCTSTR A2CT(LPCSTR lp) { return lp; }
00102 #define A2CT OW32::A2CT
00103 #endif
00104
00105 }
00106
00107 #endif // __ATLCONV_H__