| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 #include "sanity.inc"
    00031
    00041 static inline wchar_t* cswinAnsiToWide (const char* ansi,
    00042                                          UINT codePage = CP_ACP)
    00043 {
    00044   int bufsize;
    00045   WCHAR* buf;
    00046
    00047   bufsize = MultiByteToWideChar (codePage,
    00048     MB_PRECOMPOSED, ansi, -1, 0, 0);
    00049   buf = new WCHAR[bufsize];
    00050   MultiByteToWideChar (codePage,
    00051     MB_PRECOMPOSED, ansi, -1, buf, bufsize);
    00052
    00053   return buf;
    00054 }
    00055
    00065 static inline char* cswinWideToAnsi (const wchar_t* wide,
    00066                                      UINT codePage = CP_ACP)
    00067 {
    00068   int bufsize;
    00069   char* buf;
    00070
    00071   bufsize = WideCharToMultiByte (codePage,
    00072     WC_COMPOSITECHECK, wide, -1, 0, 0, 0, 0);
    00073   buf = new char[bufsize];
    00074   WideCharToMultiByte (codePage,
    00075     WC_COMPOSITECHECK, wide, -1, buf, bufsize, 0, 0);
    00076
    00077   return buf;
    00078 }
    00079
    00093 struct CS_CRYSTALSPACE_EXPORT cswinWtoA
    00094 {
    00095 private:
    00096   char* s;
    00097 public:
    00099   cswinWtoA (const wchar_t* ws)
    00100   { s = cswinWideToAnsi (ws); }
    00102   ~cswinWtoA ()
    00103   { delete[] s; }
    00105   operator const char* () const
    00106   { return s; }
    00107 };
    00108
    00118 struct CS_CRYSTALSPACE_EXPORT cswinCtoA
    00119 {
    00120 private:
    00121   char* s;
    00122 public:
    00124   cswinCtoA (const char* ws, UINT codePage = CP_ACP)
    00125   {
    00126     s = cswinWideToAnsi (csCtoW (ws), codePage);
    00127   }
    00129   ~cswinCtoA ()
    00130   { delete[] s; }
    00132   operator const char* () const
    00133   { return s; }
    00134 };
    00135
    00147 extern CS_CRYSTALSPACE_EXPORT char* cswinGetErrorMessage (HRESULT code);
    00158 extern CS_CRYSTALSPACE_EXPORT wchar_t* cswinGetErrorMessageW (HRESULT code);
    00159
    00161 enum cswinWindowsVersion
    00162 {
    00164   cswinWin9x = 30,
    00166   cswinWinNT = 40,
    00168   cswinWin2K = 50,
    00170   cswinWinXP = 51
    00171 };
    00172
    00184 extern CS_CRYSTALSPACE_EXPORT bool cswinIsWinNT (cswinWindowsVersion* version = 0);
    00185
    00186 #endif // __CS_CSSYS_WIN32_WINTOOLS_H__