public static Album GetById(MtpDevice device, uint id) { IntPtr ptr = Album.LIBMTP_Get_Album(device.Handle, id); if (ptr == IntPtr.Zero) { return(null); } else { return(new Album(device, (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct)))); } }
public static Album GetById(MtpDevice device, uint id) { IntPtr ptr = Album.LIBMTP_Get_Album(device.Handle, id); if (ptr == IntPtr.Zero) { return(null); } else { // Destroy the struct after we use it to prevent accessing freed memory // in the 'tracks' variable AlbumStruct album = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct)); var ret = new Album(device, album); LIBMTP_destroy_album_t(ptr); return(ret); } }