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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef COMSTL_INCL_COMSTL_STRING_H_OLESTRING_FUNCTIONS
00048 #define COMSTL_INCL_COMSTL_STRING_H_OLESTRING_FUNCTIONS
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define COMSTL_VER_COMSTL_STRING_H_OLESTRING_FUNCTIONS_MAJOR 5
00052 # define COMSTL_VER_COMSTL_STRING_H_OLESTRING_FUNCTIONS_MINOR 1
00053 # define COMSTL_VER_COMSTL_STRING_H_OLESTRING_FUNCTIONS_REVISION 4
00054 # define COMSTL_VER_COMSTL_STRING_H_OLESTRING_FUNCTIONS_EDIT 158
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00062 # include <comstl/comstl.h>
00063 #endif
00064 #ifndef COMSTL_INCL_COMSTL_MEMORY_H_MEMORY_FUNCTIONS
00065 # include <comstl/memory/functions.h>
00066 #endif
00067 #ifndef STLSOFT_INCL_STLSOFT_INTERNAL_H_SAFESTR
00068 # include <stlsoft/internal/safestr.h>
00069 #endif
00070
00071 #ifndef STLSOFT_INCL_H_WCHAR
00072 # define STLSOFT_INCL_H_WCHAR
00073 # include <wchar.h>
00074 #endif
00075
00076
00077
00078
00079
00080 #if !defined(_COMSTL_NO_NAMESPACE) && \
00081 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00082 # if defined(_STLSOFT_NO_NAMESPACE)
00083
00084 namespace comstl
00085 {
00086 # else
00087
00088
00089 namespace stlsoft
00090 {
00091
00092 namespace comstl_project
00093 {
00094
00095 # endif
00096 #endif
00097
00098
00099
00100
00101
00109 STLSOFT_INLINE LPOLESTR comstl__olestring_create_a(cs_char_a_t const* s)
00110 {
00111 LPOLESTR posz;
00112
00113 if(NULL == s)
00114 {
00115 posz = NULL;
00116 }
00117 else
00118 {
00119
00120
00121 cs_size_t cch = stlsoft_static_cast(cs_size_t, STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, s, -1, NULL, 0));
00122 const LPOLESTR posz2 = stlsoft_static_cast(LPOLESTR, STLSOFT_NS_GLOBAL(CoTaskMemAlloc)(sizeof(OLECHAR) * (cch + 1)));
00123
00124 posz = posz2;
00125
00126 if(NULL != posz)
00127 {
00128 cs_size_t n = stlsoft_static_cast(cs_size_t, STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, s, -1, posz2, stlsoft_static_cast(int, cch + 1)));
00129
00130 if(n < cch)
00131 {
00132 posz[n] = L'\0';
00133 }
00134 }
00135 }
00136
00137 return posz;
00138 }
00139
00147 STLSOFT_INLINE LPOLESTR comstl__olestring_create_w(cs_char_w_t const* s)
00148 {
00149 LPOLESTR posz;
00150
00151 if(NULL == s)
00152 {
00153 posz = NULL;
00154 }
00155 else
00156 {
00157 cs_size_t cch = STLSOFT_NS_GLOBAL(wcslen)(s);
00158
00159 posz = stlsoft_static_cast(LPOLESTR, STLSOFT_NS_GLOBAL(CoTaskMemAlloc)(sizeof(OLECHAR) * (cch + 1)));
00160
00161 if(NULL != posz)
00162 {
00163 #ifdef STLSOFT_USING_SAFE_STR_FUNCTIONS
00164 STLSOFT_NS_GLOBAL(wcscpy_s)(posz, 1 + cch, s);
00165 #else
00166 STLSOFT_NS_GLOBAL(wcscpy)(posz, s);
00167 #endif
00168 }
00169 }
00170
00171 return posz;
00172 }
00173
00180 STLSOFT_INLINE void comstl__olestring_destroy(LPOLESTR posz)
00181 {
00182 COMSTL_MESSAGE_ASSERT("Invalid request to destroy non-COM string", 0 != comstl__CoTaskMemDidAlloc(posz));
00183
00184 STLSOFT_NS_GLOBAL(CoTaskMemFree)(stlsoft_static_cast(LPVOID, posz));
00185 }
00186
00194 STLSOFT_INLINE LPOLESTR comstl__olestring_dup(LPCOLESTR posz)
00195 {
00196 return comstl__olestring_create_w(posz);
00197 }
00198
00199
00200
00201
00202
00203 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00204 namespace comstl
00205 {
00206 #endif
00207
00208
00209
00210
00211
00212 #ifdef __cplusplus
00213
00221 inline LPOLESTR olestring_create_a(cs_char_a_t const* s)
00222 {
00223 return comstl__olestring_create_a(s);
00224 }
00225
00233 inline LPOLESTR olestring_create_w(cs_char_w_t const* s)
00234 {
00235 return comstl__olestring_create_w(s);
00236 }
00237
00245 inline LPOLESTR olestring_create(cs_char_a_t const* s)
00246 {
00247 return olestring_create_a(s);
00248 }
00249
00257 inline LPOLESTR olestring_create(cs_char_w_t const* s)
00258 {
00259 return olestring_create_w(s);
00260 }
00261
00268 inline void olestring_destroy(LPOLESTR posz)
00269 {
00270 comstl__olestring_destroy(posz);
00271 }
00272
00280 inline LPOLESTR olestring_dup(LPCOLESTR posz)
00281 {
00282 return olestring_create(posz);
00283 }
00284
00285 #endif
00286
00287
00288
00289
00290
00291 #ifdef STLSOFT_UNITTEST
00292 # include "./unittest/olestring_functions_unittest_.h"
00293 #endif
00294
00295
00296
00297 #ifndef _COMSTL_NO_NAMESPACE
00298 # if defined(_STLSOFT_NO_NAMESPACE) || \
00299 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00300 }
00301 # else
00302 }
00303 }
00304 # endif
00305 #endif
00306
00307
00308
00309 #endif
00310
00311