Release 970509

Tue May  6 19:12:20 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [loader/task.c] [loader/module.c]
	Fixed command line in LoadModule to already include the length
	indicator (thanks to Andreas Mohr).

	* [windows/dialog.c]
	DlgDirList: fixed behavior with DDL_DRIVES | DDL_EXCLUSIVE (thanks
	to Bruce Milner for this one); correctly update file spec on exit.

	* [windows/winproc.c] [if1632/thunk.c] [include/callback.h]
	Moved emulator-specific code for calling window procedure to
	thunk.c.

Mon Apr 28 10:21:59 1997  Huw D M Davies <h.davies1@physics.oxford.ac.uk>

	* [memory/local.c]
	Better implementation of moveable blocks (first word in block is
	the handle itself) and discarded blocks. Local(Re)Alloc is much
	more like the real thing.

Thu Apr 24 19:50:19 1997  Albrecht Kleine <kleine@ak.sax.de>

	* [objects/metafile.c]
	Added handling of meta record META_DIBCREATEPATTERNBRUSH.

Mon Apr 21 14:03:32 1997  Alex Korobka <alex@trantor.pharm.sunysb.edu>

	* [multimedia/mmsystem.c] [multimedia/audio.c]
	Fixed leftover problems with masked device IDs.

	* [msdos/int21.c]
	Removed code duplications, fixed Write.

	* [windows/event.c] [windows/dce.c] [windows/nonclient.c]
	  [windows/winpos.c]
	Yet another attempt to make -managed work better.

	* [controls/combo.c]
	UI fix.

Mon Apr 21 13:10:24 1997  Marcus Meissner <msmeissn@immd4.informatik.uni-erlangen.de>

	* [debugger/*]
	All "Loading from ..." lines merged into one so important
	information before the crash doesn't scroll out.

	* [if1632/kernel.spec]
	Added some ordinal stubs used by win95 OLE and friends.

	* [win32/process.c] [if1632/kernel.spec] [loader/module.c]
	MsgWaitForMultipleObjects,GetProcessTimes,RtlImageNtHeaders,
 	LoadLibraryEx32W and GetProcAddress32W added.

	* [objects/bitmap.c]
	XImages use another memory layout for depth 4 (and poss. other
 	depths) then Windows bitmaps. Replaced speedup hack by generic
 	(and better working) code.

	* [objects/dib.c]
	Another ximage!=bitmap memory layout bug. 
	All _XinitImageFuncPtrs except one removed.

Sun Apr 20 17:12:30 1997  Andrew Taylor <andrew@riscan.com>

	* [multimedia/audio.c]
	Fixed some regression bugs.

Sun Apr 20 12:15:09 1997  Andreas Mohr <100.30936@germany.net>

	* [loader/module.c]
	Fixed MODULE_LoadExeHeader() to use the correct offset for
	fast-load area.

Sat Apr 19 16:40:00 1997  Chad Fraleigh <chadf@bookcase.com>

	* [controls/*] [debugger/*] [graphics/win16drv/*] [loader/*] [misc/*]
	  [win32/*]
	Removed <malloc.h> and added <stdlib.h> where needed.
	Changed printf formaters to match argument types (%lx instead of %x).
	Casted some types to make the compiler happy. Mostly pointer<->ulong.

	* [graphics/win16drv/init.c]
	Fixed uninitialized variable.

	* [include/msdos.h]
	Added <sys/types.h> needed for <dirent.h>.

	* [include/sigcontext.h]
	Combined a common NetBSD & FreeBSD #ifdef, and added in OpenBSD.
	Casted EIP_sig/ESP_sig to be unsigned long (declared as 'int' in *BSD).

	* [misc/crtdll.c] [misc/lstr.c]
	Casted last argument in v*printf() to be va_list. This code seems to
	make BIG assumptions about the implementation of va_list.

	* [misc/ver.c]
	Fixed impossible if() expression (unsigned < 0).

	* [misc/winsock.c]
	Removed semicolon on the end of an if() statement.

	* [windows/mdi.c]
	Changed a counter/index to unsigned since it was complaining about
	signed/unsigned comparison and didn't need to be negative.

Wed Apr 16 17:43:19 1997 Georg Beyerle <gbeyerle@awi-potsdam.de>

	* [scheduler/thread.c]
	Minor fix in thread database initialization.

Wed Apr 16 17:28:05 1997  Andreas Mohr <100.30936@germany.net>

	* [files/file.c]
	Fixed FILE_FillInfo() to omit the archive flag when handling a DOS
	directory entry.
diff --git a/loader/module.c b/loader/module.c
index d7df2fe..19bb6d0 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -451,7 +451,7 @@
        ((fastload && ((offset) >= fastload_offset) && \
          ((offset)+(size) <= fastload_offset+fastload_length)) ? \
         (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
-        (_llseek32( hFile, mz_header.ne_offset+(offset), SEEK_SET), \
+        (_llseek32( hFile, (offset), SEEK_SET), \
          _lread32( hFile, (buffer), (size) ) == (size)))
 
     _llseek32( hFile, 0, SEEK_SET );
@@ -509,10 +509,11 @@
                         fastload_offset, fastload_length );
         if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
         {
-            _llseek32( hFile, mz_header.ne_offset + fastload_offset, SEEK_SET);
+            _llseek32( hFile, fastload_offset, SEEK_SET);
             if (_lread32(hFile, fastload, fastload_length) != fastload_length)
             {
                 HeapFree( SystemHeap, 0, fastload );
+                fprintf(stderr, "Error reading fast-load area !\n");
                 fastload = NULL;
             }
         }
@@ -536,12 +537,12 @@
         int i;
         struct ne_segment_table_entry_s *pSeg;
 
-        if (!READ( ne_header.segment_tab_offset,
+        if (!READ( mz_header.ne_offset + ne_header.segment_tab_offset,
              ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
              buffer ))
         {
             HeapFree( SystemHeap, 0, buffer );
-            HeapFree( SystemHeap, 0, fastload );
+            if (fastload) HeapFree( SystemHeap, 0, fastload );
             GlobalFree16( hModule );
             return (HMODULE16)11;  /* invalid exe */
         }
