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_BSTR_FUNCTIONS
00048 #define COMSTL_INCL_COMSTL_STRING_H_BSTR_FUNCTIONS
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define COMSTL_VER_COMSTL_STRING_H_BSTR_FUNCTIONS_MAJOR 4
00052 # define COMSTL_VER_COMSTL_STRING_H_BSTR_FUNCTIONS_MINOR 2
00053 # define COMSTL_VER_COMSTL_STRING_H_BSTR_FUNCTIONS_REVISION 7
00054 # define COMSTL_VER_COMSTL_STRING_H_BSTR_FUNCTIONS_EDIT 84
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00062 # include <comstl/comstl.h>
00063 #endif
00064
00065 #ifndef STLSOFT_INCL_H_STRING
00066 # define STLSOFT_INCL_H_STRING
00067 # include <string.h>
00068 #endif
00069 #ifndef STLSOFT_INCL_H_WCHAR
00070 # define STLSOFT_INCL_H_WCHAR
00071 # include <wchar.h>
00072 #endif
00073
00074
00075
00076
00077
00078 #if !defined(_COMSTL_NO_NAMESPACE) && \
00079 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00080 # if defined(_STLSOFT_NO_NAMESPACE)
00081
00082 namespace comstl
00083 {
00084 # else
00085
00086
00087 namespace stlsoft
00088 {
00089
00090 namespace comstl_project
00091 {
00092
00093 # endif
00094 #endif
00095
00096
00097
00098
00099
00108 STLSOFT_INLINE BSTR comstl__bstr_create_w(cs_char_w_t const* s)
00109 {
00110 return STLSOFT_NS_GLOBAL(SysAllocString)(s);
00111 }
00112
00122 STLSOFT_INLINE BSTR comstl__bstr_create_len_w(cs_char_w_t const* s, cs_size_t len)
00123 {
00124 COMSTL_MESSAGE_ASSERT("Cannot pass size_t(-1) as length!", 0 != len + 1);
00125
00126 COMSTL_ASSERT(NULL == s || !STLSOFT_NS_GLOBAL(IsBadStringPtrW(s, len)));
00127
00128 return STLSOFT_NS_GLOBAL(SysAllocStringLen)(s, stlsoft_static_cast(UINT, len));
00129 }
00130
00139 STLSOFT_INLINE BSTR comstl__bstr_create_a(cs_char_a_t const* s)
00140 {
00141 BSTR bstr = NULL;
00142
00143 if(s != NULL)
00144 {
00145 const cs_size_t len = STLSOFT_NS_GLOBAL(strlen)(s);
00146 cs_char_w_t *pwsz = stlsoft_static_cast(cs_char_w_t*, STLSOFT_NS_GLOBAL(CoTaskMemAlloc)((1 + len) * sizeof(cs_char_w_t)));
00147
00148 if(NULL != pwsz)
00149 {
00150 int n = STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, s, -1, pwsz, stlsoft_static_cast(int, 1 + len));
00151
00152 if(0 != n)
00153 {
00154 if(stlsoft_static_cast(cs_size_t, n) < len)
00155 {
00156 pwsz[n] = L'\0';
00157 }
00158
00159 bstr = comstl__bstr_create_w(pwsz);
00160 }
00161
00162 STLSOFT_NS_GLOBAL(CoTaskMemFree)(pwsz);
00163 }
00164 }
00165
00166 return bstr;
00167 }
00168
00178 STLSOFT_INLINE BSTR comstl__bstr_create_len_a(cs_char_a_t const* s, cs_size_t len)
00179 {
00180 BSTR bstr = NULL;
00181
00182 COMSTL_MESSAGE_ASSERT("Cannot pass size_t(-1) as length!", 0 != len + 1);
00183
00184 if(s != NULL)
00185 {
00186 cs_char_w_t* pwsz = stlsoft_static_cast(cs_char_w_t*, STLSOFT_NS_GLOBAL(CoTaskMemAlloc)((1 + len) * sizeof(cs_char_w_t)));
00187
00188 if(NULL != pwsz)
00189 {
00190 int n = STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, s, stlsoft_static_cast(int, len), pwsz, stlsoft_static_cast(int, 1 + len));
00191
00192 #ifdef _DEBUG
00193 if(0 == n)
00194 {
00195 STLSOFT_NS_GLOBAL(GetLastError)();
00196 }
00197 #endif
00198 if(0 != n)
00199 {
00200 bstr = comstl__bstr_create_len_w(pwsz, len);
00201 }
00202
00203 STLSOFT_NS_GLOBAL(CoTaskMemFree)(pwsz);
00204 }
00205 }
00206
00207 return bstr;
00208 }
00209
00216 STLSOFT_INLINE void comstl__bstr_destroy(BSTR bstr)
00217 {
00218 STLSOFT_NS_GLOBAL(SysFreeString)(bstr);
00219 }
00220
00228 STLSOFT_INLINE BSTR comstl__bstr_dup(BSTR bstr)
00229 {
00230 return comstl__bstr_create_w(bstr);
00231 }
00232
00245 STLSOFT_INLINE int comstl__bstr_compare(BSTR s1, BSTR s2)
00246 {
00247 if(NULL == s1)
00248 {
00249 if(NULL == s2)
00250 {
00251 return 0;
00252 }
00253 else
00254 {
00255 return -1;
00256 }
00257 }
00258 else
00259 {
00260 if(NULL == s2)
00261 {
00262 return +1;
00263 }
00264 else
00265 {
00266 return STLSOFT_NS_GLOBAL(wcscmp)(s1, s2);
00267 }
00268 }
00269 }
00270
00271
00272
00273
00274
00275 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00276 namespace comstl
00277 {
00278 #endif
00279
00280
00281
00282
00283
00284 #ifdef __cplusplus
00285
00294 inline BSTR bstr_create_w(cs_char_w_t const* s)
00295 {
00296 return comstl__bstr_create_w(s);
00297 }
00298
00308 inline BSTR bstr_create_w(cs_char_w_t const* s, cs_size_t len)
00309 {
00310 return comstl__bstr_create_len_w(s, len);
00311 }
00312
00321 inline BSTR bstr_create_a(cs_char_a_t const* s)
00322 {
00323 return comstl__bstr_create_a(s);
00324 }
00325
00335 inline BSTR bstr_create_a(cs_char_a_t const* s, cs_size_t len)
00336 {
00337 return comstl__bstr_create_len_a(s, len);
00338 }
00339
00348 inline BSTR bstr_create(cs_char_a_t const* s)
00349 {
00350 return bstr_create_a(s);
00351 }
00352
00362 inline BSTR bstr_create(cs_char_a_t const* s, cs_size_t len)
00363 {
00364 return bstr_create_a(s, len);
00365 }
00366
00375 inline BSTR bstr_create(cs_char_w_t const* s)
00376 {
00377 return bstr_create_w(s);
00378 }
00379
00389 inline BSTR bstr_create(cs_char_w_t const* s, cs_size_t len)
00390 {
00391 return bstr_create_w(s, len);
00392 }
00393
00400 inline void bstr_destroy(BSTR bstr)
00401 {
00402 comstl__bstr_destroy(bstr);
00403 }
00404
00412 inline BSTR bstr_dup(BSTR bstr)
00413 {
00414 return comstl__bstr_dup(bstr);
00415 }
00416
00429 inline int bstr_compare(BSTR s1, BSTR s2)
00430 {
00431 return comstl__bstr_compare(s1, s2);
00432 }
00433
00434 #endif
00435
00436
00437
00438
00439
00440 #ifdef STLSOFT_UNITTEST
00441 # include "./unittest/BSTR_functions_unittest_.h"
00442 #endif
00443
00444
00445
00446 #ifndef _COMSTL_NO_NAMESPACE
00447 # if defined(_STLSOFT_NO_NAMESPACE) || \
00448 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00449 }
00450 # else
00451 }
00452 }
00453 # endif
00454 #endif
00455
00456
00457
00458 #endif
00459
00460