Release 960811

Sun Aug 11 13:00:20 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in] [include/acconfig.h] [tools/build.c]
	Added check for underscore on external symbols.

	* [memory/selector.c] [memory/global.c]
	Fixed FreeSelector() to free only one selector.
	Added SELECTOR_FreeBlock() to free an array of selectors.

	* [objects/color.c]
	Fixed a bug in COLOR_ToLogical() that caused GetPixel() to fail on
	hi-color displays.

	* [tools/build.c] [if1632/crtdll.spec]
	Added 'extern' type, used for external variables or functions.

	* [windows/winpos.c]
	Allow de-activating a window in WINPOS_ChangeActiveWindow().

	* [windows/winproc.c]
	Added 32-to-16 translation for button messages.
	Fixed WINPROC_GetPtr() to avoid crashes on 32-bit procedures that
	happen to be valid SEGPTRs.

Sat Aug 10 18:22:25 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [windows/message.c]
	Removed a FIXME in MSG_PeekHardwareMsg(): produces correct 
	data for the JOURNALRECORD-hook (using EVENTMSG16 structure).

	* [if1632/gdi.spec] [include/windows.h] [objects/metafile.c]
	Introduced undocumented API function IsValidMetaFile(), plus a
 	minor fix in last patch of CopyMetaFile().

	* [objects/gdiobj.c]
	Removed a FIXME in IsGDIObject(): added magic word check.

Sun Aug 10 18:10:10 1996  Bruce Milner <Bruce.Milner@genetics.utah.edu>

	* [controls/statuswin.c]
	First pass at implementing the StatusWindow class.

	* [include/commctrl.h]
	Header file for common controls.

	* [controls/widgets.c]
	Added InitCommonControls().

	* [if1632/comctl32.spec]
	Add DrawStatusTextA, CreateStatusWindowA, InitCommonControls.

	* [win32/findfile.c] [if1632/kernel32.spec]
	Add FindNextFile32A, FindClose.
	Modified FindFirstFile32A so it works with FindNextFile32A.

	* [include/winbase.h]
	Fixed WIN32_FIND_DATA structure member names.

Sat Aug 10 09:00:00 1996  Alex Korobka <alex@phm30.pharm.sunysb.edu>

	* [windows/scroll.c]
	Changed scrolling routines to benefit from DCE code update.

Thu Aug  8 18:05:09 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/file.c]
	SearchPath* could get NULL for lastpart argument.

	* [if1632/build-spec.txt] [documentation/debugging]
	Varargs documentation added, debugging hints updated.

	* [if1632/crtdll.spec][misc/crtdll.c][misc/Makefile.in]
	Started to implement CRTDLL.

	* [if1632/wsock32.spec]
	Some thunks to standard libc functions (structures have the same
 	elements, but perhaps wrong offset due to packing).

	* [include/kernel32.h][include/windows.h][win32/*.c][loader/main.c]
	Merged kernel32.h into windows.h.

	* [misc/lstr.c]
	Enhanced FormatMessage().

	* [misc/main.c] [if1632/kernel.spec] [include/windows.h]
	GetVersion() updated to new naming standard.
	Changed language handling to support language ids.

	* [misc/shell.c]
	Enhanced FindExecutable, so it finds files in the search path too.

	* [win32/environment.c]
	GetCommandLine* updated.

	* [loader/resource.c] [loader/pe_resource.c]
	FindResourceEx32* added.
	Loading of messagetables added.
	Language handling now uses Wine default language id.
diff --git a/memory/global.c b/memory/global.c
index f88d129..c7a06cc 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -111,7 +111,7 @@
 
     if (!(pArena = GLOBAL_GetArena( sel, selcount )))
     {
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, selcount );
         return 0;
     }
 
@@ -159,11 +159,13 @@
 BOOL16 GLOBAL_FreeBlock( HGLOBAL16 handle )
 {
     WORD sel;
+    GLOBALARENA *pArena;
 
     if (!handle) return TRUE;
-    sel = GlobalHandleToSel( handle );
-    if (FreeSelector( sel )) return FALSE;  /* failed */
-    memset( GET_ARENA_PTR(sel), 0, sizeof(GLOBALARENA) );
+    sel = GlobalHandleToSel( handle ); 
+    pArena = GET_ARENA_PTR(sel);
+    SELECTOR_FreeBlock( sel, (pArena->size + 0xffff) / 0x10000 );
+    memset( pArena, 0, sizeof(GLOBALARENA) );
     return TRUE;
 }
 
@@ -226,7 +228,7 @@
  * Find the arena  for a given handle
  * (when handle is not serial - e.g. DDE)
  */
