CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
marshal.h
1
2#ifndef __aspose_system_marshal_h__
3#define __aspose_system_marshal_h__
4
5#include <memory.h>
6#include <system/exception.h>
7#include <fwd.h>
8#include <cstdint>
9
10namespace System { namespace Security { class SecureString; }}
11
12namespace System { namespace Runtime { namespace InteropServices {
13
19{
20public:
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]));
30 }
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]));
40 }
41
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));
51 }
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));
61 }
62
67 static void WriteByte(IntPtr ptr, int offset, uint8_t value)
68 {
69 *((uint8_t*)ptr + offset) = value;
70 }
74 static void WriteByte(IntPtr ptr, uint8_t value)
75 {
76 WriteByte(ptr, 0, value);
77 }
78
83 static void WriteInt16(IntPtr ptr, int offset, int16_t value)
84 {
85 *((int16_t*)((uint8_t*)ptr + offset)) = value;
86 }
87
92 static void WriteInt32(IntPtr ptr, int offset, int32_t value)
93 {
94 *((int32_t*)((uint8_t*)ptr + offset)) = value;
95 }
96
101 static void WriteInt64(IntPtr ptr, int offset, int64_t value)
102 {
103 *((int64_t*)((uint8_t*)ptr + offset)) = value;
104 }
105
110 static uint8_t ReadByte(IntPtr ptr, int offset = 0)
111 {
112 return *((uint8_t*)ptr + offset);
113 }
118 static int16_t ReadInt16(IntPtr ptr, int offset = 0)
119 {
120 return *((int16_t*)((uint8_t*)ptr + offset));
121 }
126 static int32_t ReadInt32(IntPtr ptr, int offset = 0)
127 {
128 return *((int32_t*)((uint8_t*)ptr + offset));
129 }
130
134 static int32_t GetHRForException(const System::Exception& exc)
135 {
136 return exc->get_HResult();
137 }
138
142 static ASPOSECPP_SHARED_API IntPtr SecureStringToGlobalAllocAnsi(const SharedPtr<Security::SecureString>& s);
143
147 static ASPOSECPP_SHARED_API IntPtr SecureStringToGlobalAllocUnicode(const SharedPtr<Security::SecureString>& s);
148
152 static ASPOSECPP_SHARED_API IntPtr AllocHGlobal(int32_t bytes_count);
153
157 static ASPOSECPP_SHARED_API IntPtr AllocHGlobal(IntPtr bytes_count);
158
161 static ASPOSECPP_SHARED_API void FreeHGlobal(IntPtr address);
162
165 static ASPOSECPP_SHARED_API void ZeroFreeGlobalAllocAnsi(IntPtr s);
166
169 static ASPOSECPP_SHARED_API void ZeroFreeGlobalAllocUnicode(IntPtr s);
170
174 static ASPOSECPP_SHARED_API IntPtr StringToHGlobalAnsi(const String& s);
175
179 static ASPOSECPP_SHARED_API IntPtr StringToHGlobalUni(const String& s);
180
184 static ASPOSECPP_SHARED_API IntPtr StringToHGlobalAuto(const String& s);
185
189 static ASPOSECPP_SHARED_API String PtrToStringAnsi(IntPtr ptr);
190
195 static ASPOSECPP_SHARED_API String PtrToStringAnsi(IntPtr ptr, int length);
196
200 static ASPOSECPP_SHARED_API String PtrToStringAuto(IntPtr ptr);
201
206 static ASPOSECPP_SHARED_API String PtrToStringAuto(IntPtr ptr, int length);
207
211 static ASPOSECPP_SHARED_API String PtrToStringUni(IntPtr ptr);
212
217 static ASPOSECPP_SHARED_API String PtrToStringUni(IntPtr ptr, int length);
218
222 static ASPOSECPP_SHARED_API String PtrToStringUTF8(IntPtr ptr);
223
228 static ASPOSECPP_SHARED_API String PtrToStringUTF8(IntPtr ptr, int length);
229};
230
231}}} // namespace System::Runtime::InteropServices
232
233#endif
Template that represents wrapper of exceptions that are derived from Exception class.
Definition: exception.h:113
Provides marshalling implementation. For compatibility with translated code only, as no managed code ...
Definition: marshal.h:19
static void ZeroFreeGlobalAllocAnsi(IntPtr s)
Frees unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi method.
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:126
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 void WriteByte(IntPtr ptr, int offset, uint8_t value)
Writes byte to memory.
Definition: marshal.h:67
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:74
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:118
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:101
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:134
static void WriteInt32(IntPtr ptr, int offset, int32_t value)
Writes int to memory.
Definition: marshal.h:92
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:110
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:83
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:122
Definition: db_command.h:9