Patch from Martin Lange (mala-sdl at hotmail.com) to unregister SDL's win32
authorRyan C. Gordon <icculus@icculus.org>
Tue, 27 Sep 2005 09:00:42 +0000
changeset 1145d31afac94eff
parent 1144 509295d5a023
child 1146 ab0154afe938
Patch from Martin Lange (mala-sdl at hotmail.com) to unregister SDL's win32
windowclass when shutting down the video subsystem...this allows you to
safely unload/reload the SDL shared library on Windows between
initializations.

Discussion is here:
http://www.devolution.com/pipermail/sdl/2005-February/067424.html
include/SDL_main.h
src/video/wincommon/SDL_sysevents.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5video.c
     1.1 --- a/include/SDL_main.h	Tue Sep 27 08:36:28 2005 +0000
     1.2 +++ b/include/SDL_main.h	Tue Sep 27 09:00:42 2005 +0000
     1.3 @@ -69,7 +69,8 @@
     1.4  extern DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);
     1.5  /* This can also be called, but is no longer necessary */
     1.6  extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst);
     1.7 -
     1.8 +/* This can also be called, but is no longer necessary (SDL_Quit calls it) */
     1.9 +extern DECLSPEC void SDLCALL SDL_UnregisterApp();
    1.10  #ifdef __cplusplus
    1.11  }
    1.12  #endif
     2.1 --- a/src/video/wincommon/SDL_sysevents.c	Tue Sep 27 08:36:28 2005 +0000
     2.2 +++ b/src/video/wincommon/SDL_sysevents.c	Tue Sep 27 09:00:42 2005 +0000
     2.3 @@ -562,11 +562,6 @@
     2.4  	if ( SDL_handle ) {
     2.5  		handle = SDL_handle;
     2.6  	} else {
     2.7 -		/* Warning:
     2.8 -		   If SDL is built as a DLL, this will return a handle to
     2.9 -		   the DLL, not the application, and DirectInput may fail
    2.10 -		   to initialize.
    2.11 -		 */
    2.12  		handle = GetModuleHandle(NULL);
    2.13  	}
    2.14  	return(handle);
    2.15 @@ -575,17 +570,18 @@
    2.16  /* This allows the SDL_WINDOWID hack */
    2.17  const char *SDL_windowid = NULL;
    2.18  
    2.19 +static int app_registered = 0;
    2.20 +
    2.21  /* Register the class for this application -- exported for winmain.c */
    2.22  int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
    2.23  {
    2.24 -	static int initialized = 0;
    2.25  	WNDCLASS class;
    2.26  #ifdef WM_MOUSELEAVE
    2.27  	HMODULE handle;
    2.28  #endif
    2.29  
    2.30  	/* Only do this once... */
    2.31 -	if ( initialized ) {
    2.32 +	if ( app_registered ) {
    2.33  		return(0);
    2.34  	}
    2.35  
    2.36 @@ -646,7 +642,26 @@
    2.37  	/* Check for SDL_WINDOWID hack */
    2.38  	SDL_windowid = getenv("SDL_WINDOWID");
    2.39  
    2.40 -	initialized = 1;
    2.41 +	app_registered = 1;
    2.42  	return(0);
    2.43  }
    2.44  
    2.45 +/*
    2.46 + * Unregisters the windowclass registered in SDL_RegisterApp above.
    2.47 + *  Called from DIB_VideoQuit and DX5_VideoQuit when
    2.48 + *  SDL_QuitSubSystem(INIT_VIDEO) is called.
    2.49 + */
    2.50 +void SDL_UnRegisterApp()
    2.51 +{
    2.52 +	WNDCLASS class;
    2.53 +
    2.54 +	/* SDL_RegisterApp might not have been called before */
    2.55 +	if (app_registered) {
    2.56 +		/* Check for any registered windowclasses. */
    2.57 +		if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
    2.58 +			UnregisterClass(SDL_Appname, SDL_Instance);
    2.59 +		}
    2.60 +	}
    2.61 +	app_registered = 0;
    2.62 +}
    2.63 +
     3.1 --- a/src/video/windib/SDL_dibvideo.c	Tue Sep 27 08:36:28 2005 +0000
     3.2 +++ b/src/video/windib/SDL_dibvideo.c	Tue Sep 27 09:00:42 2005 +0000
     3.3 @@ -971,6 +971,7 @@
     3.4  		}
     3.5  		DIB_QuitGamma(this);
     3.6  		DIB_DestroyWindow(this);
     3.7 +		SDL_UnregisterApp();
     3.8  		FlushMessageQueue();
     3.9  
    3.10  		SDL_Window = NULL;
     4.1 --- a/src/video/windx5/SDL_dx5video.c	Tue Sep 27 08:36:28 2005 +0000
     4.2 +++ b/src/video/windx5/SDL_dx5video.c	Tue Sep 27 09:00:42 2005 +0000
     4.3 @@ -2387,6 +2387,7 @@
     4.4  	DIB_QuitGamma(this);
     4.5  	if ( SDL_Window ) {
     4.6  		DX5_DestroyWindow(this);
     4.7 +		SDL_UnregisterApp();
     4.8  		FlushMessageQueue();
     4.9  	}
    4.10