1 const char win32_rcs[] = "$Id: win32.c,v 1.2 2001/07/29 19:32:00 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/win32.c,v $
6 * Purpose : Win32 User Interface initialization and message loop
8 * Copyright : Written by and Copyright (C) 2001 the SourceForge
9 * IJBSWA team. http://ijbswa.sourceforge.net
11 * Written by and Copyright (C) 1999 Adam Lock
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 * This program is distributed in the hope that it will
21 * be useful, but WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A
23 * PARTICULAR PURPOSE. See the GNU General Public
24 * License for more details.
26 * The GNU General Public License should be included with
27 * this file. If not, you can view it at
28 * http://www.gnu.org/copyleft/gpl.html
29 * or write to the Free Software Foundation, Inc., 59
30 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 * Revision 1.2 2001/07/29 19:32:00 jongfoster
35 * Renaming _main() [mingw32 only] to real_main(), for ANSI compliance.
37 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
38 * Initial import of version 2.9.3 source tree
41 *********************************************************************/
53 /* Uncomment this if you want to build Win32 as a console app */
54 /* #define _WIN_CONSOLE */
63 const char win32_h_rcs[] = WIN32_H_VERSION;
65 const char win32_blurb[] =
66 "Internet Junkbuster Proxy(TM) Version " VERSION " for Windows is Copyright (C) 1997-8\n"
67 "by Junkbusters Corp. This is free software; it may be used and copied under\n"
68 "the GNU General Public License: http://www.gnu.org/copyleft/gpl.html .\n"
69 "This program comes with ABSOLUTELY NO WARRANTY OF ANY KIND.\n"
71 "For information about how to to configure the proxy and your browser, see\n"
72 " " REDIRECT_URL "win\n"
74 "The Internet Junkbuster Proxy(TM) is running and ready to serve!\n"
83 HINSTANCE g_hInstance;
86 static void __cdecl UserInterfaceThread(void *);
91 /*********************************************************************
95 * Description : M$ Windows "main" routine:
96 * parse the `lpCmdLine' param into main's argc and argv variables,
97 * start the user interface thread (for the systray window), and
98 * call main (i.e. patch execution into normal IJB startup).
101 * 1 : hInstance = instance handle of this IJB execution
102 * 2 : hPrevInstance = instance handle of previous IJB execution
103 * 3 : lpCmdLine = command line string which started IJB
104 * 4 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
106 * Returns : `main' never returns, so WinMain will also never return.
108 *********************************************************************/
109 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
114 const char **argv = NULL;
115 char *pszArgs = NULL;
117 char szModule[MAX_PATH+1];
119 HANDLE hInitCompleteEvent = NULL;
122 /* Split command line into arguments */
123 pszArgs = (char *)malloc(strlen(lpCmdLine) + 1);
124 strcpy(pszArgs, lpCmdLine);
126 GetModuleFileName(hInstance, szModule, MAX_PATH);
128 /* Count number of spaces */
130 if (strlen(pszArgs) > 0)
132 pszLastTok = pszArgs;
136 pszLastTok = strchr(pszLastTok+1, ' ');
137 } while (pszLastTok);
140 /* Allocate array of strings */
141 argv = (char **)malloc(sizeof(char *) * argc);
143 /* step through command line replacing spaces with zeros, initialise array */
146 pszLastTok = pszArgs;
149 argv[i] = pszLastTok;
150 pszLastTok = strchr(pszLastTok+1, ' ');
153 while (*pszLastTok != '\0' && *pszLastTok == ' ')
160 } while (pszLastTok && *pszLastTok != '\0');
163 /* Create a user-interface thread and wait for it to initialise */
164 hInitCompleteEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
165 g_hInstance = hInstance;
166 g_nCmdShow = nCmdShow;
167 _beginthread(UserInterfaceThread, 0, &hInitCompleteEvent);
168 WaitForSingleObject(hInitCompleteEvent, INFINITE);
169 DeleteObject(hInitCompleteEvent);
173 res = real_main( argc, argv );
175 res = main( argc, argv );
188 /*********************************************************************
190 * Function : InitWin32
192 * Description : Initialise windows, setting up the console or windows as appropriate.
198 *********************************************************************/
201 WORD wVersionRequested;
205 SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY);
211 wVersionRequested = MAKEWORD(2, 0);
212 if (WSAStartup(wVersionRequested, &wsaData) != 0)
215 MessageBox(NULL, "Cannot initialize WinSock library", "Internet JunkBuster Error",
216 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
232 /*********************************************************************
234 * Function : UserInterfaceThread
236 * Description : User interface thread. WinMain will wait for us to set
237 * the hInitCompleteEvent before patching over to `main'.
238 * This ensures the systray window is active before beginning
242 * 1 : pData = pointer to `hInitCompleteEvent'.
246 *********************************************************************/
247 static void __cdecl UserInterfaceThread(void *pData)
250 HANDLE hInitCompleteEvent = *((HANDLE *) pData);
254 SetEvent(hInitCompleteEvent);
256 /* Enter a message processing loop */
257 while (GetMessage(&msg, (HWND) NULL, 0, 0))
259 TranslateMessage(&msg);
260 DispatchMessage(&msg);