This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Initializing a dll question / advise wanted
- From: "Joost Kraaijeveld" <J dot Kraaijeveld at Askesis dot nl>
- To: <cygwin at cygwin dot com>
- Date: Tue, 4 Nov 2003 19:04:52 +0100
- Subject: Initializing a dll question / advise wanted
Hi all,
I need to load two dll's and each dll must, upon loading, initialize a data structure. Both dll's must run on Windows 2000 and Linux. I have written some small code that should do the trick (see below). At this moment I make a distinction between Cygwin/MinGW on Windows and GCC on Linux.
My questions:
1. Is this distinction needed or should it work the same (Linux) way for all three compilers?
2. If so, is the unloading of the dll's in the reverse order of loading and is that guaranteed somehow (that is, can I depend on it)?
3. If the distinction is needed, does Cygwin behave as GCC on Linux or does it behave as MinGW?
TIA
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
email: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl
/// Source file
#ifndef DllMain_hpp
#define DllMain_hpp
static void attachDll(unsigned long anArg);
static void detachDll(unsigned long anArg);
#if defined (__MINGW32__) || defined (__CYGWIN32__)
#warning "This must be Windows"
#include <windows.h>
extern "C" BOOL APIENTRY DllMain( HINSTANCE hInst,
DWORD reason,
LPVOID reserved )
{
switch(reason )
{
case DLL_PROCESS_ATTACH:
{
attachDll(0);
break;
}
case DLL_PROCESS_DETACH:
{
detachDll(0);
break;
}
}
return TRUE;
}
#else // linux
static void DllMainAttach() __attribute__((constructor));
static void DllMainDetach() __attribute__((destructor));
static void DllMainAttach()
{
attachDll(1);
}
static void DllMainDetach()
{
detachDll(1);
}
#endif // defined (__MINGW32__) || defined (__CYGWIN32__)
#endif // DllMain_hpp
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/