Release 960331

Sun Mar 31 13:54:46 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [tools/build.c]
	Changed BuildSpec32Files() to generate assembly instead of C code.
	Unified -spec16 and -spec32 options; DLL type is now determined by
	the 'type' declaration in the .spec file.
	New -stdcall option to build all stdcall assembly relays.

	* [if1632/relay.c] [if1632/relay32.c] [include/dlls.h]
	Started to unify 16- and 32-bit builtin DLLs.

	* [loader/module.c]
	Added MODULE_GetWndProcEntry32() to mirror MODULE_GetWndProcEntry16().

	* [loader/pe_image.c] [loader/resource.c]
	All modules now have a NE signature, and can be distinguished by
	the NE_FFLAGS_WIN32 flag.

	* [windows/alias.c]
	Aliases for built-in window procedures are now all created at
	startup in ALIAS_Init().

Fri Mar 29 14:56:39 1996  Greg Kreider <kreider@natlab.research.philips.com>

	* [controls/combo.c]
	Limit rectangle to clear to size of item when painting combo, not
 	default.  Only draw items in list when there is enough room for them.

	* [controls/listbox.c]
	Get the measure of every item that's added and store in the item's
 	data structure.  Scroll listbox if mouse near edge of box.  Only
 	draw items in list when there is enough room.

Fri Mar 29 12:00:00 1996  Alex Korobka <alex@phm30.pharm.sunysb.edu>

	* [windows/defwnd.c] [windows/dialog.c] [windows/mdi.c]
	  [windows/nonclient.c] [controls/menu.c] 
	Various changes for better keyboard handling. 

	* [windows/event.c] [windows/message.c] [misc/keyboard.c]
	Proper keyboard message ordering, working GetKeyState() (finally!), 
	improvements in ToAscii().

	* [windows/win.c] [windows/message.c]
	Small improvements in WIN_FindWinToRepaint.

	* [windows/win.c] [windows/painting.c] [windows/nonclient.c]
	Put update region in WM_NCPAINT wParam.

	* [loader/task.c]
	Kill task timers when task is deleted, switch timers to the
	new queue in SetTaskQueue().

	* [loader/signal.c] [miscemu/dosmem.c]
	Added SIGALRM signal handler to increment BIOS clock. 

	* [windows/win.c] [windows/winpos.c] [windows/mdi.c]
	Fixed ChildWindowFromPoint(), WM_PARENTNOTIFY and its handling by
	MDI client.

	* [windows/winpos.c]
	Improvements in handling of owned popups. "Floating" toolboxes 
	work better now. 

Thu Mar 28 12:38:29 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [misc/registry.c]
	New file, registry rewrite including win32 extensions
	- Unicode
	- multiple valus per key
	- different datatypes for values
	- multiple rootkeys
	- saving and loading in different registries.

	* [include/winreg.h]
	New file, definitions and structs for registry.

	* [include/winerror.h]
	Some new error defines added... there are more, someone please
 	check a (real-)windows winerror.h.
	
	* [if1632/shell.spec] [if1632/advapi32.spec] [if1632/kernel.spec]
	Registry specs added.

	* [if1632/relay.c]
	Switch internal SHELL.DLL to default 'used'.

	* [win32/string32.c] [include/string32.h]
	Some new functions added.
	char should be unsigned char when converting to 16bit ints.

	* [misc/shell.c] [include/shell.h] [win32/advapi.c]
	Removed old registry functions.

Tue Mar 26 15:01:46 1996  Frans van Dorsselaer <dorssel@rulhm1.leidenuniv.nl>

	* [include/bitmaps/ocr_ibeam]
	Fixed the position of the hotspot.

	* [objects/text.c]
	Fixed a few bugs in TEXT_TabbedTextOut().

	* [windows/event.c]
	Fixed the order of the bits in the KeyStateTable.
	0x80 is the up/down-bit.  0x01 is the toggle bit.

	* [loader/resource.c] [windows/mdi.c] [controls/edit.c]
	Fixed the calls to GetKeyState().

