X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9aee09a34bdeea9a65ecd7258d9e87f44b3d5e25..c829d62b6945c74edaf25210720129b8b749639d:/src/msw/gsockmsw.c diff --git a/src/msw/gsockmsw.c b/src/msw/gsockmsw.c index c966cfffc1..4ff547fe94 100644 --- a/src/msw/gsockmsw.c +++ b/src/msw/gsockmsw.c @@ -7,6 +7,14 @@ * ------------------------------------------------------------------------- */ +/* + * TODO: for WinCE we need to replace WSAAsyncSelect + * (Windows message-based notification of network events for a socket) + * with another mechanism. + * We may need to have a separate thread that polls for socket events + * using select() and sends a message to the main thread. + */ + /* * PLEASE don't put C++ comments here - this is a C source file. */ @@ -16,12 +24,33 @@ * RPCNOTIFICATION_ROUTINE */ #ifdef _MSC_VER -# pragma warning(disable:4115) /* named type definition in parentheses */ +# pragma warning(disable:4115) /* named type definition in parentheses */ +#endif + +/* This needs to be before the wx/defs/h inclusion + * for some reason + */ + +#ifdef __WXWINCE__ + /* windows.h results in tons of warnings at max warning level */ +# ifdef _MSC_VER +# pragma warning(push, 1) + /* + "unreferenced inline function has been removed": this is not + suppressed by push above as it is given at the end of the + compilation unit + */ +# pragma warning(disable:4514) +# endif +# include +# ifdef _MSC_VER +# pragma warning(pop) +# endif #endif #ifndef __GSOCKET_STANDALONE__ -#include "wx/defs.h" -#include "wx/setup.h" +# include "wx/platform.h" +# include "wx/setup.h" #endif #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) @@ -31,6 +60,7 @@ #include "wx/msw/gsockmsw.h" #include "wx/gsocket.h" +HINSTANCE wxGetInstance(void); #define INSTANCE wxGetInstance() #else @@ -46,7 +76,14 @@ #endif /* __GSOCKET_STANDALONE__ */ +#ifndef __WXWINCE__ #include +#else +#define assert(x) +#include +#include "wx/msw/wince/net.h" +#endif + #include #include #include @@ -60,7 +97,10 @@ #endif #define CLASSNAME TEXT("_GSocket_Internal_Window_Class") -#define WINDOWNAME TEXT("_GSocket_Internal_Window_Name") + +/* implemented in utils.cpp */ +extern WXDLLIMPEXP_BASE HWND +wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc); /* Maximum number of different GSocket objects at a given time. * This value can be modified at will, but it CANNOT be greater @@ -72,6 +112,7 @@ #error "MAXSOCKETS is too big!" #endif +typedef int (PASCAL *WSAAsyncSelectFunc)(SOCKET,HWND,u_int,long); /* Global variables */ @@ -80,34 +121,20 @@ static HWND hWin; static CRITICAL_SECTION critical; static GSocket* socketList[MAXSOCKETS]; static int firstAvailable; +static WSAAsyncSelectFunc gs_WSAAsyncSelect = NULL; +static HMODULE gs_wsock32dll = 0; /* Global initializers */ -int GSocket_Init(void) +int _GSocket_GUI_Init(void) { - WSADATA wsaData; - WNDCLASS winClass; + static LPCTSTR pclassname = NULL; int i; /* Create internal window for event notifications */ - winClass.style = 0; - winClass.lpfnWndProc = _GSocket_Internal_WinProc; - winClass.cbClsExtra = 0; - winClass.cbWndExtra = 0; - winClass.hInstance = INSTANCE; - winClass.hIcon = (HICON) NULL; - winClass.hCursor = (HCURSOR) NULL; - winClass.hbrBackground = (HBRUSH) NULL; - winClass.lpszMenuName = (LPCTSTR) NULL; - winClass.lpszClassName = CLASSNAME; - - RegisterClass(&winClass); - hWin = CreateWindow(CLASSNAME, - WINDOWNAME, - 0, 0, 0, 0, 0, - (HWND) NULL, (HMENU) NULL, INSTANCE, (LPVOID) NULL); - - if (!hWin) return FALSE; + hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, _GSocket_Internal_WinProc); + if (!hWin) + return FALSE; /* Initialize socket list */ InitializeCriticalSection(&critical); @@ -118,26 +145,40 @@ int GSocket_Init(void) } firstAvailable = 0; - /* Initialize WinSocket */ - return (WSAStartup((1 << 8) | 1, &wsaData) == 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; } -void GSocket_Cleanup(void) +void _GSocket_GUI_Cleanup(void) { /* Destroy internal window */ DestroyWindow(hWin); UnregisterClass(CLASSNAME, INSTANCE); + /* Unlock wsock32.dll */ + if (gs_wsock32dll) + { + FreeLibrary(gs_wsock32dll); + gs_wsock32dll = 0; + } + /* Delete critical section */ DeleteCriticalSection(&critical); - - /* Cleanup WinSocket */ - WSACleanup(); } /* Per-socket GUI initialization / cleanup */ -int _GSocket_GUI_Init(GSocket *socket) +int _GSocket_GUI_Init_Socket(GSocket *socket) { int i; @@ -164,7 +205,7 @@ int _GSocket_GUI_Init(GSocket *socket) return TRUE; } -void _GSocket_GUI_Destroy(GSocket *socket) +void _GSocket_GUI_Destroy_Socket(GSocket *socket) { /* Remove the socket from the list */ EnterCriticalSection(&critical); @@ -188,7 +229,7 @@ LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd, { EnterCriticalSection(&critical); socket = socketList[(uMsg - WM_USER)]; - event = -1; + event = (GSocketEvent) -1; cback = NULL; data = NULL; @@ -260,7 +301,7 @@ void _GSocket_Enable_Events(GSocket *socket) long lEvent = socket->m_server? 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); } } @@ -273,7 +314,7 @@ void _GSocket_Disable_Events(GSocket *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); } }