Release 980517

Sun May 17 16:23:56 1998  Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>

	* [file/profile.c]
	Fix the return value of PROFILE_GetSection

	* [misc/crtdll.c]
	Do _getdrive, fix _chdrive.

	* [misc/commdlg.c]
	First cut at ChooseColor[WA].

	* [misc/network.c]
	Do something sensible for WNetGetDirectoryType16.

Sun May 17 10:21:35 1998  Andreas Mohr <100.30936@germany.net>

	* [controls/menu.c]
	Fixed disabled sub menus with MF_BYPOSITION that were not disabled.

	* [misc/crtdll.c] [relay32/crtdll.spec] [include/winerror.h]
	Implemented fscanf, fsetpos, _access, _fpreset (thanks to Uwe Bonnes),
	and _ltoa. 

	* [loader/task.c]
	MakeProcInstance: must use CURRENT_DS if hInst == NULL.

	* [misc/shell.c]
	SHELL_GetResourceTable, InternalExtractIcon: fixed broken .ICO handling

	* [windows/winpos.c]
	DeferWindowPos: removed "same parent" requirement.
	Which doc states that this is required ?

Sat May 16 20:08:11 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [loader/module.c] [loader/ne/module.c]
	More NE module cleanups.

	* [loader/task.c]
	Fixed SwitchStackBack().

Fri May 15 10:04:27 1998  Marcus Meissner <marcus@jet.franken.de>

	* [configure.in][inlcude/acconfig.h]
	Fixed broken OSS check, added check for working sigaltstack,
	fixed broken statfs checks on some linux systems.

	* [files/directory.c][loader/pe_image.c][relay32/builtin.c]
	  [loader/module.c]
	Added handling of win32 module pathnames.

	* [relay32/wnaspi32.spec]
	New file.

	* [misc/lzexpand.c]
	LZCopy auto-decompresses LZ compressed files, even if they are not
	specially flagged. Fixes some InstallShield problems.

	* [misc/registry.c]
	Some fixes for RegQueryInfoKey (reference program monkey.exe
	from Win32 SDK works now better). Probably still has faults.

Fri May 15 08:58:58 1998  Martin Boehme <boehme@informatik.mu-luebeck.de>

	* [graphics/mapping.c] [include/dc.h] [include/gdi.h] [objects/dc.c]
	Reworked the way world transformations and mapping modes are handled
	so that both of these transformations can be computed in a single
	step.

	* [graphics/painting.c] [graphics/path.c] [include/path.h]
	More GDI path support.

	* [graphics/x11drv/graphics.c]
	Fixed the return value of GRAPH_DrawArc for the zero height /
	zero width case to reflect Windows' behaviour.

	* [include/windows.h] [relay32/gdi32.spec] [objects/dc.c]
	Implemented ModifyWorldTransform and CombineTransform.

