ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dllmain.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 API
00004  * FILE:        dllmain.c
00005  * PURPOSE:     DLL Entrypoint
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /*
00010  * BUGS:
00011  *       - GetAddrInfoW is completely IPv4 hacked and has some dirty code.
00012  *       - LookupNodeByAddr is missing some IPv6 support.
00013  */
00014 
00015 /* INCLUDES ******************************************************************/
00016 #include "ws2_32.h"
00017 
00018 /* DATA **********************************************************************/
00019 
00020 HANDLE WsSockHeap;
00021 HINSTANCE WsDllHandle;
00022 DWORD GlobalTlsIndex = TLS_OUT_OF_INDEXES;
00023 
00024 /* FUNCTIONS *****************************************************************/
00025 
00026 BOOL
00027 APIENTRY
00028 DllMain(HANDLE hModule,
00029         DWORD dwReason,
00030         LPVOID lpReserved)
00031 {
00032     PWSPROCESS WsProcess;
00033 
00034     /* Main Entrypoint */
00035     switch (dwReason) 
00036     {
00037         case DLL_PROCESS_ATTACH:
00038             /* Save DLL Handle */
00039             WsDllHandle = hModule;
00040 
00041             /* Get Global Heap */
00042             WsSockHeap = GetProcessHeap();
00043 
00044             /* TLS Allocation */
00045             if (GlobalTlsIndex == TLS_OUT_OF_INDEXES)
00046             {
00047                 GlobalTlsIndex = TlsAlloc();
00048                 if (GlobalTlsIndex == TLS_OUT_OF_INDEXES)
00049                 {
00050                     return FALSE;
00051                 }
00052             }
00053 
00054             /* Initialize some critical sections */
00055             WsCreateStartupSynchronization();
00056             WsAsyncGlobalInitialize();
00057             WsRasInitializeAutodial();
00058             break;
00059 
00060         case DLL_THREAD_ATTACH:
00061             break;
00062 
00063         case DLL_THREAD_DETACH:
00064             /* Destroy the attached Winsock Thread */
00065             WsThreadDestroyCurrentThread();
00066             break;
00067 
00068         case DLL_PROCESS_DETACH:
00069             /* Make sure we were initialized */
00070             if (!WsDllHandle) break;
00071 
00072             /* Check if this was a FreeLibrary call (ie: not process cleanup) */
00073             if (lpReserved)
00074             {
00075                 /* Destroy the thread which is exiting */
00076                 WsThreadDestroyCurrentThread();
00077 
00078                 /* Check if we have a process and destroy it */
00079                 WsProcess = WsGetProcess();
00080                 if (WsProcess) WsProcDelete(WsProcess);
00081 
00082                 /* Cleanup the Thread and Socket managers */
00083                 WsThreadCleanup();
00084                 WsSockCleanup();
00085 
00086                 /* Cleanup critical sections */
00087                 WsDestroyStartupSynchronization();
00088                 WsAsyncGlobalTerminate();
00089 
00090                 /* Free the TLS Index */
00091                 TlsFree(GlobalTlsIndex);
00092             }
00093 
00094             /* Cleanup RAS auto-dial helper */
00095             WsRasUninitializeAutodial();
00096 
00097             /* Clear our handle */
00098             WsDllHandle = NULL;
00099             break;
00100     }
00101 
00102     /* Return to OS */
00103     return TRUE;
00104 }
00105 
00106 /*
00107  * @implemented
00108  */
00109 INT
00110 WSAAPI
00111 WSAGetLastError(VOID)
00112 {
00113     /* Let the Windows Function do the work */
00114     return GetLastError();
00115 }
00116 
00117 /*
00118  * @implemented
00119  */
00120 VOID
00121 WSAAPI
00122 WSASetLastError(IN INT iError)
00123 {
00124     /* Let the Windows Function do the work */
00125     SetLastError(iError);
00126 }

Generated on Sat May 26 2012 04:21:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.