STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Functions
msclr::interop::details Namespace Reference

Classes

class  char_buffer
 

Functions

_Check_return_ size_t GetAnsiStringSize (System::String^_str)
 
void WriteAnsiString (_Out_writes_all_(_size) _Post_z_ char *_buf, size_t _size, System::String^_str)
 
_Check_return_ size_t GetUnicodeStringSize (_In_reads_z_(_count+1) const char *_str, size_t _count)
 
void WriteUnicodeString (_Out_writes_all_(_size) _Post_z_ wchar_t *_dest, size_t _size, _In_reads_bytes_(_count) const char *_src, size_t _count)
 
System::String InternalAnsiToStringHelper (_In_reads_z_(_count+1) const char *_src, size_t _count)
 
System::String InternalUnicodeToStringHelper (_In_reads_z_(_count+1) const wchar_t *_src, size_t _count)
 

Function Documentation

_Check_return_ size_t msclr::interop::details::GetAnsiStringSize ( System::String^  _str)
inline
79  {
80  size_t _size = 0;
81  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_str);
82 
83  _size = ::WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, _pinned_ptr, _str->Length, NULL, 0, NULL,NULL);
84  if (_size == 0 && _str->Length != 0)
85  {
86  throw gcnew System::ArgumentException(_EXCEPTION_WC2MB);
87  }
88  // adding 1 for terminating nul
89  _size+=1;
90  return _size;
91  }
#define _EXCEPTION_WC2MB
Definition: marshal.h:41
#define NULL
Definition: crtdbg.h:30
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
_Check_return_ size_t msclr::interop::details::GetUnicodeStringSize ( _In_reads_z_(_count+1) const char *  _str,
size_t  _count 
)
inline
113  {
114  size_t _size = 0;
115  if (_count > INT_MAX)
116  {
117  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_GREATER_THAN_INT_MAX);
118  }
119  _size = ::MultiByteToWideChar(CP_THREAD_ACP, 0, _str, static_cast<int>(_count), NULL, 0);
120 
121  if (_size == 0 && _count != 0)
122  {
123  throw gcnew System::ArgumentException(_EXCEPTION_MB2WC);
124  }
125  //adding 1 for terminating nul
126  _size+=1;
127  return _size;
128  }
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:38
#define NULL
Definition: crtdbg.h:30
#define _EXCEPTION_MB2WC
Definition: marshal.h:40
#define INT_MAX
Definition: limits.h:40
System::String msclr::interop::details::InternalAnsiToStringHelper ( _In_reads_z_(_count+1) const char *  _src,
size_t  _count 
)
inline
148  {
149  size_t _size = details::GetUnicodeStringSize(_src, _count);
150  if (_size > INT_MAX || _size <=0 )
151  {
152  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_GREATER_THAN_INT_MAX);
153  }
154  details::char_buffer<wchar_t> _wchar_buf(_size);
155  if (_wchar_buf.get() == NULL)
156  {
157  throw gcnew System::InsufficientMemoryException();
158  }
159 
160  details::WriteUnicodeString(_wchar_buf.get(), _size, _src, _count);
161 
162  return gcnew System::String(_wchar_buf.get(), 0, static_cast<int>(_size)-1);
163  }
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:38
_Check_return_ size_t GetUnicodeStringSize(_In_reads_z_(_count+1) const char *_str, size_t _count)
Definition: marshal.h:112
#define NULL
Definition: crtdbg.h:30
void WriteUnicodeString(_Out_writes_all_(_size) _Post_z_ wchar_t *_dest, size_t _size, _In_reads_bytes_(_count) const char *_src, size_t _count)
Definition: marshal.h:130
#define INT_MAX
Definition: limits.h:40
System::String msclr::interop::details::InternalUnicodeToStringHelper ( _In_reads_z_(_count+1) const wchar_t _src,
size_t  _count 
)
inline
166  {
167  if (_count > INT_MAX)
168  {
169  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_GREATER_THAN_INT_MAX);
170  }
171 
172  return gcnew System::String(_src, 0 ,static_cast<int>(_count));
173  }
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:38
#define INT_MAX
Definition: limits.h:40
void msclr::interop::details::WriteAnsiString ( _Out_writes_all_(_size) _Post_z_ char *  _buf,
size_t  _size,
System::String^  _str 
)
inline
94  {
95  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_str);
96 
97  //checking for overflow
98  if (_size > INT_MAX)
99  {
100  // this should never happen if _size was returned by GetAnsiStringSize()
101  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_GREATER_THAN_INT_MAX);
102  }
103  size_t _written = ::WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, _pinned_ptr, _str->Length, _buf, static_cast<int>(_size) ,NULL,NULL);
104  if( _written >= _size ||
105  (_written == 0 && _size != 1)) // allowing empty string
106  {
107  throw gcnew System::ArgumentException(_EXCEPTION_WC2MB);
108  }
109  _buf[_written] = '\0';
110  }
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:38
#define _EXCEPTION_WC2MB
Definition: marshal.h:41
#define NULL
Definition: crtdbg.h:30
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
#define INT_MAX
Definition: limits.h:40
void msclr::interop::details::WriteUnicodeString ( _Out_writes_all_(_size) _Post_z_ wchar_t _dest,
size_t  _size,
_In_reads_bytes_(_count) const char *  _src,
size_t  _count 
)
inline
131  {
132  //checking for overflow
133  if (_size > INT_MAX || _count > INT_MAX)
134  {
135  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_GREATER_THAN_INT_MAX);
136  }
137 
138  size_t _written = ::MultiByteToWideChar(CP_THREAD_ACP, 0, _src, static_cast<int>(_count), _dest, static_cast<int>(_size));
139  if( _written >= _size ||
140  (_written == 0 && _size != 1)) // allowing empty string
141  {
142  throw gcnew System::ArgumentException(_EXCEPTION_MB2WC);
143  }
144  _dest[_written] = L'\0';
145  }
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:38
#define _EXCEPTION_MB2WC
Definition: marshal.h:40
#define INT_MAX
Definition: limits.h:40