Alistair Leslie-Hughes : dpnet: Initialize winsock.

Alexandre Julliard julliard at winehq.org
Thu Nov 3 14:26:20 CDT 2016


Module: wine
Branch: master
Commit: db003d4a0860516219efe5bcb6624de2c97f8e8b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=db003d4a0860516219efe5bcb6624de2c97f8e8b

Author: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date:   Wed Nov  2 09:13:49 2016 +0000

dpnet: Initialize winsock.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 880b7bd..541e104 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 de338d8..9692e38 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 042b95a..cc80ebc 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 dc6a4f1..89e0777 100644
--- a/dlls/dpnet/dpnet_private.h
+++ b/dlls/dpnet/dpnet_private.h
@@ -26,6 +26,7 @@
 #endif
 
 #include <wine/list.h>
+#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 507a895..8ec9ad1 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 4862e67..fe62d59 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 cd54ba4..d91822e 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;
 }
 




More information about the wine-cvs mailing list