A Windows .EXE executable file can contain binary resources, which are basically arbitrary binary data embedded in the file.
In particular, it’s possible to embed one or more DLLs as binary resources into an EXE. In this article, I’ll first show you how to embed a DLL as a binary resource into an EXE using the Visual Studio IDE; then, you’ll learn how to access that binary resource data using proper Windows API calls.

Embedding a Binary Resource Using Visual Studio IDE
If you are using Visual Studio to develop your Windows C++ applications, from Solution Explorer you can right-click your EXE project node, then choose Add > Resource from the menu.

Then click the Import button, and select the binary resource to embed into the EXE, for example: TestDll.dll.

In the Custom Resource Type dialog box that appears next, enter RCDATA as Resource type.
Then click the OK button.
A hex representation of the resource bytes is shown in the IDE. Type Ctrl+S or click the diskette icon in the toolbar to save the new resource data.
You can close the binary hex representation of the resource.
The resource was automatically labeled by the Visual Studio IDE as IDR_RCDATA1. To change that resource ID, you can open Resource View. Then, expand the project node, until you see the RCDATA virtual folder, and then IDR_RCDATA1 inside it. Click the IDR_RCDATA1 item to select it.
In the Properties grid below, you can change the ID field, for example: you can rename the resource ID as IDR_TEST_DLL.
Type Ctrl+S to save the modifications.


Don’t forget to #include the resource header (for example: “resource.h”) in your C++ code when you need to refer to the embedded resource by its ID.
In particular, if you open the resource.h file that was created and modified by Visual Studio, you’ll see a #define line that associates the “symbolic” name of the resource (e.g. IDR_TEST_DLL) with an integer number that represents the integer ID of the resource, for example:
#define IDR_TEST_DLL 101
Accessing an Embedded Binary Resource from C/C++ Code
Once you have embedded a binary resource, like a DLL, into your EXE, you can access the resource’s binary data using some specific Windows APIs. In particular:
- Invoke FindResource to get the specified resource’s information block (represented by an HRSRC handle).
- Invoke LoadResource, passing the above handle to the resource information block. On success, LoadResource will return another handle (declared as HGLOBAL for backward compatibility), that can be used to access the first byte of the resource.
- Invoke LockResource passing the resource handle returned by LoadResource, to get access to the first byte of the resource.
To get the size of the resource, you can call the SizeofResource API.
The above “API dance” can be translated into the following C++ code:
#include "resource.h" // for the resource ID (e.g. IDR_TEST_DLL)
// Locate the embedded resource having ID = IDR_TEST_DLL
HRSRC hResourceInfo = ::FindResource(hModule,
MAKEINTRESOURCE(IDR_TEST_DLL),
RT_RCDATA);
if (hResourceInfo == nullptr)
{
// Handle error...
}
// Get the handle that will be used to access
// the first byte of the resource
HGLOBAL hResourceData = ::LoadResource(hModule, hResourceInfo);
if (hResourceData == nullptr)
{
// Handle error...
}
// Get the address of the first byte of the resource
const void * pvResourceData = ::LockResource(hResourceData);
if (pvResourceData == nullptr)
{
// Handle error...
}
// Get the size, in bytes, of the resource
DWORD dwResourceSize = ::SizeofResource(hModule, hResourceInfo);
if (dwResourceSize == 0)
{
// Handle error...
}
I uploaded on GitHub a C++ demo code that extracts a DLL embedded as a resource in the EXE, and, for testing purposes, invokes a function exported from the extracted DLL. In particular, you can take a look at the ResourceBinaryView.h file for a reusable C++ class to get a read-only binary view of a resource.
P.S. An EXE is not the only type of Windows Portable Executable (PE) file that can have embedded resources. For example: DLLs can contain resources, as well.
