]> git.sesse.net Git - vlc/blobdiff - src/misc/win32_specific.c
* modules/codec/libmpeg2.c: fixed the "main: cannot delete object with
[vlc] / src / misc / win32_specific.c
index 98d6a852735732b9f0daf126c3f89bad72d1968e..a2e5bbad1bfaea78069fcee7c4634b4240230494 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * win32_specific.c: Win32 specific features 
+ * win32_specific.c: Win32 specific features
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: win32_specific.c,v 1.19 2002/11/10 18:04:24 sam Exp $
+ * $Id: win32_specific.c,v 1.22 2003/03/03 14:21:08 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Gildas Bazin <gbazin@netcourrier.com>
@@ -11,7 +11,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -38,18 +38,69 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
 #if !defined( UNDER_CE )
     WSADATA Data;
-    int i_err;
 
-    /* WinSock Library Init. */
-    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
+    /* Get our full path */
+    if( ppsz_argv[0] )
+    {
+        char psz_path[MAX_PATH];
+        char *psz_vlc;
+
+        GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc );
 
-    if( i_err )
+        if( psz_vlc > psz_path && psz_vlc[-1] == '\\' )
+        {
+            psz_vlc[-1] = '\0';
+            p_this->p_libvlc->psz_vlcpath = strdup( psz_path );
+        }
+        else
+        {
+            p_this->p_libvlc->psz_vlcpath = strdup( "" );
+        }
+    }
+    else
     {
-        fprintf( stderr, "error: can't initiate WinSocks, error %i\n", i_err );
+        p_this->p_libvlc->psz_vlcpath = strdup( "" );
     }
 
     /* Set the default file-translation mode */
     _fmode = _O_BINARY;
+
+    /* WinSock Library Init. */
+    if( !WSAStartup( MAKEWORD( 2, 0 ), &Data ) )
+    {
+        /* Confirm that the WinSock DLL supports 2.0.*/
+        if( LOBYTE( Data.wVersion ) != 2 || HIBYTE( Data.wVersion ) != 0 )
+        {
+            /* We could not find a suitable WinSock DLL. */
+            WSACleanup( );
+        }
+        else
+        {
+            /* Everything went ok. */
+            return;
+        }
+    }
+
+    /* Let's try with WinSock 1.1 */
+    if( !WSAStartup( MAKEWORD( 1, 1 ), &Data ) )
+    {
+        /* Confirm that the WinSock DLL supports 1.1.*/
+        if( LOBYTE( Data.wVersion ) != 1 || HIBYTE( Data.wVersion ) != 1 )
+        {
+            /* We could not find a suitable WinSock DLL. */
+            WSACleanup( );
+        }
+        else
+        {
+            /* Everything went ok. */
+            return;
+        }
+    }
+
+    fprintf( stderr, "error: can't initialize WinSocks\n" );
+
+    return; 
+
 #endif
 }