I have a large binary file, ~1gb in size. I'd like to include this statically in a C executable compiled in Visual Studio 2019. The executable is built for Windows.
I'd like to access the binary file at runtime, but don't want to ship it alongside the application. So reading at runtime from a file is not an option.
I have seen the solution that just includes it as a byte array, but that is cumbersome, is there no better solution?
How would including it as a resource file look like?
CodePudding user response:
Can be done with Resource files. Right click project > Add > Resource File > Import > Select file > Choose a resource type name freely.
#include <Windows.h>
#include "resource.h"
...
# IDR_SOMETHING is the resource identifier, can be found in the autogenerated resource.h
HRSRC res = FindResource(NULL, MAKEINTRESOURCE(IDR_SOMETHING), "Res type name you choose");
DWORD size = SizeofResource(NULL, res);
HGLOBAL data = LoadResource(NULL, res);
data
will be a simple pointer to start of memory where the resource is located.