boolean
stw_init_thread(void)
{
- if (!stw_tls_init_thread())
- return FALSE;
-
- if (!stw_framebuffer_init_thread())
- return FALSE;
-
- return TRUE;
+ return stw_tls_init_thread();
}
void
stw_cleanup_thread(void)
{
- stw_framebuffer_cleanup_thread();
stw_tls_cleanup_thread();
}
* @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx
* @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx
*/
-static LRESULT CALLBACK
+LRESULT CALLBACK
stw_call_window_proc(
int nCode,
WPARAM wParam,
return FALSE;
}
-
-
-boolean
-stw_framebuffer_init_thread(void)
-{
- struct stw_tls_data *tls_data;
-
- tls_data = stw_tls_get_data();
- if(!tls_data)
- return FALSE;
-
- tls_data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC,
- stw_call_window_proc,
- NULL,
- GetCurrentThreadId());
- if(tls_data->hCallWndProcHook == NULL)
- return FALSE;
-
- return TRUE;
-}
-
-void
-stw_framebuffer_cleanup_thread(void)
-{
- struct stw_tls_data *tls_data;
-
- tls_data = stw_tls_get_data();
- if(!tls_data)
- return;
-
- if(tls_data->hCallWndProcHook) {
- UnhookWindowsHookEx(tls_data->hCallWndProcHook);
- tls_data->hCallWndProcHook = NULL;
- }
-}
stw_framebuffer_from_hdc(
HDC hdc );
-boolean
-stw_framebuffer_init_thread(void);
-
-void
-stw_framebuffer_cleanup_thread(void);
-
#endif /* STW_FRAMEBUFFER_H */
data = CALLOC_STRUCT(stw_tls_data);
if (!data)
- return NULL;
+ goto no_data;
+
+ data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC,
+ stw_call_window_proc,
+ NULL,
+ GetCurrentThreadId());
+ if(data->hCallWndProcHook == NULL)
+ goto no_hook;
+
+ TlsSetValue(tlsIndex, data);
return data;
+
+no_hook:
+ FREE(data);
+no_data:
+ return NULL;
}
boolean
if(!data)
return FALSE;
- TlsSetValue(tlsIndex, data);
-
return TRUE;
}
}
data = (struct stw_tls_data *) TlsGetValue(tlsIndex);
- TlsSetValue(tlsIndex, NULL);
- FREE(data);
+ if(data) {
+ TlsSetValue(tlsIndex, NULL);
+
+ if(data->hCallWndProcHook) {
+ UnhookWindowsHookEx(data->hCallWndProcHook);
+ data->hCallWndProcHook = NULL;
+ }
+
+ FREE(data);
+ }
}
void
if(!data) {
/* DllMain is called with DLL_THREAD_ATTACH only by threads created after
* the DLL is loaded by the process */
-
data = stw_tls_data_create();
if(!data)
return NULL;
-
- TlsSetValue(tlsIndex, data);
}
return data;
struct stw_tls_data *
stw_tls_get_data(void);
+LRESULT CALLBACK
+stw_call_window_proc(
+ int nCode,
+ WPARAM wParam,
+ LPARAM lParam );
+
#endif /* STW_TLS_H */