tags:

views:

196

answers:

4

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.

+3  A: 

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
A: 

You find many examples on the web, see this: Display a Web Page in a Plain C Win32 Application
See if this example can assist you: Plain C Resampling DLL
Install the Windows Software Development Kit package, there are many examples too.

lsalamon
+4  A: 

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)

valya
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
fnieto
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 ;)
valya
thank you! All the answers looked good, but I tried this one and it worked.
Ramblingwood
+3  A: 

"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