14 #ifndef _INC_MSCLR_MARSHAL
15 #define _INC_MSCLR_MARSHAL
18 #if !defined _CRT_WINDOWS && !defined BUILD_WINDOWS
30 #pragma comment(lib, "comsupp.lib")
31 #pragma comment(lib, "oleaut32.lib")
34 #pragma warning(error : 4996)
41 #define _EXCEPTION_GREATER_THAN_INT_MAX "Size of string exceeds INT_MAX."
42 #define _EXCEPTION_NULLPTR "NULLPTR is not supported for this conversion."
43 #define _EXCEPTION_MB2WC "Conversion from MultiByte to WideChar failed. Please check the content of the string and/or locale settings."
44 #define _EXCEPTION_WC2MB "Conversion from WideChar to MultiByte failed. Please check the content of the string and/or locale settings."
86 _size = ::WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, _pinned_ptr, _str->Length,
NULL, 0,
NULL,
NULL);
87 if (_size == 0 && _str->Length != 0)
106 size_t _written = ::WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, _pinned_ptr, _str->Length, _buf, static_cast<int>(_size) ,
NULL,
NULL);
107 if( _written >= _size ||
108 (_written == 0 && _size != 1))
112 _buf[_written] =
'\0';
122 _size = ::MultiByteToWideChar(CP_THREAD_ACP, 0, _str, static_cast<int>(_count),
NULL, 0);
124 if (_size == 0 && _count != 0)
141 size_t _written = ::MultiByteToWideChar(CP_THREAD_ACP, 0, _src, static_cast<int>(_count), _dest, static_cast<int>(_size));
142 if( _written >= _size ||
143 (_written == 0 && _size != 1))
147 _dest[_written] = L
'\0';
153 if (_size >
INT_MAX || _size <=0 )
160 throw gcnew System::InsufficientMemoryException();
165 return gcnew System::String(_wchar_buf.
get(), 0,
static_cast<int>(_size)-1);
175 return gcnew System::String(_src, 0 ,static_cast<int>(_count));
183 ref class context_node_base;
185 template<
class _To_Type,
class _From_Type>
188 template <
class _To_Type,
class _From_Type,
192 template<
class _To_Type>
195 const char* _ptr = _from_object;
196 return marshal_as<_To_Type, const char *>(_ptr);
199 template<
class _To_Type>
202 const wchar_t* _ptr = _from_object;
203 return marshal_as<_To_Type, const wchar_t*>(_ptr);
206 ref class marshal_context;
208 template <
class _To_Type,
class _From_Type>
209 inline _To_Type
marshal_as(
const _From_Type&);
215 template <
class _To_Type,
class _From_Type>
219 __declspec(deprecated(
"This conversion is not supported by the library or the header file needed for this conversion is not included. Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method."))
220 static _To_Type
marshal_as(const _From_Type& _from_object)
222 return _This_conversion_is_not_supported;
226 template <
class _To_Type,
class _From_Type>
230 __declspec(deprecated(
"This conversion requires a marshal_context. Please use a marshal_context for this conversion."))
231 static _To_Type
marshal_as(const _From_Type& _from_object)
233 return _This_conversion_requires_a_context;
237 template <
class _To_Type,
class _From_Type>
250 static const bool _Needs_Context=
true;
253 template<
class _To_Type,
class _From_Type>
257 static const bool _Needs_Context=
false;
264 System::Collections::Generic::LinkedList <Object^> _clean_up_list;
266 template<
class _To_Type,
class _From_Type,
bool _Needs_Context>
269 template<
class _To_Type,
class _From_Type>
275 static inline _To_Type
marshal_as(
const _From_Type& _from, System::Collections::Generic::LinkedList<Object^>% _clean_up_list)
281 _cn^ _obj =
gcnew _cn(_to_object, _from);
282 _clean_up_list.AddLast(_obj);
287 template<
class _To_Type,
class _From_Type>
294 static inline _To_Type
marshal_as(
const _From_Type& _from, System::Collections::Generic::LinkedList<Object^>% _clean_up_list)
297 return ::msclr::interop::marshal_as<_To_Type, _From_Type>(_from);
302 template<
class _To_Type,
class _From_Type>
309 template<
class _To_Type,
class _From_Type>
317 template<
class _To_Type>
324 template<
class _To_Type>
331 template<
class _To_Type>
334 return ::msclr::interop::marshal_as<_To_Type>(_from);
342 for each(Object^ _obj
in _clean_up_list)
364 return marshal_as<System::String^, const char *>(_from_object);
370 if (_from_object ==
NULL)
374 return gcnew System::String(_from_object);
382 return marshal_as<System::String^, const wchar_t *>(_from_object);
399 if (_from_object ==
nullptr)
410 throw gcnew System::InsufficientMemoryException();
441 _ip = System::Runtime::InteropServices::Marshal::StringToHGlobalUni (_from_object);
442 _to_object =
static_cast<wchar_t*
>(_ip.ToPointer());
453 if(_ip != System::IntPtr::Zero)
454 System::Runtime::InteropServices::Marshal::FreeHGlobal(_ip);
461 #pragma warning(pop) // error:4996
char_buffer & operator=(const char_buffer &)
System::String marshal_as(_In_z_ wchar_t *const &_from_object)
Definition: marshal.h:380
T * release()
Definition: marshal.h:66
#define _EXCEPTION_GREATER_THAN_INT_MAX
Definition: marshal.h:41
context_node(_Outref_ _Post_z_ const wchar_t *&_to_object, System::String^_from_object)
Definition: marshal.h:439
Definition: marshal.h:267
#define _Out_writes_all_(size)
Definition: sal.h:354
_Check_return_ size_t GetUnicodeStringSize(_In_reads_z_(_count+1) const char *_str, size_t _count)
Definition: marshal.h:115
_Check_return_ size_t GetAnsiStringSize(System::String^_str)
Definition: marshal.h:81
Definition: marshal.h:190
#define _In_reads_bytes_(size)
Definition: sal.h:318
_To_Type marshal_as(_In_z_ const char _from[])
Definition: marshal.h:318
#define _EXCEPTION_WC2MB
Definition: marshal.h:44
static _To_Type marshal_as(const _From_Type &_from, System::Collections::Generic::LinkedList< Object^>%_clean_up_list)
Definition: marshal.h:294
System::String InternalAnsiToStringHelper(_In_reads_z_(_count+1) const char *_src, size_t _count)
Definition: marshal.h:150
_Check_return_ size_t __cdecl strlen(_In_z_ char const *_Str)
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
marshal_context()
Definition: marshal.h:337
#define _Post_z_
Definition: sal.h:688
Definition: marshal.h:247
#define _In_reads_z_(size)
Definition: sal.h:320
#define _Check_return_
Definition: sal.h:554
#define _In_z_
Definition: sal.h:310
static _To_Type marshal_as(const _From_Type &_from, System::Collections::Generic::LinkedList< Object^>%_clean_up_list)
Definition: marshal.h:275
T * _ptr
Definition: marshal.h:78
_To_Type marshal_as(_From_Type^_from)
Definition: marshal.h:310
~context_node()
Definition: marshal.h:419
T * get() const
Definition: marshal.h:61
unsigned char
Definition: mbstring.h:107
_To_Type marshal_as(_In_z_ const char _from_object[])
Definition: marshal.h:193
#define false
Definition: stdbool.h:16
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:133
void WriteAnsiString(_Out_writes_all_(_size) _Post_z_ char *_buf, size_t _size, System::String^_str)
Definition: marshal.h:96
_To_Type marshal_as(_In_z_ const wchar_t _from[])
Definition: marshal.h:325
Definition: marshal.h:260
#define _EXCEPTION_MB2WC
Definition: marshal.h:43
__declspec(deprecated("This conversion is not supported by the library or the header file needed for this conversion is not included. Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method.")) static _To_Type marshal_as(const _From_Type &_from_object)
Definition: marshal.h:219
#define _Outref_
Definition: sal.h:487
char * _ptr
Definition: marshal.h:394
_To_Type marshal_as(System::IntPtr _from)
Definition: marshal.h:332
Definition: marshal.h:186
unsigned short wchar_t
Definition: sourceannotations.h:25
~marshal_context()
Definition: marshal.h:340
__declspec(deprecated("This conversion requires a marshal_context. Please use a marshal_context for this conversion.")) static _To_Type marshal_as(const _From_Type &_from_object)
Definition: marshal.h:230
char_buffer(size_t _size)
Definition: marshal.h:51
~char_buffer()
Definition: marshal.h:56
_To_Type marshal_as(const _From_Type &_from)
Definition: marshal.h:303
#define INT_MAX
Definition: limits.h:35
#define _Outref_result_maybenull_
Definition: sal.h:488
~context_node()
Definition: marshal.h:445
#define true
Definition: stdbool.h:17
context_node(_Outref_result_maybenull_ _Post_z_ const char *&_to_object, System::String^_from_object)
Definition: marshal.h:396
#define NULL
Definition: corecrt.h:158
System::IntPtr _ip
Definition: marshal.h:437
System::String InternalUnicodeToStringHelper(_In_reads_z_(_count+1) const wchar_t *_src, size_t _count)
Definition: marshal.h:168