Here's an example. The following is a code sample for a simple Windows program. Cut and paste it into a file named hello.c to try it out.
Code:
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
MessageBox (NULL, "Hello", "Hello Demo", MB_OK);
return (0);
}
If you want to create a Windows executable hello.exe, from a c file called hello.c, try the following:
This compiles hello.c into an object file, hello.o
Code:
gcc -o hello hello.o -mwindows
This creates an executable hello.exe from hello.o The -mwindows switch is needed to create Windows executables instead of console applications. It assures the appropriate Windows libraries are linked in for you. To get a console screen along with a standard windows application, add the -mconsole flag as well as -mwindows.
If you have resources from a resource file (.rc) that also need to be added to your executable, you'll need to compile the resource file as well as your other source files and include the compiled resources when linking to create the executable. Here's an example that shows how to compile and link in a resource file named resfile.rc.
Code:
windres -o resfile.o resfile.rc
gcc -o hello hello.o resfile.o -mwindows