0

Am working in VC++ 2008 (express) and I would like to write something in C that creates an "empty" exe that I can later call LoadLibrary on and use BeginUpdateResource, UpdateResource, EndUpdateResource to modify the contents.

Just writing a 0-byte file doesn't allow me to open it with LoadLibrary because it isn't a resource.

Alec Gorge
  • 17,110
  • 10
  • 59
  • 71

3 Answers3

4

You can compile an empty .exe file with, for example,

int main() { return 0; }

and use it as a template. (Or an empty .dll, whatever)

Valentin Golev
  • 9,965
  • 10
  • 60
  • 84
  • 1
    that "return 0;" is redundant. http://stackoverflow.com/questions/1610030/why-can-you-return-from-a-non-void-function-without-returning-a-value-without-pro/1610454#1610454 – Fernando N. Oct 30 '09 at 18:31
  • Oh, I didn't know it, thanks! Btw, I don't use C. I used to use C but just for 'fun' purposes, and now prefer C#, PHP, JS or something even more odd ;) – Valentin Golev Oct 30 '09 at 18:39
  • thank you! All the answers looked good, but I tried this one and it worked. – Alec Gorge Oct 30 '09 at 20:24
3

The .EXE format is a complicated file format. It has a bunch of required headers just to describe its basic execution properties (16 bit, 32 bit or 64 bit, and DOS/Win16/Win32/Win64 mode and EXE versus DLL). After that, it has to have a correct table for address relocations. Its not trivial, and you have do some amount of research into the .EXE file format to do this properly.

Paul Hsieh
  • 1,466
  • 7
  • 9
3

"Creating" an exe is something the compiler is very good at. So why not have the compiler create the executable you want, and use that file (or a binary representation of it's contents) to copy around?

xtofl
  • 40,723
  • 12
  • 105
  • 192