Tools and libraries to glue C/C++ APIs to high-level languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
881 B

using System;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Text;
namespace CppSharp.Runtime
{
public static class Helpers
{
public static string MarshalEncodedString(IntPtr ptr, Encoding encoding)
{
if (ptr == IntPtr.Zero)
return null;
var size = 0;
while (Marshal.ReadInt32(ptr, size) != 0)
size += sizeof(int);
var buffer = new byte[size];
Marshal.Copy(ptr, buffer, 0, buffer.Length);
return encoding.GetString(buffer);
}
#if WINDOWS
[DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl)]
#else
[DllImport("libc", EntryPoint = "memcpy")]
#endif
public static extern IntPtr memcpy(IntPtr dest, IntPtr src, UIntPtr count);
}
}