tags:

views:

79

answers:

2

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?

+4  A: 

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.

Chris Lutz
Heh. Google Desktop Searched my hard drive and I already have xxd! Came with Vim. Thanks!
Nosredna
The resources answer given by Vinay Sajip is closer to what I was asking for, but using xxd is so easy I decided to chuck the custom code I had written and use it instead. If my files were bigger, I might choose the binary resources.
Nosredna
+2  A: 

The last time I had to do this (some while ago) I used binary resources. Here's an article which describes the approach. I'm not sure if there's anything more recent which does it better, though.

Vinay Sajip
This is promising. Thanks.
Nosredna