Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

strconv.h

Go to the documentation of this file.
00001 /*  strconv.h - ATL like string conversion functions.
00002 
00003     This is a simplified version which suffices for my use
00004     of the functions.  For more complicated uses, you will probably
00005     need to include ATL.
00006 
00007     Copyright (C) 2001-2004 Mark Weaver
00008     Written by Mark Weaver <mark@npsl.co.uk>
00009 
00010     Part of the Open-Win32 library.
00011     This library is free software; you can redistribute it and/or
00012     modify it under the terms of the GNU Library General Public
00013     License as published by the Free Software Foundation; either
00014     version 2 of the License, or (at your option) any later version.
00015 
00016     This library is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019     Library General Public License for more details.
00020 
00021     You should have received a copy of the GNU Library General Public
00022     License along with this library; if not, write to the
00023     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00024     Boston, MA  02111-1307, USA.
00025 */
00026 
00032 // Uses __ATL_CONV_H__ for compatability with ATL projects
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 } // namespace OW32
00106 
00107 #endif // __ATLCONV_H__

Generated on Sun Jun 5 01:29:18 2005 for OW32 by  doxygen 1.3.9.1