@@ -555,7 +556,7 @@
     }
     else
     {
-        HeapFree( SystemHeap, 0, fastload );
+        if (fastload) HeapFree( SystemHeap, 0, fastload );
         GlobalFree16( hModule );
         return (HMODULE16)11;  /* invalid exe */
     }
@@ -565,7 +566,7 @@
     if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
     {
         pModule->res_table = (int)pData - (int)pModule;
-        if (!READ(ne_header.resource_tab_offset,
+        if (!READ(mz_header.ne_offset + ne_header.resource_tab_offset,
                   ne_header.rname_tab_offset - ne_header.resource_tab_offset,
                   pData )) return (HMODULE16)11;  /* invalid exe */
         pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
@@ -575,11 +576,11 @@
     /* Get the resident names table */
 
     pModule->name_table = (int)pData - (int)pModule;
-    if (!READ( ne_header.rname_tab_offset,
+    if (!READ( mz_header.ne_offset + ne_header.rname_tab_offset,
                ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
                pData ))
     {
-        HeapFree( SystemHeap, 0, fastload );
+        if (fastload) HeapFree( SystemHeap, 0, fastload );
         GlobalFree16( hModule );
         return (HMODULE16)11;  /* invalid exe */
     }
@@ -590,11 +591,11 @@
     if (ne_header.n_mod_ref_tab > 0)
     {
         pModule->modref_table = (int)pData - (int)pModule;
-        if (!READ( ne_header.moduleref_tab_offset,
+        if (!READ( mz_header.ne_offset + ne_header.moduleref_tab_offset,
                   ne_header.n_mod_ref_tab * sizeof(WORD),
                   pData ))
         {
-            HeapFree( SystemHeap, 0, fastload );
+            if (fastload) HeapFree( SystemHeap, 0, fastload );
             GlobalFree16( hModule );
             return (HMODULE16)11;  /* invalid exe */
         }
@@ -605,11 +606,11 @@
     /* Get the imported names table */
 
     pModule->import_table = (int)pData - (int)pModule;
-    if (!READ( ne_header.iname_tab_offset, 
+    if (!READ( mz_header.ne_offset + ne_header.iname_tab_offset, 
                ne_header.entry_tab_offset - ne_header.iname_tab_offset,
                pData ))
     {
-        HeapFree( SystemHeap, 0, fastload );
+        if (fastload) HeapFree( SystemHeap, 0, fastload );
         GlobalFree16( hModule );
         return (HMODULE16)11;  /* invalid exe */
     }
@@ -618,11 +619,11 @@
     /* Get the entry table */
 
     pModule->entry_table = (int)pData - (int)pModule;
-    if (!READ( ne_header.entry_tab_offset,
+    if (!READ( mz_header.ne_offset + ne_header.entry_tab_offset,
                ne_header.entry_tab_length,
                pData ))
     {
-        HeapFree( SystemHeap, 0, fastload );
+        if (fastload) HeapFree( SystemHeap, 0, fastload );
         GlobalFree16( hModule );
         return (HMODULE16)11;  /* invalid exe */
     }
@@ -631,7 +632,7 @@
     /* Free the fast-load area */
 
 #undef READ
-    HeapFree( SystemHeap, 0, fastload );
+    if (fastload) HeapFree( SystemHeap, 0, fastload );
 
     /* Get the non-resident names table */
 
@@ -1380,6 +1381,17 @@
 
 
 /***********************************************************************
+ *           LoadLibraryEx32W   (KERNEL.513)
+ */
+HINSTANCE16 LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf, DWORD flags )
+{
+    fprintf(stderr,"LoadLibraryEx32W(%s,%d,%08lx)\n",libname,hf,flags);
+    if (!flags && !hf)
+    	return LoadLibrary32A(libname);
+    return 0;
+}
+
+/***********************************************************************
  *           LoadLibrary   (KERNEL.95)
  */
 HINSTANCE16 LoadLibrary16( LPCSTR libname )
@@ -1459,8 +1471,9 @@
     cmdline = (char *)GlobalLock16( cmdLineHandle );
     lstrcpyn32A(filename, lpCmdLine, sizeof(filename) - 4 /* for extension */);
     for (p = filename; *p && (*p != ' ') && (*p != '\t'); p++);
-    if (*p) lstrcpyn32A( cmdline, p + 1, 128 );
-    else cmdline[0] = '\0';
+    if (*p) lstrcpyn32A( cmdline + 1, p + 1, 127 );
+    else cmdline[1] = '\0';
+    cmdline[0] = strlen( cmdline + 1 ) + 1;
     *p = '\0';
 
       /* Now load the executable file */
@@ -1603,6 +1616,10 @@
 #ifndef WINELIB
     NE_MODULE *pModule;
 
+    if (HIWORD(function))
+	dprintf_win32(stddeb,"GetProcAddress32(%08lx,%s)\n",(DWORD)hModule,function);
+    else
+	dprintf_win32(stddeb,"GetProcAddress32(%08lx,%p)\n",(DWORD)hModule,function);
     hModule = GetExePtr( hModule );
     if (!(pModule = MODULE_GetPtr( hModule )))
         return (FARPROC32)0;
@@ -1616,6 +1633,26 @@
 #endif
 }
 
+/***********************************************************************
+ *           RtlImageNtHeaders   (NTDLL)
+ */
+LPIMAGE_NT_HEADERS
+RtlImageNtHeader(HMODULE32 hModule)
+{
+#ifndef WINELIB
+    NE_MODULE *pModule;
+
+    hModule = GetExePtr( hModule );
+    if (!(pModule = MODULE_GetPtr( hModule )))
+        return (LPIMAGE_NT_HEADERS)0;
+    if (!(pModule->flags & NE_FFLAGS_WIN32) || !pModule->pe_module)
+        return (LPIMAGE_NT_HEADERS)0;
+    return pModule->pe_module->pe_header;
+#else
+    return NULL;
+#endif
+}
+
 
 /**********************************************************************
  *	    GetExpWinVer    (KERNEL.167)