Commit 73f14c79 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Safe handle class for LibVLC heap allocation

parent d2e7edbd
......@@ -98,7 +98,7 @@ namespace VideoLAN.LibVLC
[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_mrl")]
public static extern
void MediaGetMRL (MediaHandle media);
MemoryHandle MediaGetMRL (MediaHandle media, NativeException ex);
[DllImport ("libvlc.dll", EntryPoint="libvlc_media_duplicate")]
public static extern
......
......@@ -33,7 +33,7 @@ namespace VideoLAN.LibVLC
* arrays (as used by the native LibVLC) and managed strings.
*/
[StructLayout (LayoutKind.Sequential)]
public struct U8String
internal struct U8String
{
public byte[] mb_str; /**< nul-terminated UTF-8 bytes array */
......@@ -91,4 +91,34 @@ namespace VideoLAN.LibVLC
return new U8String (ptr).ToString ();
}
};
/**
* @brief MemoryHandle: heap allocation by the C run-time
* @ingroup Internals
*/
internal sealed class MemoryHandle : NonNullHandle
{
[DllImport ("libvlc.dll", EntryPoint="libvlc_free")]
private static extern void Free (IntPtr ptr);
/**
* NonNullHandle.Destroy
*/
protected override void Destroy ()
{
Free (handle);
}
public override string ToString ()
{
return U8String.FromNative (handle);
}
public string Transform ()
{
string value = ToString ();
Close ();
return value;
}
};
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment