2009-06-03 19:10:57 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
2009-08-05 14:57:20 +00:00
|
|
|
using Gst.GLib;
|
2009-06-03 19:10:57 +00:00
|
|
|
|
|
|
|
namespace Gst {
|
2009-09-20 08:19:49 +00:00
|
|
|
internal static class Marshaller {
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
public static IntPtr StringArrayToNullTermPointer (string[] strs) {
|
|
|
|
if (strs == null)
|
|
|
|
return IntPtr.Zero;
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
IntPtr result = Gst.GLib.Marshaller.Malloc ( (ulong) ( (strs.Length + 1) * IntPtr.Size));
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
for (int i = 0; i < strs.Length; i++)
|
|
|
|
Marshal.WriteIntPtr (result, i * IntPtr.Size, Gst.GLib.Marshaller.StringToPtrGStrdup (strs [i]));
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
Marshal.WriteIntPtr (result, strs.Length * IntPtr.Size, IntPtr.Zero);
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll") ]
|
|
|
|
static extern void g_strfreev (IntPtr mem);
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
public static string[] NullTermPtrToStringArray (IntPtr null_term_array, bool owned) {
|
|
|
|
if (null_term_array == IntPtr.Zero)
|
|
|
|
return new string [0];
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
int count = 0;
|
|
|
|
System.Collections.ArrayList result = new System.Collections.ArrayList ();
|
|
|
|
IntPtr s = Marshal.ReadIntPtr (null_term_array, count++ * IntPtr.Size);
|
|
|
|
while (s != IntPtr.Zero) {
|
|
|
|
result.Add (Gst.GLib.Marshaller.Utf8PtrToString (s));
|
|
|
|
s = Marshal.ReadIntPtr (null_term_array, count++ * IntPtr.Size);
|
|
|
|
}
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
if (owned)
|
|
|
|
g_strfreev (null_term_array);
|
2009-06-03 19:10:57 +00:00
|
|
|
|
2009-09-20 08:19:49 +00:00
|
|
|
return (string[]) result.ToArray (typeof (string));
|
|
|
|
}
|
|
|
|
}
|
2009-06-03 19:10:57 +00:00
|
|
|
}
|