VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Sample 2 - Virtual File"
   ClientHeight    =   5370
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6795
   LinkTopic       =   "Form1"
   ScaleHeight     =   5370
   ScaleWidth      =   6795
   StartUpPosition =   3  'Windows Default
   Begin VB.Label Label2 
      Caption         =   $"MainForm.frx":0000
      Height          =   975
      Left            =   120
      TabIndex        =   1
      Top             =   1080
      Width           =   6495
   End
   Begin VB.Label Label1 
      Caption         =   $"MainForm.frx":0123
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6615
   End
   Begin VB.Image Image1 
      Height          =   3135
      Left            =   120
      Top             =   2160
      Width           =   6615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" _
   (ByVal ApplicationFileName As String) As Integer
   
Private Declare Function FindResource Lib "kernel32" _
    Alias "FindResourceA" _
   (ByVal hInstance As Long, _
    ByVal lpName As String, _
    ByVal lpType As String) As Long
   
Private Declare Function LoadResource Lib "kernel32" _
   (ByVal hInstance As Long, _
    ByVal hResInfo As Long) As Long
   
Private Declare Function LockResource Lib "kernel32" _
   (ByVal hResData As Long) As Long
   
Private Declare Function SizeofResource Lib "kernel32" _
   (ByVal hInstance As Long, _
    ByVal hResInfo As Long) As Long

Private Declare Function CreateFile Lib "kernel32" _
    Alias "CreateFileA" _
   (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As Long) As Long

Private Declare Function WriteFile Lib "kernel32" _
   (ByVal hfile As Long, _
    ByVal pBuffer As Long, _
    ByVal dwBufferSize As Long, _
    ByRef NumberOfBytesWritten As Long, _
    ByVal Overlapped As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
   (ByVal hfile As Long) As Long

Const INVALID_HANDLE_VALUE As Long = -1
Const GENERIC_READ As Long = &H80000000
Const GENERIC_WRITE As Long = &H40000000
Const FILE_SHARE_READ As Long = &H1
Const CREATE_ALWAYS As Long = &H1

Private Sub Form_Load()
    ' Always init BoxedAppSDK!
    BoxedAppSDK_Init

    Dim hModule As Long
    Dim hResInfo As Long
    Dim hResData As Long
    Dim lpImageData As Long
    Dim dwImageSize As Long
    
    ' Get data and size of the picture
    hModule = GetModuleHandle(vbNullString)
    hResInfo = FindResource(hModule, "IMAGE", "IMG")
    hResData = LoadResource(hModule, hResInfo)
    lpImageData = LockResource(hResData)
    dwImageSize = SizeofResource(hModule, hResInfo)
    
    If hResData = 0 Then
        MsgBox ("flash ocx code not found")
        Exit Sub
        End
    End If
    
    ' After this line all changes you made are saving in virtual environment: virtual file system and virtual registry
    BoxedAppSDK_EnableOption DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, True
    
    ' We create file as usually, but as we enabled DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, the
    ' file will be virtual
    Dim hfile As Long
    hfile = CreateFile("virtual.jpg", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0)
    Dim temo As Long
    WriteFile hfile, lpImageData, dwImageSize, temp, 0
    
    ' Restore the option's state
    BoxedAppSDK_EnableOption DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, False

    ' Load picture from the virtual file
    Image1.Picture = LoadPicture("virtual.jpg")
End Sub

Private Sub Form_Unload(Cancel As Integer)
End Sub