Tue May 14 18:03:46 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [controls/commctrl.c][relay32/comctl32.spec]
	  [controls/*.c][include/*.h]
	Implemented InitCommonControlsEx (dll version 4.72 compatible).
	InitCommonControls calls ImageCommonControlsEx.
	Registering code of the common controls had to be changed
	(see XXXX_Register functions).

	* [controls/status.c][include/commctrl.h][include/status.h]
	Implemented most new features and fixed the look and feel.

	* [contols/commctrl.c][include/commctrl.h][relay32/comctl32.spec]
	Implemented MenuHelp (incomplete).

	* [controls/status.c][controls/progress.c]
	Changed allocation strategy for control specific memory.

	* [controls/header.c][include/header.h][include/commctrl.h]
	First implementation of header control.

	* [windows/defwnd.c][windows/syscolors.c]
	Fixed default control colors for Win95 look.

	* [windows/nonclient.c]
	Fixed off by one error for Win95 look. Top border of child windows
	should be visible.

	* [misc/imagelist.h]
	Improved documentation and fixed some bugs.

Thu May 14 15:42:21 1998  Robert Wilhelm  <robert@physiol.med.tu-muenchen.de>

	* [relay32/crtdll.spec]
	Added hypot,j0,j1,jn and ceil.

Wed May 13 19:10:10 1998  Pascal Cuoq <pcuoq@ens-lyon.fr>

	* [controls/listbox.c]
	Item height is now exactly font height.
	Wine listboxes now behave like Windows' when they are 
	created without WS_VSCROLL but the program subsequently 
	calls ShowScrollBar or SetScrollInfo.

Wed May 13 18:33:01 1998  Ulrich Weigand <weigand@informatik.uni-erlangen.de>

	* [relay32/relay386.c]
	Restore ES also in the non-debug case.

	* [windows/event.c]
	Bugfix: Blocking TSXNextEvent could deadlock Wine.

	* [win32/process.c] [windows/message.c]
	Silly stubs for MsgWaitForMultipleObjects / PostThreadMessage
	that make some programs run better.

	* [windows/winproc.c]
	WINPROC_MapMsg32Ato16/16To32A: added WM_NOTIFY.  

        * [win32/kernel32.c]
	Added 16->32 thunking and improved 32->16 thunking functions.

	* [tools/build.c]
	Added new variant of CallFrom16 stub for use with Win95 thunks.

	* [if1632/kernel.spec] [if1632/builtin.c] [win32/kernel32.c]
	Added a few undocumented KERNEL functions.

	* [loader/ne/module.c] [loader/ne/segment.c]
	Call DllEntryPoint for 16-bit DLLs with subsystem >= 4.0.

	* [win32/kernel32.spec] [win32/wow32.spec] [win32/ordinals.c]
	Use names from the Oct 94 beta release for undoc. functions.

Wed May 13 14:18:26 1998  Matthew Becker <mbecker@glasscity.net>

	* [misc/registry.c]
	Code cleanup.

	* [misc/cpu.c]
	Commented out the registry puts temporarily.

	* [programs/regtest/*]
	New registry testing program.

Tue May 12 22:54:03 1998  Michael Mess <michael@kawo2.rwth-aachen.de>

	* [multimedia/audio.c]
	ioctl's do not commute in /dev/dsp initialization.

Tue May 12 20:11:42 1998  Karl Garrison <karlos@eznet.net>

	* [win32/console.c]
	Implemented SetConsoleTextAttribute, FillConsoleOutputCharacter.
	Improved cursor positioning.
	This allows for text colors in an xterm, rxvt, or console.

Tue May 12 17:57:52 1998  Petter Reinholdtsen <pere@td.org.uit.no>

	* [Makefile.in]
	Create prefix/{bin|lib} directories if missing during install.

Sun May 10 19:37:51 1998  Jan Willamowius <jan@janhh.shnet.org>

	* [multimedia/mmio.c]
	Have mmioSetBuffer return success (0), so Corel Draw 4
	keeps working. (IO is still unbuffered)

Wed May  6 16:57:55 1998  James Juran <jrj120@psu.edu>

        * [Makefile.in] [Make.rules.in]
	Changed "make clean" to remove `textedit` backup files (*%)

	* [controls/menu.c][graphics/x11drv/xfont.c][include/libres.h]
	  [loader/main.c][loader/ne/module.c][scheduler/synchro.c]
	  [win32/time.c][windows/winpos.c][include/windows.h]
	Fixed miscellaneous compilation warnings.

	* [misc/main.c][miscemu/main.c][include/main.h]
	Moved prototypes to new include file main.h, various cleanups.

Tue May  5 21:05:06 1998  Morten Welinder  <terra@diku.dk>

	* [misc/winsock.c]
	Don't refer to __FreeBSD__ when HAVE_STRERROR is meant.

	* [misc/debugstr.c]
	For debug_dumpstrSend, send strings to stderr.

Tue May  5 21:47:40 1998  Huw D M Davies <h.davies1@physics.oxford.ac.uk>

	* [objects/region.c]
	Fix for REGION_RegionOp() if newReg is one of the source regions.

Tue May  5 18:27:32 1998  Jim Peterson <jspeter@roanoke.infi.net>

	* [misc/main.c]
	Add '-h/-help' option and print WINE_RELEASE_INFO with usage message.

	* [misc/spy.c]
	Realign trace messages.

Tue May  5 15:46:47 1998  Donnie V. Savage <dsavage@cisco.com>

	* [graphics/ddraw.c]
	Fixed compile warnings

	* [misc/winsock.c]
	Warnings should not be errors.

Tue May  5 13:40:42 1998  Jim Peterson <jspeter@roanoke.infi.net>

	* [*/*]
	Remove many warnings through explicit casts, added #include's,
	and corrected printf formats.

Tue May  5 05:18:12 1998  Insomnia (Stea Greene) <insomnia@core.binghamton.edu>

	* [graphics/ddraw.c]
	Kept unchanged portion of old palette when changing only a few
	palette entries.  Really should only deallocate the changed cells.
	This make StarCraft work almost perfectly (sound overflows still
	cause static).

