#include <windows.h>
#include <stdio.h>

void FAR PASCAL MessageCallback(WORD,LONG);
void FAR PASCAL RegisterHelperApp(HTASK);

void LogMessage(MSG *pMsg)
{
	FILE *fp;

	fp = fopen("c:\\tmp\\iwloader.log","a");
	if(fp){
		fprintf(fp,"hwnd %4.4X   msg %4.4X   wParam %4.4X   lParam %4.4x:%4.4x\n",
				pMsg->hwnd,pMsg->message,pMsg->wParam,HIWORD(pMsg->lParam),LOWORD(pMsg->lParam));
    	fclose(fp);
    }
}

int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG msg;
	HTASK hTask;

	if(hPrevInstance)
		return 0;

	hTask = GetCurrentTask();
	RegisterHelperApp(hTask);

	while(GetMessage(&msg,NULL,0,0)){
//		LogMessage(&msg);
		if(msg.message == WM_USER){
			MessageCallback(msg.wParam,msg.lParam);
		}
		else if(msg.message == WM_USER + 1 ){
			PostQuitMessage(0);
		}
		else{
			TranslateMessage(&msg);
            DispatchMessage(&msg);
		}
	}
	return 0;       
}
