wininet: Call WSAStartup/WSACleanup to mime the Windows behavior

Bruno Jesus 00cpxxx at gmail.com
Thu Jul 3 12:28:49 CDT 2014


The application from bug 36830 expects wine to auto start winsock from
inside wininet as Windows does.

Full Anastasius analysis at https://bugs.winehq.org/show_bug.cgi?id=36830#c0
-------------- next part --------------
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index aa58e34..d497c78 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -118,9 +118,13 @@ typedef struct
     LPWSTR proxyPassword;
 } proxyinfo_t;
 
-static ULONG max_conns = 2, max_1_0_conns = 4;
+static ULONG max_conns = 2, max_1_0_conns = 4, winsock_init = 0;
 static ULONG connect_timeout = 60000;
 
+static HMODULE hws2_32;
+static int (WINAPI *pWSAStartup)(DWORD, LPVOID);
+static int (WINAPI *pWSACleanup)(void);
+
 static const WCHAR szInternetSettings[] =
     { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
       'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
@@ -237,6 +241,20 @@ static void invalidate_handle(object_header_t *info)
     WININET_Release(info);
 }
 
+static void init_ws2_32(void)
+{
+    static int once;
+    if (once++) return;
+    hws2_32 = GetModuleHandleA("ws2_32.dll");
+    pWSAStartup = (void *)GetProcAddress(hws2_32, "WSAStartup");
+    pWSACleanup = (void *)GetProcAddress(hws2_32, "WSACleanup");
+}
+
+static void free_ws2_32(void)
+{
+    FreeLibrary(hws2_32);
+}
+
 BOOL WININET_Release( object_header_t *info )
 {
     ULONG refs = InterlockedDecrement(&info->refs);
@@ -329,6 +347,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
             NETCON_unload();
             free_urlcache();
             free_cookie();
+            free_ws2_32();
 
             if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
             {
@@ -1099,8 +1118,15 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
         lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
     }
 
-    TRACE("returning %p\n", lpwai);
+    /* initialize winsock DLL here as expected by some broken applications */
+    if (!winsock_init++)
+    {
+        char buffer[128];
+        init_ws2_32();
+        pWSAStartup(MAKEWORD( 1, 1 ), buffer);
+    }
 
+    TRACE("returning %p\n", lpwai);
     return lpwai->hdr.hInternet;
 }
 
@@ -1485,6 +1511,8 @@ BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
     invalidate_handle(obj);
     WININET_Release(obj);
 
+    if(!(--winsock_init))
+        pWSACleanup();
     return TRUE;
 }
 


More information about the wine-patches mailing list