home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / odbc / quiktest / dllstub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-21  |  2.5 KB  |  97 lines

  1. //*------------------------------------------------------------------------
  2. //|    File:            DLLSTUB.C
  3. //|
  4. //|    Purpose:        This is a generic module which contains the entry points
  5. //|                        required to compile a DLL.
  6. //*------------------------------------------------------------------------
  7. #include <windows.h>
  8. #include "autotest.h"
  9.  
  10. HINSTANCE        hLoadedInst;
  11.  
  12.  
  13.  
  14. //-------------------------------------------------------------------------
  15. //    For WIN32 programs, there is only one entry point which takes care of
  16. //        everything.  For 16 bit apps, however, there are two entry points,
  17. //        LibMain which is called upon initialization, and WEP which is the
  18. //        windows exit procedure.
  19. //-------------------------------------------------------------------------
  20.  
  21.  
  22. #ifdef WIN32
  23. #include <winnt.h>
  24.  
  25. int EXTFUN TstLibMain(HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
  26. {
  27.     BOOL WINAPI _CRT_INIT(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved);
  28.  
  29.     switch(fdwReason) {
  30.         case DLL_PROCESS_ATTACH:
  31.         case DLL_THREAD_ATTACH:
  32.             hLoadedInst = hInst;
  33.             if(!hLoadedInst || !(_CRT_INIT(hInst, fdwReason, lpReserved)))
  34.                 return FALSE;
  35.             break;
  36.             
  37.         case DLL_PROCESS_DETACH:
  38.         case DLL_THREAD_DETACH:
  39.             if(!(_CRT_INIT(hInst, fdwReason, lpReserved)))
  40.                 return FALSE;
  41.             break;
  42.         }
  43.  
  44.     return TRUE;
  45. }
  46.  
  47. #else
  48.  
  49.  
  50. //*---------------------------------------------------------------------------------
  51. //| LibMain:
  52. //|    This entry point will simply take care of our data segment.
  53. //| Parms:
  54. //|    in            hInst                        Current hInstance (data segment)
  55. //|    in            wDataSeg                    
  56. //|    in            cbHeapSize
  57. //|    in            szCmdLine                Command line arguments
  58. //| Returns:
  59. //|    TRUE if successful, FALSE on a failure
  60. //*---------------------------------------------------------------------------------
  61. int EXTFUN LibMain(HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR szCmdLine)
  62. {
  63.     if(cbHeapSize != 0)
  64.         UnlockData(0);
  65.  
  66.     hLoadedInst = hInst;
  67.  
  68.     return TRUE;
  69. }
  70.  
  71.  
  72.  
  73. //*---------------------------------------------------------------------------------
  74. //| WEP:
  75. //|    This is the windows exit procedure.  We will be passed a flag which
  76. //|        tells us if we are being unloaded by a normal Unload call or if
  77. //|        the system is shutting down.
  78. //| Parms:
  79. //|    int        fParm                        What type of unload?
  80. //| Returns:
  81. //|    TRUE always
  82. //*---------------------------------------------------------------------------------
  83. int EXTFUN WEP(int fParm)
  84. {
  85.     switch (fParm) {
  86.         case WEP_SYSTEM_EXIT:
  87.         case WEP_FREE_DLL:
  88.         default:
  89.             return TRUE;
  90.     }
  91. }
  92.  
  93.  
  94.  
  95. #endif
  96. 
  97.