I did this one a while ago to show that you can write minimum sized code using a Microsoft C compiler. This example bloats you hard disk up to the tune of 1.5k. :bg
While I confess that my C gets rustier by the minute, it is in fact not particularly difficult to write small C code as long as you are willing to abandon the crappy runtime libraries that come with it and write your own.
/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */
#include <windows.h>
#include <stdlib.h>
HANDLE hWnd; // global main window handle
HINSTANCE hInstance; // global instance handle
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */
void main()
{
HICON hIcon; // local icon handle
MSG msg; // local msg structure
WNDCLASSEX wc; // local structure for RegisterClassEx
char szTitle[] = "Small C";
char szWindowClass[] = "SC_Class";
hInstance = GetModuleHandle(0);
hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_BYTEALIGNWINDOW | CS_BYTEALIGNCLIENT;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szWindowClass;
wc.hIconSm = hIcon;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(WS_EX_LEFT,
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,
CW_USEDEFAULT,0,
NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */
LRESULT CALLBACK WndProc(HWND hWin,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWin,uMsg,wParam,lParam);
}
/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */
[attachment deleted by admin]
Hi Hutch,
Pelles and Microsoft C compilers are very powerfull tools enabling the creation of fast and small sized executables :U
I have a little project about tiny C startup modules to build smaller C executables:
http://www.masmforum.com/simple/index.php?topic=166.0