From db003d4a0860516219efe5bcb6624de2c97f8e8b Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Wed, 2 Nov 2016 09:13:49 +0000 Subject: [PATCH] dpnet: Initialize winsock. Signed-off-by: Alistair Leslie-Hughes Signed-off-by: Alexandre Julliard --- dlls/dpnet/Makefile.in | 2 +- dlls/dpnet/client.c | 4 ++++ dlls/dpnet/dpnet_main.c | 43 ++++++++++++++++++++++++++++++++------ dlls/dpnet/dpnet_private.h | 2 ++ dlls/dpnet/lobbiedapp.c | 2 ++ dlls/dpnet/peer.c | 2 ++ dlls/dpnet/server.c | 2 ++ 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/dlls/dpnet/Makefile.in b/dlls/dpnet/Makefile.in index 880b7bdb93b..541e104c64a 100644 --- a/dlls/dpnet/Makefile.in +++ b/dlls/dpnet/Makefile.in @@ -1,6 +1,6 @@ MODULE = dpnet.dll IMPORTLIB = dpnet -IMPORTS = dxguid uuid ole32 advapi32 +IMPORTS = dxguid uuid ole32 advapi32 ws2_32 C_SRCS = \ address.c \ diff --git a/dlls/dpnet/client.c b/dlls/dpnet/client.c index de338d8deef..9692e382cb1 100644 --- a/dlls/dpnet/client.c +++ b/dlls/dpnet/client.c @@ -115,6 +115,8 @@ static HRESULT WINAPI IDirectPlay8ClientImpl_Initialize(IDirectPlay8Client *ifac This->msghandler = pfn; This->flags = dwFlags; + init_winsock(); + return DPN_OK; } @@ -443,6 +445,8 @@ static HRESULT WINAPI lobbyclient_Initialize(IDirectPlay8LobbyClient *iface, voi This->msghandler = msghandler; This->flags = flags; + init_winsock(); + return DPN_OK; } diff --git a/dlls/dpnet/dpnet_main.c b/dlls/dpnet/dpnet_main.c index 042b95a515e..cc80ebc07ab 100644 --- a/dlls/dpnet/dpnet_main.c +++ b/dlls/dpnet/dpnet_main.c @@ -40,15 +40,46 @@ WINE_DEFAULT_DEBUG_CHANNEL(dpnet); static HINSTANCE instance; +static BOOL winsock_loaded = FALSE; + +static BOOL WINAPI winsock_startup(INIT_ONCE *once, void *param, void **context) +{ + WSADATA wsa_data; + DWORD res; + + res = WSAStartup(MAKEWORD(1,1), &wsa_data); + if(res == ERROR_SUCCESS) + winsock_loaded = TRUE; + else + ERR("WSAStartup failed: %u\n", res); + return TRUE; +} + +void init_winsock(void) +{ + static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; + InitOnceExecuteOnce(&init_once, winsock_startup, NULL, NULL); +} + /* At process attach */ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) { - TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved); - if (fdwReason == DLL_PROCESS_ATTACH) { - instance = hInstDLL; - DisableThreadLibraryCalls(hInstDLL); - } - return TRUE; + TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved); + + switch(fdwReason) + { + case DLL_PROCESS_ATTACH: + instance = hInstDLL; + DisableThreadLibraryCalls(hInstDLL); + break; + + case DLL_PROCESS_DETACH: + if (lpvReserved) break; + if(winsock_loaded) + WSACleanup(); + break; + } + return TRUE; } /*********************************************************************** diff --git a/dlls/dpnet/dpnet_private.h b/dlls/dpnet/dpnet_private.h index dc6a4f13cba..89e07770be2 100644 --- a/dlls/dpnet/dpnet_private.h +++ b/dlls/dpnet/dpnet_private.h @@ -26,6 +26,7 @@ #endif #include +#include "winsock2.h" #include "wine/unicode.h" #include "dplay8.h" @@ -135,6 +136,7 @@ extern HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN extern HRESULT DPNET_CreateDirectPlay8LobbyClient(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppobj) DECLSPEC_HIDDEN; extern void init_dpn_sp_caps(DPN_SP_CAPS *dpnspcaps) DECLSPEC_HIDDEN; +extern void init_winsock(void) DECLSPEC_HIDDEN; /* used for generic dumping (copied from ddraw) */ typedef struct { diff --git a/dlls/dpnet/lobbiedapp.c b/dlls/dpnet/lobbiedapp.c index 507a895b0b9..8ec9ad1fa1c 100644 --- a/dlls/dpnet/lobbiedapp.c +++ b/dlls/dpnet/lobbiedapp.c @@ -101,6 +101,8 @@ static HRESULT WINAPI IDirectPlay8LobbiedApplicationImpl_Initialize(IDirectPlay8 This->usercontext = pvUserContext; This->connection = pdpnhConnection; + init_winsock(); + return DPN_OK; } diff --git a/dlls/dpnet/peer.c b/dlls/dpnet/peer.c index 4862e67d864..fe62d59413a 100644 --- a/dlls/dpnet/peer.c +++ b/dlls/dpnet/peer.c @@ -122,6 +122,8 @@ static HRESULT WINAPI IDirectPlay8PeerImpl_Initialize(IDirectPlay8Peer *iface, This->msghandler = pfn; This->flags = dwFlags; + init_winsock(); + return DPN_OK; } diff --git a/dlls/dpnet/server.c b/dlls/dpnet/server.c index cd54ba49e5a..d91822e486c 100644 --- a/dlls/dpnet/server.c +++ b/dlls/dpnet/server.c @@ -118,6 +118,8 @@ static HRESULT WINAPI IDirectPlay8ServerImpl_Initialize(IDirectPlay8Server *ifac This->msghandler = pfn; This->flags = dwFlags; + init_winsock(); + return DPN_OK; }