I have some binary files that I'd like to embed in a dll I'm compiling with VC++ Express Edition.
I have a couple ways to do it (like converting the data to arrays that I compile along with the code), but I'm not satisfied and I feel like I'm probably missing an easy, straightforward solution.
What's the cleanest, easiest way to do this?
I don't know if this is an option, but the Unix (and probably easily avaliable on Windows) program xxd
has an option to output a C header:
xxd -i file.bin > file.h
file.h
will contain the definition of an array of unsigned char
containing the data and an unsigned int
that tells you the length of the array. Of course, it may be better to output to file.c
and then write file.h
as:
extern unsigned char file[];
extern unsigned int file_len;
The names of the variables depend on the input file. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With