|
|
|
| 1 |
|
/*** |
| 2 |
|
*marshal_cppstd.h |
| 3 |
|
* |
| 4 |
|
* Copyright (c) Microsoft Corporation. All rights reserved. |
| 5 |
|
* |
| 6 |
|
*Purpose: Marshalling classes |
| 7 |
|
* |
| 8 |
|
* [Public] |
| 9 |
|
* |
| 10 |
|
****/ |
| 11 |
|
|
| 12 |
|
#pragma once |
| 13 |
|
|
| 14 |
|
#ifndef _INC_MSCLR_MARSHAL_CPPSTD |
| 15 |
|
#define _INC_MSCLR_MARSHAL_CPPSTD |
| 16 |
|
|
| 17 |
|
#include <string> |
| 18 |
|
#include <vector> |
| 19 |
|
#include <vcclr.h> |
| 20 |
|
|
| 21 |
|
#include "marshal.h" |
| 22 |
|
|
| 23 |
|
#using <mscorlib.dll> |
| 24 |
|
|
| 25 |
|
namespace msclr{ |
| 26 |
|
namespace interop{ |
| 27 |
|
|
| 28 |
|
template <> |
| 29 |
|
inline System::String^ marshal_as(const std::string& _from_obj) |
| 30 |
|
{ |
| 31 |
|
return details::InternalAnsiToStringHelper(_from_obj.c_str(), _from_obj.length()); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
template <> |
| 35 |
|
inline std::string marshal_as(System::String^ const & _from_obj) |
| 36 |
|
{ |
| 37 |
|
if (_from_obj == nullptr) |
| 38 |
|
{ |
| 39 |
|
throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR); |
| 40 |
|
} |
| 41 |
|
std::string _to_obj; |
| 42 |
|
size_t _size = details::GetAnsiStringSize(_from_obj); |
| 53 |
|
template <> |
| 54 |
|
inline System::String^ marshal_as(const std::wstring& _from_obj) |
| 55 |
|
{ |
| 56 |
|
return details::InternalUnicodeToStringHelper(_from_obj.c_str(), _from_obj.length()); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
template <> |
| 60 |
|
inline std::wstring marshal_as(System::String^ const & _from_obj) |
| 61 |
|
{ |
| 62 |
|
if(_from_obj != nullptr) |
| 63 |
|
{ |
| 64 |
|
cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(_from_obj); |
| 65 |
|
std::wstring _to_obj(static_cast<const wchar_t *>(_pinned_ptr), _from_obj->Length); |
| 66 |
|
|
| 67 |
|
return _to_obj; |
| 68 |
|
} |
| 69 |
|
else |
| 70 |
|
{ |
| 71 |
|
throw gcnew System::ArgumentNullException(_EXCEPTION_NULLPTR); |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
} //namespace interop |
| 76 |
|
} //namespace msclr |
| 77 |
|
|
| 78 |
|
#endif // _INC_MSCLR_MARSHAL_CPPSTD |
| 79 |
|
|
|
|
|