12 #include "prototypes.h"
17 /* #define DEBUG_EXEC /* */
18 /* #undef DEBUG_EXEC /* */
21 #define HELP_CONTEXT 0x0001
22 #define HELP_QUIT 0x0002
23 #define HELP_INDEX 0x0003
24 #define HELP_CONTENTS 0x0003
25 #define HELP_HELPONHELP 0x0004
26 #define HELP_SETINDEX 0x0005
27 #define HELP_SETCONTENTS 0x0005
28 #define HELP_CONTEXTPOPUP 0x0008
29 #define HELP_FORCEFILE 0x0009
30 #define HELP_KEY 0x0101
31 #define HELP_COMMAND 0x0102
32 #define HELP_PARTIALKEY 0x0105
33 #define HELP_MULTIKEY 0x0201
34 #define HELP_SETWINPOS 0x0203
36 extern struct w_files
* wine_files
;
45 typedef BOOL (CALLBACK
* LPFNWINMAIN
)(HANDLE
, HANDLE
, LPSTR
, int);
48 extern int CallToInit16(unsigned long csip
, unsigned long sssp
,
50 HANDLE
CreateNewTask(HINSTANCE hInst
);
53 void InitializeLoadedNewDLLs(HINSTANCE hInst
)
56 struct w_files
* wpnt
;
57 int cs_reg
, ds_reg
, ip_reg
;
60 dprintf_exec(stddeb
, "Initializing New DLLs\n");
63 * Initialize libraries
66 "InitializeLoadedNewDLLs() before searching hInst=%04X !\n", hInst
);
68 while (w
&& w
->hinstance
!= hInst
) w
= w
->next
;
69 if (w
== NULL
) return;
70 dprintf_exec(stddeb
,"InitializeLoadedNewDLLs() // before InitLoop !\n");
71 for(wpnt
= w
; wpnt
; wpnt
= wpnt
->next
)
76 if (wpnt
->ne
->ne_header
->format_flags
& 0x8000)
78 if (!(wpnt
->ne
->ne_header
->format_flags
& 0x0001))
81 fprintf(stderr
, "Library is not marked SINGLEDATA\n");
85 ds_reg
= wpnt
->ne
->selector_table
[wpnt
->ne
->
86 ne_header
->auto_data_seg
-1].selector
;
87 cs_reg
= wpnt
->ne
->selector_table
[wpnt
->ne
->ne_header
->cs
-1].selector
;
88 ip_reg
= wpnt
->ne
->ne_header
->ip
;
90 dprintf_exec(stddeb
, "Initializing %s, cs:ip %04x:%04x, ds %04x\n",
91 wpnt
->name
, cs_reg
, ip_reg
, ds_reg
);
93 rv
= CallTo16(cs_reg
<< 16 | ip_reg
, ds_reg
);
94 dprintf_exec(stddeb
,"rv = %x\n", rv
);
100 void StartNewTask(HINSTANCE hInst
)
102 struct w_files
* wpnt
;
104 int cs_reg
, ds_reg
, ss_reg
, ip_reg
, sp_reg
;
109 "StartNewTask() before searching hInst=%04X !\n", hInst
);
111 while (wpnt
&& wpnt
->hinstance
!= hInst
) wpnt
= wpnt
->next
;
112 if (wpnt
== NULL
) return;
113 dprintf_exec(stddeb
,"StartNewTask() // before FixupSegment !\n");
114 for(w
= wpnt
; w
; w
= w
->next
) {
115 for (segment
= 0; segment
< w
->ne
->ne_header
->n_segment_tab
; segment
++) {
116 if (FixupSegment(w
, segment
) < 0) {
117 myerror("fixup failed.");
121 dprintf_exec(stddeb
,"StartNewTask() before InitializeLoadedNewDLLs !\n");
122 InitializeLoadedNewDLLs(hInst
);
123 dprintf_exec(stddeb
,"StartNewTask() before setup register !\n");
124 ds_reg
= (wpnt
->ne
->selector_table
[wpnt
->ne
->ne_header
->auto_data_seg
-1].selector
);
125 cs_reg
= wpnt
->ne
->selector_table
[wpnt
->ne
->ne_header
->cs
-1].selector
;
126 ip_reg
= wpnt
->ne
->ne_header
->ip
;
127 ss_reg
= wpnt
->ne
->selector_table
[wpnt
->ne
->ne_header
->ss
-1].selector
;
128 sp_reg
= wpnt
->ne
->ne_header
->sp
;
130 dprintf_exec(stddeb
,"StartNewTask() before CallToInit16() !\n");
131 rv
= CallToInit16(cs_reg
<< 16 | ip_reg
, ss_reg
<< 16 | sp_reg
, ds_reg
);
132 printf ("rv = %x\n", rv
);
137 void StartNewTask (HINSTANCE hInst
)
139 printf ("Not yet implemented\n");
143 /**********************************************************************
144 * LoadModule [KERNEL.45]
146 HANDLE
LoadModule(LPSTR modulefile
, LPVOID lpParamBlk
)
148 PARAMBLOCK
*pblk
= lpParamBlk
;
150 dprintf_exec(stddeb
,"LoadModule '%s' %08X\n", modulefile
, lpParamBlk
);
151 if (lpParamBlk
== NULL
) return 0;
152 lpCmdShow
= (WORD
*)pblk
->lpCmdShow
;
153 return WinExec(pblk
->lpCmdLine
, lpCmdShow
[1]);
157 /**********************************************************************
158 * WinExec [KERNEL.166]
160 WORD
WinExec(LPSTR lpCmdLine
, WORD nCmdShow
)
165 LPFNWINMAIN lpfnMain
;
168 dprintf_exec(stddeb
,"WinExec('%s', %04X)\n", lpCmdLine
, nCmdShow
);
171 for (x
= x2
= 0; x
< strlen(lpCmdLine
) + 1; x
++) {
172 if ((lpCmdLine
[x
] == ' ') || (lpCmdLine
[x
] == '\0')) {
173 ArgV
[c
] = (char *)malloc(x
- x2
+ 1);
174 strncpy(ArgV
[c
], &lpCmdLine
[x2
], x
- x2
);
175 ArgV
[c
][x
- x2
] = '\0';
180 for (c
= 0; ArgV
[c
] != NULL
; c
++)
181 dprintf_exec(stddeb
,"--> '%s' \n", ArgV
[c
]);
184 fprintf(stderr
,"Can't 'fork' process !\n");
187 if ((hInst
= LoadImage(ArgV
[0], EXE
, 1)) == (HINSTANCE
) NULL
) {
188 fprintf(stderr
, "wine: can't find %s!.\n", ArgV
[0]);
189 fprintf(stderr
,"Child process died !\n");
192 hTask
= CreateNewTask(hInst
);
194 "WinExec // hTask=%04X hInst=%04X !\n", hTask
, hInst
);
197 lpfnMain = (LPFNWINMAIN)GetProcAddress(hInst, (LPSTR)0L);
199 "WineExec() // lpfnMain=%08X\n", (LONG)lpfnMain);
200 if (lpfnMain != NULL) {
201 (lpfnMain)(hInst, 0, lpCmdLine, nCmdShow);
203 "WineExec() // after lpfnMain\n");
206 /* hTask = CreateNewTask(0);
208 "WinExec // New Task hTask=%04X !\n", hTask);
209 execvp(ArgV[0], ArgV); */
211 fprintf(stderr
,"Child process died !\n");
215 "WinExec (Main process stay alive) hTask=%04X !\n",
219 for (c
= 0; ArgV
[c
] != NULL
; c
++) free(ArgV
[c
]);
224 /**********************************************************************
225 * ExitWindows [USER.7]
227 BOOL
ExitWindows(DWORD dwReserved
, WORD wRetCode
)
229 dprintf_exec(stdnimp
,"EMPTY STUB !!! ExitWindows(%08X, %04X) !\n",
230 dwReserved
, wRetCode
);
234 /**********************************************************************
237 BOOL
WinHelp(HWND hWnd
, LPSTR lpHelpFile
, WORD wCommand
, DWORD dwData
)
240 dprintf_exec(stddeb
,"WinHelp(%s, %u, %lu)\n",
241 lpHelpFile
, wCommand
, dwData
);
244 case HELP_HELPONHELP
:
245 GetWindowsDirectory(str
, sizeof(str
));
246 strcat(str
, "\\winhelp.exe");
247 dprintf_exec(stddeb
,"'%s'\n", str
);
250 GetWindowsDirectory(str
, sizeof(str
));
251 strcat(str
, "\\winhelp.exe");
252 dprintf_exec(stddeb
,"'%s'\n", str
);
257 WinExec(str
, SW_SHOWNORMAL
);