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

Namespaces

 details
 

Classes

class  context_node
 
class  context_node< BSTR, System::String^>
 
class  context_node< const char *, System::String^>
 
class  context_node< const wchar_t *, System::String^>
 
class  context_node_base
 
class  error_reporting_helper
 
class  error_reporting_helper< _To_Type, _From_Type, false >
 
class  error_reporting_helper< _To_Type, _From_Type, true >
 
class  marshal_context
 

Functions

template<class _To_Type >
_To_Type marshal_as (_In_z_ const char _from_object[])
 
template<class _To_Type >
_To_Type marshal_as (_In_z_ const wchar_t _from_object[])
 
template<class _To_Type , class _From_Type >
_To_Type marshal_as (const _From_Type &)
 
template<>
System::String marshal_as (_In_z_ const char *const &_from_object)
 
template<>
System::String marshal_as (_In_z_ char *const &_from_object)
 
template<>
System::String marshal_as (_In_z_ const wchar_t *const &_from_object)
 
template<>
System::String marshal_as (_In_z_ wchar_t *const &_from_object)
 
template<>
System::String marshal_as (const CComBSTR &_from_object)
 
template<>
CComBSTR marshal_as (System::String^const &_from_object)
 
template<>
System::String marshal_as (const CStringA &_from_obj)
 
template<>
System::String marshal_as (const CStringW &_from_obj)
 
template<>
CStringA marshal_as (System::String^const &_from_obj)
 
template<>
CStringW marshal_as (System::String^const &_from_obj)
 
template<>
System::String marshal_as (const std::string &_from_obj)
 
template<>
std::string marshal_as (System::String^const &_from_obj)
 
template<>
System::String marshal_as (const std::wstring &_from_obj)
 
template<>
std::wstring marshal_as (System::String^const &_from_obj)
 
template<>
System::String marshal_as (const _bstr_t &_from_object)
 
template<>
_bstr_t marshal_as (System::String^const &_from_object)
 
template<>
System::IntPtr marshal_as (const HANDLE &_from_object)
 
template<class _To_Type >
_To_Type marshal_as (System::IntPtr _from_object)
 
template<>
HANDLE marshal_as (System::IntPtr _from_object)
 

Function Documentation

