Check all Callouts function pointers for NULL before using them.
[wine] / miscemu / main.c
1 /*
2  * Emulator initialisation code
3  *
4  */
5
6 #include "winbase.h"
7 #include "wine/winbase16.h"
8 #include "wingdi.h"
9 #include "winuser.h"
10
11 #include "callback.h"
12 #include "options.h"
13 #include "dosexe.h"
14 #include "process.h"
15 #include "debugtools.h"
16
17 /***********************************************************************
18  *           Main loop of initial task
19  */
20 void wine_initial_task(void)
21 {
22     MSG msg;
23     HINSTANCE16 instance;
24     STARTUPINFOA info;
25
26     if (!LoadLibraryA( "user32.dll" ))
27     {
28         MESSAGE( "Cannot load user32.dll\n" );
29         ExitProcess( GetLastError() );
30     }
31     THUNK_InitCallout();
32
33     GetStartupInfoA( &info );
34     if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = SW_SHOWNORMAL;
35
36     if ((instance = WinExec16( GetCommandLineA(), info.wShowWindow )) < 32)
37     {
38         if (instance == 11)  /* try DOS format */
39         {
40             MZ_LoadImage( GetCommandLineA() );
41             /* if we get back here it failed */
42             instance = GetLastError();
43         }
44
45         MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() );
46         switch (instance) 
47         {
48         case  2: MESSAGE("file not found\n" ); break;
49         case 11: MESSAGE("invalid exe file\n" ); break;
50         default: MESSAGE("error=%d\n", instance ); break;
51         }
52         ExitProcess(instance);
53     }
54
55     /* Start message loop for desktop window */
56
57     while ( GetNumTasks16() > 1  && Callout.GetMessageA( &msg, 0, 0, 0 ) )
58     {
59         Callout.TranslateMessage( &msg );
60         Callout.DispatchMessageA( &msg );
61     }
62
63     ExitProcess( 0 );
64 }
65
66
67 /**********************************************************************
68  *           main
69  */
70 int main( int argc, char *argv[] )
71 {
72     PROCESS_InitWine( argc, argv );
73     return 1;  /* not reached */
74 }