-static GLOBALARENA *GLOBAL_FindArena( HGLOBAL handle)
+static GLOBALARENA *GLOBAL_FindArena( HGLOBAL16 handle)
 {
     int i;
     for (i = globalArenaSize-1 ; i>=0 ; i--) {
@@ -241,7 +243,7 @@
  *           DDE_GlobalHandleToSel
  */
 
-WORD DDE_GlobalHandleToSel( HGLOBAL handle )
+WORD DDE_GlobalHandleToSel( HGLOBAL16 handle )
 {
     GLOBALARENA *pArena;
     SEGPTR segptr;
@@ -341,7 +343,7 @@
     ptr = HeapReAlloc( SystemHeap, 0, ptr, size );
     if (!ptr)
     {
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, (oldsize + 0xffff) / 0x10000 );
         memset( pArena, 0, sizeof(GLOBALARENA) );
         return 0;
     }
@@ -360,7 +362,7 @@
     if (!(pNewArena = GLOBAL_GetArena( sel, selcount )))
     {
         HeapFree( SystemHeap, 0, ptr );
-        FreeSelector( sel );
+        SELECTOR_FreeBlock( sel, selcount );
         return 0;
     }
 
diff --git a/memory/heap.c b/memory/heap.c
index 5c3573c..d2f25af 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -10,7 +10,6 @@
 #include <string.h>
 #include "windows.h"
 #include "debugger.h"
-#include "kernel32.h"  /* for CRITICAL_SECTION */
 #include "selectors.h"
 #include "winbase.h"
 #include "winerror.h"
diff --git a/memory/selector.c b/memory/selector.c
index ecf7df4..bec8469 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -64,31 +64,8 @@
  */
 WORD FreeSelector( WORD sel )
 {
-    WORD i, count, nextsel;
-    ldt_entry entry;
-    STACK16FRAME *frame;
-
-    dprintf_selector( stddeb, "FreeSelector(%04x)\n", sel );
     if (IS_SELECTOR_FREE(sel)) return sel;  /* error */
-    count = (GET_SEL_LIMIT(sel) >> 16) + 1;
-    sel &= ~(__AHINCR - 1);  /* clear bottom bits of selector */
-    nextsel = sel + (count << __AHSHIFT);
-    memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
-    /* FIXME: is it correct to free the whole array? */
-    for (i = SELECTOR_TO_ENTRY(sel); count; i++, count--)
-    {
-        LDT_SetEntry( i, &entry );
-        ldt_flags_copy[i] &= ~LDT_FLAGS_ALLOCATED;
-    }
-
-    /* Clear the saved 16-bit selector */
-    frame = CURRENT_STACK16;
-    while (frame)
-    {
-        if ((frame->ds >= sel) && (frame->ds < nextsel)) frame->ds = 0;
-        if ((frame->es >= sel) && (frame->es < nextsel)) frame->es = 0;
-	frame = PTR_SEG_OFF_TO_LIN(frame->saved_ss, frame->saved_sp);
-    }
+    SELECTOR_FreeBlock( sel, 1 );
     return 0;
 }
 
@@ -147,6 +124,38 @@
 
 
 /***********************************************************************
+ *           SELECTOR_FreeBlock
+ *
+ * Free a block of selectors.
+ */
+void SELECTOR_FreeBlock( WORD sel, WORD count )
+{
+    WORD i, nextsel;
+    ldt_entry entry;
+    STACK16FRAME *frame;
+
+    dprintf_selector( stddeb, "SELECTOR_FreeBlock(%04x,%d)\n", sel, count );
+    sel &= ~(__AHINCR - 1);  /* clear bottom bits of selector */
+    nextsel = sel + (count << __AHSHIFT);
+    memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
+    for (i = SELECTOR_TO_ENTRY(sel); count; i++, count--)
+    {
+        LDT_SetEntry( i, &entry );
+        ldt_flags_copy[i] &= ~LDT_FLAGS_ALLOCATED;
+    }
+
+    /* Clear the saved 16-bit selector */
+    frame = CURRENT_STACK16;
+    while (frame)
+    {
+        if ((frame->ds >= sel) && (frame->ds < nextsel)) frame->ds = 0;
+        if ((frame->es >= sel) && (frame->es < nextsel)) frame->es = 0;
+	frame = PTR_SEG_OFF_TO_LIN(frame->saved_ss, frame->saved_sp);
+    }
+}
+
+
+/***********************************************************************
  *           SELECTOR_ReallocBlock
  *
  * Change the size of a block of selectors.
@@ -155,7 +164,6 @@
                            enum seg_type type, BOOL32 is32bit, BOOL32 readonly)
 {
     WORD i, oldcount, newcount;
-    ldt_entry entry;
 
     if (!size) size = 1;
     oldcount = (GET_SEL_LIMIT(sel) >> 16) + 1;
@@ -171,7 +179,7 @@
 
         if (i < newcount)  /* they are not free */
         {
-            FreeSelector( sel );
+            SELECTOR_FreeBlock( sel, oldcount );
             sel = AllocSelectorArray( newcount );
         }
         else  /* mark the selectors as allocated */
@@ -182,12 +190,8 @@
     }
     else if (oldcount > newcount) /* We need to remove selectors */
     {
-        memset( &entry, 0, sizeof(entry) );  /* clear the LDT entries */
-        for (i = oldcount; i < newcount; i++)
-        {
-            LDT_SetEntry( SELECTOR_TO_ENTRY(sel) + i, &entry );
-            ldt_flags_copy[SELECTOR_TO_ENTRY(sel) + i] &= ~LDT_FLAGS_ALLOCATED;
-        }
+        SELECTOR_FreeBlock( ENTRY_TO_SELECTOR(SELECTOR_TO_ENTRY(sel)+newcount),
+                            oldcount - newcount );
     }
     if (sel) SELECTOR_SetEntries( sel, base, size, type, is32bit, readonly );
     return sel;