1 /*****************************************************************************
2 * winvlc.c: the Windows VLC media player
3 *****************************************************************************
4 * Copyright (C) 1998-2011 the VideoLAN team
6 * Authors: Vincent Seguin <seguin@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Lots of other people, see the libvlc AUTHORS file
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
35 #if !defined(UNDER_CE)
37 # define _WIN32_IE 0x501
41 # define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
43 static void check_crashdump(void);
44 LONG WINAPI
vlc_exception_filter(struct _EXCEPTION_POINTERS
*lpExceptionInfo
);
49 static char *FromWide (const wchar_t *wide
)
52 len
= WideCharToMultiByte (CP_UTF8
, 0, wide
, -1, NULL
, 0, NULL
, NULL
);
54 char *out
= (char *)malloc (len
);
56 WideCharToMultiByte (CP_UTF8
, 0, wide
, -1, out
, len
, NULL
, NULL
);
60 static int parse_cmdline (char *line
, char ***argvp
)
62 char **argv
= malloc (sizeof (char *));
69 /* Skips white spaces */
70 while (strchr ("\t ", *line
))
75 /* Starts a new parameter */
76 argv
= realloc (argv
, (argc
+ 2) * sizeof (char *));
85 while (*line
&& !strchr ("\t ", *line
))
88 if (line
> argv
[argc
- 1] && line
[-1] == quote
)
89 /* End of quoted parameter */
94 /* Space within a quote */
99 /* End of unquoted parameter */
109 int WINAPI
WinMain( HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
121 putenv("VLC_PLUGIN_PATH=Z:"TOP_BUILDDIR
"/modules");
124 HeapSetInformation(NULL
, HeapEnableTerminationOnCorruption
, NULL
, 0);
126 /* SetProcessDEPPolicy */
127 HINSTANCE h_Kernel32
= LoadLibraryW(L
"kernel32.dll");
130 BOOL (WINAPI
* mySetProcessDEPPolicy
)( DWORD dwFlags
);
131 BOOL (WINAPI
* mySetDllDirectoryA
)(const char* lpPathName
);
132 # define PROCESS_DEP_ENABLE 1
134 mySetProcessDEPPolicy
= (BOOL
WINAPI (*)(DWORD
))
135 GetProcAddress(h_Kernel32
, "SetProcessDEPPolicy");
136 if(mySetProcessDEPPolicy
)
137 mySetProcessDEPPolicy(PROCESS_DEP_ENABLE
);
139 /* Do NOT load any library from cwd. */
140 mySetDllDirectoryA
= (BOOL
WINAPI (*)(const char*)) GetProcAddress(h_Kernel32
, "SetDllDirectoryA");
141 if(mySetDllDirectoryA
)
142 mySetDllDirectoryA("");
144 FreeLibrary(h_Kernel32
);
148 wchar_t **wargv
= CommandLineToArgvW (GetCommandLine (), &argc
);
152 char *argv
[argc
+ 3];
153 BOOL crash_handling
= TRUE
;
156 argv
[j
++] = FromWide( L
"--media-library" );
157 argv
[j
++] = FromWide( L
"--no-ignore-config" );
159 argv
[j
++] = FromWide (L
"--data-path=Z:"TOP_SRCDIR
"/share");
161 for (int i
= 1; i
< argc
; i
++)
163 if(!wcscmp(wargv
[i
], L
"--no-crashdump"))
165 crash_handling
= FALSE
;
166 continue; /* don't give argument to libvlc */
169 argv
[j
++] = FromWide (wargv
[i
]);
177 /* We don't know how to manage crashes on Win64 yet */
181 SetUnhandledExceptionFilter(vlc_exception_filter
);
186 char **argv
, psz_cmdline
[wcslen(lpCmdLine
) * 4];
188 WideCharToMultiByte( CP_UTF8
, 0, lpCmdLine
, -1,
189 psz_cmdline
, sizeof (psz_cmdline
), NULL
, NULL
);
191 argc
= parse_cmdline (psz_cmdline
, &argv
);
194 /* Initialize libvlc */
195 libvlc_instance_t
*vlc
;
196 vlc
= libvlc_new (argc
, (const char **)argv
);
199 libvlc_add_intf (vlc
, "globalhotkeys,none");
200 libvlc_add_intf (vlc
, NULL
);
201 libvlc_playlist_play (vlc
, -1, 0, NULL
);
203 libvlc_release (vlc
);
206 for (int i
= 0; i
< argc
; i
++)
209 (void)hInstance
; (void)hPrevInstance
; (void)lpCmdLine
; (void)nCmdShow
;
213 #if !defined( UNDER_CE ) && !defined( _WIN64 )
214 /* Crashdumps handling */
215 static void get_crashdump_path(wchar_t * wdir
)
217 if( S_OK
!= SHGetFolderPathW( NULL
,
218 CSIDL_APPDATA
| CSIDL_FLAG_CREATE
,
219 NULL
, SHGFP_TYPE_CURRENT
, wdir
) )
220 fprintf( stderr
, "Can't open the vlc conf PATH\n" );
222 swprintf( wdir
+wcslen( wdir
), L
"%s", L
"\\vlc\\crashdump" );
225 static void check_crashdump()
227 wchar_t * wdir
= (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH
);
228 get_crashdump_path(wdir
);
230 FILE * fd
= _wfopen ( wdir
, L
"r, ccs=UTF-8" );
234 int answer
= MessageBox( NULL
, L
"VLC media player just crashed." \
235 " Do you want to send a bug report to the developers team?",
236 L
"VLC crash reporting", MB_YESNO
);
240 HINTERNET Hint
= InternetOpen(L
"VLC Crash Reporter", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
,NULL
,0);
243 HINTERNET ftp
= InternetConnect(Hint
, L
"crash.videolan.org", INTERNET_DEFAULT_FTP_PORT
,
244 NULL
, NULL
, INTERNET_SERVICE_FTP
, 0, 0);
249 wchar_t remote_file
[MAX_PATH
];
250 swprintf( remote_file
, L
"/crashs/%04d%02d%02d%02d%02d%02d",now
.wYear
,
251 now
.wMonth
, now
.wDay
, now
.wHour
, now
.wMinute
, now
.wSecond
);
253 if( FtpPutFile( ftp
, wdir
, remote_file
, FTP_TRANSFER_TYPE_BINARY
, 0) )
254 MessageBox( NULL
, L
"Report sent correctly. Thanks a lot for the help.",
255 L
"Report sent", MB_OK
);
257 MessageBox( NULL
, L
"There was an error while transferring to the FTP server. "\
258 "Thanks a lot for the help anyway.",
259 L
"Report sending failed", MB_OK
);
260 InternetCloseHandle(ftp
);
264 MessageBox( NULL
, L
"There was an error while connecting to the FTP server. "\
265 "Thanks a lot for the help anyway.",
266 L
"Report sending failed", MB_OK
);
267 fprintf(stderr
,"Can't connect to FTP server 0x%08lu\n",
268 (unsigned long)GetLastError());
270 InternetCloseHandle(Hint
);
274 MessageBox( NULL
, L
"There was an error while connecting to Internet. "\
275 "Thanks a lot for the help anyway.",
276 L
"Report sending failed", MB_OK
);
285 /*****************************************************************************
286 * vlc_exception_filter: handles unhandled exceptions, like segfaults
287 *****************************************************************************/
288 LONG WINAPI
vlc_exception_filter(struct _EXCEPTION_POINTERS
*lpExceptionInfo
)
290 if(IsDebuggerPresent())
292 //If a debugger is present, pass the exception to the debugger with EXCEPTION_CONTINUE_SEARCH
293 return EXCEPTION_CONTINUE_SEARCH
;
297 fprintf( stderr
, "unhandled vlc exception\n" );
299 wchar_t * wdir
= (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH
);
300 get_crashdump_path(wdir
);
301 FILE * fd
= _wfopen ( wdir
, L
"w, ccs=UTF-8" );
306 fprintf( stderr
, "\nerror while opening file" );
311 ZeroMemory( &osvi
, sizeof(OSVERSIONINFO
) );
312 osvi
.dwOSVersionInfoSize
= sizeof( OSVERSIONINFO
);
313 GetVersionEx( &osvi
);
315 fwprintf( fd
, L
"[version]\nOS=%d.%d.%d.%d.%s\nVLC=" VERSION_MESSAGE
, osvi
.dwMajorVersion
,
321 const CONTEXT
*const pContext
= (const CONTEXT
*)lpExceptionInfo
->ContextRecord
;
322 const EXCEPTION_RECORD
*const pException
= (const EXCEPTION_RECORD
*)lpExceptionInfo
->ExceptionRecord
;
323 /*No nested exceptions for now*/
324 fwprintf( fd
, L
"\n\n[exceptions]\n%08x at %08x",pException
->ExceptionCode
,
325 pException
->ExceptionAddress
);
326 if( pException
->NumberParameters
> 0 )
329 for( i
= 0; i
< pException
->NumberParameters
; i
++ )
330 fwprintf( fd
, L
" | %08x", pException
->ExceptionInformation
[i
] );
333 fwprintf( fd
, L
"\n\n[context]\nEDI:%08x\nESI:%08x\n" \
334 "EBX:%08x\nEDX:%08x\nECX:%08x\nEAX:%08x\n" \
335 "EBP:%08x\nEIP:%08x\nESP:%08x\n",
336 pContext
->Edi
,pContext
->Esi
,pContext
->Ebx
,
337 pContext
->Edx
,pContext
->Ecx
,pContext
->Eax
,
338 pContext
->Ebp
,pContext
->Eip
,pContext
->Esp
);
340 fwprintf( fd
, L
"\n[stacktrace]\n#EIP|base|module\n" );
342 wchar_t module
[ 256 ];
343 MEMORY_BASIC_INFORMATION mbi
;
344 VirtualQuery( (DWORD
*)pContext
->Eip
, &mbi
, sizeof( mbi
) ) ;
345 HINSTANCE hInstance
= mbi
.AllocationBase
;
346 GetModuleFileName( hInstance
, module
, 256 ) ;
347 fwprintf( fd
, L
"%08x|%s\n", pContext
->Eip
, module
);
349 DWORD pEbp
= pContext
->Ebp
;
350 DWORD caller
= *((DWORD
*)pEbp
+ 1);
355 VirtualQuery( (DWORD
*)caller
, &mbi
, sizeof( mbi
) ) ;
356 HINSTANCE hInstance
= mbi
.AllocationBase
;
357 GetModuleFileName( hInstance
, module
, 256 ) ;
358 fwprintf( fd
, L
"%08x|%s\n", caller
, module
);
359 pEbp
= *(DWORD
*)pEbp
;
360 caller
= *((DWORD
*)pEbp
+ 1) ;
362 /*The last EBP points to NULL!*/
363 }while(caller
&& i_line
< 100);