home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Varie / server / ENTRY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-04  |  2.0 KB  |  64 lines

  1. #define WIN32_LEAN_AND_MEAN         // the bare essential Win32 API
  2. #include <windows.h>
  3. #include <httpext.h>
  4.  
  5. //
  6. // The DLL's name is used to determine which EXE to launch in
  7. // response to a server request.  In LibMain, the path name of
  8. // the DLL is used to determine the EXE name.  The DLL extension
  9. // is stripped, and an EXE extension is added.
  10. //
  11. // This approach avoids problems when passing in the CGI name from
  12. // the client.  No other programs are allowed to run.  The other approach,
  13. // using one copy of this DLL for all Windows CGI apps introduces the
  14. // ability to run anything.
  15. //
  16. // Other approaches to this problem include using the registry
  17. // or some other untouchable configuration file--untouchable from
  18. // the web client that is.
  19. //
  20.  
  21. //
  22. // DllEntryPoint also allows us to initialize our state variables.
  23. // You might keep state information, as the DLL often remains
  24. // loaded for several client requests.  The server may choose 
  25. // to unload this DLL, and you should save your state to disk,
  26. // and reload it here.  DllEntryPoint is called for both
  27. // loading and unloading.  See the Win32 SDK for more info
  28. // on how DLLs load and unload.
  29. //
  30.  
  31. TCHAR gszAppName[MAX_PATH];
  32.  
  33. BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpv)
  34.     {
  35.     int nLen;
  36.  
  37.     switch (dwReason)
  38.         {
  39.         case DLL_THREAD_ATTACH:
  40.         case DLL_PROCESS_ATTACH:
  41.             {
  42.  
  43.             // Get our DLL's name, abort if this fails
  44.             if (!GetModuleFileName (hinstDLL, gszAppName, MAX_PATH))
  45.                 return TRUE; //return FALSE;
  46.  
  47.             // Strip DLL extension, add EXE extension
  48.             nLen = lstrlen (gszAppName);
  49.             if (nLen > 4)
  50.                 {
  51.                 if (!lstrcmpi (&gszAppName[nLen - 4], TEXT(".DLL")))
  52.                     {
  53.                     gszAppName[nLen - 4] = 0;
  54.                     lstrcat (gszAppName, TEXT(".EXE"));
  55.                     }
  56.                 }
  57.  
  58.             break;
  59.             }
  60.         }
  61.     return TRUE;
  62.     }
  63.  
  64.