"Fossies" - the Fresh Open Source Software Archive

Member "usr/include/cygwin/cygwin_dll.h" (19 Aug 2019, 3019 Bytes) of package /windows/misc/cygwin-20190819-x86.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* cygwin_dll.h
    2 
    3 This file is part of Cygwin.
    4 
    5 This software is a copyrighted work licensed under the terms of the
    6 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
    7 details. */
    8 
    9 #ifndef __CYGWIN_CYGWIN_DLL_H__
   10 #define __CYGWIN_CYGWIN_DLL_H__
   11 
   12 #include <windows.h>
   13 
   14 #ifdef __cplusplus
   15 #define CDECL_BEGIN extern "C" {
   16 #define CDECL_END }
   17 #else
   18 #define CDECL_BEGIN
   19 #define CDECL_END
   20 #endif
   21 
   22 #define DECLARE_CYGWIN_DLL(Entry)                         \
   23                                           \
   24 CDECL_BEGIN                                   \
   25   int WINAPI Entry (HINSTANCE h, DWORD reason, void *ptr);                \
   26   typedef int (*mainfunc) (int, char **, char **);                \
   27   extern PVOID cygwin_attach_dll (HMODULE, mainfunc);                 \
   28   extern void cygwin_detach_dll (PVOID);                      \
   29 CDECL_END                                     \
   30                                           \
   31 static HINSTANCE storedHandle;                            \
   32 static DWORD storedReason;                            \
   33 static void* storedPtr;                               \
   34 int __dynamically_loaded;                             \
   35                                           \
   36 static int __dllMain (int a __attribute__ ((__unused__)),             \
   37               char **b __attribute__ ((__unused__)),              \
   38               char **c __attribute__ ((__unused__)))              \
   39 {                                         \
   40   return Entry (storedHandle, storedReason, storedPtr);                   \
   41 }                                         \
   42                                           \
   43 static PVOID dll_index;                               \
   44                                           \
   45 int WINAPI _cygwin_dll_entry (HINSTANCE h, DWORD reason, void *ptr)       \
   46 {                                         \
   47   int ret;                                    \
   48   ret = 1;                                    \
   49                                           \
   50   switch (reason)                                 \
   51   {                                       \
   52     case DLL_PROCESS_ATTACH:                              \
   53     {                                         \
   54       storedHandle = h;                               \
   55       storedReason = reason;                              \
   56       storedPtr = ptr;                                \
   57       __dynamically_loaded = (ptr == NULL);                   \
   58       dll_index = cygwin_attach_dll (h, &__dllMain);                  \
   59       if (dll_index == (PVOID) -1)                        \
   60     ret = 0;                                  \
   61     }                                         \
   62     break;                                    \
   63                                           \
   64     case DLL_PROCESS_DETACH:                              \
   65     {                                         \
   66       ret = Entry (h, reason, ptr);                       \
   67       if (ret)                                    \
   68       {                                       \
   69     cygwin_detach_dll (dll_index);                        \
   70     dll_index = (PVOID) -1;                           \
   71       }                                       \
   72     }                                         \
   73     break;                                    \
   74                                           \
   75     case DLL_THREAD_ATTACH:                           \
   76     {                                         \
   77       ret = Entry (h, reason, ptr);                       \
   78     }                                         \
   79     break;                                    \
   80                                           \
   81     case DLL_THREAD_DETACH:                           \
   82     {                                         \
   83       ret = Entry (h, reason, ptr);                       \
   84     }                                         \
   85     break;                                    \
   86   }                                       \
   87   return ret;                                     \
   88 }                                         \
   89                                           \
   90 /* OBSOLETE: This is only provided for source level compatibility. */         \
   91 int WINAPI _cygwin_noncygwin_dll_entry (HINSTANCE h, DWORD reason, void *ptr) \
   92 {                                         \
   93   return _cygwin_dll_entry (h, reason, ptr);                      \
   94 }                                         \
   95 
   96 #endif /* __CYGWIN_CYGWIN_DLL_H__ */