]> git.sesse.net Git - vlc/blobdiff - src/win32/specific.c
Win32: correct the 'one-instance' deallocation code
[vlc] / src / win32 / specific.c
index c896be5ab11daa0f22b5a15c6432203d9a85c8ce..93001409be58f00c45d69b6f11af562475fa05f7 100644 (file)
@@ -48,18 +48,23 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
 {
     VLC_UNUSED( p_this ); VLC_UNUSED( pi_argc ); VLC_UNUSED( ppsz_argv );
     WSADATA Data;
+    MEMORY_BASIC_INFORMATION mbi;
 
     /* Get our full path */
     char psz_path[MAX_PATH];
     char *psz_vlc;
 
     wchar_t psz_wpath[MAX_PATH];
-    if( GetModuleFileName( NULL, psz_wpath, MAX_PATH ) )
+    if( VirtualQuery(system_Init, &mbi, sizeof(mbi) ) )
     {
-        WideCharToMultiByte( CP_UTF8, 0, psz_wpath, -1,
-                             psz_path, MAX_PATH, NULL, NULL );
+        HMODULE hMod = (HMODULE) mbi.AllocationBase;
+        if( GetModuleFileName( hMod, psz_wpath, MAX_PATH ) )
+        {
+            WideCharToMultiByte( CP_UTF8, 0, psz_wpath, -1,
+                                psz_path, MAX_PATH, NULL, NULL );
+        }
+        else psz_path[0] = '\0';
     }
-    else psz_path[0] = '\0';
 
     if( (psz_vlc = strrchr( psz_path, '\\' )) ) *psz_vlc = '\0';
 
@@ -153,7 +158,7 @@ void system_Configure( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv
         }
     }
 
-    if( varInheritBool( p_this, "one-instance" )
+    if( var_InheritBool( p_this, "one-instance" )
      || ( var_InheritBool( p_this, "one-instance-when-started-from-file" )
        && var_InheritBool( p_this, "started-from-file" ) ) )
     {
@@ -305,7 +310,11 @@ static unsigned __stdcall IPCHelperThread( void *data )
 LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                                 LPARAM lParam )
 {
-    if( uMsg == WM_COPYDATA )
+    if( uMsg == WM_QUIT  )
+    {
+        PostQuitMessage( 0 );
+    }
+    else if( uMsg == WM_COPYDATA )
     {
         COPYDATASTRUCT *pwm_data = (COPYDATASTRUCT*)lParam;
         vlc_object_t *p_this;
@@ -377,13 +386,16 @@ void system_End( libvlc_int_t *p_this )
         psz_vlcpath = NULL;
     }
 
-    if( ( ipcwindow = FindWindow( 0, L"VLC ipc "VERSION ) ) != 0 )
-    {
-        SendMessage( ipcwindow, WM_QUIT, 0, 0 );
-    }
-
     if (p_helper && p_helper->p_parent == VLC_OBJECT(p_this) )
     {
+        /* this is the first instance (in a one-instance system)
+         * it is the owner of the helper thread
+         */
+        if( ( ipcwindow = FindWindow( 0, L"VLC ipc "VERSION ) ) != 0 )
+        {
+            SendMessage( ipcwindow, WM_QUIT, 0, 0 );
+        }
+
         /* FIXME: thread-safety... */
         vlc_object_detach (p_helper);
         vlc_object_release (p_helper);