2#ifndef __aspose_system_marshal_h__
3#define __aspose_system_marshal_h__
6#include <system/exceptions.h>
10namespace System {
namespace Security {
class SecureString; }}
12namespace System {
namespace Runtime {
namespace InteropServices {
27 template<
typename container>
28 static void Copy(
const IntPtr source, container&& destination,
int startIndex,
int length) {
29 memcpy(&destination->data()[0]+startIndex, (
const void *)source, length*
sizeof(destination->data()[0]));
37 template<
typename container>
38 static void Copy(
const void * source, container&& destination,
int startIndex,
int length) {
39 memcpy(&destination->data()[0]+startIndex, source, length*
sizeof(destination->data()[0]));
48 template<
typename container>
49 static void Copy(
const container &source,
int startIndex,
void * destination,
int length) {
50 memcpy(destination, &source->data()[0]+startIndex, length*
sizeof(
typename container::ValueType));
58 template<
typename container>
59 static void Copy(
const container &source,
int startIndex, IntPtr destination,
int length) {
60 memcpy((
void *)destination, &source->data()[0]+startIndex, length*
sizeof(
typename container::ValueType));
68 template<
typename TDelegate>
73 throw ArgumentNullException(u
"ptr");
76 return TDelegate().connect(
reinterpret_cast<typename TDelegate::Function*
>(ptr));
83 static void WriteByte(IntPtr ptr,
int offset, uint8_t value)
85 *((uint8_t*)ptr + offset) = value;
99 static void WriteInt16(IntPtr ptr,
int offset, int16_t value)
101 *((int16_t*)((uint8_t*)ptr + offset)) = value;
108 static void WriteInt32(IntPtr ptr,
int offset, int32_t value)
110 *((int32_t*)((uint8_t*)ptr + offset)) = value;
117 static void WriteInt64(IntPtr ptr,
int offset, int64_t value)
119 *((int64_t*)((uint8_t*)ptr + offset)) = value;
128 *((IntPtr*)((uint8_t*)ptr + offset)) = value;
135 static uint8_t
ReadByte(IntPtr ptr,
int offset = 0)
137 return *((uint8_t*)ptr + offset);
146 return *((int16_t*)((uint8_t*)ptr + offset));
155 return *((int32_t*)((uint8_t*)ptr + offset));
164 return *((IntPtr*)((uint8_t*)ptr + offset));
172 return exc->get_HResult();
Template that represents wrapper of exceptions that are derived from Exception class.
Definition: exception.h:118
Provides marshalling implementation. For compatibility with translated code only, as no managed code ...
Definition: marshal.h:19
static void WriteIntPtr(IntPtr ptr, int offset, IntPtr value)
Writes IntPtr to memory.
Definition: marshal.h:126
static void ZeroFreeGlobalAllocAnsi(IntPtr s)
Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method.
static TDelegate GetDelegateForFunctionPointer(IntPtr ptr)
Converts an unmanaged function pointer to a delegate of a specified type.
Definition: marshal.h:69
static IntPtr StringToHGlobalUni(const String &s)
Copies the contents of a specified string into unmanaged memory.
static IntPtr SecureStringToGlobalAllocUnicode(const SharedPtr< Security::SecureString > &s)
Copies contents of specified secure string into unmanaged memory.
static void Copy(const container &source, int startIndex, void *destination, int length)
Implements public static void Copy(char[] source, int startIndex, IntPtr destination,...
Definition: marshal.h:49
static void Copy(const container &source, int startIndex, IntPtr destination, int length)
Implements public static void Copy(char[] source, int startIndex, IntPtr destination,...
Definition: marshal.h:59
static String PtrToStringAnsi(IntPtr ptr)
Creates a managed String from an unmanaged zero-terminated UTF8-string.
static String PtrToStringAuto(IntPtr ptr, int length)
Creates a managed String from an unmanaged string.
static int32_t ReadInt32(IntPtr ptr, int offset=0)
Reads int from memory.
Definition: marshal.h:153
static void Copy(const IntPtr source, container &&destination, int startIndex, int length)
Implements public static void Copy(IntPtr source, byte[] destination, int startIndex,...
Definition: marshal.h:28
static void FreeHGlobal(IntPtr address)
Frees unmanaged memory.
static String PtrToStringUni(IntPtr ptr, int length)
Creates a managed String from an unmanaged unicode string.
static IntPtr ReadIntPtr(IntPtr ptr, int offset=0)
Reads IntPtr from memory.
Definition: marshal.h:162
static void WriteByte(IntPtr ptr, int offset, uint8_t value)
Writes byte to memory.
Definition: marshal.h:83
static IntPtr StringToHGlobalAnsi(const String &s)
Copies the contents of a specified string into unmanaged memory.
static void WriteByte(IntPtr ptr, uint8_t value)
Writes byte to memory.
Definition: marshal.h:90
static IntPtr SecureStringToGlobalAllocAnsi(const SharedPtr< Security::SecureString > &s)
Copies contents of specified secure string into unmanaged memory, converting into ANSI format.
static IntPtr StringToHGlobalAuto(const String &s)
Copies the contents of a specified string into unmanaged memory, converting to ANSI format if require...
static int16_t ReadInt16(IntPtr ptr, int offset=0)
Reads short from memory.
Definition: marshal.h:144
static String PtrToStringUni(IntPtr ptr)
Creates a managed String from an unmanaged zero-terminated unicode string.
static void WriteInt64(IntPtr ptr, int offset, int64_t value)
Writes long to memory.
Definition: marshal.h:117
static void ZeroFreeGlobalAllocUnicode(IntPtr s)
Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode method.
static int32_t GetHRForException(const System::Exception &exc)
Gets HResult from exception.
Definition: marshal.h:170
static void WriteInt32(IntPtr ptr, int offset, int32_t value)
Writes int to memory.
Definition: marshal.h:108
static String PtrToStringAuto(IntPtr ptr)
Creates a managed String from an unmanaged zero-terminated string.
static uint8_t ReadByte(IntPtr ptr, int offset=0)
Reads byte from memory.
Definition: marshal.h:135
static IntPtr AllocHGlobal(int32_t bytes_count)
Allocates unmanaged memory.
static void WriteInt16(IntPtr ptr, int offset, int16_t value)
Writes short to memory.
Definition: marshal.h:99
static String PtrToStringUTF8(IntPtr ptr)
Creates a managed String from an unmanaged zero-terminated UTF8-string.
static void Copy(const void *source, container &&destination, int startIndex, int length)
Implements public static void Copy(IntPtr source, byte[] destination, int startIndex,...
Definition: marshal.h:38
static String PtrToStringAnsi(IntPtr ptr, int length)
Creates a managed String from an unmanaged UTF8-string.
static IntPtr AllocHGlobal(IntPtr bytes_count)
Allocates unmanaged memory.
static String PtrToStringUTF8(IntPtr ptr, int length)
Creates a managed String from an unmanaged UTF8-string.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:125
Definition: db_command.h:9