public MediaTrackInfo[] GetTrackInfo() { IntPtr pointer; var count = _getTracksInfoFunction.Delegate(InstancePointer, out pointer); var result = new MediaTrackInfo[count]; var temp = pointer; for (var i = 0; i < count; i++) { result[i] = (MediaTrackInfo)Marshal.PtrToStructure(temp, typeof(MediaTrackInfo)); temp = (IntPtr)((int)temp + Marshal.SizeOf(typeof(MediaTrackInfo))); } LibVlcManager.Free(pointer); return(result); }
/// <summary> /// Convert a pointer of string to manmaged <see cref="String" />. /// </summary> /// <param name="ptr">pointer of string</param> /// <param name="count">count of string, -1 mean auto check the end char</param> /// <param name="toBeFree">free this pointer when convert over</param> /// <param name="encoding">encoding of string</param> /// <returns>result string</returns> public static String PtrToString(IntPtr ptr, int count = -1, bool toBeFree = false, Encoding encoding = null) { if (ptr == IntPtr.Zero) { return(null); } if (encoding == null) { encoding = Encoding.UTF8; } List <byte> buffer = new List <byte>(1024); if (count == -1) { int offset = 0; byte tmp = Marshal.ReadByte(ptr, offset); while (tmp != 0) { buffer.Add(tmp); offset++; tmp = Marshal.ReadByte(ptr, offset); } } else { byte tmp = 0; for (int i = 0; i < count; i++) { tmp = Marshal.ReadByte(ptr, i); buffer.Add(tmp); } } if (toBeFree) { LibVlcManager.Free(ptr); } return(encoding.GetString(buffer.ToArray())); }