Mon May  4 15:04:57 1998  Alexander V. Lukyanov <lav@long.yar.ru>

	* [misc/lstr.c]
	FormatMessage: terminate string on %0, undo linefeed strip.
diff --git a/loader/ne/segment.c b/loader/ne/segment.c
index 99f78ce..a6478a5 100644
--- a/loader/ne/segment.c
+++ b/loader/ne/segment.c
@@ -72,7 +72,7 @@
 
     if (!pSeg->filepos) return TRUE;  /* No file image, just return */
 	
-    fd = MODULE_OpenFile( pModule->self );
+    fd = NE_OpenFile( pModule );
     TRACE(module, "Loading segment %d, selector=%04x, flags=%04x\n",
                     segnum, pSeg->selector, pSeg->flags );
     lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
@@ -118,8 +118,8 @@
  		   pSeg->minsize ? pSeg->minsize : 0x10000);
  	    FreeSelector(newselector);
  	    pSeg->selector = oldselector;
- 	    fprintf(stderr, "A new selector was allocated for the dgroup segment\n"
- 		    "Old selector is %d, new one is %d", oldselector, newselector);
+ 	    TRACE(module, "New selector allocated for dgroup segment:Old=%d,New=%d\n", 
+                oldselector, newselector);
  	  } else {
  	    FreeSelector(pSeg->selector);
  	    pSeg->selector = newselector;
@@ -201,22 +201,22 @@
             address = NE_GetEntryPoint( module, ordinal );
             if (!address)
             {
-                NE_MODULE *pTarget = MODULE_GetPtr16( module );
+                NE_MODULE *pTarget = NE_GetPtr( module );
                 if (!pTarget)
-                    fprintf( stderr, "Module not found: %04x, reference %d of module %*.*s\n",
+                    WARN(module, "Module not found: %04x, reference %d of module %*.*s\n",
                              module, rep->target1, 
                              *((BYTE *)pModule + pModule->name_table),
                              *((BYTE *)pModule + pModule->name_table),
                              (char *)pModule + pModule->name_table + 1 );
                 else
-                    fprintf( stderr, "Warning: no handler for %.*s.%d, setting to 0:0\n",
+                    WARN(module, "No handler for %.*s.%d, setting to 0:0\n",
                             *((BYTE *)pTarget + pTarget->name_table),
                             (char *)pTarget + pTarget->name_table + 1,
                             ordinal );
             }
             if (TRACE_ON(fixup))
             {
-                NE_MODULE *pTarget = MODULE_GetPtr16( module );
+                NE_MODULE *pTarget = NE_GetPtr( module );
                 TRACE( fixup, "%d: %.*s.%d=%04x:%04x %s\n", i + 1, 
                        *((BYTE *)pTarget + pTarget->name_table),
                        (char *)pTarget + pTarget->name_table + 1,
@@ -236,14 +236,14 @@
 
             if (ERR_ON(fixup) && !address)
             {
-                NE_MODULE *pTarget = MODULE_GetPtr16( module );
+                NE_MODULE *pTarget = NE_GetPtr( module );
                 ERR(fixup, "Warning: no handler for %.*s.%s, setting to 0:0\n",
                     *((BYTE *)pTarget + pTarget->name_table),
                     (char *)pTarget + pTarget->name_table + 1, func_name );
             }
             if (TRACE_ON(fixup))
             {
-	        NE_MODULE *pTarget = MODULE_GetPtr16( module );
+	        NE_MODULE *pTarget = NE_GetPtr( module );
                 TRACE( fixup, "%d: %.*s.%s=%04x:%04x %s\n", i + 1, 
                        *((BYTE *)pTarget + pTarget->name_table),
                        (char *)pTarget + pTarget->name_table + 1,
@@ -288,8 +288,12 @@
         /* Apparently, high bit of address_type is sometimes set; */
         /* we ignore it for now */
 	if (rep->address_type > NE_RADDR_OFFSET32)
+        {
+            char module[10];
+            GetModuleName( pModule->self, module, sizeof(module) );
             ERR( fixup, "WARNING: module %s: unknown reloc addr type = 0x%02x. Please report.\n",
-                 MODULE_GetModuleName(pModule->self), rep->address_type );
+                 module, rep->address_type );
+        }
 
         if (additive)
         {
@@ -405,7 +409,7 @@
         stack16Top->ip = 0;
         stack16Top->cs = 0;
 
-        hf = FILE_DupUnixHandle( MODULE_OpenFile( pModule->self ) );
+        hf = FILE_DupUnixHandle( NE_OpenFile( pModule ) );
         Callbacks->CallBootAppProc(selfloadheader->BootApp, pModule->self, hf);
         _lclose32(hf);
         /* some BootApp procs overwrite the selector of dgroup */
@@ -490,7 +494,7 @@
 			if (pModule->flags & NE_FFLAGS_MULTIPLEDATA)
                         {
 			    /* can this happen? */
-			    fprintf( stderr, "FixupPrologs got confused\n" );
+			    ERR(fixup, "FixupPrologs got confused\n" );
 			}
                         else if (pModule->flags & NE_FFLAGS_SINGLEDATA)
                         {
@@ -523,9 +527,8 @@
  *
  * Call the DLL initialization code
  */
-static BOOL32 NE_InitDLL( TDB* pTask, HMODULE16 hModule )
+static BOOL32 NE_InitDLL( TDB* pTask, NE_MODULE *pModule )
 {
-    NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
     CONTEXT context;
 
@@ -536,7 +539,6 @@
      * es:si  command line (always 0)
      */
 
-    if (!(pModule = MODULE_GetPtr16( hModule ))) return FALSE;
     pSegTable = NE_SEG_TABLE( pModule );
 
     if (!(pModule->flags & NE_FFLAGS_LIBMODULE) ||
@@ -548,7 +550,7 @@
 
     if (pTask && pTask->userhandler)
     {
-        pTask->userhandler( hModule, USIG_DLL_LOAD, 0, pTask->hInstance,
+        pTask->userhandler( pModule->self, USIG_DLL_LOAD, 0, pTask->hInstance,
                             pTask->hQueue );
     }
 
@@ -561,7 +563,7 @@
         if (pModule->flags & NE_FFLAGS_MULTIPLEDATA || pModule->dgroup)
         {
             /* Not SINGLEDATA */
-            fprintf(stderr, "Library is not marked SINGLEDATA\n");
+            ERR(dll, "Library is not marked SINGLEDATA\n");
             exit(1);
         }
         else  /* DATA NONE DLL */
@@ -589,7 +591,7 @@
     EIP_reg(&context) = pModule->ip;
     EBP_reg(&context) = OFFSETOF(THREAD_Current()->cur_stack)
                           + (WORD)&((STACK16FRAME*)0)->bp;
-    EDI_reg(&context) = DS_reg(&context) ? DS_reg(&context) : hModule;
+    EDI_reg(&context) = DS_reg(&context) ? DS_reg(&context) : pModule->self;
 
 
     pModule->cs = 0;  /* Don't initialize it twice */
@@ -600,6 +602,44 @@
     return TRUE;
 }
 
+/***********************************************************************
+ *           NE_CallDllEntryPoint
+ *
+ * Call the DllEntryPoint of DLLs with subsystem >= 4.0 
+ */
+
+static void NE_CallDllEntryPoint( NE_MODULE *pModule, DWORD dwReason )
+{
+    FARPROC16 entryPoint;
+    WORD ordinal;
+    CONTEXT context;
+    THDB *thdb = THREAD_Current();
+    LPBYTE stack = (LPBYTE)THREAD_STACK16(thdb);
+
+    if (pModule->expected_version < 0x0400) return;
+    if (!(ordinal = NE_GetOrdinal( pModule->self, "DllEntryPoint" ))) return;
+    if (!(entryPoint = NE_GetEntryPoint( pModule->self, ordinal ))) return;
+
+    memset( &context, 0, sizeof(context) );
+
+    CS_reg(&context) = HIWORD(entryPoint);
+    IP_reg(&context) = LOWORD(entryPoint);
+    EBP_reg(&context) =  OFFSETOF( thdb->cur_stack )
+                         + (WORD)&((STACK16FRAME*)0)->bp;
+
+    *(DWORD *)(stack -  4) = dwReason;      /* dwReason */
+    *(WORD *) (stack -  6) = pModule->self; /* hInst */
+    *(WORD *) (stack -  8) = 0;             /* wDS */
+    *(WORD *) (stack - 10) = 0;             /* wHeapSize */
+    *(DWORD *)(stack - 14) = 0;             /* dwReserved1 */
+    *(WORD *) (stack - 16) = 0;             /* wReserved2 */
+
+    TRACE(dll, "Calling DllEntryPoint, cs:ip=%04lx:%04x\n",
+          CS_reg(&context), IP_reg(&context));
+
+    Callbacks->CallRegisterShortProc( &context, 16 );
+}
+
 
 /***********************************************************************
  *           NE_InitializeDLLs
@@ -613,8 +653,8 @@
     NE_MODULE *pModule;
     HMODULE16 *pDLL;
 
-    if (!(pModule = MODULE_GetPtr16( hModule ))) return;
-    if (pModule->flags & NE_FFLAGS_WIN32) return;
+    if (!(pModule = NE_GetPtr( hModule ))) return;
+    assert( !(pModule->flags & NE_FFLAGS_WIN32) );
 
     if (pModule->dlls_to_init)
     {
@@ -626,7 +666,47 @@
         }
         GlobalFree16( to_init );
     }
-    NE_InitDLL( pTask, hModule );
+    NE_InitDLL( pTask, pModule );
+    NE_CallDllEntryPoint( pModule, DLL_PROCESS_ATTACH );
+}
+
+
+/***********************************************************************
+ *           NE_CreateInstance
+ *
+ * If lib_only is TRUE, handle the module like a library even if it is a .EXE
+ */
+HINSTANCE16 NE_CreateInstance( NE_MODULE *pModule, HINSTANCE16 *prev,
+                               BOOL32 lib_only )
+{
+    SEGTABLEENTRY *pSegment;
+    int minsize;
+    HINSTANCE16 hNewInstance;
+
+    if (pModule->dgroup == 0)
+    {
+        if (prev) *prev = pModule->self;
+        return pModule->self;
+    }
+
+    pSegment = NE_SEG_TABLE( pModule ) + pModule->dgroup - 1;
+    if (prev) *prev = pSegment->selector;
+
+      /* if it's a library, create a new instance only the first time */
+    if (pSegment->selector)
+    {
+        if (pModule->flags & NE_FFLAGS_LIBMODULE) return pSegment->selector;
+        if (lib_only) return pSegment->selector;
+    }
+
+    minsize = pSegment->minsize ? pSegment->minsize : 0x10000;
+    if (pModule->ss == pModule->dgroup) minsize += pModule->stack_size;
+    minsize += pModule->heap_size;
+    hNewInstance = GLOBAL_Alloc( GMEM_ZEROINIT | GMEM_FIXED, minsize,
+                                 pModule->self, FALSE, FALSE, FALSE );
+    if (!hNewInstance) return 0;
+    pSegment->selector = hNewInstance;
+    return hNewInstance;
 }
 
 
@@ -639,7 +719,7 @@
 /* It does nothing */
 void WINAPI PatchCodeHandle(HANDLE16 hSel)
 {
-	fprintf(stderr,"PatchCodeHandle(%04x),stub!\n",hSel);
+    FIXME(module,"(%04x): stub.\n",hSel);
 }
 
 
@@ -682,13 +762,11 @@
 /***********************************************************************
  *           NE_CreateSegments
  */
-BOOL32 NE_CreateSegments( HMODULE16 hModule )
+BOOL32 NE_CreateSegments( NE_MODULE *pModule )
 {
     SEGTABLEENTRY *pSegment;
-    NE_MODULE *pModule;
     int i, minsize;
 
-    if (!(pModule = MODULE_GetPtr16( hModule ))) return FALSE;
     assert( !(pModule->flags & NE_FFLAGS_WIN32) );
 
     pSegment = NE_SEG_TABLE( pModule );
@@ -696,10 +774,10 @@
     {
         minsize = pSegment->minsize ? pSegment->minsize : 0x10000;
         if (i == pModule->ss) minsize += pModule->stack_size;
-	/* The DGROUP is allocated by MODULE_CreateInstance */
+	/* The DGROUP is allocated by NE_CreateInstance */
         if (i == pModule->dgroup) continue;
         pSegment->selector = GLOBAL_Alloc( NE_Ne2MemFlags(pSegment->flags),
-                                      minsize, hModule,
+                                      minsize, pModule->self,
                                       !(pSegment->flags & NE_SEGFLAGS_DATA),
                                       FALSE,
                             FALSE /*pSegment->flags & NE_SEGFLAGS_READONLY*/ );
@@ -710,3 +788,15 @@
                             (pModule->dgroup - 1) * sizeof(SEGTABLEENTRY) : 0;
     return TRUE;
 }
+
+
+/**********************************************************************
+ *	    IsSharedSelector    (KERNEL.345)
+ */
+BOOL16 WINAPI IsSharedSelector( HANDLE16 selector )
+{
+    /* Check whether the selector belongs to a DLL */
+    NE_MODULE *pModule = NE_GetPtr( selector );
+    if (!pModule) return FALSE;
+    return (pModule->flags & NE_FFLAGS_LIBMODULE) != 0;
+}