Binary Resource Tutorial

Hello! Are there any resources for learning how to access and use assets that are bundled together as binary data (specifically in visual studio if that matters).
I see quite a few references to using BinaryData but I haven’t run into any clear examples and I don’t see it mentioned in the JUCE: Class Index so maybe it’s depreciated?

I’m sure I’m overlooking them or I’m using the wrong words in my google searches
Thanks

A couple threads.

These resources are added in the Projucer which creates the BinaryData h/cpp to access in code.

See; 5.2 File Explorer Folder Settings

Binary Resource - The file is added as a binary resource in your executable. Counts towards your platform-specific binary app size limits.

Thanks @TeotiGraphix

I believe I was missing some fundamental aspects of BinaryData that were just assumed knowledge. After tracking down some example usage, I have a better understanding of BinaryData and how to use it. I’ll add these notes here for any future-self’s that aren’t sure where to start.

First off, BinaryData is code generated by the Projucer based on files that the user has added and checked the “Binary Resources” option in the Projucer’s File Explorer. Therefore, BinaryData is NOT a JUCE module and that explains why there is no API documentation for it in the JUCE Class Index.

It does have some standard variables and functions available though

// Number of elements in the namedResourceList and originalFileNames arrays.
const int namedResourceListSize = 33; // value depends on # of files you've added

// Points to the start of a list of resource names.
extern const char* namedResourceList[];

// Points to the start of a list of resource filenames.
extern const char* originalFilenames[];

// If you provide the name of one of the binary resource variables above, this function will
// return the corresponding data and its size (or a null pointer if the name isn't found).
const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes);

// If you provide the name of one of the binary resource variables above, this function will
// return the corresponding original, non-mangled filename (or a null pointer if the name isn't found).
const char* getNamedResourceOriginalFilename (const char* resourceNameUTF8);

You don’t have to explicitly import BinaryData. just access the variables and functions directly.

ie,

char* firstItem = BinaryData::namedResourceList[0];
// or 
char* firstItem = BinaryData::example_test_txt
2 Likes