Imports Microsoft.Win32.SafeHandles
Imports System.IO

Public Class MainForm

    Private Sub buttonPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        BoxedAppSDK.NativeMethods.BoxedAppSDK_Init()

        Dim MemoryStream As MemoryStream = New MemoryStream()
        Dim Data As Byte() = File.ReadAllBytes("source.avi")
        MemoryStream.Write(Data, 0, Data.Length)

        ' 1.avi is the name of the pseudo file
        Using fileHandle As SafeFileHandle = New SafeFileHandle( _
            BoxedAppSDK.NativeMethods.BoxedAppSDK_CreateVirtualFileBasedOnIStream( _
                "1.avi", _
                BoxedAppSDK.NativeMethods.EFileAccess.GenericWrite, _
                BoxedAppSDK.NativeMethods.EFileShare.Read, _
                IntPtr.Zero, _
                BoxedAppSDK.NativeMethods.ECreationDisposition.New, _
                BoxedAppSDK.NativeMethods.EFileAttributes.Normal, _
                IntPtr.Zero, _
                New VirtualFileStream(MemoryStream)), True)
            ' We use "using" to close the allocated handle
            ' The virtual file will still exist
            AxWindowsMediaPlayer1.URL = "1.avi"
        End Using
    End Sub
End Class
