System::Runtime::InteropServices::Marshal Class Reference

Provides marshalling implementation. For compatibility with translated code only, as no managed code is supported on C++ side. This is a static type with no instance services. You should never create instances of it by any means. More...

#include <marshal.h>

Static Public Member Functions

template<typename container >
static void Copy (const IntPtr source, container &&destination, int startIndex, int length)
 Implements public static void Copy(IntPtr source, byte[] destination, int startIndex, int length) semantics. More...
 
template<typename container >
static void Copy (const void *source, container &&destination, int startIndex, int length)
 Implements public static void Copy(IntPtr source, byte[] destination, int startIndex, int length) semantics. More...
 
template<typename container >
static void Copy (const container &source, int startIndex, void *destination, int length)
 Implements public static void Copy(char[] source, int startIndex, IntPtr destination, int length). More...
 
template<typename container >
static void Copy (const container &source, int startIndex, IntPtr destination, int length)
 Implements public static void Copy(char[] source, int startIndex, IntPtr destination, int length). More...
 
static void WriteByte (IntPtr ptr, int offset, uint8_t value)
 Writes byte to memory. More...
 
static void WriteByte (IntPtr ptr, uint8_t value)
 Writes byte to memory. More...
 
static void WriteInt16 (IntPtr ptr, int offset, int16_t value)
 Writes short to memory. More...
 
static void WriteInt32 (IntPtr ptr, int offset, int32_t value)
 Writes int to memory. More...
 
static void WriteInt64 (IntPtr ptr, int offset, int64_t value)
 Writes long to memory. More...
 
static uint8_t ReadByte (IntPtr ptr, int offset=0)
 Reads byte from memory. More...
 
static int16_t ReadInt16 (IntPtr ptr, int offset=0)
 Reads short from memory. More...
 
static int32_t ReadInt32 (IntPtr ptr, int offset=0)
 Reads int from memory. More...
 
static int32_t GetHRForException (const System::Exception &exc)
 Gets HResult from exception. More...
 
static IntPtr SecureStringToGlobalAllocAnsi (const SharedPtr< Security::SecureString > &s)
 Copies contents of specified secure string into unmanaged memory, converting into ANSI format. More...
 
static IntPtr SecureStringToGlobalAllocUnicode (const SharedPtr< Security::SecureString > &s)
 Copies contents of specified secure string into unmanaged memory. More...
 
static IntPtr AllocHGlobal (int32_t bytes_count)
 Allocates unmanaged memory. More...
 
static IntPtr AllocHGlobal (IntPtr bytes_count)
 Allocates unmanaged memory. More...
 
static void FreeHGlobal (IntPtr address)
 Frees unmanaged memory. More...
 
static void ZeroFreeGlobalAllocAnsi (IntPtr s)
 Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method. More...
 
static void ZeroFreeGlobalAllocUnicode (IntPtr s)
 Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode method. More...
 
static IntPtr StringToHGlobalAnsi (const String &s)
 Copies the contents of a specified string into unmanaged memory. More...
 
static IntPtr StringToHGlobalUni (const String &s)
 Copies the contents of a specified string into unmanaged memory. More...
 
static IntPtr StringToHGlobalAuto (const String &s)
 Copies the contents of a specified string into unmanaged memory, converting to ANSI format if required. More...
 
static String PtrToStringAnsi (IntPtr ptr)
 Creates a managed String from an unmanaged zero-terminated UTF8-string. More...
 
static String PtrToStringAnsi (IntPtr ptr, int length)
 Creates a managed String from an unmanaged UTF8-string. More...
 
static String PtrToStringAuto (IntPtr ptr)
 Creates a managed String from an unmanaged zero-terminated string. More...
 
static String PtrToStringAuto (IntPtr ptr, int length)
 Creates a managed String from an unmanaged string. More...
 
static String PtrToStringUni (IntPtr ptr)
 Creates a managed String from an unmanaged zero-terminated unicode string. More...
 
static String PtrToStringUni (IntPtr ptr, int length)
 Creates a managed String from an unmanaged unicode string. More...
 
static String PtrToStringUTF8 (IntPtr ptr)
 Creates a managed String from an unmanaged zero-terminated UTF8-string. More...
 
static String PtrToStringUTF8 (IntPtr ptr, int length)
 Creates a managed String from an unmanaged UTF8-string. More...
 

Detailed Description

Provides marshalling implementation. For compatibility with translated code only, as no managed code is supported on C++ side. This is a static type with no instance services. You should never create instances of it by any means.

