Virtual File Sample with BoxedApp SDK

This example shows how to create a memory-based virtual file using BoxedApp SDK and write data into it without touching the real file system.

We create a virtual file, get a pointer to an embedded resource, and write its bytes into the virtual file. The file exists only in the virtualization layer.

A virtual file is never created on disk. It is visible only to the process that created it and to child processes that inherit the same virtual environment. From the operating system’s perspective, there is no physical file — all file operations are handled by the BoxedApp SDK layer.

This mechanism is useful whenever you want to work with data as if it were a regular file, but without exposing it to the file system. Typical scenarios include loading a DLL directly from memory, streaming and decoding protected video, rendering embedded documents or images, or handling other sensitive assets that you prefer not to unpack to disk.

C++ Sample

// Creates a virtual file and writes resource bytes into it
// Note: replace IDC_BIN / "BIN" with your own resource identifiers.
 
HANDLE hVirtualFile = BoxedAppSDK_CreateVirtualFile(
  L"c:\v1.swf",          // virtual path (doesn't touch disk)
  GENERIC_READ | GENERIC_WRITE,
  FILE_SHARE_READ,
  NULL,
  CREATE_NEW,
  0,
  NULL);
 
// Get resource handle and size
HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDC_BIN), L"BIN");
HGLOBAL hResData = LoadResource(NULL, hResInfo);
LPVOID pData = LockResource(hResData);
DWORD  cbData = SizeofResource(NULL, hResInfo);
 
// Write bytes to the virtual file
DWORD cbWritten = 0;
WriteFile(hVirtualFile, pData, cbData, &cbWritten, NULL);
 
// Done
CloseHandle(hVirtualFile);