1 /*****************************************************************************
2 * specific.c: Win32 specific initilization
3 *****************************************************************************
4 * Copyright (C) 2001-2004, 2010 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #include <vlc_common.h>
33 #include "../lib/libvlc_internal.h"
34 #include "config/vlc_getopt.h"
39 static int system_InitWSA(int hi
, int lo
)
43 if (WSAStartup(MAKEWORD(hi
, lo
), &data
) == 0)
45 if (LOBYTE(data
.wVersion
) == 2 && HIBYTE(data
.wVersion
) == 2)
47 /* Winsock DLL is not usable */
54 * Initializes MME timer, Winsock.
56 void system_Init(void)
58 if (system_InitWSA(2, 2) && system_InitWSA(1, 1))
59 fputs("Error: cannot initialize Winsocks\n", stderr
);
62 /*****************************************************************************
63 * system_Configure: check for system specific configuration options.
64 *****************************************************************************/
66 /* Must be same as in modules/control/win_msg.c */
74 void system_Configure( libvlc_int_t
*p_this
, int i_argc
, const char *const ppsz_argv
[] )
77 if( var_InheritBool( p_this
, "one-instance" )
78 || ( var_InheritBool( p_this
, "one-instance-when-started-from-file" )
79 && var_InheritBool( p_this
, "started-from-file" ) ) )
83 msg_Info( p_this
, "one instance mode ENABLED");
85 /* Use a named mutex to check if another instance is already running */
86 if( !( hmutex
= CreateMutex( 0, TRUE
, L
"VLC ipc " TEXT(VERSION
) ) ) )
88 /* Failed for some reason. Just ignore the option and go on as
90 msg_Err( p_this
, "one instance mode DISABLED "
91 "(mutex couldn't be created)" );
95 if( GetLastError() != ERROR_ALREADY_EXISTS
)
97 libvlc_InternalAddIntf( p_this
, "win_msg,none" );
98 /* Initialization done.
99 * Release the mutex to unblock other instances */
100 ReleaseMutex( hmutex
);
104 /* Another instance is running */
108 /* Wait until the 1st instance is initialized */
109 WaitForSingleObject( hmutex
, INFINITE
);
111 /* Locate the window created by the IPC helper thread of the
113 if( !( ipcwindow
= FindWindow( 0, L
"VLC ipc " TEXT(VERSION
) ) ) )
115 msg_Err( p_this
, "one instance mode DISABLED "
116 "(couldn't find 1st instance of program)" );
117 ReleaseMutex( hmutex
);
121 /* We assume that the remaining parameters are filenames
122 * and their input options */
125 COPYDATASTRUCT wm_data
;
127 vlc_ipc_data_t
*p_data
;
128 size_t i_data
= sizeof (*p_data
);
130 for( i_opt
= 0; i_opt
< i_argc
; i_opt
++ )
132 i_data
+= sizeof (size_t);
133 i_data
+= strlen( ppsz_argv
[ i_opt
] ) + 1;
136 p_data
= malloc( i_data
);
137 p_data
->argc
= i_argc
;
138 p_data
->enqueue
= var_InheritBool( p_this
, "playlist-enqueue" );
140 for( i_opt
= 0; i_opt
< i_argc
; i_opt
++ )
142 size_t i_len
= strlen( ppsz_argv
[ i_opt
] ) + 1;
143 /* Windows will never switch to an architecture
144 * with stronger alignment requirements, right. */
145 *((size_t *)(p_data
->data
+ i_data
)) = i_len
;
146 i_data
+= sizeof (size_t);
147 memcpy( &p_data
->data
[i_data
], ppsz_argv
[ i_opt
], i_len
);
150 i_data
+= sizeof (*p_data
);
152 /* Send our playlist items to the 1st instance */
154 wm_data
.cbData
= i_data
;
155 wm_data
.lpData
= p_data
;
156 SendMessage( ipcwindow
, WM_COPYDATA
, 0, (LPARAM
)&wm_data
);
159 /* Initialization done.
160 * Release the mutex to unblock other instances */
161 ReleaseMutex( hmutex
);
172 * Cleans up after system_Init() and system_Configure().
174 void system_End(void)
176 /* XXX: In theory, we should not call this if WSAStartup() failed. */