Member Function Documentation

◆ AllocHGlobal() [1/2]

static IntPtr System::Runtime::InteropServices::Marshal::AllocHGlobal ( int32_t  bytes_count)
static

Allocates unmanaged memory.

Parameters
bytes_countRequired number of bytes.
Returns
Pointer to the allocated memory.

◆ AllocHGlobal() [2/2]

static IntPtr System::Runtime::InteropServices::Marshal::AllocHGlobal ( IntPtr  bytes_count)
static

Allocates unmanaged memory.

Parameters
bytes_countRequired number of bytes.
Returns
Pointer to the allocated memory.

◆ Copy() [1/4]

template<typename container >
static void System::Runtime::InteropServices::Marshal::Copy ( const container &  source,
int  startIndex,
IntPtr  destination,
int  length 
)
inlinestatic

Implements public static void Copy(char[] source, int startIndex, IntPtr destination, int length).

Template Parameters
containerSource container type.
Parameters
sourceSource data pointer.
startIndexSource start index.
destinationDestination data pointer.
lengthNumber of elements to copy.

◆ Copy() [2/4]

template<typename container >
static void System::Runtime::InteropServices::Marshal::Copy ( const container &  source,
int  startIndex,
void *  destination,
int  length 
)
inlinestatic

Implements public static void Copy(char[] source, int startIndex, IntPtr destination, int length).

Template Parameters
containerSource container type.
Parameters
sourceSource data pointer.
startIndexSource start index.
destinationDestination data pointer.
lengthNumber of elements to copy.

◆ Copy() [3/4]

template<typename container >
static void System::Runtime::InteropServices::Marshal::Copy ( const IntPtr  source,
container &&  destination,
int  startIndex,
int  length 
)
inlinestatic

Implements public static void Copy(IntPtr source, byte[] destination, int startIndex, int length) semantics.

Template Parameters
containerDestination container type.
Parameters
sourceSource data pointer.
destinationContainer to copy data into.
startIndexSource start index.
lengthNumber of elements to copy.

◆ Copy() [4/4]

template<typename container >
static void System::Runtime::InteropServices::Marshal::Copy ( const void *  source,
container &&  destination,
int  startIndex,
int  length 
)
inlinestatic

Implements public static void Copy(IntPtr source, byte[] destination, int startIndex, int length) semantics.

Template Parameters
containerDestination container type.
Parameters
sourceSource data pointer.
destinationContainer to copy data into.
startIndexSource start index.
lengthNumber of elements to copy.

◆ FreeHGlobal()

static void System::Runtime::InteropServices::Marshal::FreeHGlobal ( IntPtr  address)
static

Frees unmanaged memory.

Parameters
addressPointer to the allocated memory.

◆ GetHRForException()

static int32_t System::Runtime::InteropServices::Marshal::GetHRForException ( const System::Exception exc)
inlinestatic

Gets HResult from exception.

Parameters
excException to get HResult for.
Returns
HResult value.

