home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / delayimp.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  6KB  |  156 lines

  1. /****************************************************************************
  2.  * filename - DelayImp.h
  3.  *
  4.  *   structures and prototypes necessary for delay loading of imports.
  5.  *   Delay loading of DLL imports is selected when building a module by
  6.  *
  7.  *
  8.  *  This technology supports delayed loading of DLLs for arbitrary images.
  9.  *
  10.  *  Restrictions:
  11.  *      You cannot delay loading of a reference to imported data.
  12.  *      You cannot delay loading of KERNEL32.DLL.
  13.  *      You cannot delay loading of the RTLDLL (since these routines need
  14.  *        to be present to support delayed loading).
  15.  *      You must be very careful with using __FUnloadDelayLoadedDLL in a
  16.  *          multithreaded environment.  It is possible to cause problems
  17.  *          if one thread gets a delay loaded function address from this
  18.  *          module, at the same time as another thread unloads the delayed
  19.  *          load DLL.  There is no way for us to guard against that, so
  20.  *          the user has to be aware of the possibility.
  21.  *
  22.  *  Notes:
  23.  *      TLS support works for delayed load DLLs with Borland tools, as we
  24.  *      have worked around the OS restrictions of handling TLS variables in
  25.  *      dynamically loaded DLLs.
  26.  *
  27.  ****************************************************************************/
  28.  
  29. /*
  30.  *      C/C++ Run Time Library - Version 10.0
  31.  *
  32.  *      Copyright (c) 1999, 2000 by Inprise Corporation
  33.  *      All Rights Reserved.
  34.  *
  35.  */
  36.  
  37. /* $Revision:   9.4  $ */
  38.  
  39. #ifndef __DELAYIMP_H
  40. #define __DELAYIMP_H
  41.  
  42. #include <windows.h>
  43.  
  44. #ifdef  __cplusplus
  45. extern "C" {
  46. #endif
  47.  
  48. typedef struct ImgDelayDescr
  49. {
  50.     DWORD               grAttrs;        /* attributes                        */
  51.     LPCSTR              szName;         /* pointer to dll name               */
  52.     HMODULE             hmod;           /* address of module handle          */
  53.     IMAGE_THUNK_DATA *  pIAT;           /* address of the IAT                */
  54.     IMAGE_THUNK_DATA *  pINT;           /* address of the INT                */
  55.     IMAGE_THUNK_DATA *  pBoundIAT;      /* address of the optional bound IAT */
  56.     IMAGE_THUNK_DATA *  pUnloadIAT;     /* address of optional copy of
  57.                                            original IAT                      */
  58.     DWORD               dwTimeStamp;    /* 0 if not bound,                   */
  59.                                         /* O.W. date/time stamp of DLL bound
  60.                                            to (Old BIND)                     */
  61. }   ImgDelayDescr;
  62.  
  63. /* Delay load import hook notifications */
  64.  
  65. typedef enum
  66. {
  67.     dliNoteStartProcessing,        /* used to bypass or note helper only     */
  68.     dliNotePreLoadLibrary,         /* called just before LoadLibrary, can    */
  69.                                    /*  override w/ new HMODULE return val    */
  70.     dliNotePreGetProcAddress,      /* called just before GetProcAddress, can */
  71.                                    /*  override w/ new FARPROC return value  */
  72.     dliFailLoadLibrary,            /* failed to load library, fix it by      */
  73.                                    /*  returning a valid HMODULE             */
  74.     dliFailGetProcAddress,         /* failed to get proc address, fix it by  */
  75.                                    /*  returning a valid FARPROC             */
  76.     dliNoteEndProcessing,          /* called after all processing is done,   */
  77.                                    /*  no bypass possible at this point      */
  78.                                    /*  except by longjmp(), throw(), or
  79.                                        RaiseException.                       */
  80. } dliNotification;
  81.  
  82. typedef struct DelayLoadProc
  83. {
  84.     BOOL                fImportByName;
  85.     union
  86.     {
  87.         LPCSTR          szProcName;
  88.         DWORD           dwOrdinal;
  89.     };
  90. } DelayLoadProc;
  91.  
  92. typedef struct DelayLoadInfo
  93. {
  94.     DWORD                   cb;         /* size of structure                 */
  95.     const ImgDelayDescr *   pidd;       /* raw form of data (everything is
  96.                                            there)                            */
  97.     FARPROC *               ppfn;       /* points to address of function to
  98.                                            load                              */
  99.     LPCSTR                  szDll;      /* name of dll                       */
  100.     DelayLoadProc           dlp;        /* name or ordinal of procedure      */
  101.     HMODULE                 hmodCur;    /* the hInstance of the library we
  102.                                            have loaded                       */
  103.     FARPROC                 pfnCur;     /* the actual function that will be
  104.                                            called                            */
  105.     DWORD                   dwLastError;/* error received (if an error
  106.                                            notification)                     */
  107. } DelayLoadInfo, *PDelayLoadInfo;
  108.  
  109. typedef FARPROC (WINAPI *DelayedLoadHook)(
  110.     dliNotification dliNotify,
  111.     DelayLoadInfo * pdli
  112. );
  113.  
  114. /* Unload support */
  115.  
  116. /* routine definition; takes a pointer to a name to unload, or NULL to
  117.    unload all the delay load dlls in the list.
  118.  */
  119.  
  120. BOOL WINAPI __FUnloadDelayLoadedDLL(LPCSTR szDll);
  121.  
  122. /* Hook pointers */
  123.  
  124. /* The "notify hook" gets called for every call to the
  125.    delay load helper.  This allows a user to hook every call and
  126.    skip the delay load helper entirely.
  127.  
  128.    dliNotify ==
  129.    {
  130.        dliNoteStartProcessing   |
  131.        dliNotePreLoadLibrary    |
  132.        dliNotePreGetProcAddress |
  133.        dliNoteEndProcessing
  134.    }
  135.  
  136.    on this call.
  137.  */
  138. extern DelayedLoadHook _EXPDATA __pfnDliNotifyHook;
  139.  
  140. /* This is the failure hook,
  141.  
  142.    dliNotify ==
  143.    {
  144.        dliFailLoadLibrary       |
  145.        dliFailGetProcAddress
  146.    }
  147. */
  148. extern DelayedLoadHook _EXPDATA __pfnDliFailureHook;
  149.  
  150. #ifdef  __cplusplus
  151. }
  152. #endif
  153.  
  154. #endif /* __DELAYIMP_H */
  155.  
  156.