1 /*****************************************************************************
2 * winvlc.c: the Windows VLC player
3 *****************************************************************************
4 * Copyright (C) 1998-2008 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 *****************************************************************************/
38 #if !defined(UNDER_CE)
40 # define _WIN32_IE 0x501
43 # include <tlhelp32.h>
46 static void check_crashdump(void);
47 LONG WINAPI
vlc_exception_filter(struct _EXCEPTION_POINTERS
*lpExceptionInfo
);
49 #define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
53 static char *FromWide (const wchar_t *wide
)
56 len
= WideCharToMultiByte (CP_UTF8
, 0, wide
, -1, NULL
, 0, NULL
, NULL
);
58 char *out
= (char *)malloc (len
);
60 WideCharToMultiByte (CP_UTF8
, 0, wide
, -1, out
, len
, NULL
, NULL
);
64 static int parse_cmdline (char *line
, char ***argvp
)
66 char **argv
= malloc (sizeof (char *));
73 /* Skips white spaces */
74 while (strchr ("\t ", *line
))
79 /* Starts a new parameter */
80 argv
= realloc (argv
, (argc
+ 2) * sizeof (char *));
89 while (*line
&& !strchr ("\t ", *line
))
92 if (line
> argv
[argc
- 1] && line
[-1] == quote
)
93 /* End of quoted parameter */
98 /* Space within a quote */
103 /* End of unquoted parameter */
113 int WINAPI
WinMain( HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
123 HeapSetInformation(NULL
, HeapEnableTerminationOnCorruption
, NULL
, 0);
125 HINSTANCE h_Kernel32
= LoadLibraryW(L
"kernel32.dll");
128 BOOL (WINAPI
* mySetProcessDEPPolicy
)( DWORD dwFlags
);
129 # define PROCESS_DEP_ENABLE 1
131 mySetProcessDEPPolicy
= (BOOL
WINAPI (*)(DWORD
))
132 GetProcAddress(h_Kernel32
, "SetProcessDEPPolicy");
133 if(mySetProcessDEPPolicy
)
134 mySetProcessDEPPolicy(PROCESS_DEP_ENABLE
);
135 FreeLibrary(h_Kernel32
);
138 wchar_t **wargv
= CommandLineToArgvW (GetCommandLine (), &argc
);
142 char *argv
[argc
+ 1];
143 BOOL crash_handling
= TRUE
;
146 argv
[j
++] = FromWide( L
"--no-ignore-config" );
147 for (int i
= 1; i
< argc
; i
++)
149 if(!wcscmp(wargv
[i
], L
"--no-crashdump"))
151 crash_handling
= FALSE
;
155 argv
[j
] = FromWide (wargv
[i
]);
168 SetUnhandledExceptionFilter(vlc_exception_filter
);
173 char **argv
, psz_cmdline
[wcslen(lpCmdLine
) * 4];
175 WideCharToMultiByte( CP_UTF8
, 0, lpCmdLine
, -1,
176 psz_cmdline
, sizeof (psz_cmdline
), NULL
, NULL
);
178 argc
= parse_cmdline (psz_cmdline
, &argv
);
181 /* Initialize libvlc */
182 libvlc_instance_t
*vlc
;
183 vlc
= libvlc_new (argc
, (const char **)argv
);
186 libvlc_add_intf (vlc
, "globalhotkeys,none");
187 libvlc_add_intf (vlc
, NULL
);
188 libvlc_playlist_play (vlc
, -1, 0, NULL
);
190 libvlc_release (vlc
);
193 for (int i
= 0; i
< argc
; i
++)
196 (void)hInstance
; (void)hPrevInstance
; (void)lpCmdLine
; (void)nCmdShow
;
200 #if !defined( UNDER_CE ) && !defined( _WIN64 )
202 static void get_crashdump_path(wchar_t * wdir
)
204 if( S_OK
!= SHGetFolderPathW( NULL
,
205 CSIDL_APPDATA
| CSIDL_FLAG_CREATE
,
206 NULL
, SHGFP_TYPE_CURRENT
, wdir
) )
207 fprintf( stderr
, "Can't open the vlc conf PATH\n" );
209 swprintf( wdir
+wcslen( wdir
), L
"%s", L
"\\vlc\\crashdump" );
212 static void check_crashdump()
214 wchar_t * wdir
= (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH
);
215 get_crashdump_path(wdir
);
217 FILE * fd
= _wfopen ( wdir
, L
"r, ccs=UTF-8" );
221 int answer
= MessageBox( NULL
, L
"VLC media player just crashed." \
222 " Do you want to send a bug report to the developers team?",
223 L
"VLC crash reporting", MB_YESNO
);
227 HINTERNET Hint
= InternetOpen(L
"VLC Crash Reporter", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
,NULL
,0);
230 HINTERNET ftp
= InternetConnect(Hint
, L
"crash.videolan.org", INTERNET_DEFAULT_FTP_PORT
,
231 NULL
, NULL
, INTERNET_SERVICE_FTP
, 0, 0);
236 wchar_t remote_file
[MAX_PATH
];
237 swprintf( remote_file
, L
"/crashs/%04d%02d%02d%02d%02d%02d",now
.wYear
,
238 now
.wMonth
, now
.wDay
, now
.wHour
, now
.wMinute
, now
.wSecond
);
240 FtpPutFile( ftp
, wdir
, remote_file
, FTP_TRANSFER_TYPE_BINARY
, 0);
241 InternetCloseHandle(ftp
);
244 fprintf(stderr
,"Can't connect to FTP server%d\n",GetLastError());
245 InternetCloseHandle(Hint
);
254 /*****************************************************************************
255 * vlc_exception_filter: handles unhandled exceptions, like segfaults
256 *****************************************************************************/
257 LONG WINAPI
vlc_exception_filter(struct _EXCEPTION_POINTERS
*lpExceptionInfo
)
259 if(IsDebuggerPresent())
261 //If a debugger is present, pass the exception to the debugger with EXCEPTION_CONTINUE_SEARCH
262 return EXCEPTION_CONTINUE_SEARCH
;
266 fprintf( stderr
, "unhandled vlc exception\n" );
268 wchar_t * wdir
= (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH
);
269 get_crashdump_path(wdir
);
270 FILE * fd
= _wfopen ( wdir
, L
"w, ccs=UTF-8" );
275 fprintf( stderr
, "\nerror while opening file" );
280 ZeroMemory( &osvi
, sizeof(OSVERSIONINFO
) );
281 osvi
.dwOSVersionInfoSize
= sizeof( OSVERSIONINFO
);
282 GetVersionEx( &osvi
);
284 fwprintf( fd
, L
"[version]\nOS=%d.%d.%d.%d.%s\nVLC=" VERSION_MESSAGE
, osvi
.dwMajorVersion
,
290 const CONTEXT
*const pContext
= (const CONTEXT
*)lpExceptionInfo
->ContextRecord
;
291 const EXCEPTION_RECORD
*const pException
= (const EXCEPTION_RECORD
*)lpExceptionInfo
->ExceptionRecord
;
292 /*No nested exceptions for now*/
293 fwprintf( fd
, L
"\n\n[exceptions]\n%08x at %08x",pException
->ExceptionCode
,
294 pException
->ExceptionAddress
);
295 if( pException
->NumberParameters
> 0 )
298 for( i
= 0; i
< pException
->NumberParameters
; i
++ )
299 fprintf( fd
, " | %08x", pException
->ExceptionInformation
[i
] );
302 fwprintf( fd
, L
"\n\n[context]\nEDI:%08x\nESI:%08x\n" \
303 "EBX:%08x\nEDX:%08x\nECX:%08x\nEAX:%08x\n" \
304 "EBP:%08x\nEIP:%08x\nESP:%08x\n",
305 pContext
->Edi
,pContext
->Esi
,pContext
->Ebx
,
306 pContext
->Edx
,pContext
->Ecx
,pContext
->Eax
,
307 pContext
->Ebp
,pContext
->Eip
,pContext
->Esp
);
309 fwprintf( fd
, L
"\n[stacktrace]\n#EIP|base|module\n" );
311 wchar_t module
[ 256 ];
312 MEMORY_BASIC_INFORMATION mbi
;
313 VirtualQuery( (DWORD
*)pContext
->Eip
, &mbi
, sizeof( mbi
) ) ;
314 HINSTANCE hInstance
= mbi
.AllocationBase
;
315 GetModuleFileName( hInstance
, module
, 256 ) ;
316 fwprintf( fd
, L
"%08x|%s\n", pContext
->Eip
, module
);
318 DWORD pEbp
= pContext
->Ebp
;
319 DWORD caller
= *((DWORD
*)pEbp
+ 1);
323 VirtualQuery( (DWORD
*)caller
, &mbi
, sizeof( mbi
) ) ;
324 HINSTANCE hInstance
= mbi
.AllocationBase
;
325 GetModuleFileName( hInstance
, module
, 256 ) ;
326 fwprintf( fd
, L
"%08x|%s\n", caller
, module
);
327 pEbp
= *(DWORD
*)pEbp
;
328 caller
= *((DWORD
*)pEbp
+ 1) ;
329 /*The last EBP points to NULL!*/