◆ PtrToStringAnsi() [1/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringAnsi ( IntPtr  ptr)
static

Creates a managed String from an unmanaged zero-terminated UTF8-string.

Parameters
ptrPointer to the unmanaged string.
Returns
A managed string.

◆ PtrToStringAnsi() [2/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringAnsi ( IntPtr  ptr,
int  length 
)
static

Creates a managed String from an unmanaged UTF8-string.

Parameters
ptrPointer to the unmanaged string.
lengthLength of the unmanaged string.
Returns
A managed string.

◆ PtrToStringAuto() [1/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringAuto ( IntPtr  ptr)
static

Creates a managed String from an unmanaged zero-terminated string.

Parameters
ptrPointer to the unmanaged string.
Returns
A managed string.

◆ PtrToStringAuto() [2/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringAuto ( IntPtr  ptr,
int  length 
)
static

Creates a managed String from an unmanaged string.

Parameters
ptrPointer to the unmanaged string.
lengthLength of the unmanaged string.
Returns
A managed string.

◆ PtrToStringUni() [1/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringUni ( IntPtr  ptr)
static

Creates a managed String from an unmanaged zero-terminated unicode string.

Parameters
ptrPointer to the unmanaged string.
Returns
A managed string.

◆ PtrToStringUni() [2/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringUni ( IntPtr  ptr,
int  length 
)
static

Creates a managed String from an unmanaged unicode string.

Parameters
ptrPointer to the unmanaged string.
lengthLength of the unmanaged string.
Returns
A managed string.

◆ PtrToStringUTF8() [1/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringUTF8 ( IntPtr  ptr)
static

Creates a managed String from an unmanaged zero-terminated UTF8-string.

Parameters
ptrPointer to the unmanaged string.
Returns
A managed string.

◆ PtrToStringUTF8() [2/2]

static String System::Runtime::InteropServices::Marshal::PtrToStringUTF8 ( IntPtr  ptr,
int  length 
)
static

Creates a managed String from an unmanaged UTF8-string.

Parameters
ptrPointer to the unmanaged string.
lengthLength of the unmanaged string.
Returns
A managed string.

◆ ReadByte()

static uint8_t System::Runtime::InteropServices::Marshal::ReadByte ( IntPtr  ptr,
int  offset = 0 
)
inlinestatic

Reads byte from memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
Returns
Read value.

◆ ReadInt16()

static int16_t System::Runtime::InteropServices::Marshal::ReadInt16 ( IntPtr  ptr,
int  offset = 0 
)
inlinestatic

Reads short from memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
Returns
Read value.

◆ ReadInt32()

static int32_t System::Runtime::InteropServices::Marshal::ReadInt32 ( IntPtr  ptr,
int  offset = 0 
)
inlinestatic

Reads int from memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
Returns
Read value.

◆ SecureStringToGlobalAllocAnsi()

static IntPtr System::Runtime::InteropServices::Marshal::SecureStringToGlobalAllocAnsi ( const SharedPtr< Security::SecureString > &  s)
static

Copies contents of specified secure string into unmanaged memory, converting into ANSI format.

Parameters
sSecure string.
Returns
The address in unmanaged memory.

◆ SecureStringToGlobalAllocUnicode()

static IntPtr System::Runtime::InteropServices::Marshal::SecureStringToGlobalAllocUnicode ( const SharedPtr< Security::SecureString > &  s)
static

Copies contents of specified secure string into unmanaged memory.

Parameters
sSecure string.
Returns
The address in unmanaged memory.

◆ StringToHGlobalAnsi()

static IntPtr System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi ( const String s)
static

Copies the contents of a specified string into unmanaged memory.

Parameters
sA string to be copied.
Returns
The address, in unmanaged memory.

◆ StringToHGlobalAuto()

static IntPtr System::Runtime::InteropServices::Marshal::StringToHGlobalAuto ( const String s)
static

Copies the contents of a specified string into unmanaged memory, converting to ANSI format if required.

Parameters
sA string to be copied.
Returns
The address, in unmanaged memory.

◆ StringToHGlobalUni()

static IntPtr System::Runtime::InteropServices::Marshal::StringToHGlobalUni ( const String s)
static

Copies the contents of a specified string into unmanaged memory.

Parameters
sA string to be copied.
Returns
The address, in unmanaged memory.

◆ WriteByte() [1/2]

static void System::Runtime::InteropServices::Marshal::WriteByte ( IntPtr  ptr,
int  offset,
uint8_t  value 
)
inlinestatic

Writes byte to memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
valueto write.

◆ WriteByte() [2/2]

static void System::Runtime::InteropServices::Marshal::WriteByte ( IntPtr  ptr,
uint8_t  value 
)
inlinestatic

Writes byte to memory.

Parameters
ptrMemory buffer.
valueto write.

◆ WriteInt16()

static void System::Runtime::InteropServices::Marshal::WriteInt16 ( IntPtr  ptr,
int  offset,
int16_t  value 
)
inlinestatic

Writes short to memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
valueto write.

◆ WriteInt32()

static void System::Runtime::InteropServices::Marshal::WriteInt32 ( IntPtr  ptr,
int  offset,
int32_t  value 
)
inlinestatic

Writes int to memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
valueto write.

◆ WriteInt64()

static void System::Runtime::InteropServices::Marshal::WriteInt64 ( IntPtr  ptr,
int  offset,
int64_t  value 
)
inlinestatic

Writes long to memory.

Parameters
ptrMemory buffer.
offsetOffset to memory buffer.
valueto write.

◆ ZeroFreeGlobalAllocAnsi()

static void System::Runtime::InteropServices::Marshal::ZeroFreeGlobalAllocAnsi ( IntPtr  s)
static

Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method.

Parameters
sPointer to the unmanaged string.

◆ ZeroFreeGlobalAllocUnicode()

static void System::Runtime::InteropServices::Marshal::ZeroFreeGlobalAllocUnicode ( IntPtr  s)
static

Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode method.

Parameters
sPointer to the unmanaged string.