Applied gsockmsw.c 1.20 to 1.25 changes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2004-07-29 01:40:07 +00:00
parent 79099b80ad
commit 1c8681b4d8

View File

@@ -24,7 +24,7 @@
* RPCNOTIFICATION_ROUTINE * RPCNOTIFICATION_ROUTINE
*/ */
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(disable:4115) /* named type definition in parentheses */ # pragma warning(disable:4115) /* named type definition in parentheses */
#endif #endif
/* This needs to be before the wx/defs/h inclusion /* This needs to be before the wx/defs/h inclusion
@@ -32,7 +32,15 @@
*/ */
#ifdef __WXWINCE__ #ifdef __WXWINCE__
#include <windows.h> /* windows.h results in tons of warnings at max warning level */
# ifdef _MSC_VER
# pragma warning(push, 1)
# endif
# include <windows.h>
# ifdef _MSC_VER
# pragma warning(pop)
# pragma warning(disable:4514)
# endif
#endif #endif
#ifndef __GSOCKET_STANDALONE__ #ifndef __GSOCKET_STANDALONE__
@@ -99,6 +107,7 @@ wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc);
#error "MAXSOCKETS is too big!" #error "MAXSOCKETS is too big!"
#endif #endif
typedef int (PASCAL *WSAAsyncSelectFunc)(SOCKET,HWND,u_int,long);
/* Global variables */ /* Global variables */
@@ -107,6 +116,8 @@ static HWND hWin;
static CRITICAL_SECTION critical; static CRITICAL_SECTION critical;
static GSocket* socketList[MAXSOCKETS]; static GSocket* socketList[MAXSOCKETS];
static int firstAvailable; static int firstAvailable;
static WSAAsyncSelectFunc gs_WSAAsyncSelect = NULL;
static HMODULE gs_wsock32dll = 0;
/* Global initializers */ /* Global initializers */
@@ -129,6 +140,17 @@ int _GSocket_GUI_Init(void)
} }
firstAvailable = 0; firstAvailable = 0;
/* Load WSAAsyncSelect from wsock32.dll (we don't link against it
statically to avoid dependency on wsock32.dll for apps that don't use
sockets): */
gs_wsock32dll = LoadLibraryA("wsock32.dll");
if (!gs_wsock32dll)
return FALSE;
gs_WSAAsyncSelect =(WSAAsyncSelectFunc)GetProcAddress(gs_wsock32dll,
"WSAAsyncSelect");
if (!gs_WSAAsyncSelect)
return FALSE;
return TRUE; return TRUE;
} }
@@ -138,6 +160,13 @@ void _GSocket_GUI_Cleanup(void)
DestroyWindow(hWin); DestroyWindow(hWin);
UnregisterClass(CLASSNAME, INSTANCE); UnregisterClass(CLASSNAME, INSTANCE);
/* Unlock wsock32.dll */
if (gs_wsock32dll)
{
FreeLibrary(gs_wsock32dll);
gs_wsock32dll = 0;
}
/* Delete critical section */ /* Delete critical section */
DeleteCriticalSection(&critical); DeleteCriticalSection(&critical);
} }
@@ -267,7 +296,7 @@ void _GSocket_Enable_Events(GSocket *socket)
long lEvent = socket->m_server? long lEvent = socket->m_server?
FD_ACCEPT : (FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE); FD_ACCEPT : (FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE);
WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, lEvent); gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, lEvent);
} }
} }
@@ -280,7 +309,7 @@ void _GSocket_Disable_Events(GSocket *socket)
if (socket->m_fd != INVALID_SOCKET) if (socket->m_fd != INVALID_SOCKET)
{ {
WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, 0); gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, 0);
} }
} }