Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cleanest way to include and access binary data in VC++ Express?

Tags:

c++

c

dll

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?

like image 866
Nosredna Avatar asked Sep 06 '09 21:09

Nosredna


1 Answers

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.

like image 64
Chris Lutz Avatar answered Oct 09 '22 01:10

Chris Lutz