2001-01-12 00:32:03 +01:00
|
|
|
#include <cygwin/version.h>
|
|
|
|
#if CYGWIN_VERSION_DLL_MAJOR < 1001
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
/* dllinit.c -- Portable DLL initialization.
|
1999-01-18 13:43:55 +01:00
|
|
|
Copyright (C) 1998 Free Software Foundation, Inc.
|
|
|
|
Contributed by Mumit Khan (khan@xraylith.wisc.edu).
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
I've used DllMain as the DLL "main" since that's the most common
|
1999-01-18 13:43:55 +01:00
|
|
|
usage. MSVC and Mingw32 both default to DllMain as the standard
|
1999-05-25 18:15:34 +02:00
|
|
|
callback from the linker entry point. Cygwin32 b19+ uses essentially
|
1999-01-18 13:43:55 +01:00
|
|
|
the same, albeit slightly differently implemented, scheme. Please
|
1999-05-25 18:15:34 +02:00
|
|
|
see DECLARE_CYGWIN_DLL macro in <cygwin32/cygwin_dll.h> for more
|
1999-01-18 13:43:55 +01:00
|
|
|
info on how Cygwin32 uses the callback function.
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
The real entry point is typically always defined by the runtime
|
|
|
|
library, and usually never overridden by (casual) user. What you can
|
|
|
|
override however is the callback routine that the entry point calls,
|
1999-01-18 13:43:55 +01:00
|
|
|
and this file provides such a callback function, DllMain.
|
|
|
|
|
|
|
|
Mingw32: The default entry point for mingw32 is DllMainCRTStartup
|
|
|
|
which is defined in libmingw32.a This in turn calls DllMain which is
|
|
|
|
defined here. If not defined, there is a stub in libmingw32.a which
|
|
|
|
does nothing.
|
|
|
|
|
|
|
|
Cygwin32: The default entry point for cygwin32 b19 or newer is
|
|
|
|
__cygwin32_dll_entry which is defined in libcygwin.a. This in turn
|
|
|
|
calls the routine you supply to the DECLARE_CYGWIN_DLL (see below)
|
|
|
|
and, for this example, I've chose DllMain to be consistent with all
|
|
|
|
the other platforms.
|
|
|
|
|
|
|
|
MSVC: MSVC runtime calls DllMain, just like Mingw32.
|
|
|
|
|
|
|
|
Summary: If you need to do anything special in DllMain, just add it
|
|
|
|
here. Otherwise, the default setup should be just fine for 99%+ of
|
|
|
|
the time. I strongly suggest that you *not* change the entry point,
|
|
|
|
but rather change DllMain as appropriate.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason,
|
|
|
|
LPVOID reserved /* Not used. */ );
|
1999-01-18 13:43:55 +01:00
|
|
|
|
2000-09-29 15:53:35 +02:00
|
|
|
#ifdef __CYGWIN__
|
1999-01-18 13:43:55 +01:00
|
|
|
|
|
|
|
#include <cygwin/cygwin_dll.h>
|
1999-05-25 18:15:34 +02:00
|
|
|
DECLARE_CYGWIN_DLL(DllMain);
|
1999-01-18 13:43:55 +01:00
|
|
|
/* save hInstance from DllMain */
|
1999-05-25 18:15:34 +02:00
|
|
|
HINSTANCE __hDllInstance_base;
|
1999-01-18 13:43:55 +01:00
|
|
|
|
2000-09-29 15:53:35 +02:00
|
|
|
#endif /* __CYGWIN__ */
|
1999-01-18 13:43:55 +01:00
|
|
|
|
|
|
|
struct _reent *_impure_ptr;
|
|
|
|
|
|
|
|
extern struct _reent *__imp_reent_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*
|
1999-05-25 18:15:34 +02:00
|
|
|
* DllMain
|
1999-01-18 13:43:55 +01:00
|
|
|
*
|
1999-05-25 18:15:34 +02:00
|
|
|
* This routine is called by the Mingw32, Cygwin32 or VC++ C run
|
|
|
|
* time library init code, or the Borland DllEntryPoint routine. It
|
|
|
|
* is responsible for initializing various dynamically loaded
|
1999-01-18 13:43:55 +01:00
|
|
|
* libraries.
|
|
|
|
*
|
|
|
|
* Results:
|
1999-05-25 18:15:34 +02:00
|
|
|
* TRUE on sucess, FALSE on failure.
|
1999-01-18 13:43:55 +01:00
|
|
|
*
|
|
|
|
* Side effects:
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
1999-05-25 18:15:34 +02:00
|
|
|
BOOL APIENTRY
|
|
|
|
DllMain(
|
|
|
|
HINSTANCE hInst /* Library instance handle. */ ,
|
|
|
|
DWORD reason /* Reason this function is being called. */ ,
|
|
|
|
LPVOID reserved /* Not used. */ )
|
1999-01-18 13:43:55 +01:00
|
|
|
{
|
|
|
|
|
2000-09-29 15:53:35 +02:00
|
|
|
#ifdef __CYGWIN__
|
1999-05-25 18:15:34 +02:00
|
|
|
__hDllInstance_base = hInst;
|
2000-09-29 15:53:35 +02:00
|
|
|
#endif /* __CYGWIN__ */
|
1999-05-25 18:15:34 +02:00
|
|
|
|
|
|
|
_impure_ptr = __imp_reent_data;
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
break;
|
1999-01-18 13:43:55 +01:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-01-12 00:32:03 +01:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#endif /* CYGWIN_VERSION_DLL_MAJOR < 1001 */
|