4 * Copyright 1995 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winuser16.h"
26 #include "selectors.h"
27 #include "stackframe.h"
32 extern BOOL32 THREAD_InitDone
;
35 /*************************************************************************
36 * MODULE32_LookupHMODULE
37 * looks for the referenced HMODULE in the current process
40 MODULE32_LookupHMODULE(PDB32
*process
,HMODULE32 hmod
) {
44 return process
->exe_modref
;
46 ERR(module
,"tried to lookup 0x%04x in win32 module handler!\n",hmod
);
49 for (wm
= process
->modref_list
;wm
;wm
=wm
->next
)
50 if (wm
->module
== hmod
)
55 /*************************************************************************
56 * MODULE_InitializeDLLs
58 * Call the initialization routines of all DLLs belonging to the
59 * current process. This is somewhat complicated due to the fact that
61 * - we have to respect the module dependencies, i.e. modules implicitly
62 * referenced by another module have to be initialized before the module
63 * itself can be initialized
65 * - the initialization routine of a DLL can itself call LoadLibrary,
66 * thereby introducing a whole new set of dependencies (even involving
67 * the 'old' modules) at any time during the whole process
69 * (Note that this routine can be recursively entered not only directly
70 * from itself, but also via LoadLibrary from one of the called initialization
73 static void MODULE_DoInitializeDLLs( PDB32
*process
, WINE_MODREF
*wm
,
74 DWORD type
, LPVOID lpReserved
)
78 assert( wm
&& !wm
->initDone
);
79 TRACE( module
, "(%p,%08x,%ld,%p) - START\n",
80 process
, wm
->module
, type
, lpReserved
);
82 /* Tag current MODREF to prevent recursive loop */
85 /* Recursively initialize all child DLLs */
86 for ( i
= 0; i
< wm
->nDeps
; i
++ )
87 if ( wm
->deps
[i
] && !wm
->deps
[i
]->initDone
)
88 MODULE_DoInitializeDLLs( process
,
89 wm
->deps
[i
], type
, lpReserved
);
91 /* Now we can call the initialization routine */
95 PE_InitDLL( wm
, type
, lpReserved
);
99 /* no need to do that, dlopen() already does */
102 ERR(module
, "wine_modref type %d not handled.\n", wm
->type
);
106 TRACE( module
, "(%p,%08x,%ld,%p) - END\n",
107 process
, wm
->module
, type
, lpReserved
);
110 void MODULE_InitializeDLLs( PDB32
*process
, HMODULE32 root
,
111 DWORD type
, LPVOID lpReserved
)
113 BOOL32 inProgress
= FALSE
;
116 /* Grab the process critical section to protect the recursion flags */
117 /* FIXME: This is probably overkill! */
118 EnterCriticalSection( &process
->crit_section
);
120 TRACE( module
, "(%p,%08x,%ld,%p) - START\n", process
, root
, type
, lpReserved
);
122 /* First, check whether initialization is currently in progress */
123 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
133 * If this a LoadLibrary call from within an initialization routine,
134 * treat it analogously to an implicitly referenced DLL.
135 * Anything else may not happen at this point!
139 wm
= MODULE32_LookupHMODULE( process
, root
);
140 if ( wm
&& !wm
->initDone
)
141 MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
144 FIXME(module
, "Invalid recursion!\n");
148 /* If we arrive here, this is the start of an initialization run */
151 /* If called for main EXE, initialize all DLLs */
152 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
154 MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
158 /* If called for a specific DLL, initialize only it and its children */
159 wm
= MODULE32_LookupHMODULE( process
, root
);
160 if (wm
) MODULE_DoInitializeDLLs( process
, wm
, type
, lpReserved
);
163 /* We're finished, so we reset all recursion flags */
164 for ( wm
= process
->modref_list
; wm
; wm
= wm
->next
)
165 wm
->initDone
= FALSE
;
168 TRACE( module
, "(%p,%08x,%ld,%p) - END\n", process
, root
, type
, lpReserved
);
170 /* Release critical section */
171 LeaveCriticalSection( &process
->crit_section
);
175 /***********************************************************************
176 * MODULE_CreateDummyModule
178 * Create a dummy NE module for Win32 or Winelib.
180 HMODULE32
MODULE_CreateDummyModule( const OFSTRUCT
*ofs
)
184 SEGTABLEENTRY
*pSegment
;
187 const char* basename
;
189 INT32 of_size
= sizeof(OFSTRUCT
) - sizeof(ofs
->szPathName
)
190 + strlen(ofs
->szPathName
) + 1;
191 INT32 size
= sizeof(NE_MODULE
) +
192 /* loaded file info */
194 /* segment table: DS,CS */
195 2 * sizeof(SEGTABLEENTRY
) +
198 /* several empty tables */
201 hModule
= GlobalAlloc16( GMEM_MOVEABLE
| GMEM_ZEROINIT
, size
);
202 if (!hModule
) return (HMODULE32
)11; /* invalid exe */
204 FarSetOwner( hModule
, hModule
);
205 pModule
= (NE_MODULE
*)GlobalLock16( hModule
);
207 /* Set all used entries */
208 pModule
->magic
= IMAGE_OS2_SIGNATURE
;
215 pModule
->heap_size
= 0xe000;
216 pModule
->stack_size
= 0x1000;
217 pModule
->seg_count
= 2;
218 pModule
->modref_count
= 0;
219 pModule
->nrname_size
= 0;
220 pModule
->fileinfo
= sizeof(NE_MODULE
);
221 pModule
->os_flags
= NE_OSFLAGS_WINDOWS
;
222 pModule
->expected_version
= 0x030a;
223 pModule
->self
= hModule
;
225 /* Set loaded file information */
226 memcpy( pModule
+ 1, ofs
, of_size
);
227 ((OFSTRUCT
*)(pModule
+1))->cBytes
= of_size
- 1;
229 pSegment
= (SEGTABLEENTRY
*)((char*)(pModule
+ 1) + of_size
);
230 pModule
->seg_table
= pModule
->dgroup_entry
= (int)pSegment
- (int)pModule
;
233 pSegment
->flags
= NE_SEGFLAGS_DATA
;
234 pSegment
->minsize
= 0x1000;
241 pStr
= (char *)pSegment
;
242 pModule
->name_table
= (int)pStr
- (int)pModule
;
243 basename
= strrchr(ofs
->szPathName
,'\\');
244 if (!basename
) basename
= ofs
->szPathName
;
246 len
= strlen(basename
);
247 if ((s
= strchr(basename
,'.'))) len
= s
- basename
;
248 if (len
> 8) len
= 8;
250 strncpy( pStr
+1, basename
, len
);
251 if (len
< 8) pStr
[len
+1] = 0;
254 /* All tables zero terminated */
255 pModule
->res_table
= pModule
->import_table
= pModule
->entry_table
=
256 (int)pStr
- (int)pModule
;
258 NE_RegisterModule( pModule
);
263 /***********************************************************************
264 * MODULE_GetWndProcEntry16 (not a Windows API function)
266 * Return an entry point from the WPROCS dll.
268 FARPROC16
MODULE_GetWndProcEntry16( LPCSTR name
)
270 FARPROC16 ret
= NULL
;
274 /* FIXME: hack for Winelib */
275 extern LRESULT
ColorDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
276 extern LRESULT
FileOpenDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
277 extern LRESULT
FileSaveDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
278 extern LRESULT
FindTextDlgProc16(HWND16
,UINT16
,WPARAM16
,LPARAM
);
279 extern LRESULT
PrintDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
280 extern LRESULT
PrintSetupDlgProc(HWND16
,UINT16
,WPARAM16
,LPARAM
);
281 extern LRESULT
ReplaceTextDlgProc16(HWND16
,UINT16
,WPARAM16
,LPARAM
);
283 if (!strcmp(name
,"ColorDlgProc"))
284 return (FARPROC16
)ColorDlgProc
;
285 if (!strcmp(name
,"FileOpenDlgProc"))
286 return (FARPROC16
)FileOpenDlgProc
;
287 if (!strcmp(name
,"FileSaveDlgProc"))
288 return (FARPROC16
)FileSaveDlgProc
;
289 if (!strcmp(name
,"FindTextDlgProc"))
290 return (FARPROC16
)FindTextDlgProc16
;
291 if (!strcmp(name
,"PrintDlgProc"))
292 return (FARPROC16
)PrintDlgProc
;
293 if (!strcmp(name
,"PrintSetupDlgProc"))
294 return (FARPROC16
)PrintSetupDlgProc
;
295 if (!strcmp(name
,"ReplaceTextDlgProc"))
296 return (FARPROC16
)ReplaceTextDlgProc16
;
297 if (!strcmp(name
,"DefResourceHandler"))
298 return (FARPROC16
)NE_DefResourceHandler
;
299 if (!strcmp(name
,"LoadDIBIconHandler"))
300 return (FARPROC16
)LoadDIBIconHandler
;
301 if (!strcmp(name
,"LoadDIBCursorHandler"))
302 return (FARPROC16
)LoadDIBCursorHandler
;
303 FIXME(module
,"No mapping for %s(), add one in library/miscstubs.c\n",name
);
310 static HMODULE32 hModule
= 0;
312 if (!hModule
) hModule
= GetModuleHandle16( "WPROCS" );
313 ordinal
= NE_GetOrdinal( hModule
, name
);
314 if (!(ret
= NE_GetEntryPoint( hModule
, ordinal
)))
316 WARN( module
, "%s not found\n", name
);
324 /**********************************************************************
325 * MODULE_FindModule32
327 * Find a (loaded) win32 module depending on path
328 * The handling of '.' is a bit weird, but we need it that way,
329 * for sometimes the programs use '<name>.exe' and '<name>.dll' and
330 * this is the only way to differentiate. (mainly hypertrm.exe)
333 * the module handle if found
336 HMODULE32
MODULE_FindModule32(
337 PDB32
* process
, /* [in] process in which to find the library */
338 LPCSTR path
/* [in] pathname of module/library to be found */
346 if (!(filename
= strrchr( path
, '\\' )))
347 filename
= HEAP_strdupA(process
->heap
,0,path
);
349 filename
= HEAP_strdupA(process
->heap
,0,filename
+1);
350 dotptr
=strrchr(filename
,'.');
352 for (wm
=process
->modref_list
;wm
;wm
=wm
->next
) {
353 LPSTR xmodname
,xdotptr
;
355 assert (wm
->modname
);
356 xmodname
= HEAP_strdupA(process
->heap
,0,wm
->modname
);
357 xdotptr
=strrchr(xmodname
,'.');
358 if ( (xdotptr
&& !dotptr
) ||
361 if (dotptr
) *dotptr
= '\0';
362 if (xdotptr
) *xdotptr
= '\0';
364 if (!strcasecmp( filename
, xmodname
)) {
365 HeapFree(process
->heap
,0,filename
);
366 HeapFree(process
->heap
,0,xmodname
);
369 if (dotptr
) *dotptr
='.';
370 /* FIXME: add paths, shortname */
371 HeapFree(process
->heap
,0,xmodname
);
373 /* if that fails, try looking for the filename... */
374 for (wm
=process
->modref_list
;wm
;wm
=wm
->next
) {
375 LPSTR xlname
,xdotptr
;
377 assert (wm
->longname
);
378 xlname
= strrchr(wm
->longname
,'\\');
380 xlname
= wm
->longname
;
383 xlname
= HEAP_strdupA(process
->heap
,0,xlname
);
384 xdotptr
=strrchr(xlname
,'.');
385 if ( (xdotptr
&& !dotptr
) ||
388 if (dotptr
) *dotptr
= '\0';
389 if (xdotptr
) *xdotptr
= '\0';
391 if (!strcasecmp( filename
, xlname
)) {
392 HeapFree(process
->heap
,0,filename
);
393 HeapFree(process
->heap
,0,xlname
);
396 if (dotptr
) *dotptr
='.';
397 /* FIXME: add paths, shortname */
398 HeapFree(process
->heap
,0,xlname
);
400 HeapFree(process
->heap
,0,filename
);
406 /**********************************************************************
409 static HINSTANCE16
NE_CreateProcess( LPCSTR name
, LPCSTR cmd_line
, LPCSTR env
,
410 BOOL32 inherit
, LPSTARTUPINFO32A startup
,
411 LPPROCESS_INFORMATION info
)
413 HINSTANCE16 hInstance
, hPrevInstance
;
418 hInstance
= NE_LoadModule( name
, &hPrevInstance
, TRUE
, FALSE
);
419 if (hInstance
< 32) return hInstance
;
421 if ( !(pModule
= NE_GetPtr(hInstance
))
422 || (pModule
->flags
& NE_FFLAGS_LIBMODULE
))
428 /* Create a task for this instance */
430 pModule
->flags
|= NE_FFLAGS_GUI
; /* FIXME: is this necessary? */
432 PROCESS_Create( pModule
, cmd_line
, env
, hInstance
,
433 hPrevInstance
, inherit
, startup
, info
);
439 /**********************************************************************
440 * LoadModule16 (KERNEL.45)
442 HINSTANCE16 WINAPI
LoadModule16( LPCSTR name
, LPVOID paramBlock
)
445 LPSTR cmd_line
, new_cmd_line
;
447 STARTUPINFO32A startup
;
448 PROCESS_INFORMATION info
;
449 HINSTANCE16 hInstance
, hPrevInstance
;
455 if (!paramBlock
|| (paramBlock
== (LPVOID
)-1))
456 return LoadLibrary16( name
);
458 hInstance
= NE_LoadModule( name
, &hPrevInstance
, FALSE
, FALSE
);
459 if ( hInstance
< 32 || !(pModule
= NE_GetPtr(hInstance
))
460 || (pModule
->flags
& NE_FFLAGS_LIBMODULE
))
463 /* Create a task for this instance */
465 pModule
->flags
|= NE_FFLAGS_GUI
; /* FIXME: is this necessary? */
467 params
= (LOADPARAMS
*)paramBlock
;
468 cmd_line
= (LPSTR
)PTR_SEG_TO_LIN( params
->cmdLine
);
469 if (!cmd_line
) cmd_line
= "";
470 else if (*cmd_line
) cmd_line
++; /* skip the length byte */
472 if (!(new_cmd_line
= HeapAlloc( GetProcessHeap(), 0,
473 strlen(cmd_line
)+strlen(name
)+2 )))
475 strcpy( new_cmd_line
, name
);
476 strcat( new_cmd_line
, " " );
477 strcat( new_cmd_line
, cmd_line
);
479 if (params
->hEnvironment
) env
= GlobalLock16( params
->hEnvironment
);
481 memset( &info
, '\0', sizeof(info
) );
482 memset( &startup
, '\0', sizeof(startup
) );
483 startup
.cb
= sizeof(startup
);
486 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
487 startup
.wShowWindow
= ((UINT16
*)PTR_SEG_TO_LIN(params
->showCmd
))[1];
490 pdb
= PROCESS_Create( pModule
, new_cmd_line
, env
,
491 hInstance
, hPrevInstance
, TRUE
, &startup
, &info
);
493 CloseHandle( info
.hThread
);
494 CloseHandle( info
.hProcess
);
496 if (params
->hEnvironment
) GlobalUnlock16( params
->hEnvironment
);
497 HeapFree( GetProcessHeap(), 0, new_cmd_line
);
501 if (pdb
) TASK_StartTask( pdb
->task
);
506 /**********************************************************************
507 * LoadModule32 (KERNEL32.499)
509 HINSTANCE32 WINAPI
LoadModule32( LPCSTR name
, LPVOID paramBlock
)
511 LOADPARAMS32
*params
= (LOADPARAMS32
*)paramBlock
;
512 PROCESS_INFORMATION info
;
513 STARTUPINFO32A startup
;
514 HINSTANCE32 hInstance
;
518 memset( &startup
, '\0', sizeof(startup
) );
519 startup
.cb
= sizeof(startup
);
520 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
521 startup
.wShowWindow
= params
->lpCmdShow
? params
->lpCmdShow
[1] : 0;
523 if (!CreateProcess32A( name
, params
->lpCmdLine
,
524 NULL
, NULL
, FALSE
, 0, params
->lpEnvAddress
,
525 NULL
, &startup
, &info
))
526 return GetLastError(); /* guaranteed to be < 32 */
528 /* Get 16-bit hInstance/hTask from process */
529 pdb
= PROCESS_IdToPDB( info
.dwProcessId
);
530 tdb
= pdb
? (TDB
*)GlobalLock16( pdb
->task
) : NULL
;
531 hInstance
= tdb
&& tdb
->hInstance
? tdb
->hInstance
: pdb
? pdb
->task
: 0;
533 /* Close off the handles */
534 CloseHandle( info
.hThread
);
535 CloseHandle( info
.hProcess
);
540 /**********************************************************************
541 * CreateProcess32A (KERNEL32.171)
543 BOOL32 WINAPI
CreateProcess32A( LPCSTR lpApplicationName
, LPSTR lpCommandLine
,
544 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
545 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
546 BOOL32 bInheritHandles
, DWORD dwCreationFlags
,
547 LPVOID lpEnvironment
, LPCSTR lpCurrentDirectory
,
548 LPSTARTUPINFO32A lpStartupInfo
,
549 LPPROCESS_INFORMATION lpProcessInfo
)
551 HINSTANCE16 hInstance
;
556 /* Get name and command line */
558 if (!lpApplicationName
&& !lpCommandLine
)
560 SetLastError( ERROR_FILE_NOT_FOUND
);
564 cmdline
= lpCommandLine
? lpCommandLine
: lpApplicationName
;
566 if (lpApplicationName
)
567 lstrcpyn32A(name
, lpApplicationName
, sizeof(name
) - 4);
572 /* Take care off .exes with spaces in their names */
573 ptr
= strchr(lpCommandLine
, ' ');
575 len
= (ptr
? ptr
-lpCommandLine
: strlen(lpCommandLine
)) + 1;
576 if (len
> sizeof(name
) - 4) len
= sizeof(name
) - 4;
577 lstrcpyn32A(name
, lpCommandLine
, len
);
578 if (!strchr(name
, '\\') && !strchr(name
, '.'))
579 strcat(name
, ".exe");
580 if (GetFileAttributes32A(name
)!=-1)
582 /* if there is a space and no file found yet, include the word
583 * up to the next space too. If there is no next space, just
584 * use the first word.
587 ptr
= strchr(ptr
+1, ' ');
589 ptr
= strchr(lpCommandLine
, ' ');
590 len
= (ptr
? ptr
-lpCommandLine
: strlen(lpCommandLine
)) + 1;
591 if (len
> sizeof(name
) - 4) len
= sizeof(name
) - 4;
592 lstrcpyn32A(name
, lpCommandLine
, len
);
598 if (!strchr(name
, '\\') && !strchr(name
, '.'))
599 strcat(name
, ".exe");
602 /* Warn if unsupported features are used */
604 if (lpProcessAttributes
)
605 FIXME(module
, "(%s,...): lpProcessAttributes ignored\n", name
);
606 if (lpThreadAttributes
)
607 FIXME(module
, "(%s,...): lpThreadAttributes ignored\n", name
);
608 if (dwCreationFlags
& DEBUG_PROCESS
)
609 FIXME(module
, "(%s,...): DEBUG_PROCESS ignored\n", name
);
610 if (dwCreationFlags
& DEBUG_ONLY_THIS_PROCESS
)
611 FIXME(module
, "(%s,...): DEBUG_ONLY_THIS_PROCESS ignored\n", name
);
612 if (dwCreationFlags
& CREATE_SUSPENDED
)
613 FIXME(module
, "(%s,...): CREATE_SUSPENDED ignored\n", name
);
614 if (dwCreationFlags
& DETACHED_PROCESS
)
615 FIXME(module
, "(%s,...): DETACHED_PROCESS ignored\n", name
);
616 if (dwCreationFlags
& CREATE_NEW_CONSOLE
)
617 FIXME(module
, "(%s,...): CREATE_NEW_CONSOLE ignored\n", name
);
618 if (dwCreationFlags
& NORMAL_PRIORITY_CLASS
)
619 FIXME(module
, "(%s,...): NORMAL_PRIORITY_CLASS ignored\n", name
);
620 if (dwCreationFlags
& IDLE_PRIORITY_CLASS
)
621 FIXME(module
, "(%s,...): IDLE_PRIORITY_CLASS ignored\n", name
);
622 if (dwCreationFlags
& HIGH_PRIORITY_CLASS
)
623 FIXME(module
, "(%s,...): HIGH_PRIORITY_CLASS ignored\n", name
);
624 if (dwCreationFlags
& REALTIME_PRIORITY_CLASS
)
625 FIXME(module
, "(%s,...): REALTIME_PRIORITY_CLASS ignored\n", name
);
626 if (dwCreationFlags
& CREATE_NEW_PROCESS_GROUP
)
627 FIXME(module
, "(%s,...): CREATE_NEW_PROCESS_GROUP ignored\n", name
);
628 if (dwCreationFlags
& CREATE_UNICODE_ENVIRONMENT
)
629 FIXME(module
, "(%s,...): CREATE_UNICODE_ENVIRONMENT ignored\n", name
);
630 if (dwCreationFlags
& CREATE_SEPARATE_WOW_VDM
)
631 FIXME(module
, "(%s,...): CREATE_SEPARATE_WOW_VDM ignored\n", name
);
632 if (dwCreationFlags
& CREATE_SHARED_WOW_VDM
)
633 FIXME(module
, "(%s,...): CREATE_SHARED_WOW_VDM ignored\n", name
);
634 if (dwCreationFlags
& CREATE_DEFAULT_ERROR_MODE
)
635 FIXME(module
, "(%s,...): CREATE_DEFAULT_ERROR_MODE ignored\n", name
);
636 if (dwCreationFlags
& CREATE_NO_WINDOW
)
637 FIXME(module
, "(%s,...): CREATE_NO_WINDOW ignored\n", name
);
638 if (dwCreationFlags
& PROFILE_USER
)
639 FIXME(module
, "(%s,...): PROFILE_USER ignored\n", name
);
640 if (dwCreationFlags
& PROFILE_KERNEL
)
641 FIXME(module
, "(%s,...): PROFILE_KERNEL ignored\n", name
);
642 if (dwCreationFlags
& PROFILE_SERVER
)
643 FIXME(module
, "(%s,...): PROFILE_SERVER ignored\n", name
);
644 if (lpCurrentDirectory
)
645 FIXME(module
, "(%s,...): lpCurrentDirectory %s ignored\n",
646 name
, lpCurrentDirectory
);
647 if (lpStartupInfo
->lpDesktop
)
648 FIXME(module
, "(%s,...): lpStartupInfo->lpDesktop %s ignored\n",
649 name
, lpStartupInfo
->lpDesktop
);
650 if (lpStartupInfo
->lpTitle
)
651 FIXME(module
, "(%s,...): lpStartupInfo->lpTitle %s ignored\n",
652 name
, lpStartupInfo
->lpTitle
);
653 if (lpStartupInfo
->dwFlags
& STARTF_USECOUNTCHARS
)
654 FIXME(module
, "(%s,...): STARTF_USECOUNTCHARS (%ld,%ld) ignored\n",
655 name
, lpStartupInfo
->dwXCountChars
, lpStartupInfo
->dwYCountChars
);
656 if (lpStartupInfo
->dwFlags
& STARTF_USEFILLATTRIBUTE
)
657 FIXME(module
, "(%s,...): STARTF_USEFILLATTRIBUTE %lx ignored\n",
658 name
, lpStartupInfo
->dwFillAttribute
);
659 if (lpStartupInfo
->dwFlags
& STARTF_RUNFULLSCREEN
)
660 FIXME(module
, "(%s,...): STARTF_RUNFULLSCREEN ignored\n", name
);
661 if (lpStartupInfo
->dwFlags
& STARTF_FORCEONFEEDBACK
)
662 FIXME(module
, "(%s,...): STARTF_FORCEONFEEDBACK ignored\n", name
);
663 if (lpStartupInfo
->dwFlags
& STARTF_FORCEOFFFEEDBACK
)
664 FIXME(module
, "(%s,...): STARTF_FORCEOFFFEEDBACK ignored\n", name
);
665 if (lpStartupInfo
->dwFlags
& STARTF_USEHOTKEY
)
666 FIXME(module
, "(%s,...): STARTF_USEHOTKEY ignored\n", name
);
670 hInstance
= NE_CreateProcess( name
, cmdline
, lpEnvironment
, bInheritHandles
,
671 lpStartupInfo
, lpProcessInfo
);
675 hInstance
= PE_CreateProcess( name
, cmdline
, lpEnvironment
, bInheritHandles
,
676 lpStartupInfo
, lpProcessInfo
);
680 hInstance
= MZ_CreateProcess( name
, cmdline
, lpEnvironment
, bInheritHandles
,
681 lpStartupInfo
, lpProcessInfo
);
685 SetLastError( hInstance
);
689 /* Get hTask from process and start the task */
690 pdb
= PROCESS_IdToPDB( lpProcessInfo
->dwProcessId
);
691 if (pdb
) TASK_StartTask( pdb
->task
);
696 /**********************************************************************
697 * CreateProcess32W (KERNEL32.172)
699 * lpReserved is not converted
701 BOOL32 WINAPI
CreateProcess32W( LPCWSTR lpApplicationName
, LPWSTR lpCommandLine
,
702 LPSECURITY_ATTRIBUTES lpProcessAttributes
,
703 LPSECURITY_ATTRIBUTES lpThreadAttributes
,
704 BOOL32 bInheritHandles
, DWORD dwCreationFlags
,
705 LPVOID lpEnvironment
, LPCWSTR lpCurrentDirectory
,
706 LPSTARTUPINFO32W lpStartupInfo
,
707 LPPROCESS_INFORMATION lpProcessInfo
)
709 STARTUPINFO32A StartupInfoA
;
711 LPSTR lpApplicationNameA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpApplicationName
);
712 LPSTR lpCommandLineA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpCommandLine
);
713 LPSTR lpCurrentDirectoryA
= HEAP_strdupWtoA (GetProcessHeap(),0,lpCurrentDirectory
);
715 memcpy (&StartupInfoA
, lpStartupInfo
, sizeof(STARTUPINFO32A
));
716 StartupInfoA
.lpDesktop
= HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo
->lpDesktop
);
717 StartupInfoA
.lpTitle
= HEAP_strdupWtoA (GetProcessHeap(),0,lpStartupInfo
->lpTitle
);
719 TRACE(win32
, "(%s,%s,...)\n", debugstr_w(lpApplicationName
), debugstr_w(lpCommandLine
));
721 if (lpStartupInfo
->lpReserved
)
722 FIXME(win32
,"StartupInfo.lpReserved is used, please report (%s)\n", debugstr_w(lpStartupInfo
->lpReserved
));
724 ret
= CreateProcess32A( lpApplicationNameA
, lpCommandLineA
,
725 lpProcessAttributes
, lpThreadAttributes
,
726 bInheritHandles
, dwCreationFlags
,
727 lpEnvironment
, lpCurrentDirectoryA
,
728 &StartupInfoA
, lpProcessInfo
);
730 HeapFree( GetProcessHeap(), 0, lpCurrentDirectoryA
);
731 HeapFree( GetProcessHeap(), 0, lpCommandLineA
);
732 HeapFree( GetProcessHeap(), 0, StartupInfoA
.lpDesktop
);
733 HeapFree( GetProcessHeap(), 0, StartupInfoA
.lpTitle
);
738 /***********************************************************************
739 * GetModuleHandle (KERNEL32.237)
741 HMODULE32 WINAPI
GetModuleHandle32A(LPCSTR module
)
744 return PROCESS_Current()->exe_modref
->module
;
746 return MODULE_FindModule32(PROCESS_Current(),module
);
749 HMODULE32 WINAPI
GetModuleHandle32W(LPCWSTR module
)
752 LPSTR modulea
= HEAP_strdupWtoA( GetProcessHeap(), 0, module
);
753 hModule
= GetModuleHandle32A( modulea
);
754 HeapFree( GetProcessHeap(), 0, modulea
);
759 /***********************************************************************
760 * GetModuleFileName32A (KERNEL32.235)
762 DWORD WINAPI
GetModuleFileName32A(
763 HMODULE32 hModule
, /* [in] module handle (32bit) */
764 LPSTR lpFileName
, /* [out] filenamebuffer */
765 DWORD size
/* [in] size of filenamebuffer */
767 WINE_MODREF
*wm
= MODULE32_LookupHMODULE(PROCESS_Current(),hModule
);
769 if (!wm
) /* can happen on start up or the like */
772 if (PE_HEADER(wm
->module
)->OptionalHeader
.MajorOperatingSystemVersion
>= 4.0)
773 lstrcpyn32A( lpFileName
, wm
->longname
, size
);
775 lstrcpyn32A( lpFileName
, wm
->shortname
, size
);
777 TRACE(module
, "%s\n", lpFileName
);
778 return strlen(lpFileName
);
782 /***********************************************************************
783 * GetModuleFileName32W (KERNEL32.236)
785 DWORD WINAPI
GetModuleFileName32W( HMODULE32 hModule
, LPWSTR lpFileName
,
788 LPSTR fnA
= (char*)HeapAlloc( GetProcessHeap(), 0, size
);
789 DWORD res
= GetModuleFileName32A( hModule
, fnA
, size
);
790 lstrcpynAtoW( lpFileName
, fnA
, size
);
791 HeapFree( GetProcessHeap(), 0, fnA
);
796 /***********************************************************************
797 * LoadLibraryEx32W (KERNEL.513)
800 HMODULE32 WINAPI
LoadLibraryEx32W16( LPCSTR libname
, HANDLE16 hf
,
803 TRACE(module
,"(%s,%d,%08lx)\n",libname
,hf
,flags
);
804 return LoadLibraryEx32A(libname
, hf
,flags
);
807 /***********************************************************************
808 * LoadLibraryEx32A (KERNEL32)
810 HMODULE32 WINAPI
LoadLibraryEx32A(LPCSTR libname
,HFILE32 hfile
,DWORD flags
)
813 hmod
= MODULE_LoadLibraryEx32A(libname
,PROCESS_Current(),hfile
,flags
);
815 /* at least call not the dllmain...*/
816 if ( DONT_RESOLVE_DLL_REFERENCES
==flags
|| LOAD_LIBRARY_AS_DATAFILE
==flags
)
817 { FIXME(module
,"flag not properly supported %lx\n", flags
);
821 /* initialize DLL just loaded */
823 MODULE_InitializeDLLs( PROCESS_Current(), hmod
,
824 DLL_PROCESS_ATTACH
, (LPVOID
)-1 );
829 HMODULE32
MODULE_LoadLibraryEx32A(LPCSTR libname
,PDB32
*process
,HFILE32 hfile
,DWORD flags
)
833 hmod
= ELF_LoadLibraryEx32A(libname
,process
,hfile
,flags
);
834 if (hmod
) return hmod
;
836 hmod
= PE_LoadLibraryEx32A(libname
,process
,hfile
,flags
);
840 /***********************************************************************
841 * LoadLibraryA (KERNEL32)
843 HMODULE32 WINAPI
LoadLibrary32A(LPCSTR libname
) {
844 return LoadLibraryEx32A(libname
,0,0);
847 /***********************************************************************
848 * LoadLibraryW (KERNEL32)
850 HMODULE32 WINAPI
LoadLibrary32W(LPCWSTR libnameW
)
852 return LoadLibraryEx32W(libnameW
,0,0);
855 /***********************************************************************
856 * LoadLibraryExW (KERNEL32)
858 HMODULE32 WINAPI
LoadLibraryEx32W(LPCWSTR libnameW
,HFILE32 hfile
,DWORD flags
)
860 LPSTR libnameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW
);
861 HMODULE32 ret
= LoadLibraryEx32A( libnameA
, hfile
, flags
);
863 HeapFree( GetProcessHeap(), 0, libnameA
);
867 /***********************************************************************
870 BOOL32 WINAPI
FreeLibrary32(HINSTANCE32 hLibModule
)
872 FIXME(module
,"(0x%08x): stub\n", hLibModule
);
873 return TRUE
; /* FIXME */
877 /***********************************************************************
878 * PrivateLoadLibrary (KERNEL32)
880 * FIXME: rough guesswork, don't know what "Private" means
882 HINSTANCE32 WINAPI
PrivateLoadLibrary(LPCSTR libname
)
884 return (HINSTANCE32
)LoadLibrary16(libname
);
889 /***********************************************************************
890 * PrivateFreeLibrary (KERNEL32)
892 * FIXME: rough guesswork, don't know what "Private" means
894 void WINAPI
PrivateFreeLibrary(HINSTANCE32 handle
)
896 FreeLibrary16((HINSTANCE16
)handle
);
900 /***********************************************************************
901 * WinExec16 (KERNEL.166)
903 HINSTANCE16 WINAPI
WinExec16( LPCSTR lpCmdLine
, UINT16 nCmdShow
)
905 return WinExec32( lpCmdLine
, nCmdShow
);
909 /***********************************************************************
910 * WinExec32 (KERNEL32.566)
912 HINSTANCE32 WINAPI
WinExec32( LPCSTR lpCmdLine
, UINT32 nCmdShow
)
914 HINSTANCE32 handle
= 2;
915 char *p
, filename
[256];
916 int spacelimit
= 0, exhausted
= 0;
918 UINT16 paramCmdShow
[2];
921 return 2; /* File not found */
923 /* Set up LOADPARAMS32 buffer for LoadModule32 */
925 memset( ¶ms
, '\0', sizeof(params
) );
926 params
.lpCmdLine
= (LPSTR
)lpCmdLine
;
927 params
.lpCmdShow
= paramCmdShow
;
928 params
.lpCmdShow
[0] = 2;
929 params
.lpCmdShow
[1] = nCmdShow
;
932 /* Keep trying to load a file by trying different filenames; e.g.,
933 for the cmdline "abcd efg hij", try "abcd" with args "efg hij",
934 then "abcd efg" with arg "hij", and finally "abcd efg hij" with
937 while(!exhausted
&& handle
== 2) {
940 /* Build the filename and command-line */
942 lstrcpyn32A(filename
, lpCmdLine
,
943 sizeof(filename
) - 4 /* for extension */);
945 /* Keep grabbing characters until end-of-string, tab, or until the
946 number of spaces is greater than the spacelimit */
948 for (p
= filename
; ; p
++) {
951 if(spacecount
> spacelimit
) {
957 if(*p
== '\0' || *p
== '\t') {
965 /* Now load the executable file */
969 handle
= LoadModule32( filename
, ¶ms
);
970 if (handle
== 2) /* file not found */
972 /* Check that the original file name did not have a suffix */
973 p
= strrchr(filename
, '.');
974 /* if there is a '.', check if either \ OR / follow */
975 if (!p
|| strchr(p
, '/') || strchr(p
, '\\'))
977 p
= filename
+ strlen(filename
);
979 handle
= LoadModule32( filename
, ¶ms
);
980 *p
= '\0'; /* Remove extension */
985 handle
= 2; /* file not found */
989 /* Try to start it as a unix program */
993 DOS_FULL_NAME full_name
;
994 const char *unixfilename
= NULL
;
995 const char *argv
[256], **argptr
;
996 int iconic
= (nCmdShow
== SW_SHOWMINIMIZED
||
997 nCmdShow
== SW_SHOWMINNOACTIVE
);
999 THREAD_InitDone
= FALSE
; /* we didn't init this process */
1000 /* get unixfilename */
1001 if (strchr(filename
, '/') ||
1002 strchr(filename
, ':') ||
1003 strchr(filename
, '\\'))
1005 if (DOSFS_GetFullName( filename
, TRUE
, &full_name
))
1006 unixfilename
= full_name
.long_name
;
1008 else unixfilename
= filename
;
1014 if (iconic
) *argptr
++ = "-iconic";
1015 *argptr
++ = unixfilename
;
1016 p
= strdup(lpCmdLine
);
1019 while (*p
&& (*p
== ' ' || *p
== '\t')) *p
++ = '\0';
1022 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
1027 execvp(argv
[0], (char**)argv
);
1037 if (iconic
) *argptr
++ = "-iconic";
1038 *argptr
++ = lpCmdLine
;
1042 execvp(argv
[0] , (char**)argv
);
1045 MSG("WinExec: can't exec 'wine %s'\n",
1051 } /* while (!exhausted && handle < 32) */
1057 /***********************************************************************
1058 * WIN32_GetProcAddress16 (KERNEL32.36)
1059 * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
1061 FARPROC16 WINAPI
WIN32_GetProcAddress16( HMODULE32 hModule
, LPCSTR name
)
1067 WARN(module
,"hModule may not be 0!\n");
1068 return (FARPROC16
)0;
1070 if (HIWORD(hModule
))
1072 WARN( module
, "hModule is Win32 handle (%08x)\n", hModule
);
1073 return (FARPROC16
)0;
1075 hModule
= GetExePtr( hModule
);
1077 ordinal
= NE_GetOrdinal( hModule
, name
);
1078 TRACE(module
, "%04x '%s'\n",
1081 ordinal
= LOWORD(name
);
1082 TRACE(module
, "%04x %04x\n",
1085 if (!ordinal
) return (FARPROC16
)0;
1086 ret
= NE_GetEntryPoint( hModule
, ordinal
);
1087 TRACE(module
,"returning %08x\n",(UINT32
)ret
);
1091 /***********************************************************************
1092 * GetProcAddress16 (KERNEL.50)
1094 FARPROC16 WINAPI
GetProcAddress16( HMODULE16 hModule
, SEGPTR name
)
1099 if (!hModule
) hModule
= GetCurrentTask();
1100 hModule
= GetExePtr( hModule
);
1102 if (HIWORD(name
) != 0)
1104 ordinal
= NE_GetOrdinal( hModule
, (LPSTR
)PTR_SEG_TO_LIN(name
) );
1105 TRACE(module
, "%04x '%s'\n",
1106 hModule
, (LPSTR
)PTR_SEG_TO_LIN(name
) );
1110 ordinal
= LOWORD(name
);
1111 TRACE(module
, "%04x %04x\n",
1114 if (!ordinal
) return (FARPROC16
)0;
1116 ret
= NE_GetEntryPoint( hModule
, ordinal
);
1118 TRACE(module
, "returning %08x\n", (UINT32
)ret
);
1123 /***********************************************************************
1124 * GetProcAddress32 (KERNEL32.257)
1126 FARPROC32 WINAPI
GetProcAddress32( HMODULE32 hModule
, LPCSTR function
)
1128 return MODULE_GetProcAddress32( PROCESS_Current(), hModule
, function
, TRUE
);
1131 /***********************************************************************
1132 * WIN16_GetProcAddress32 (KERNEL.453)
1134 FARPROC32 WINAPI
WIN16_GetProcAddress32( HMODULE32 hModule
, LPCSTR function
)
1136 return MODULE_GetProcAddress32( PROCESS_Current(), hModule
, function
, FALSE
);
1139 /***********************************************************************
1140 * MODULE_GetProcAddress32 (internal)
1142 FARPROC32
MODULE_GetProcAddress32(
1143 PDB32
*process
, /* [in] process context */
1144 HMODULE32 hModule
, /* [in] current module handle */
1145 LPCSTR function
, /* [in] function to be looked up */
1148 WINE_MODREF
*wm
= MODULE32_LookupHMODULE(process
,hModule
);
1150 if (HIWORD(function
))
1151 TRACE(win32
,"(%08lx,%s)\n",(DWORD
)hModule
,function
);
1153 TRACE(win32
,"(%08lx,%p)\n",(DWORD
)hModule
,function
);
1155 return (FARPROC32
)0;
1159 return PE_FindExportedFunction( process
, wm
, function
, snoop
);
1161 return ELF_FindExportedFunction( process
, wm
, function
);
1163 ERR(module
,"wine_modref type %d not handled.\n",wm
->type
);
1164 return (FARPROC32
)0;
1169 /***********************************************************************
1170 * RtlImageNtHeaders (NTDLL)
1172 PIMAGE_NT_HEADERS WINAPI
RtlImageNtHeader(HMODULE32 hModule
)
1175 * return hModule+(((IMAGE_DOS_HEADER*)hModule)->e_lfanew);
1176 * but we could get HMODULE16 or the like (think builtin modules)
1179 WINE_MODREF
*wm
= MODULE32_LookupHMODULE( PROCESS_Current(), hModule
);
1180 if (!wm
|| (wm
->type
!= MODULE32_PE
)) return (PIMAGE_NT_HEADERS
)0;
1181 return PE_HEADER(wm
->module
);
1185 /***************************************************************************
1186 * HasGPHandler (KERNEL.338)
1190 typedef struct _GPHANDLERDEF
1199 SEGPTR WINAPI
HasGPHandler( SEGPTR address
)
1204 GPHANDLERDEF
*gpHandler
;
1206 if ( (hModule
= FarGetOwner( SELECTOROF(address
) )) != 0
1207 && (gpOrdinal
= NE_GetOrdinal( hModule
, "__GP" )) != 0
1208 && (gpPtr
= (SEGPTR
)NE_GetEntryPointEx( hModule
, gpOrdinal
, FALSE
)) != 0
1209 && !IsBadReadPtr16( gpPtr
, sizeof(GPHANDLERDEF
) )
1210 && (gpHandler
= PTR_SEG_TO_LIN( gpPtr
)) != NULL
)
1212 while (gpHandler
->selector
)
1214 if ( SELECTOROF(address
) == gpHandler
->selector
1215 && OFFSETOF(address
) >= gpHandler
->rangeStart
1216 && OFFSETOF(address
) < gpHandler
->rangeEnd
)
1217 return PTR_SEG_OFF_TO_SEGPTR( gpHandler
->selector
,
1218 gpHandler
->handler
);