As BoxedApp SDK can create pseudofiles, a developer just creates virtual file of the interop DLL and the application works as expected even if real file of the interop DLL doesn't exist.
In this sample we use the Windows Media Player ActiveX. Let's add the control to the project. As you see two interop DLLs, AxInterop.WMPLib.dll and Interop.WMPLib.dll, are added to References:
Now the task is to virtualize these two DLLs. For that we need to get data for the files somewhere. The easiest way is just to add the file to the project and mark them as Embedded Resources.
Important: Mark Files as Embedded Resources.
After adding the file to embed, go to their properties and set Build Action as "Embedded Resources".
If you don't do it, GetManifestResourceStream() fails.
Look how to do it in Visual Studio:
Let's go to the code! First thing you need to do when BoxedApp SDK in the game is BoxedApp SDK initialization:
/// The main entry point for the application.
static void Main()
// First of all initialize BoxedApp SDK
Then create virtual files of the interop DLLs. Then should be located at the application directory, that's why we use Application.StartupPath:
// Create virtual files using the data of embedded resources
Application.StartupPath + @"\\AxInterop.WMPLib.dll",
Application.StartupPath + @"\\Interop.WMPLib.dll",
The method CreateFileInMemory creates a virtual file using the data from embedded resources.
Firstly it creates a virtual file calling BoxedAppSDK_CreateVirtualFile. This method returns virtual file handle. Close it immediately, you don't need it now. SafeFileHandle from Microsoft.Win32.SafeHandles helps.
Then just copies the data from embedded resource to virtual file:
static void CreateFileInMemory(string virtualPath, Stream stream)
const int bufferSize = 1024;
byte buffer = new byte[bufferSize];
using (new SafeFileHandle(
using (FileStream virtualFileStream = new FileStream(virtualPath, FileMode.Open))
while ((readBytes = stream.Read(buffer, 0, bufferSize)) > 0)
virtualFileStream.Write(buffer, 0, readBytes);
That's all! Once the process asks for AxInterop.WMPLib.dll or Interop.WMPLib.dll, they are provided by BoxedApp virtualization.