]> git.sesse.net Git - vlc/blobdiff - src/misc/win32_specific.c
* prepare 0.8.2-test3
[vlc] / src / misc / win32_specific.c
index ee248fc81cc94aaba494e1b95d261907226efeb2..4ce7914d00fcba48e968ccc9f4ba59c485a4ee98 100644 (file)
@@ -2,10 +2,10 @@
  * win32_specific.c: Win32 specific features
  *****************************************************************************
  * Copyright (C) 2001-2004 VideoLAN
- * $Id: win32_specific.c,v 1.34 2004/01/29 19:38:17 gbazin Exp $
+ * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
- *          Gildas Bazin <gbazin@netcourrier.com>
+ *          Gildas Bazin <gbazin@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
 #include <stdlib.h>                                                /* free() */
 
 #include <vlc/vlc.h>
+#include <vlc/input.h>
 #include "vlc_playlist.h"
 
 #ifdef WIN32                       /* optind, getopt(), included in unistd.h */
 #if !defined( UNDER_CE )
 #   include <io.h>
 #   include <fcntl.h>
-#   include <winsock2.h>
 #endif
 
+#include <winsock.h>
+
 /*****************************************************************************
  * system_Init: initialize winsock and misc other things.
  *****************************************************************************/
 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
-#if !defined( UNDER_CE )
     WSADATA Data;
 
     /* Get our full path */
-    if( ppsz_argv[0] )
+    char psz_path[MAX_PATH];
+    char *psz_vlc;
+
+#if defined( UNDER_CE )
+    wchar_t psz_wpath[MAX_PATH];
+    if( GetModuleFileName( NULL, psz_wpath, MAX_PATH ) )
     {
-        char psz_path[MAX_PATH];
-        char *psz_vlc;
+        WideCharToMultiByte( CP_ACP, 0, psz_wpath, -1,
+                             psz_path, MAX_PATH, NULL, NULL );
+    }
+    else psz_path[0] = '\0';
 
+#else
+    if( ppsz_argv[0] )
+    {
         GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc );
-
-        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
+    else if( !GetModuleFileName( NULL, psz_path, MAX_PATH ) )
     {
-        p_this->p_libvlc->psz_vlcpath = strdup( "" );
+        psz_path[0] = '\0';
     }
+#endif
+
+    if( (psz_vlc = strrchr( psz_path, '\\' )) ) *psz_vlc = '\0';
+
+    p_this->p_libvlc->psz_vlcpath = strdup( psz_path );
 
     /* Set the default file-translation mode */
+#if !defined( UNDER_CE )
     _fmode = _O_BINARY;
     _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
+#endif
 
     /* Call mdate() once to make sure it is initialized properly */
     mdate();
@@ -110,8 +118,6 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
     fprintf( stderr, "error: can't initialize WinSocks\n" );
 
     return;
-
-#endif
 }
 
 /*****************************************************************************
@@ -150,7 +156,7 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
         msg_Info( p_this, "one instance mode ENABLED");
 
         /* Use a named mutex to check if another instance is already running */
-        if( ( hmutex = CreateMutex( NULL, TRUE, "VLC ipc "VERSION ) ) == NULL )
+        if( !( hmutex = CreateMutex( 0, TRUE, _T("VLC ipc ") _T(VERSION) ) ) )
         {
             /* Failed for some reason. Just ignore the option and go on as
              * normal. */
@@ -189,8 +195,7 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 
             /* Locate the window created by the IPC helper thread of the
              * 1st instance */
-            if( ( ipcwindow = FindWindow( NULL, "VLC ipc "VERSION ) )
-                == NULL )
+            if( !( ipcwindow = FindWindow( 0, _T("VLC ipc ") _T(VERSION) ) ) )
             {
                 msg_Err( p_this, "one instance mode DISABLED "
                          "(couldn't find 1st instance of program)" );
@@ -251,8 +256,8 @@ static void IPCHelperThread( vlc_object_t *p_this )
     MSG message;
 
     ipcwindow =
-        CreateWindow( "STATIC",                      /* name of window class */
-                  "VLC ipc "VERSION,                /* window title bar text */
+        CreateWindow( _T("STATIC"),                  /* name of window class */
+                  _T("VLC ipc ") _T(VERSION),       /* window title bar text */
                   0,                                         /* window style */
                   0,                                 /* default X coordinate */
                   0,                                 /* default Y coordinate */
@@ -345,7 +350,5 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
  *****************************************************************************/
 void system_End( vlc_t *p_this )
 {
-#if !defined( UNDER_CE )
     WSACleanup();
-#endif
 }