diff options
Diffstat (limited to 'win/tkWin32Dll.c')
-rw-r--r-- | win/tkWin32Dll.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/win/tkWin32Dll.c b/win/tkWin32Dll.c index 4570a5a..fde647b 100644 --- a/win/tkWin32Dll.c +++ b/win/tkWin32Dll.c @@ -8,16 +8,17 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWin32Dll.c,v 1.6 2002/12/08 00:46:51 hobbs Exp $ + * RCS: @(#) $Id: tkWin32Dll.c,v 1.6.2.1 2004/10/27 00:37:38 davygrvy Exp $ */ #include "tkWinInt.h" +#ifndef STATIC_BUILD /* * The following declaration is for the VC++ DLL entry point. */ -BOOL APIENTRY DllMain _ANSI_ARGS_((HINSTANCE hInst, +BOOL WINAPI DllMain _ANSI_ARGS_((HINSTANCE hInst, DWORD reason, LPVOID reserved)); /* @@ -38,7 +39,7 @@ BOOL APIENTRY DllMain _ANSI_ARGS_((HINSTANCE hInst, *---------------------------------------------------------------------- */ -BOOL APIENTRY +BOOL WINAPI DllEntryPoint(hInst, reason, reserved) HINSTANCE hInst; /* Library instance handle. */ DWORD reason; /* Reason this function is being called. */ @@ -61,12 +62,14 @@ DllEntryPoint(hInst, reason, reserved) * Always TRUE. * * Side effects: - * None. + * This might call some sycronization functions, but MSDN + * documentation states: "Waiting on synchronization objects in + * DllMain can cause a deadlock." * *---------------------------------------------------------------------- */ -BOOL APIENTRY +BOOL WINAPI DllMain(hInstance, reason, reserved) HINSTANCE hInstance; DWORD reason; @@ -77,8 +80,33 @@ DllMain(hInstance, reason, reserved) * the hInstance to use. */ - if (reason == DLL_PROCESS_ATTACH) { + switch (reason) { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hInstance); TkWinSetHINSTANCE(hInstance); + break; + + case DLL_PROCESS_DETACH: + /* + * Protect the call to TkFinalize in an SEH block. We can't + * be guarenteed Tk is always being unloaded from a stable + * condition. + */ + + __try { + /* + * Run and remove our exit handlers, if they haven't already + * been run. Just in case we are being unloaded prior to + * Tcl (it can happen), we won't leave any dangling pointers + * hanging around for when Tcl gets unloaded later. + */ + + TkFinalize(NULL); + } __except (EXCEPTION_EXECUTE_HANDLER) { + /* empty handler body */ + } + break; } - return (TRUE); + return TRUE; } +#endif /* !STATIC_BUILD */ |