csutil/win32/wintools.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Frank Richter 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSSYS_WIN32_WINTOOLS_H__ 00020 #define __CS_CSSYS_WIN32_WINTOOLS_H__ 00021 00026 #include "csextern.h" 00027 #include "csutil/csunicode.h" 00028 #include "csutil/util.h" 00029 #include <winnls.h> // contains MultiByteToWideChar()/WideCharToMultiByte() 00030 00040 static inline wchar_t* cswinAnsiToWide (const char* ansi, 00041 UINT codePage = CP_ACP) 00042 { 00043 int bufsize; 00044 WCHAR* buf; 00045 00046 bufsize = MultiByteToWideChar (codePage, 00047 MB_PRECOMPOSED, ansi, -1, 0, 0); 00048 buf = new WCHAR[bufsize]; 00049 MultiByteToWideChar (codePage, 00050 MB_PRECOMPOSED, ansi, -1, buf, bufsize); 00051 00052 return buf; 00053 } 00054 00064 static inline char* cswinWideToAnsi (const wchar_t* wide, 00065 UINT codePage = CP_ACP) 00066 { 00067 int bufsize; 00068 char* buf; 00069 00070 bufsize = WideCharToMultiByte (codePage, 00071 WC_COMPOSITECHECK, wide, -1, 0, 0, 0, 0); 00072 buf = new char[bufsize]; 00073 WideCharToMultiByte (codePage, 00074 WC_COMPOSITECHECK, wide, -1, buf, bufsize, 0, 0); 00075 00076 return buf; 00077 } 00078 00092 struct CS_CSUTIL_EXPORT cswinWtoA 00093 { 00094 private: 00095 char* s; 00096 public: 00098 cswinWtoA (const wchar_t* ws) 00099 { s = cswinWideToAnsi (ws); } 00101 ~cswinWtoA () 00102 { delete[] s; } 00104 operator const char* () const 00105 { return s; } 00106 }; 00107 00117 struct CS_CSUTIL_EXPORT cswinCtoA 00118 { 00119 private: 00120 char* s; 00121 public: 00123 cswinCtoA (const char* ws, UINT codePage = CP_ACP) 00124 { 00125 s = cswinWideToAnsi (csCtoW (ws), codePage); 00126 } 00128 ~cswinCtoA () 00129 { delete[] s; } 00131 operator const char* () const 00132 { return s; } 00133 }; 00134 00146 extern CS_CSUTIL_EXPORT char* cswinGetErrorMessage (HRESULT code); 00157 extern CS_CSUTIL_EXPORT wchar_t* cswinGetErrorMessageW (HRESULT code); 00167 extern CS_CSUTIL_EXPORT bool cswinIsWinNT (); 00168 00169 #endif
Generated for Crystal Space by doxygen 1.2.18