strbasic.h

Go to the documentation of this file.
00001 
00002 /*******************************************************************
00003  *
00004  *    DESCRIPTION:      Basic string definitions header file
00005  *
00006  *    AUTHOR:           Tom Hudson
00007  *
00008  *    HISTORY:          File created 9/6/94
00009  *
00010  *******************************************************************/
00011 
00012 #pragma once
00013 
00014 #define WIN95STUFF
00015 
00016 // To set up Max to use Unicode, define _UNICODE, and don't define _MBCS
00017 // To set up Max to use multi-byte character sets, define _MBCS and 
00018 //              don't define _UNICODE
00019 // To set up Max to use single-byte ANSI character strings, don't define
00020 //              either _UNICODE or _MBCS
00021 
00022 #if defined(_UNICODE) && defined(_MBCS)
00023 #error Cannot compile with both _UNICODE and _MBCS enabled!
00024 #endif
00025 
00026 // #define _UNICODE     // turn on Unicode support
00027 
00028 #ifndef _MBCS
00029 #define _MBCS   // if Unicode is off, turn on multi-byte character support
00030 #endif
00031 
00032 
00033 #ifdef _UNICODE
00034 
00035 #ifdef _MBCS
00036 #undef _MBCS    // can't have both Unicode and MBCS at once -- Unicode wins
00037 #endif
00038 
00039 #undef UNICODE
00040 #define UNICODE
00041 
00042 #undef STRCONST
00043 #define STRCONST L
00044 
00045 #endif
00046 
00047 // Bring in the generic international text header file
00048 #include <tchar.h>
00049 
00050 // Starting with VS2005 the default is to have wchar_t defined as a type, so that's
00051 // what we'll use as well (plus it coincides with the VS2005 Max9 release)
00052 typedef __wchar_t       mwchar_t;
00053 
00054 //
00055 // MAX is not compiled in UNICODE (yet).  TCHAR has been changed to MCHAR where
00056 // appropriate, so you can compile in UNICODE or not, and not have Max's headers
00057 // change.
00058 // 
00059 
00060 #ifdef _UNICODE
00061     // If the module uses Unicode and needs to translate to
00062     // an MBCS Max, define _UNICODE_MODULE_FOR_MBCS_MAX
00063     #ifdef _UNICODE_MODULE_FOR_MBCS_MAX
00064         #define MCHAR           char
00065         #define LPCMSTR         const MCHAR*
00066         #define LPMSTR          MCHAR*
00067         #define _M_TEXT(x)      x
00068         #define M_STD_STRING    std::string
00069         #define M_LOADSTRING    ::LoadStringA
00070         #define M_STD_OSTRINGSTREAM     std::ostringstream
00071         #define M_STD_ISTRINGSTREAM     std::istringstream
00072         #define M_STD_CERR              std::cerr
00073         #define M_STD_OSTREAM           std::ostream
00074         #define M_STD_ISTREAM           std::istream
00075         #define M_STD_COUT              std::cout
00076     #else
00077         #define MCHAR           mwchar_t
00078         #define LPCMSTR         const MCHAR*
00079         #define LPMSTR          MCHAR*
00080         #define _M_TEXT(x)      L ## x
00081         #define M_STD_STRING    std::wstring
00082         #define M_LOADSTRING    ::LoadStringW
00083         #define M_STD_OSTRINGSTREAM     std::wostringstream
00084         #define M_STD_ISTRINGSTREAM     std::wistringstream
00085         #define M_STD_CERR              std::wcerr
00086         #define M_STD_OSTREAM           std::wostream
00087         #define M_STD_ISTREAM           std::wistream
00088         #define M_STD_COUT              std::wcout
00089     #endif
00090 #else
00091     #define MCHAR           char
00092     #define LPCMSTR         const MCHAR*
00093     #define LPMSTR          MCHAR*
00094     #define _M_TEXT(x)      x
00095     #define M_STD_STRING    std::string
00096     #define M_LOADSTRING    ::LoadStringA
00097     #define M_STD_OSTRINGSTREAM     std::ostringstream
00098     #define M_STD_ISTRINGSTREAM     std::istringstream
00099     #define M_STD_CERR              std::cerr
00100     #define M_STD_OSTREAM           std::ostream
00101     #define M_STD_ISTREAM           std::istream
00102     #define M_STD_COUT              std::cout
00103 #endif
00104 #define _M(x)           _M_TEXT(x)
00105 
00106 // These macros work in conjunction with the VC conversion macros (A2W, A2T, W2T, etc)
00107 // See the MSDN documentation for details.  If you get compile errors such as
00108 // 
00109 // error C2065: '_lpa' : undeclared identifier
00110 // error C2065: '_convert' : undeclared identifier
00111 // error C2065: '_acp' : undeclared identifier
00112 // 
00113 // when trying to use any of these macros, it's probably because there's a
00114 // 
00115 // USES_CONVERSION
00116 // 
00117 // missing in your function.
00118 
00119 // M2A: Build-specific to ASCII
00120 // A2M: ASCII to build-specific
00121 // M2W: Build-specific to wide char
00122 // W2M: Wide char to build-specific
00123 // M2T: Max definition of TCHAR to current project definition of TCHAR
00124 // T2M: current project definition of TCHAR to Max definition of TCHAR 
00125 
00126 // NOTE: converted strings are stored in a stack-based buffer. so don't say
00127 // something like:
00128 //   return A2M(msg.data());
00129 
00130 #ifdef _UNICODE
00131     // If the module uses Unicode and needs to translate to
00132     // an MBCS Max, define _UNICODE_MODULE_FOR_MBCS_MAX
00133     #ifdef _UNICODE_MODULE_FOR_MBCS_MAX
00134         #define M2A(p)          (p)
00135         #define A2M(p)          (p)
00136         #define M2W(p)          A2W(p)
00137         #define W2M(p)          W2A(p)
00138         #define M2T(p)          A2T(p)
00139         #define T2M(p)          T2A(p)
00140     #else
00141         #define M2A(p)          W2A(p)
00142         #define A2M(p)          A2W(p)
00143         #define M2W(p)          (p)
00144         #define W2M(p)          (p)
00145         #define M2T(p)          (p)
00146         #define T2M(p)          (p)
00147     #endif
00148 #else
00149     #define M2A(p)          (p)
00150     #define A2M(p)          (p)
00151     #define M2W(p)          A2W(p)
00152     #define W2M(p)          W2A(p)
00153     #define M2T(p)          A2T(p)
00154     #define T2M(p)          T2A(p)
00155 #endif