template<>
System::String msclr::interop::marshal_as ( const std::string _from_obj)
inline
28 {
29  return details::InternalAnsiToStringHelper(_from_obj.c_str(), _from_obj.length());
30 }
System::String InternalAnsiToStringHelper(_In_reads_z_(_count+1) const char *_src, size_t _count)
Definition: marshal.h:147
template<>
System::String msclr::interop::marshal_as ( const CComBSTR &  _from_object)
inline
30 {
31  if (_from_object.m_str == NULL)
32  {
33  return nullptr;
34  }
35  // Using PtrToStringBSTR here instead of marshal_as<String^, BSTR>() because we want to perserve the embedded NULLs
36  return System::Runtime::InteropServices::Marshal::PtrToStringBSTR(System::IntPtr(_from_object.m_str));
37 }
#define NULL
Definition: crtdbg.h:30
template<>
System::String msclr::interop::marshal_as ( const _bstr_t _from_object)
inline
34 {
35  BSTR _bstr = _from_object.copy(false);
36  if (_bstr == NULL)
37  {
38  return nullptr;
39  }
40  // Using PtrToStringBSTR here instead of marshal_as<String^, BSTR>() because we want to perserve the embedded NULLs
41  return System::Runtime::InteropServices::Marshal::PtrToStringBSTR(System::IntPtr(_bstr));
42 }
#define NULL
Definition: crtdbg.h:30
BSTR copy(bool fCopy=true) const
Definition: comutil.h:545
template<>
std::string msclr::interop::marshal_as ( System::String^const &  _from_obj)
inline
34 {
35  if (_from_obj == nullptr)
36  {
37  throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR);
38  }
39  std::string _to_obj;
40  size_t _size = details::GetAnsiStringSize(_from_obj);
41 
42  if (_size > 1)
43  {
44  // -1 because resize will automatically +1 for the NULL
45  _to_obj.resize(_size-1);
46  char *_dest_buf = &(_to_obj[0]);
47 
48  details::WriteAnsiString(_dest_buf, _size, _from_obj);
49  }
50 
51  return _to_obj;
52 }
#define _EXCEPTION_NULLPTR
Definition: marshal.h:39
_Check_return_ size_t GetAnsiStringSize(System::String^_str)
Definition: marshal.h:78
void WriteAnsiString(_Out_writes_all_(_size) _Post_z_ char *_buf, size_t _size, System::String^_str)
Definition: marshal.h:93
basic_string< char, char_traits< char >, allocator< char > > string
Definition: xstring:2643
template<>
CComBSTR msclr::interop::marshal_as ( System::String^const &  _from_object)
inline
41 {
42  if (_from_object == nullptr)
43  {
44  return CComBSTR(static_cast<const wchar_t*>(NULL));
45  }
46  if(_from_object->Length == 0)
47  {
48  return CComBSTR(static_cast<const wchar_t*>(L""));
49  }
50 
51  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_from_object);
52  return CComBSTR( _from_object->Length, static_cast<const wchar_t *>(_pinned_ptr));
53 }
#define NULL
Definition: crtdbg.h:30
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
template<>
_bstr_t msclr::interop::marshal_as ( System::String^const &  _from_object)
inline
46 {
47  if (_from_object == nullptr)
48  {
49  return _bstr_t(static_cast<BSTR>(NULL));
50  }
51 
52  _bstr_t _ret_bstr_t;
53  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_from_object);
54  _ret_bstr_t.Attach(::SysAllocStringLen(_pinned_ptr, _from_object->Length));
55  if (!_ret_bstr_t)
56  {
57  throw gcnew System::InsufficientMemoryException();
58  }
59  return _ret_bstr_t;
60 }
Definition: comutil.h:144
void Attach(BSTR s)
Definition: comutil.h:597
#define NULL
Definition: crtdbg.h:30
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
template<>
System::String msclr::interop::marshal_as ( const std::wstring _from_obj)
inline
56 {
57  return details::InternalUnicodeToStringHelper(_from_obj.c_str(), _from_obj.length());
58 }
System::String InternalUnicodeToStringHelper(_In_reads_z_(_count+1) const wchar_t *_src, size_t _count)
Definition: marshal.h:165
template<>
System::String msclr::interop::marshal_as ( const CStringA &  _from_obj)
inline
57 {
58  return details::InternalAnsiToStringHelper(_from_obj.operator LPCSTR(), _from_obj.GetLength());
59 }
System::String InternalAnsiToStringHelper(_In_reads_z_(_count+1) const char *_src, size_t _count)
Definition: marshal.h:147
template<>
std::wstring msclr::interop::marshal_as ( System::String^const &  _from_obj)
inline
62 {
63  if(_from_obj != nullptr)
64  {
65  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_from_obj);
66  std::wstring _to_obj(static_cast<const wchar_t *>(_pinned_ptr), _from_obj->Length);
67 
68  return _to_obj;
69  }
70  else
71  {
72  throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR);
73  }
74 }
#define _EXCEPTION_NULLPTR
Definition: marshal.h:39
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
basic_string< wchar_t, char_traits< wchar_t >, allocator< wchar_t > > wstring
Definition: xstring:2645
template<>
System::String msclr::interop::marshal_as ( const CStringW &  _from_obj)
inline
63 {
64  // this will perserve the embedded nulls
65  return details::InternalUnicodeToStringHelper(_from_obj.operator LPCWSTR(), _from_obj.GetLength());
66 }
System::String InternalUnicodeToStringHelper(_In_reads_z_(_count+1) const wchar_t *_src, size_t _count)
Definition: marshal.h:165
template<>
System::IntPtr msclr::interop::marshal_as ( const HANDLE _from_object)
inline
64 {
65  return System::IntPtr(_from_object);
66 }
template<class _To_Type >
_To_Type msclr::interop::marshal_as ( System::IntPtr  _from_object)
inline
73 {
74  return static_cast<HANDLE>(_from_object.ToPointer());
75 }
void * HANDLE
Definition: concrt.h:66
template<>
CStringA msclr::interop::marshal_as ( System::String^const &  _from_obj)
inline
70 {
71  if (_from_obj == nullptr)
72  {
73  throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR);
74  }
75  CStringA _to_obj;
76  size_t _size = details::GetAnsiStringSize(_from_obj);
77 
78  //checking for overflow
79  if (_size > INT_MAX)
80  {
81  throw gcnew System::ArgumentOutOfRangeException(_EXCEPTION_NULLPTR);
82  }
83 
84  int _length = static_cast<int>(_size)-1;
85 
86  //GetBuffer() throws, so we don't need to check for NULL
87  char* _dest_buf = _to_obj.GetBuffer(_length);
88 
89  details::WriteAnsiString(_dest_buf, _size, _from_obj);
90  _to_obj.ReleaseBuffer(_length); // We don't want to include the NULL. This call will set the length to _length
91 
92  return _to_obj;
93 }
#define _EXCEPTION_NULLPTR
Definition: marshal.h:39
_Check_return_ size_t GetAnsiStringSize(System::String^_str)
Definition: marshal.h:78
void WriteAnsiString(_Out_writes_all_(_size) _Post_z_ char *_buf, size_t _size, System::String^_str)
Definition: marshal.h:93
#define INT_MAX
Definition: limits.h:40
template<>
HANDLE msclr::interop::marshal_as ( System::IntPtr  _from_object)
inline
73 {
74  return static_cast<HANDLE>(_from_object.ToPointer());
75 }
void * HANDLE
Definition: concrt.h:66
template<>
CStringW msclr::interop::marshal_as ( System::String^const &  _from_obj)
inline
97 {
98  if (_from_obj == nullptr)
99  {
100  throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR);
101  }
102  cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_from_obj);
103  return CStringW(static_cast<const wchar_t *>(_pinned_ptr), _from_obj->Length);
104 }
#define _EXCEPTION_NULLPTR
Definition: marshal.h:39
__const_Char_ptr PtrToStringChars(__const_String_handle s)
Definition: vcclr.h:40
template<class _To_Type >
_To_Type msclr::interop::marshal_as ( _In_z_ const char  _from_object[])
inline
188 {
189  const char* _ptr = _from_object;
190  return marshal_as<_To_Type, const char *>(_ptr);
191 }
template<class _To_Type >
_To_Type msclr::interop::marshal_as ( _In_z_ const wchar_t  _from_object[])
inline
195 {
196  const wchar_t* _ptr = _from_object;
197  return marshal_as<_To_Type, const wchar_t*>(_ptr);
198 }
template<class _To_Type , class _From_Type >
_To_Type msclr::interop::marshal_as ( const _From_Type &  _from_object)
inline
236 {
238 }
System::String marshal_as(_In_z_ wchar_t *const &_from_object)
Definition: marshal.h:377
template<>
System::String msclr::interop::marshal_as ( _In_z_ const char *const &  _from_object)
inline
350 {
351  if (!_from_object)
352  {
353  return nullptr;
354  }
355  return details::InternalAnsiToStringHelper(_from_object, strlen(_from_object));
356 }
System::String InternalAnsiToStringHelper(_In_reads_z_(_count+1) const char *_src, size_t _count)
Definition: marshal.h:147
_Check_return_ size_t __cdecl strlen(_In_z_ const char *_Str)
template<>
System::String msclr::interop::marshal_as ( _In_z_ char *const &  _from_object)
inline
360 {
361  return marshal_as<System::String^, const char *>(_from_object);
362 }
template<>
System::String msclr::interop::marshal_as ( _In_z_ const wchar_t *const &  _from_object)
inline
366 {
367  if (_from_object == NULL)
368  {
369  return nullptr;
370  }
371  return gcnew System::String(_from_object);
372 }
#define NULL
Definition: crtdbg.h:30
template<>
System::String msclr::interop::marshal_as ( _In_z_ wchar_t *const &  _from_object)
inline
378 {
379  return marshal_as<System::String^, const wchar_t *>(_from_object);
380 }