Tue Mar 26 08:43:15 1996  Robert Pouliot <krynos@qbc.clic.net>

	* [resources/sysres_Fr.rc] [resources/TODO]
	Updated FIND_TEXT and REPLACE_TEXT to work like the English version.

Mon Mar 25 17:38:59 1996  Tristan Tarrant <tst@dcs.ed.ac.uk>

	* [resources/sysres_it.rc]
	Added support for Italian [It] language.
diff --git a/loader/main.c b/loader/main.c
index 0aca285..0c49037 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -11,11 +11,13 @@
 #include <string.h>
 #include <errno.h>
 #include "windows.h"
+#include "alias.h"
 #include "module.h"
 #include "task.h"
 #include "selectors.h"
 #include "comm.h"
 #include "user.h"
+#include "win.h"
 #include "menu.h"
 #include "kernel32.h"
 #include "atom.h"
@@ -99,10 +101,13 @@
     
       /* Global atom table initialisation */
     if (!ATOM_Init()) return 0;
-    
+
       /* GDI initialisation */
     if (!GDI_Init()) return 0;
 
+    /* Initialise window procedures aliases */
+    if (!ALIAS_Init()) return 0;
+
       /* Initialize system colors and metrics*/
     SYSMETRICS_Init();
     SYSCOLOR_Init();
diff --git a/loader/module.c b/loader/module.c
index 7cece76..fce734c 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -48,20 +48,18 @@
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
     struct dll_table_s *table;
-    int i;
     char dllname[16], *p;
 
     /* Fix the name in case we have a full path and extension */
 
     if ((p = strrchr( name, '\\' ))) name = p + 1;
-    strncpy( dllname, name, 15 );
-    dllname[15] = '\0';
+    lstrcpyn( dllname, name, sizeof(dllname) );
     if ((p = strrchr( dllname, '.' ))) *p = '\0';
 
-    for (i = 0, table = dll_builtin_table; i < N_BUILTINS; i++, table++)
+    for (table = dll_builtin_table; table->name; table++)
         if (!lstrcmpi( table->name, dllname )) break;
-    if (i >= N_BUILTINS) return 0;
-    if (!table->used && !force) return 0;
+    if (!table->name) return 0;
+    if ((table->flags & DLL_FLAG_NOT_USED) && !force) return 0;
 
     hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, table->module_start,
                                   table->module_end - table->module_start,
@@ -486,6 +484,10 @@
         }
     }
 
+    /* Clear internal Wine flags in case they are set in the EXE file */
+
+    pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
+
     /* Store the filename information */
 
     pModule->fileinfo = (int)pData - (int)pModule;
@@ -601,7 +603,7 @@
  *
  * Lookup the ordinal for a given name.
  */
