Imports System.Reflection
Imports System.IO

Namespace My

    ' The following events are availble for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Private Sub InstallFlashOCXInVirtualRegistry()

            ' We enable option DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL
            ' So all changes will be virtual
            ' We can create new file, it will be created as a virtual file
            BoxedAppSDK.NativeMethods.BoxedAppSDK_EnableOption(BoxedAppSDK.NativeMethods.DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, True)

            Dim fs As Stream
            fs = New System.IO.FileStream("Flash.ocx", IO.FileMode.CreateNew, IO.FileAccess.Write)
            Dim VirtualFileStream As Stream
            VirtualFileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Sample1_FlashActiveXEmbedding.Flash.ocx")
            Dim buffer(VirtualFileStream.Length) As Byte
            VirtualFileStream.Read(buffer, 0, VirtualFileStream.Length)
            fs.Write(buffer, 0, VirtualFileStream.Length)
            fs.Close()

            ' Disable option DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL
            BoxedAppSDK.NativeMethods.BoxedAppSDK_EnableOption(BoxedAppSDK.NativeMethods.DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, False)

            ' Register virtual file "Flash.ocx" in virtual registry
            BoxedAppSDK.NativeMethods.BoxedAppSDK_RegisterCOMLibraryInVirtualRegistry("Flash.ocx")
        End Sub

        Private Sub CreateVirtualFlashFile()

            ' We enable option DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL
            ' So all changes will be virtual
            ' We can create new file, it will be created as a virtual file
            BoxedAppSDK.NativeMethods.BoxedAppSDK_EnableOption(BoxedAppSDK.NativeMethods.DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, True)

            Dim fs As Stream
            fs = New System.IO.FileStream("C:\movie.swf", IO.FileMode.CreateNew, IO.FileAccess.Write)
            Dim VirtualFileStream As Stream
            VirtualFileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Sample1_FlashActiveXEmbedding.movie.swf")
            Dim buffer(VirtualFileStream.Length) As Byte
            VirtualFileStream.Read(buffer, 0, VirtualFileStream.Length)
            fs.Write(buffer, 0, VirtualFileStream.Length)
            fs.Close()

            ' Disable option DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL
            BoxedAppSDK.NativeMethods.BoxedAppSDK_EnableOption(BoxedAppSDK.NativeMethods.DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, False)
        End Sub

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            BoxedAppSDK.NativeMethods.BoxedAppSDK_Init()

            InstallFlashOCXInVirtualRegistry()
            CreateVirtualFlashFile()
        End Sub

        Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
        End Sub
    End Class

End Namespace

