Imports Microsoft.Win32.SafeHandles

Public Class MainForm

    Private Sub buttonEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim EncryptVideoForm As EncryptVideoForm = New EncryptVideoForm
        EncryptVideoForm.ShowDialog()
    End Sub

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

        Dim dlg As OpenFileDialog = New OpenFileDialog

        ' 1.avi is the name of the pseudo file
        If dlg.ShowDialog() = DialogResult.OK Then
            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(dlg.FileName)), True)
                ' We use "using" to close the allocated handle
                ' The virtual file will still exist
                AxWindowsMediaPlayer1.URL = "1.avi"
            End Using
        End If
    End Sub
End Class