-WORD MODULE_GetOrdinal( HMODULE hModule, char *name )
+WORD MODULE_GetOrdinal( HMODULE hModule, const char *name )
 {
     char buffer[256], *cpnt;
     BYTE len;
@@ -630,7 +632,6 @@
     cpnt += *cpnt + 1 + sizeof(WORD);
     while (*cpnt)
     {
-        dprintf_module( stddeb, "  Checking '%*.*s'\n", *cpnt, *cpnt, cpnt+1 );
         if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
         {
             dprintf_module( stddeb, "  Found: ordinal=%d\n",
@@ -649,7 +650,6 @@
     cpnt += *cpnt + 1 + sizeof(WORD);
     while (*cpnt)
     {
-        dprintf_module( stddeb, "  Checking '%*.*s'\n", *cpnt, *cpnt, cpnt+1 );
         if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
         {
             dprintf_module( stddeb, "  Found: ordinal=%d\n",
@@ -794,6 +794,40 @@
 
 
 /***********************************************************************
+ *           MODULE_GetWndProcEntry16  (not a Windows API function)
+ *
+ * Return an entry point from the WINPROCS dll.
+ */
+#ifndef WINELIB
+WNDPROC MODULE_GetWndProcEntry16( const char *name )
+{
+    WORD ordinal;
+    static HMODULE hModule = 0;
+
+    if (!hModule) hModule = GetModuleHandle( "WINPROCS" );
+    ordinal = MODULE_GetOrdinal( hModule, name );
+    return MODULE_GetEntryPoint( hModule, ordinal );
+}
+#endif
+
+
+/***********************************************************************
+ *           MODULE_GetWndProcEntry32  (not a Windows API function)
+ *
+ * Return an entry point from the WINPROCS32 dll.
+ */
+#ifndef WINELIB
+WNDPROC MODULE_GetWndProcEntry32( const char *name )
+{
+    static HMODULE hModule = 0;
+
+    if (!hModule) hModule = GetModuleHandle( "WINPROCS32" );
+    return PE_GetProcAddress( hModule, name );
+}
+#endif
+
+
+/***********************************************************************
  *           MODULE_GetModuleName
  */
 LPSTR MODULE_GetModuleName( HMODULE hModule )
@@ -1103,10 +1137,6 @@
           /* the module, even if it contains circular DLL references */
 
         pModule->count = 1;
-
-          /* Clear built-in flag in case it was set in the EXE file */
-
-        pModule->flags &= ~NE_FFLAGS_BUILTIN;
     }
     else
     {
@@ -1422,24 +1452,6 @@
 }
 
 
-/***********************************************************************
- *           GetWndProcEntry16 (not a Windows API function)
- *
- * Return an entry point from the WINPROCS dll.
- */
-#ifndef WINELIB
-WNDPROC GetWndProcEntry16( char *name )
-{
-    WORD ordinal;
-    static HMODULE hModule = 0;
-
-    if (!hModule) hModule = GetModuleHandle( "WINPROCS" );
-    ordinal = MODULE_GetOrdinal( hModule, name );
-    return MODULE_GetEntryPoint( hModule, ordinal );
-}
-#endif
-
-
 /**********************************************************************
  *	    ModuleFirst    (TOOLHELP.59)
  */
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 1b8c0a6..8ae9004 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -510,11 +510,11 @@
     HMODULE *pDLL;
 
     pModule = (NE_MODULE *)GlobalLock( hModule );
-	if (pModule->magic == PE_SIGNATURE)
-	{
-		PE_InitializeDLLs(hModule);
-		return;
-	}
+    if (pModule->flags & NE_FFLAGS_WIN32)
+    {
+        PE_InitializeDLLs(hModule);
+        return;
+    }
     if (pModule->dlls_to_init)
     {
 	HANDLE to_init = pModule->dlls_to_init;
diff --git a/loader/pe_image.c b/loader/pe_image.c
index e95ade2..ced45d0 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -29,7 +29,6 @@
 #include "task.h"
 #include "ldt.h"
 #include "registers.h"
-#include "selectors.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
@@ -581,10 +580,10 @@
 	pModule = (NE_MODULE*)GlobalLock(hModule);
 
 	/* Set all used entries */
-	pModule->magic=PE_SIGNATURE;
+	pModule->magic=NE_SIGNATURE;
 	pModule->count=1;
 	pModule->next=0;
-	pModule->flags=0;
+	pModule->flags=NE_FFLAGS_WIN32;
 	pModule->dgroup=1;
 	pModule->ss=1;
 	pModule->cs=2;
@@ -610,7 +609,7 @@
 	pSegment->minsize=0x1000;
 	pSegment++;
 
-	cts=(DWORD)GetWndProcEntry16("Win32CallToStart");
+	cts=(DWORD)MODULE_GetWndProcEntry16("Win32CallToStart");
 #ifdef WINELIB32
 	pSegment->selector=(void*)cts;
 	pModule->ip=0;
diff --git a/loader/resource.c b/loader/resource.c
index dee9027..0de3993 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -37,7 +37,7 @@
  */
 HRSRC FindResource( HMODULE hModule, SEGPTR name, SEGPTR type )
 {
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "FindResource: module=%04x type=", hModule );
@@ -52,17 +52,14 @@
     dprintf_resource( stddeb, " name=" );
     PrintId( name );
     dprintf_resource( stddeb, "\n" );
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 #ifndef WINELIB
-    switch(*pModule)
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_FindResource( hModule, type, name );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to FindResource() for Win32 module\n");
         return 0;
     }
+    return NE_FindResource( hModule, type, name );
 #else
     return LIBRES_FindResource( hModule, name, type );
 #endif
@@ -74,23 +71,20 @@
  */
 HGLOBAL LoadResource( HMODULE hModule, HRSRC hRsrc )
 {
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "LoadResource: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 #ifndef WINELIB
-    switch(*pModule)
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_LoadResource( hModule, hRsrc );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to LoadResource() for Win32 module\n");
         return 0;
     }
+    return NE_LoadResource( hModule, hRsrc );
 #else
     return LIBRES_LoadResource( hModule, hRsrc );
 #endif
@@ -105,21 +99,18 @@
 {
 #ifndef WINELIB
     HMODULE hModule;
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
     if (!handle) return (SEGPTR)0;
     hModule = GetExePtr( handle );
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
-    switch(*pModule)
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_LockResource( hModule, handle );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to LockResource() for Win32 module\n");
         return 0;
     }
+    return NE_LockResource( hModule, handle );
 #else
     return LIBRES_LockResource( handle );
 #endif
@@ -130,21 +121,18 @@
 {
 #ifndef WINELIB
     HMODULE hModule;
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
     if (!handle) return NULL;
     hModule = GetExePtr( handle );
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
-    switch(*pModule)
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return (LPSTR)PTR_SEG_TO_LIN( NE_LockResource( hModule, handle ) );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to LockResource() for Win32 module\n");
         return 0;
     }
+    return (LPSTR)PTR_SEG_TO_LIN( NE_LockResource( hModule, handle ) );
 #else
     return LIBRES_LockResource( handle );
 #endif
@@ -158,21 +146,18 @@
 {
 #ifndef WINELIB
     HMODULE hModule;
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     dprintf_resource(stddeb, "FreeResource: handle=%04x\n", handle );
     if (!handle) return FALSE;
     hModule = GetExePtr( handle );
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
-    switch(*pModule)
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_FreeResource( hModule, handle );
-      case PE_SIGNATURE:
-        return FALSE;
-      default:
-        return FALSE;
+        fprintf(stderr,"Don't know how to FreeResource() for Win32 module\n");
+        return 0;
     }
+    return NE_FreeResource( hModule, handle );
 #else
     return LIBRES_FreeResource( handle );
 #endif
@@ -184,25 +169,22 @@
  */
 INT AccessResource( HINSTANCE hModule, HRSRC hRsrc )
 {
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "AccessResource: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 #ifndef WINELIB
-    switch(*pModule)
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_AccessResource( hModule, hRsrc );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to AccessResource() for Win32 module\n");
         return 0;
     }
+    return NE_AccessResource( hModule, hRsrc );
 #else
-        return LIBRES_AccessResource( hModule, hRsrc );
+    return LIBRES_AccessResource( hModule, hRsrc );
 #endif
 }
 
@@ -212,22 +194,19 @@
  */
 DWORD SizeofResource( HMODULE hModule, HRSRC hRsrc )
 {
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "SizeofResource: module=%04x res=%04x\n",
                      hModule, hRsrc );
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 #ifndef WINELIB
-    switch(*pModule)
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_SizeofResource( hModule, hRsrc );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to SizeOfResource() for Win32 module\n");
         return 0;
     }
+    return NE_SizeofResource( hModule, hRsrc );
 #else
     return LIBRES_SizeofResource( hModule, hRsrc );
 #endif
@@ -239,23 +218,20 @@
  */
 HGLOBAL AllocResource( HMODULE hModule, HRSRC hRsrc, DWORD size )
 {
-    WORD *pModule;
+    NE_MODULE *pModule;
 
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "AllocResource: module=%04x res=%04x size=%ld\n",
                      hModule, hRsrc, size );
     if (!hRsrc) return 0;
-    if (!(pModule = (WORD *)GlobalLock( hModule ))) return 0;
+    if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
 #ifndef WINELIB
-    switch(*pModule)
+    if (pModule->flags & NE_FFLAGS_WIN32)
     {
-      case NE_SIGNATURE:
-        return NE_AllocResource( hModule, hRsrc, size );
-      case PE_SIGNATURE:
-        return 0;
-      default:
+        fprintf(stderr,"Don't know how to AllocResource() for Win32 module\n");
         return 0;
     }
+    return NE_AllocResource( hModule, hRsrc, size );
 #else
     return LIBRES_AllocResource( hModule, hRsrc, size );
 #endif
@@ -350,9 +326,9 @@
 	       (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)) {
 		INT mask = 0;
 
-		if(GetKeyState(VK_SHIFT) & 0xf) mask |= SHIFT_ACCEL;
-		if(GetKeyState(VK_CONTROL) & 0xf) mask |= CONTROL_ACCEL;
-		if(GetKeyState(VK_MENU) & 0xf) mask |= ALT_ACCEL;
+		if(GetKeyState(VK_SHIFT) & 0x8000) mask |= SHIFT_ACCEL;
+		if(GetKeyState(VK_CONTROL) & 0x8000) mask |= CONTROL_ACCEL;
+		if(GetKeyState(VK_MENU) & 0x8000) mask |= ALT_ACCEL;
 		if(mask == (lpAccelTbl->tbl[i].type &
 			    (SHIFT_ACCEL | CONTROL_ACCEL | ALT_ACCEL))) {
 		    SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval,
diff --git a/loader/signal.c b/loader/signal.c
index 995741b..8ebc0b6 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -7,6 +7,9 @@
 #include <time.h>
 #include <setjmp.h>
 
+#include <sys/time.h>
+#include <sys/timeb.h>
+
 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__svr4__)
 #include <sys/syscall.h>
 #include <sys/param.h>
@@ -43,7 +46,33 @@
 #endif
 
 
-#if defined(linux) 
+/**********************************************************************
+ *		wine_timer
+ *
+ * SIGALRM handler.
+ */
+#ifdef linux
+static void wine_timer(int signal, struct sigcontext_struct context_struct)
+{
+#elif defined(__svr4__)
+static void wine_timer(int signal, void *siginfo, ucontext_t *context)
+{
+#else
+static void wine_timer(int signal, int code, struct sigcontext *context)
+{
+#endif
+    /* Should do real-time timers here */
+
+    DOSMEM_Tick();
+}
+
+
+/**********************************************************************
+ *		win_fault
+ *
+ * Segfault handler.
+ */
+#ifdef linux
 static void win_fault(int signal, struct sigcontext_struct context_struct)
 {
     struct sigcontext_struct *context = &context_struct;
@@ -99,6 +128,7 @@
 
 #ifdef linux
     sig_act.sa_handler = func;
+    sig_act.sa_flags = SA_RESTART;
     /* Point to the top of the stack, minus 4 just in case, and make
        it aligned  */
     sig_act.sa_restorer = 
@@ -131,14 +161,14 @@
     }
 }
 
+extern void stop_wait(int a);
+
 
 /**********************************************************************
  *		init_wine_signals
  */
 void init_wine_signals(void)
 {
-    extern void stop_wait(int a);
-
 #if defined(__NetBSD__) || defined(__FreeBSD__)
     struct sigaltstack ss;
         
@@ -174,7 +204,8 @@
         exit(1);
     }
 #endif  /* __svr4__ */
-
+    
+    SIGNAL_SetHandler( SIGALRM, (void (*)())wine_timer );
     SIGNAL_SetHandler( SIGSEGV, (void (*)())win_fault );
     SIGNAL_SetHandler( SIGILL,  (void (*)())win_fault );
     SIGNAL_SetHandler( SIGFPE,  (void (*)())win_fault );
@@ -186,6 +217,24 @@
 #ifdef CONFIG_IPC
     SIGNAL_SetHandler( SIGUSR2, (void (*)())stop_wait ); /* For IPC */
 #endif
+    SIGNAL_StartBIOSTimer();
+}
+
+
+/**********************************************************************
+ *		SIGNAL_StartTimer
+ *
+ * Start the BIOS tick timer.
+ */
+void SIGNAL_StartBIOSTimer(void)
+{
+    struct itimerval vt_timer;
+
+    vt_timer.it_interval.tv_sec = 0;
+    vt_timer.it_interval.tv_usec = 54929;
+    vt_timer.it_value = vt_timer.it_interval;
+
+    setitimer(ITIMER_REAL, &vt_timer, NULL);
 }
 
 #endif /* ifndef WINELIB */
diff --git a/loader/task.c b/loader/task.c
index 1b6c557..0fc4a67 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -21,7 +21,6 @@
 #include "neexe.h"
 #include "options.h"
 #include "queue.h"
-#include "selectors.h"
 #include "toolhelp.h"
 #include "stddebug.h"
 #include "debug.h"
@@ -34,6 +33,9 @@
   /* Must not be greater than 64k, or MAKE_SEGPTR won't work */
 #define STACK32_SIZE 0x10000
 
+extern void TIMER_SwitchQueue(HQUEUE, HQUEUE );
+extern void TIMER_NukeTimers(HWND, HQUEUE );
+
 /* ------ Internal variables ------ */
 
 static HTASK hFirstTask = 0;
@@ -61,7 +63,7 @@
  */
 BOOL TASK_Init(void)
 {
-    TASK_RescheduleProc = (FARPROC)GetWndProcEntry16( "TASK_Reschedule" );
+    TASK_RescheduleProc = MODULE_GetWndProcEntry16( "TASK_Reschedule" );
     if (!(hDOSEnvironment = TASK_CreateDOSEnvironment()))
         fprintf( stderr, "Not enough memory for DOS Environment\n" );
     return (hDOSEnvironment != 0);
@@ -581,6 +583,10 @@
 
     FILE_CloseAllFiles( pTask->hPDB );
 
+    /* Nuke timers */
+
+    TIMER_NukeTimers( 0, pTask->hQueue );
+
     /* Free the message queue */
 
     QUEUE_DeleteMsgQueue( pTask->hQueue );
@@ -999,8 +1005,12 @@
 
     if (!hTask) hTask = hCurrentTask;
     if (!(pTask = (TDB *)GlobalLock( hTask ))) return 0;
+
     hPrev = pTask->hQueue;
     pTask->hQueue = hQueue;
+
+    TIMER_SwitchQueue( hPrev, hQueue );
+
     return hPrev;
 }
 
@@ -1153,8 +1163,6 @@
 
     if (!(ptr = GlobalLock( handle ))) return 0;
     if (((NE_MODULE *)ptr)->magic == NE_SIGNATURE) return handle;
-	/* Fake modules describing PE modules have a PE signature */
-    if (((NE_MODULE *)ptr)->magic == PE_SIGNATURE) return handle;
 
       /* Check the owner for module handle */
 
@@ -1165,7 +1173,6 @@
 #endif
     if (!(ptr = GlobalLock( owner ))) return 0;
     if (((NE_MODULE *)ptr)->magic == NE_SIGNATURE) return owner;
-    if (((NE_MODULE *)ptr)->magic == PE_SIGNATURE) return owner;
 
       /* Search for this handle and its owner inside all tasks */