src/main/win32/SDL_win32_main.c
changeset 1423 4ed717f9e509
parent 1379 c0a74f199ecf
child 1433 bb6839704ed6
equal deleted inserted replaced
1422:d2ee8da60262 1423:4ed717f9e509
   186 /* This is where execution begins [console apps] */
   186 /* This is where execution begins [console apps] */
   187 int console_main(int argc, char *argv[])
   187 int console_main(int argc, char *argv[])
   188 {
   188 {
   189 	int n;
   189 	int n;
   190 	char *bufp, *appname;
   190 	char *bufp, *appname;
       
   191 	int status;
   191 
   192 
   192 	/* Get the class name from argv[0] */
   193 	/* Get the class name from argv[0] */
   193 	appname = argv[0];
   194 	appname = argv[0];
   194 	if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) {
   195 	if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) {
   195 		appname = bufp+1;
   196 		appname = bufp+1;
   201 	if ( (bufp=SDL_strrchr(appname, '.')) == NULL )
   202 	if ( (bufp=SDL_strrchr(appname, '.')) == NULL )
   202 		n = SDL_strlen(appname);
   203 		n = SDL_strlen(appname);
   203 	else
   204 	else
   204 		n = (bufp-appname);
   205 		n = (bufp-appname);
   205 
   206 
   206 	bufp = (char *)alloca(n+1);
   207 	bufp = SDL_stack_alloc(char, n+1);
   207 	if ( bufp == NULL ) {
   208 	if ( bufp == NULL ) {
   208 		return OutOfMemory();
   209 		return OutOfMemory();
   209 	}
   210 	}
   210 	SDL_strlcpy(bufp, appname, n);
   211 	SDL_strlcpy(bufp, appname, n);
   211 	appname = bufp;
   212 	appname = bufp;
   224 	   is called later in the video initialization.
   225 	   is called later in the video initialization.
   225 	 */
   226 	 */
   226 	SDL_SetModuleHandle(GetModuleHandle(NULL));
   227 	SDL_SetModuleHandle(GetModuleHandle(NULL));
   227 
   228 
   228 	/* Run the application main() code */
   229 	/* Run the application main() code */
   229 	SDL_main(argc, argv);
   230 	status = SDL_main(argc, argv);
   230 
   231 
   231 	/* Exit cleanly, calling atexit() functions */
   232 	/* Exit cleanly, calling atexit() functions */
   232 	exit(0);
   233 	exit(status);
   233 
   234 
   234 	/* Hush little compiler, don't you cry... */
   235 	/* Hush little compiler, don't you cry... */
   235 	return(0);
   236 	return 0;
   236 }
   237 }
   237 
   238 
   238 /* This is where execution begins [windowed apps] */
   239 /* This is where execution begins [windowed apps] */
   239 #ifdef _WIN32_WCE
   240 #ifdef _WIN32_WCE
   240 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
   241 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
   260 	size_t nLen;
   261 	size_t nLen;
   261 #endif
   262 #endif
   262 #ifndef NO_STDIO_REDIRECT
   263 #ifndef NO_STDIO_REDIRECT
   263 	FILE *newfp;
   264 	FILE *newfp;
   264 #endif
   265 #endif
   265 	int retval;
       
   266 
   266 
   267 	/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
   267 	/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
   268 	   keep them open.  This is a hack.. hopefully it will be fixed 
   268 	   keep them open.  This is a hack.. hopefully it will be fixed 
   269 	   someday.  DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
   269 	   someday.  DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
   270 	 */
   270 	 */
   320 	setbuf(stderr, NULL);			/* No buffering */
   320 	setbuf(stderr, NULL);			/* No buffering */
   321 #endif /* !NO_STDIO_REDIRECT */
   321 #endif /* !NO_STDIO_REDIRECT */
   322 
   322 
   323 #ifdef _WIN32_WCE
   323 #ifdef _WIN32_WCE
   324 	nLen = wcslen(szCmdLine)+128+1;
   324 	nLen = wcslen(szCmdLine)+128+1;
   325 	bufp = (wchar_t *)alloca(nLen*2);
   325 	bufp = SDL_stack_alloc(wchar_t, nLen*2);
   326 	wcscpy (bufp, TEXT("\""));
   326 	wcscpy (bufp, TEXT("\""));
   327 	GetModuleFileName(NULL, bufp+1, 128-3);
   327 	GetModuleFileName(NULL, bufp+1, 128-3);
   328 	wcscpy (bufp+wcslen(bufp), TEXT("\" "));
   328 	wcscpy (bufp+wcslen(bufp), TEXT("\" "));
   329 	wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
   329 	wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
   330 	nLen = wcslen(bufp)+1;
   330 	nLen = wcslen(bufp)+1;
   332 	if ( cmdline == NULL ) {
   332 	if ( cmdline == NULL ) {
   333 		return OutOfMemory();
   333 		return OutOfMemory();
   334 	}
   334 	}
   335 	WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
   335 	WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
   336 #else
   336 #else
   337 	/* Grab the command line (use alloca() on Windows) */
   337 	/* Grab the command line */
   338 	bufp = GetCommandLine();
   338 	bufp = GetCommandLine();
   339 	nLen = SDL_strlen(bufp)+1;
   339 	nLen = SDL_strlen(bufp)+1;
   340 	cmdline = SDL_stack_alloc(char, nLen);
   340 	cmdline = SDL_stack_alloc(char, nLen);
   341 	if ( cmdline == NULL ) {
   341 	if ( cmdline == NULL ) {
   342 		return OutOfMemory();
   342 		return OutOfMemory();
   351 		return OutOfMemory();
   351 		return OutOfMemory();
   352 	}
   352 	}
   353 	ParseCommandLine(cmdline, argv);
   353 	ParseCommandLine(cmdline, argv);
   354 
   354 
   355 	/* Run the main program (after a little SDL initialization) */
   355 	/* Run the main program (after a little SDL initialization) */
   356 	retval = console_main(argc, argv);
   356 	console_main(argc, argv);
   357 
   357 
   358 	SDL_stack_free(cmdline);
   358 	/* Hush little compiler, don't you cry... */
   359 	SDL_stack_free(argv);
   359 	return 0;
   360 	return retval;
   360 }
   361 }