Release 970112
[wine/multimedia.git] / library / winestub.c
blobd1c53e6a1cc7093ac0f24d5d0d76f3d84509354f
1 /* Sample winestub.c file for compiling programs with libwine.so. */
3 #include <string.h>
4 #include "windows.h"
5 #include "xmalloc.h"
7 extern int WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
8 extern int MAIN_Init(void);
9 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
10 extern void TASK_Reschedule(void);
12 int main( int argc, char *argv [] )
14 HINSTANCE16 hInstance;
15 LPSTR lpszCmdParam;
16 int i, len = 0;
18 MAIN_WineInit( &argc, argv );
20 /* Alloc szCmdParam */
21 for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1;
22 lpszCmdParam = (LPSTR) xmalloc(len + 1);
23 /* Concatenate arguments */
24 if (argc > 1) strcpy(lpszCmdParam, argv[1]);
25 else lpszCmdParam[0] = '\0';
26 for (i = 2; i < argc; i++) strcat(strcat(lpszCmdParam, " "), argv[i]);
28 if(!MAIN_Init()) return 0; /* JBP: Needed for DosDrives[] structure, etc. */
29 hInstance = WinExec32( *argv, SW_SHOWNORMAL );
30 TASK_Reschedule();
31 InitApp( hInstance );
33 return WinMain (hInstance, /* hInstance */
34 0, /* hPrevInstance */
35 lpszCmdParam, /* lpszCmdParam */
36 SW_NORMAL); /* nCmdShow */
39 #if 0
41 extern int WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
42 /* This is the renamed main() subroutine in misc/main.c. */
43 /* Note that the libdll `init()' won't work: */
44 extern HINSTANCE32 _wine_main(int, char *[]);
46 int main (int argc, char *argv [])
48 HINSTANCE32 hInstance;
49 char szCmdParam[256] = {0};
50 int index, buffer_pos;
51 char *arg_holder;
52 /* "Wired-in" command-line options for Wine: */
53 /*char *wine_argv[] = {argv[0], "-managed", "-dll", "+commdlg",
54 "-dll", "+shell", ""};*/
55 char *wine_argv[] = {argv[0], ""};
57 /* Initialize the library dll: */
58 hInstance = (HINSTANCE32)_wine_main((sizeof(wine_argv)/sizeof(char *))-1, wine_argv);
60 #ifdef WIN_DEBUG
61 fprintf(stderr,"In winestub, reporting hInstance = %d\n", hInstance);
62 #endif
64 /* Move things from argv to the szCmdParam that WinMain expects: */
65 for (index = 1, buffer_pos = 0;
66 (index < argc) && (buffer_pos < 255);
67 index++, buffer_pos++)
69 for (arg_holder = argv[index]; ; buffer_pos++, arg_holder++)
70 if ((szCmdParam[buffer_pos] = *arg_holder) == '\0') break;
71 szCmdParam[buffer_pos] = ' ';
73 szCmdParam[buffer_pos] = '\0';
75 #ifdef WIN_DEBUG
76 fprintf(stderr,"In winestub, Program Name: %s, Parameters: %s\n",
77 progname, szCmdParam);
78 #endif
80 return WinMain (hInstance, /* hInstance */
81 0, /* hPrevInstance */
82 (LPSTR)szCmdParam, /* lpszCmdParam */
83 SW_NORMAL); /* nCmdShow */
85 #endif