Fix: DllMain creation/destroy of the window handle, by Andy Fillebrown

This commit is contained in:
Pedro Lopez-Cabanillas 2010-09-20 21:43:18 +00:00
parent b86c115898
commit bc9bc38229

View file

@ -24,15 +24,31 @@
static HINSTANCE fluid_hinstance = NULL;
static HWND fluid_wnd = NULL;
static int fluid_refCount = 0;
int fluid_win32_create_window(void);
void fluid_win32_destroy_window(void);
HWND fluid_win32_get_window(void);
#ifndef FLUIDSYNTH_NOT_A_DLL
BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
FLUID_LOG(FLUID_DBG, "DllMain");
fluid_set_hinstance((void*) hModule);
fluid_win32_create_window();
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
fluid_refCount++;
if (1 == fluid_refCount) {
fluid_set_hinstance((void*) hModule);
fluid_win32_create_window();
}
break;
case DLL_PROCESS_DETACH:
fluid_refCount--;
if (fluid_refCount == 0) {
fluid_win32_destroy_window();
}
break;
}
return TRUE;
}
#endif
@ -91,8 +107,8 @@ int fluid_win32_create_window(void)
return -100;
}
fluid_wnd = CreateWindow((LPSTR) "FluidSynth", (LPSTR) "FluidSynth", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL,
fluid_hinstance, (LPSTR) NULL);
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL,
fluid_hinstance, (LPSTR) NULL);
if (fluid_wnd == NULL) {
FLUID_LOG(FLUID_ERR, "Can't create window");
return -101;
@ -100,9 +116,18 @@ int fluid_win32_create_window(void)
return 0;
}
void fluid_win32_destroy_window(void)
{
HWND hwnd = fluid_win32_get_window();
if (hwnd) {
DestroyWindow(hwnd);
fluid_wnd = 0;
}
}
HWND fluid_win32_get_window(void)
{
return fluid_wnd;
return fluid_wnd;
}
#endif // #ifdef WIN32