As BoxedApp SDK can create pseudofiles, the developer just creates a virtual file of interop DLL, and the application works as expected even though the real file of interop DLL doesn't exist.
In this sample, we will use 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. In order to do 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() will fail.
Look how to do this in Visual Studio:
Let's go to the code! The first thing you need to take care of 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 the virtual files of interop DLLs. They 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 data from embedded resources.
First, it creates a virtual file called 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 copy the data from the embedded resource to the 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.