Sat Aug 8 19:11:46 1998 Marcus Meissner <marcus@jet.franken.de> * [*/*] Added some missing WINAPI and some missing prototypes for functions. * [controls/static.c] Got rid of the MODULE32_LookupHMODULE error showing up for every message box. * [windows/winproc.c] WM_NOTIFY 16->32 mapping (AOL Instant Messenger or however it is called). * [misc/winsock.c] hostent/servent/protoent should not use the same static buffers. (has broken nt3.15 finger.exe which does hp=gethostbyname(), then getservbyname("finger","tcp") and the references hp->h_addr_list[0]). Sat Aug 8 13:21:24 1998 Alexandre Julliard <julliard@lrc.epfl.ch> * [include/server.h] [tools/make_requests] [server/request.c] [server/trace.c] Automated part of the client/server request code generation. Added tracing of client/server communication. * [scheduler/*.c] [server/process.c] Added support for server-side handles. * [scheduler/thread.c] Added DLL_THREAD_ATTACH/DETACH notifications. * [configure.in] Added check for -lsocket. * [windows/winproc.c] Return the thunk address in WINPROC_GetProc if the function types don't match. Sat Aug 8 02:44:04 1998 Douglas Ridgway <ridgway@winehq.com> * [windows/winproc.c][windows/win.c][windows/message.c] Documentation for CallWindowProc, SetWindowLong, DispatchMessage, WaitMessage, GetMessage, and PeekMessage. Sat Aug 8 01:00:00 1998 Juergen Schmied <juergen.schmied@metronet.de> * [controls/commctrl.c][controls/widgets.c][include/builtin32.h] [include/commctrl.h][relay32/builtin32.c][relay32/comctl32.spec] [tools/build.c] [relay32/shell32.spec] Added the functionality of the LibMain function. The common controls are properly initialized now. * [controls/treeview.c][memory/atom.c][scheduler/thread.c][windows/class.c] [windows/msgbox.c][windows/win.c] Put TRACE in, put SetLastError() in. * [include/interfaces.h] Added IClassFactory::LockServer. * [include/ole2.h] Added struct for LPOLEMENUGROUPWIDTHS32, HOLEMENU32. * [include/shell.h][include/shlobj.h][misc/shell.c][ole/folders.c] Reorganized and many structs and classes (IShellBrowser,IShellView) added. shell32.dll should work in many cases now. Started SHGetFileInfoA implementeation, rewrote SHGetPathFromIDList32A. New Shell32LibMain started ShellIconCache Implementation. * [misc/shellord.c] Rewrote ILCombine, ILGetSize New stubs SHFind_InitMenuPopup, FileMenu_Create, ShellExecuteEx, SHSetInstanceExplorer, SHGetInstanceExplorer, SHFreeUnusedLibraries. * [include/winerror.h] Class and window related error codes added. * [memory/heap.c] Changed lstrlen32A to strlen to get rid of milions of TRACE lines. * [misc/ddeml.c] First lines for DdeCreateStringHandle32A / DdeFreeStringHandle32. * [misc/network.c][relay32/mpr.spec] Fixed some bugs, changed ordinals. * [windows/class.c] Workarounds for incorrect hInstance handling. Fixes parts of MSWord95/Excel95 and Money95. Thu Aug 6 21:05:35 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de> * [windows/nonclient.c][misc/tweak.c][include/tweak.h] [documentation/win95look] Removed some tweak variables. They are no longer needed. * [files/dos_fs.c] Added check for null pointer in DOSFS_GetDevice(). * [controls/tooltips.c][include/commctrl.h] Improved tooltips. * [controls/status.c][include/commctrl.h] Cleaned up code and added tooltip support. * [controls/toolbar.c][include/commctrl.h] Added tooltip support. * [documentation/common_controls] Updated. Thu Aug 6 00:05:22 1998 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de> * [include/ver.h] [misc/ver.c] Write VIF_BUFFTOOSMALL, not VIF_BUFTOSMALL. * [debugger/hash.c] [debugger/stabs.c] Make debug output more friendly for posting. * [files/file.c] Partial implementation of OF_SHARE_EXCLUSIVE. Needed for Quicklogic/QuickChip (InstallShield). * [files/profile.c] When a cached-only entry is found, return it. * [graphics/x11drv/xfont.c] Accept a space as delimiter for a fontname and inhibit overrun (Make xplasim.ex from the Phillips Coolrunner CPLD suite proceed). * [miscemu/main.c] Delay setting IF1632_CallLargeStack after loading the executables. Stops fpgaexp.exe from the Viewlogic FPGA suite from crashing when showing the Blinker error Message Box. * [misc/network.c] Make WNetGetConnection16 recognise a CDROM as a local drive. * [multimedia/mmsystem.c] Preliminary check for MCI_ALL_DEVICE_ID in MCI_Close by a FIXME. Tue Aug 4 21:15:23 1998 James Juran <jrj120@psu.edu> * [ole/ole2nls.c] Fixed bug in CompareString32A. strcmp() doesn't necessarily return -1, 0, or 1, which the previous code depended on. Changed name of is_punctuation to OLE2NLS_isPunctuation. Made NORM_IGNOREWIDTH not print a FIXME message in LCMapString32A. Other debugging messages, documentation, and code cleanups. * [objects/font.c] [relay32/gdi32.spec] [include/winerror.h] Added stub for GetFontData32, and added GDI_ERROR constant to winerror.h. Tue Aug 4 07:44:43 1998 Ove Kaaven <ovek@arcticnet.no> * [multimedia/mmio.c] Implemented mmioSetBuffer, mmioAdvance, mmioAscend, and mmioCreateChunk to the best of my knowledge. But watch out, there's bound to be bugs in there... * [include/mmsystem.h] [multimedia/mmsystem.c] Hacked in support for 32-bit multimedia function callbacks. * [AUTHORS] [misc/shell.c] Selfishly credited my authorship. Hopefully I'm excused. * [include/dosexe.h] [include/module.h] [loader/dos/*] [loader/module.c] [loader/task.c] [Makefile.in] [configure.in] [Makefile.in] Added DOS EXE (MZ) loader and virtual machine. Task structure integration thanks to Ulrich Weigand. * [files/dos_fs.c] Work around a null pointer dereference if ioctlGetDeviceInfo-ing a FILE_DupUnixHandle'd file (i.e. GetStdHandle'd). * [include/miscemu.h] [include/winnt.h] [loader/main.c] [memory/global.c] [msdos/dpmi.c] [msdos/dosmem.c] Added support for DOS memory images, and added DOSMEM_ResizeBlock() and DOSMEM_Available(). * [msdos/int21.c] Added support for the DOS virtual machine, tweaked handle assignment to avoid stdio clashes, forced INT21_FindNext to exit wildcardless searches after finding one entry, added AH=7, 8, 9, C, 48, 49, 4A, and 7160 CL=1 (Get Short Filename), and made the long filename calls only respond if running with with -winver win95. * [objects/cursoricon.c] DestroyCursor32 and DestroyIcon32 should now free the objects (hopefully) correctly. Sun Aug 2 21:42:09 1998 Huw D M Davies <daviesh@abacus.physics.ox.ac.uk> * [graphics/psdrv/*] [include/psdrv.h] Added PPD file parsing - at the moment it reads a file called default.ppd from the directory in which you start Wine. Page sizes other than A4 should now work (landscape may not). All fonts that are present on your printer (according to the PPD) should be available, providing you have the AFM files. Fonts should now be the correct size. Graphics is still basically lines only. See graphics/psdrv/README . * [misc/printdrv.c] Yet more Drv[Get/Set]PrinterData fixes. Fri Jul 31 21:33:22 1998 Per Lindström <pelinstr@algonet.se> * [relay32/crtdll.spec] [misc/crtdll.c] Added stub for freopen, _findfirst, _findnext, _fstat and _read. * [files/directory.c] Modified warning message. Wed Jul 29 11:25:28 1998 Luiz Otavio L. Zorzella <zorzella@nr.conexware.com> * [objects/font.c] Added stub for GetFontData. * [multimedia/msvideo.c] Created this file to hold the msvideo.dll calls (and maybe also msvfw32.dll). * [objects/cursoricon.c] Added search in Global Heap for cursor when trying to destroy it with DestroyCursor16. This test should be done in many (all?) other functions that use FreeResource. * [controls/treeview.c] [include/commctrl.h] Minor correction in name and addition of many placeholders for TVM messages in TREEVIEW_WindowProc. * [msdos/dpmi.c] Fixed a bug in DPMI_xrealloc where in a copy of a memory region "A" of size "a" to a region "B" of size "b", "b" bytes were being copied, instead of "a", as the new version does. This both increases speed, as well as avoids segfaults.
832 lines
24 KiB
C
832 lines
24 KiB
C
/*
|
|
* Modules
|
|
*
|
|
* Copyright 1995 Alexandre Julliard
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include "windows.h"
|
|
#include "class.h"
|
|
#include "file.h"
|
|
#include "global.h"
|
|
#include "heap.h"
|
|
#include "module.h"
|
|
#include "neexe.h"
|
|
#include "pe_image.h"
|
|
#include "dosexe.h"
|
|
#include "process.h"
|
|
#include "thread.h"
|
|
#include "resource.h"
|
|
#include "selectors.h"
|
|
#include "stackframe.h"
|
|
#include "task.h"
|
|
#include "debug.h"
|
|
#include "callback.h"
|
|
|
|
extern BOOL32 THREAD_InitDone;
|
|
|
|
|
|
/*************************************************************************
|
|
* MODULE32_LookupHMODULE
|
|
* looks for the referenced HMODULE in the current process
|
|
*/
|
|
WINE_MODREF*
|
|
MODULE32_LookupHMODULE(PDB32 *process,HMODULE32 hmod) {
|
|
WINE_MODREF *wm;
|
|
|
|
if (!hmod)
|
|
return process->exe_modref;
|
|
if (!HIWORD(hmod)) {
|
|
ERR(module,"tried to lookup 0x%04x in win32 module handler!\n",hmod);
|
|
return NULL;
|
|
}
|
|
for (wm = process->modref_list;wm;wm=wm->next)
|
|
if (wm->module == hmod)
|
|
return wm;
|
|
return NULL;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* MODULE_CreateDummyModule
|
|
*
|
|
* Create a dummy NE module for Win32 or Winelib.
|
|
*/
|
|
HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs )
|
|
{
|
|
HMODULE32 hModule;
|
|
NE_MODULE *pModule;
|
|
SEGTABLEENTRY *pSegment;
|
|
char *pStr,*s;
|
|
int len;
|
|
const char* basename;
|
|
|
|
INT32 of_size = sizeof(OFSTRUCT) - sizeof(ofs->szPathName)
|
|
+ strlen(ofs->szPathName) + 1;
|
|
INT32 size = sizeof(NE_MODULE) +
|
|
/* loaded file info */
|
|
of_size +
|
|
/* segment table: DS,CS */
|
|
2 * sizeof(SEGTABLEENTRY) +
|
|
/* name table */
|
|
9 +
|
|
/* several empty tables */
|
|
8;
|
|
|
|
hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
|
|
if (!hModule) return (HMODULE32)11; /* invalid exe */
|
|
|
|
FarSetOwner( hModule, hModule );
|
|
pModule = (NE_MODULE *)GlobalLock16( hModule );
|
|
|
|
/* Set all used entries */
|
|
pModule->magic = IMAGE_OS2_SIGNATURE;
|
|
pModule->count = 1;
|
|
pModule->next = 0;
|
|
pModule->flags = 0;
|
|
pModule->dgroup = 1;
|
|
pModule->ss = 1;
|
|
pModule->cs = 2;
|
|
pModule->heap_size = 0xe000;
|
|
pModule->stack_size = 0x1000;
|
|
pModule->seg_count = 2;
|
|
pModule->modref_count = 0;
|
|
pModule->nrname_size = 0;
|
|
pModule->fileinfo = sizeof(NE_MODULE);
|
|
pModule->os_flags = NE_OSFLAGS_WINDOWS;
|
|
pModule->expected_version = 0x030a;
|
|
pModule->self = hModule;
|
|
|
|
/* Set loaded file information */
|
|
memcpy( pModule + 1, ofs, of_size );
|
|
((OFSTRUCT *)(pModule+1))->cBytes = of_size - 1;
|
|
|
|
pSegment = (SEGTABLEENTRY*)((char*)(pModule + 1) + of_size);
|
|
pModule->seg_table = pModule->dgroup_entry = (int)pSegment - (int)pModule;
|
|
/* Data segment */
|
|
pSegment->size = 0;
|
|
pSegment->flags = NE_SEGFLAGS_DATA;
|
|
pSegment->minsize = 0x1000;
|
|
pSegment++;
|
|
/* Code segment */
|
|
pSegment->flags = 0;
|
|
pSegment++;
|
|
|
|
/* Module name */
|
|
pStr = (char *)pSegment;
|
|
pModule->name_table = (int)pStr - (int)pModule;
|
|
basename = strrchr(ofs->szPathName,'\\');
|
|
if (!basename) basename = ofs->szPathName;
|
|
else basename++;
|
|
len = strlen(basename);
|
|
if ((s = strchr(basename,'.'))) len = s - basename;
|
|
if (len > 8) len = 8;
|
|
*pStr = len;
|
|
strncpy( pStr+1, basename, len );
|
|
if (len < 8) pStr[len+1] = 0;
|
|
pStr += 9;
|
|
|
|
/* All tables zero terminated */
|
|
pModule->res_table = pModule->import_table = pModule->entry_table =
|
|
(int)pStr - (int)pModule;
|
|
|
|
NE_RegisterModule( pModule );
|
|
return hModule;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* MODULE_GetWndProcEntry16 (not a Windows API function)
|
|
*
|
|
* Return an entry point from the WPROCS dll.
|
|
*/
|
|
FARPROC16 MODULE_GetWndProcEntry16( LPCSTR name )
|
|
{
|
|
FARPROC16 ret = NULL;
|
|
|
|
if (__winelib)
|
|
{
|
|
/* FIXME: hack for Winelib */
|
|
extern LRESULT ColorDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT FileOpenDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT FileSaveDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT FindTextDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT PrintDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT PrintSetupDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
|
|
extern LRESULT ReplaceTextDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
|
|
|
|
if (!strcmp(name,"ColorDlgProc"))
|
|
return (FARPROC16)ColorDlgProc;
|
|
if (!strcmp(name,"FileOpenDlgProc"))
|
|
return (FARPROC16)FileOpenDlgProc;
|
|
if (!strcmp(name,"FileSaveDlgProc"))
|
|
return (FARPROC16)FileSaveDlgProc;
|
|
if (!strcmp(name,"FindTextDlgProc"))
|
|
return (FARPROC16)FindTextDlgProc16;
|
|
if (!strcmp(name,"PrintDlgProc"))
|
|
return (FARPROC16)PrintDlgProc;
|
|
if (!strcmp(name,"PrintSetupDlgProc"))
|
|
return (FARPROC16)PrintSetupDlgProc;
|
|
if (!strcmp(name,"ReplaceTextDlgProc"))
|
|
return (FARPROC16)ReplaceTextDlgProc16;
|
|
if (!strcmp(name,"DefResourceHandler"))
|
|
return (FARPROC16)NE_DefResourceHandler;
|
|
if (!strcmp(name,"LoadDIBIconHandler"))
|
|
return (FARPROC16)LoadDIBIconHandler;
|
|
if (!strcmp(name,"LoadDIBCursorHandler"))
|
|
return (FARPROC16)LoadDIBCursorHandler;
|
|
FIXME(module,"No mapping for %s(), add one in library/miscstubs.c\n",name);
|
|
assert( FALSE );
|
|
return NULL;
|
|
}
|
|
else
|
|
{
|
|
WORD ordinal;
|
|
static HMODULE32 hModule = 0;
|
|
|
|
if (!hModule) hModule = GetModuleHandle16( "WPROCS" );
|
|
ordinal = NE_GetOrdinal( hModule, name );
|
|
if (!(ret = NE_GetEntryPoint( hModule, ordinal )))
|
|
{
|
|
WARN( module, "%s not found\n", name );
|
|
assert( FALSE );
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* MODULE_FindModule32
|
|
*
|
|
* Find a (loaded) win32 module depending on path
|
|
* The handling of '.' is a bit weird, but we need it that way,
|
|
* for sometimes the programs use '<name>.exe' and '<name>.dll' and
|
|
* this is the only way to differentiate. (mainly hypertrm.exe)
|
|
*
|
|
* RETURNS
|
|
* the module handle if found
|
|
* 0 if not
|
|
*/
|
|
HMODULE32 MODULE_FindModule32(
|
|
PDB32* process, /* [in] process in which to find the library */
|
|
LPCSTR path /* [in] pathname of module/library to be found */
|
|
) {
|
|
LPSTR filename;
|
|
LPSTR dotptr;
|
|
WINE_MODREF *wm;
|
|
|
|
if (!process)
|
|
return 0;
|
|
if (!(filename = strrchr( path, '\\' )))
|
|
filename = HEAP_strdupA(process->heap,0,path);
|
|
else
|
|
filename = HEAP_strdupA(process->heap,0,filename+1);
|
|
dotptr=strrchr(filename,'.');
|
|
|
|
for (wm=process->modref_list;wm;wm=wm->next) {
|
|
LPSTR xmodname,xdotptr;
|
|
|
|
assert (wm->modname);
|
|
xmodname = HEAP_strdupA(process->heap,0,wm->modname);
|
|
xdotptr=strrchr(xmodname,'.');
|
|
if ( (xdotptr && !dotptr) ||
|
|
(!xdotptr && dotptr)
|
|
) {
|
|
if (dotptr) *dotptr = '\0';
|
|
if (xdotptr) *xdotptr = '\0';
|
|
}
|
|
if (!strcasecmp( filename, xmodname)) {
|
|
HeapFree(process->heap,0,filename);
|
|
HeapFree(process->heap,0,xmodname);
|
|
return wm->module;
|
|
}
|
|
if (dotptr) *dotptr='.';
|
|
/* FIXME: add paths, shortname */
|
|
HeapFree(process->heap,0,xmodname);
|
|
}
|
|
/* if that fails, try looking for the filename... */
|
|
for (wm=process->modref_list;wm;wm=wm->next) {
|
|
LPSTR xlname,xdotptr;
|
|
|
|
assert (wm->longname);
|
|
xlname = strrchr(wm->longname,'/');
|
|
if (!xlname)
|
|
xlname = wm->longname;
|
|
else
|
|
xlname++;
|
|
xlname = HEAP_strdupA(process->heap,0,xlname);
|
|
xdotptr=strrchr(xlname,'.');
|
|
if ( (xdotptr && !dotptr) ||
|
|
(!xdotptr && dotptr)
|
|
) {
|
|
if (dotptr) *dotptr = '\0';
|
|
if (xdotptr) *xdotptr = '\0';
|
|
}
|
|
if (!strcasecmp( filename, xlname)) {
|
|
HeapFree(process->heap,0,filename);
|
|
HeapFree(process->heap,0,xlname);
|
|
return wm->module;
|
|
}
|
|
if (dotptr) *dotptr='.';
|
|
/* FIXME: add paths, shortname */
|
|
HeapFree(process->heap,0,xlname);
|
|
}
|
|
HeapFree(process->heap,0,filename);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
* MODULE_Load
|
|
*
|
|
* Implementation of LoadModule().
|
|
*
|
|
* cmd_line must contain the whole command-line, including argv[0] (and
|
|
* without a preceding length byte).
|
|
* If cmd_line is NULL, the module is loaded as a library even if it is a .exe
|
|
*/
|
|
HINSTANCE16 MODULE_Load( LPCSTR name, BOOL32 implicit,
|
|
LPCSTR cmd_line, LPCSTR env, UINT32 show_cmd )
|
|
{
|
|
HMODULE16 hModule;
|
|
HINSTANCE16 hInstance, hPrevInstance;
|
|
NE_MODULE *pModule;
|
|
|
|
if (__winelib)
|
|
{
|
|
OFSTRUCT ofs;
|
|
lstrcpyn32A( ofs.szPathName, name, sizeof(ofs.szPathName) );
|
|
if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return hModule;
|
|
pModule = (NE_MODULE *)GlobalLock16( hModule );
|
|
hInstance = NE_CreateInstance( pModule, &hPrevInstance,
|
|
(cmd_line == NULL) );
|
|
}
|
|
else
|
|
{
|
|
hInstance = NE_LoadModule( name, &hPrevInstance, implicit,
|
|
(cmd_line == NULL) );
|
|
if ((hInstance == 21) && cmd_line)
|
|
return PE_LoadModule( name, cmd_line, env, show_cmd );
|
|
#ifdef linux
|
|
if (hInstance == 11)
|
|
return MZ_LoadModule(name, cmd_line, env, show_cmd );
|
|
#endif
|
|
}
|
|
|
|
/* Create a task for this instance */
|
|
|
|
if (hInstance < 32) return hInstance;
|
|
pModule = NE_GetPtr( hInstance );
|
|
if (cmd_line && !(pModule->flags & NE_FFLAGS_LIBMODULE))
|
|
{
|
|
PDB32 *pdb;
|
|
PROCESS_INFORMATION info;
|
|
|
|
pModule->flags |= NE_FFLAGS_GUI;
|
|
|
|
pdb = PROCESS_Create( pModule, cmd_line, env, hInstance,
|
|
hPrevInstance, show_cmd, &info );
|
|
/* we don't need the handles for now */
|
|
CloseHandle( info.hThread );
|
|
CloseHandle( info.hProcess );
|
|
if (pdb && (GetNumTasks() > 1)) Yield16();
|
|
}
|
|
|
|
return hInstance;
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* LoadModule16 (KERNEL.45)
|
|
*/
|
|
HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
|
|
{
|
|
LOADPARAMS *params;
|
|
LPSTR cmd_line, new_cmd_line;
|
|
UINT16 show_cmd = 0;
|
|
LPCVOID env = NULL;
|
|
HINSTANCE16 hInstance;
|
|
|
|
if (!paramBlock || (paramBlock == (LPVOID)-1))
|
|
return LoadLibrary16( name );
|
|
|
|
params = (LOADPARAMS *)paramBlock;
|
|
cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
|
|
/* PowerPoint passes NULL as showCmd */
|
|
if (params->showCmd)
|
|
show_cmd = *((UINT16 *)PTR_SEG_TO_LIN(params->showCmd)+1);
|
|
|
|
if (!cmd_line) cmd_line = "";
|
|
else if (*cmd_line) cmd_line++; /* skip the length byte */
|
|
|
|
if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
|
|
strlen(cmd_line) + strlen(name) + 2 )))
|
|
return 0;
|
|
strcpy( new_cmd_line, name );
|
|
strcat( new_cmd_line, " " );
|
|
strcat( new_cmd_line, cmd_line );
|
|
|
|
if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
|
|
hInstance = MODULE_Load( name, FALSE, new_cmd_line, env, show_cmd );
|
|
if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
|
|
HeapFree( GetProcessHeap(), 0, new_cmd_line );
|
|
return hInstance;
|
|
}
|
|
|
|
/**********************************************************************
|
|
* LoadModule32 (KERNEL32.499)
|
|
*
|
|
* FIXME
|
|
*
|
|
* This should get implemented via CreateProcess -- MODULE_Load
|
|
* is resolutely 16-bit.
|
|
*/
|
|
DWORD WINAPI LoadModule32( LPCSTR name, LPVOID paramBlock )
|
|
{
|
|
LOADPARAMS32 *params = (LOADPARAMS32 *)paramBlock;
|
|
#if 0
|
|
STARTUPINFO st;
|
|
PROCESSINFORMATION pi;
|
|
st.cb = sizeof(STARTUPINFO);
|
|
st.wShowWindow = p->lpCmdShow[2] ; WRONG
|
|
|
|
BOOL32 ret = CreateProcess32A( name, p->lpCmdLine,
|
|
NULL, NULL, FALSE, 0, p->lpEnvAddress,
|
|
NULL, &st, &pi);
|
|
if (!ret) {
|
|
/* handle errors appropriately */
|
|
}
|
|
CloseHandle32(pi.hProcess);
|
|
CloseHandle32(pi.hThread);
|
|
|
|
#else
|
|
return MODULE_Load( name, FALSE, params->lpCmdLine, params->lpEnvAddress,
|
|
*((UINT16 *)params->lpCmdShow + 1) );
|
|
#endif
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetModuleHandle (KERNEL32.237)
|
|
*/
|
|
HMODULE32 WINAPI GetModuleHandle32A(LPCSTR module)
|
|
{
|
|
|
|
TRACE(win32, "%s\n", module ? module : "NULL");
|
|
if (module == NULL)
|
|
return PROCESS_Current()->exe_modref->module;
|
|
else
|
|
return MODULE_FindModule32(PROCESS_Current(),module);
|
|
}
|
|
|
|
HMODULE32 WINAPI GetModuleHandle32W(LPCWSTR module)
|
|
{
|
|
HMODULE32 hModule;
|
|
LPSTR modulea = HEAP_strdupWtoA( GetProcessHeap(), 0, module );
|
|
hModule = GetModuleHandle32A( modulea );
|
|
HeapFree( GetProcessHeap(), 0, modulea );
|
|
return hModule;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetModuleFileName32A (KERNEL32.235)
|
|
*/
|
|
DWORD WINAPI GetModuleFileName32A(
|
|
HMODULE32 hModule, /* [in] module handle (32bit) */
|
|
LPSTR lpFileName, /* [out] filenamebuffer */
|
|
DWORD size /* [in] size of filenamebuffer */
|
|
) {
|
|
WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule);
|
|
|
|
if (!wm) /* can happen on start up or the like */
|
|
return 0;
|
|
|
|
/* FIXME: we should probably get a real long name, but wm->longname
|
|
* is currently a UNIX filename!
|
|
*/
|
|
lstrcpyn32A( lpFileName, wm->shortname, size );
|
|
TRACE(module, "%s\n", lpFileName );
|
|
return strlen(lpFileName);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetModuleFileName32W (KERNEL32.236)
|
|
*/
|
|
DWORD WINAPI GetModuleFileName32W( HMODULE32 hModule, LPWSTR lpFileName,
|
|
DWORD size )
|
|
{
|
|
LPSTR fnA = (char*)HeapAlloc( GetProcessHeap(), 0, size );
|
|
DWORD res = GetModuleFileName32A( hModule, fnA, size );
|
|
lstrcpynAtoW( lpFileName, fnA, size );
|
|
HeapFree( GetProcessHeap(), 0, fnA );
|
|
return res;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LoadLibraryEx32W (KERNEL.513)
|
|
* FIXME
|
|
*/
|
|
HMODULE32 WINAPI LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf,
|
|
DWORD flags )
|
|
{
|
|
TRACE(module,"(%s,%d,%08lx)\n",libname,hf,flags);
|
|
return LoadLibraryEx32A(libname, hf,flags);
|
|
}
|
|
|
|
/***********************************************************************
|
|
* LoadLibraryEx32A (KERNEL32)
|
|
*/
|
|
HMODULE32 WINAPI LoadLibraryEx32A(LPCSTR libname,HFILE32 hfile,DWORD flags)
|
|
{
|
|
HMODULE32 hmod;
|
|
|
|
hmod = PE_LoadLibraryEx32A(libname,PROCESS_Current(),hfile,flags);
|
|
if (hmod < 32) {
|
|
char buffer[256];
|
|
|
|
strcpy( buffer, libname );
|
|
strcat( buffer, ".dll" );
|
|
hmod = PE_LoadLibraryEx32A(buffer,PROCESS_Current(),hfile,flags);
|
|
}
|
|
/* initialize all DLLs, which haven't been initialized yet. */
|
|
if (hmod >= 32)
|
|
PE_InitializeDLLs( PROCESS_Current(), DLL_PROCESS_ATTACH, NULL);
|
|
return hmod;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* LoadLibraryA (KERNEL32)
|
|
*/
|
|
HMODULE32 WINAPI LoadLibrary32A(LPCSTR libname) {
|
|
return LoadLibraryEx32A(libname,0,0);
|
|
}
|
|
|
|
/***********************************************************************
|
|
* LoadLibraryW (KERNEL32)
|
|
*/
|
|
HMODULE32 WINAPI LoadLibrary32W(LPCWSTR libnameW)
|
|
{
|
|
return LoadLibraryEx32W(libnameW,0,0);
|
|
}
|
|
|
|
/***********************************************************************
|
|
* LoadLibraryExW (KERNEL32)
|
|
*/
|
|
HMODULE32 WINAPI LoadLibraryEx32W(LPCWSTR libnameW,HFILE32 hfile,DWORD flags)
|
|
{
|
|
LPSTR libnameA = HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW );
|
|
HMODULE32 ret = LoadLibraryEx32A( libnameA , hfile, flags );
|
|
|
|
HeapFree( GetProcessHeap(), 0, libnameA );
|
|
return ret;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* FreeLibrary
|
|
*/
|
|
BOOL32 WINAPI FreeLibrary32(HINSTANCE32 hLibModule)
|
|
{
|
|
FIXME(module,"(%08x): stub\n", hLibModule);
|
|
return TRUE; /* FIXME */
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* PrivateLoadLibrary (KERNEL32)
|
|
*
|
|
* FIXME: rough guesswork, don't know what "Private" means
|
|
*/
|
|
HINSTANCE32 WINAPI PrivateLoadLibrary(LPCSTR libname)
|
|
{
|
|
return (HINSTANCE32)LoadLibrary16(libname);
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
* PrivateFreeLibrary (KERNEL32)
|
|
*
|
|
* FIXME: rough guesswork, don't know what "Private" means
|
|
*/
|
|
void WINAPI PrivateFreeLibrary(HINSTANCE32 handle)
|
|
{
|
|
FreeLibrary16((HINSTANCE16)handle);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* WinExec16 (KERNEL.166)
|
|
*/
|
|
HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
|
|
{
|
|
return WinExec32( lpCmdLine, nCmdShow );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* WinExec32 (KERNEL32.566)
|
|
*/
|
|
HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
|
|
{
|
|
HINSTANCE32 handle = 2;
|
|
char *p, filename[256];
|
|
static int use_load_module = 1;
|
|
int spacelimit = 0, exhausted = 0;
|
|
|
|
if (!lpCmdLine)
|
|
return 2; /* File not found */
|
|
|
|
/* Keep trying to load a file by trying different filenames; e.g.,
|
|
for the cmdline "abcd efg hij", try "abcd" with args "efg hij",
|
|
then "abcd efg" with arg "hij", and finally "abcd efg hij" with
|
|
no args */
|
|
|
|
while(!exhausted && handle == 2) {
|
|
int spacecount = 0;
|
|
|
|
/* Build the filename and command-line */
|
|
|
|
lstrcpyn32A(filename, lpCmdLine,
|
|
sizeof(filename) - 4 /* for extension */);
|
|
|
|
/* Keep grabbing characters until end-of-string, tab, or until the
|
|
number of spaces is greater than the spacelimit */
|
|
|
|
for (p = filename; ; p++) {
|
|
if(*p == ' ') {
|
|
++spacecount;
|
|
if(spacecount > spacelimit) {
|
|
++spacelimit;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(*p == '\0' || *p == '\t') {
|
|
exhausted = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
/* Now load the executable file */
|
|
|
|
if (use_load_module)
|
|
{
|
|
/* Winelib: Use LoadModule() only for the program itself */
|
|
if (__winelib) use_load_module = 0;
|
|
handle = MODULE_Load( filename, FALSE, lpCmdLine, NULL, nCmdShow );
|
|
if (handle == 2) /* file not found */
|
|
{
|
|
/* Check that the original file name did not have a suffix */
|
|
p = strrchr(filename, '.');
|
|
/* if there is a '.', check if either \ OR / follow */
|
|
if (!p || strchr(p, '/') || strchr(p, '\\'))
|
|
{
|
|
p = filename + strlen(filename);
|
|
strcpy( p, ".exe" );
|
|
handle = MODULE_Load( filename, FALSE, lpCmdLine,
|
|
NULL, nCmdShow );
|
|
*p = '\0'; /* Remove extension */
|
|
}
|
|
}
|
|
}
|
|
else
|
|
handle = 2; /* file not found */
|
|
|
|
if (handle < 32)
|
|
{
|
|
/* Try to start it as a unix program */
|
|
if (!fork())
|
|
{
|
|
/* Child process */
|
|
DOS_FULL_NAME full_name;
|
|
const char *unixfilename = NULL;
|
|
const char *argv[256], **argptr;
|
|
int iconic = (nCmdShow == SW_SHOWMINIMIZED ||
|
|
nCmdShow == SW_SHOWMINNOACTIVE);
|
|
|
|
THREAD_InitDone = FALSE; /* we didn't init this process */
|
|
/* get unixfilename */
|
|
if (strchr(filename, '/') ||
|
|
strchr(filename, ':') ||
|
|
strchr(filename, '\\'))
|
|
{
|
|
if (DOSFS_GetFullName( filename, TRUE, &full_name ))
|
|
unixfilename = full_name.long_name;
|
|
}
|
|
else unixfilename = filename;
|
|
|
|
if (unixfilename)
|
|
{
|
|
/* build argv */
|
|
argptr = argv;
|
|
if (iconic) *argptr++ = "-iconic";
|
|
*argptr++ = unixfilename;
|
|
p = strdup(lpCmdLine);
|
|
while (1)
|
|
{
|
|
while (*p && (*p == ' ' || *p == '\t')) *p++ = '\0';
|
|
if (!*p) break;
|
|
*argptr++ = p;
|
|
while (*p && *p != ' ' && *p != '\t') p++;
|
|
}
|
|
*argptr++ = 0;
|
|
|
|
/* Execute */
|
|
execvp(argv[0], (char**)argv);
|
|
}
|
|
|
|
/* Failed ! */
|
|
|
|
if (__winelib)
|
|
{
|
|
/* build argv */
|
|
argptr = argv;
|
|
*argptr++ = "wine";
|
|
if (iconic) *argptr++ = "-iconic";
|
|
*argptr++ = lpCmdLine;
|
|
*argptr++ = 0;
|
|
|
|
/* Execute */
|
|
execvp(argv[0] , (char**)argv);
|
|
|
|
/* Failed ! */
|
|
MSG("WinExec: can't exec 'wine %s'\n",
|
|
lpCmdLine);
|
|
}
|
|
exit(1);
|
|
}
|
|
}
|
|
} /* while (!exhausted && handle < 32) */
|
|
|
|
return handle;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* WIN32_GetProcAddress16 (KERNEL32.36)
|
|
* Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
|
|
*/
|
|
FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hModule, LPCSTR name )
|
|
{
|
|
WORD ordinal;
|
|
FARPROC16 ret;
|
|
|
|
if (!hModule) {
|
|
WARN(module,"hModule may not be 0!\n");
|
|
return (FARPROC16)0;
|
|
}
|
|
if (HIWORD(hModule))
|
|
{
|
|
WARN( module, "hModule is Win32 handle (%08x)\n", hModule );
|
|
return (FARPROC16)0;
|
|
}
|
|
hModule = GetExePtr( hModule );
|
|
if (HIWORD(name)) {
|
|
ordinal = NE_GetOrdinal( hModule, name );
|
|
TRACE(module, "%04x '%s'\n",
|
|
hModule, name );
|
|
} else {
|
|
ordinal = LOWORD(name);
|
|
TRACE(module, "%04x %04x\n",
|
|
hModule, ordinal );
|
|
}
|
|
if (!ordinal) return (FARPROC16)0;
|
|
ret = NE_GetEntryPoint( hModule, ordinal );
|
|
TRACE(module,"returning %08x\n",(UINT32)ret);
|
|
return ret;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* GetProcAddress16 (KERNEL.50)
|
|
*/
|
|
FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name )
|
|
{
|
|
WORD ordinal;
|
|
FARPROC16 ret;
|
|
|
|
if (!hModule) hModule = GetCurrentTask();
|
|
hModule = GetExePtr( hModule );
|
|
|
|
if (HIWORD(name) != 0)
|
|
{
|
|
ordinal = NE_GetOrdinal( hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
|
|
TRACE(module, "%04x '%s'\n",
|
|
hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
|
|
}
|
|
else
|
|
{
|
|
ordinal = LOWORD(name);
|
|
TRACE(module, "%04x %04x\n",
|
|
hModule, ordinal );
|
|
}
|
|
if (!ordinal) return (FARPROC16)0;
|
|
|
|
ret = NE_GetEntryPoint( hModule, ordinal );
|
|
|
|
TRACE(module, "returning %08x\n", (UINT32)ret );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetProcAddress32 (KERNEL32.257)
|
|
*/
|
|
FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function )
|
|
{
|
|
return MODULE_GetProcAddress32( PROCESS_Current(), hModule, function );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* MODULE_GetProcAddress32 (internal)
|
|
*/
|
|
FARPROC32 MODULE_GetProcAddress32(
|
|
PDB32 *process, /* [in] process context */
|
|
HMODULE32 hModule, /* [in] current module handle */
|
|
LPCSTR function ) /* [in] function to be looked up */
|
|
{
|
|
WINE_MODREF *wm = MODULE32_LookupHMODULE(process,hModule);
|
|
|
|
if (HIWORD(function))
|
|
TRACE(win32,"(%08lx,%s)\n",(DWORD)hModule,function);
|
|
else
|
|
TRACE(win32,"(%08lx,%p)\n",(DWORD)hModule,function);
|
|
if (!wm)
|
|
return (FARPROC32)0;
|
|
switch (wm->type)
|
|
{
|
|
case MODULE32_PE:
|
|
return PE_FindExportedFunction( process, wm, function);
|
|
default:
|
|
ERR(module,"wine_modref type %d not handled.\n",wm->type);
|
|
return (FARPROC32)0;
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* RtlImageNtHeaders (NTDLL)
|
|
*/
|
|
LPIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE32 hModule)
|
|
{
|
|
/* basically:
|
|
* return hModule+(((IMAGE_DOS_HEADER*)hModule)->e_lfanew);
|
|
* but we could get HMODULE16 or the like (think builtin modules)
|
|
*/
|
|
|
|
WINE_MODREF *wm = MODULE32_LookupHMODULE( PROCESS_Current(), hModule );
|
|
if (!wm || (wm->type != MODULE32_PE)) return (LPIMAGE_NT_HEADERS)0;
|
|
return PE_HEADER(wm->module);
|
|
}
|