Release 950727

Sat Jul 22 22:39:09 IDT 1995 Michael Veksler <e1678223@tochnapc2.technion.ac.il>

	* [ipc/*]
	New directory. This directory contains the new inter-wine
 	communications support. It enables DDE protocols between two wine
 	instances.  Currently it is limited to DDE, but can be enhanced to
 	support OLE between 2 different wine instances.  This is very
 	important for libwine.a DDE/OLE support.

	* [tools/ipcl]
    	A script to delete garbage IPC handles (shared memory, semaphores
 	and message queues).  The current inter-wine communication is not
 	perfect, and sometimes leaves garbage behind.

	* [if1632/relay.c] [include/atom.h] [include/global.h]
 	[loader/selector.c] [loader/task.c] [loader/module.c]
 	[loader/signal.c] [memory/global.c] [misc/atom.c]
 	[windows/class.c] [windows/message.c] [windows/win.c]
	[Imakefile]
    	Hooks for inter-wine DDE support, current Global.*Atom functions
 	renamed to Local.*Atom since Global.*Atom are used for Inter-Wine
 	DDE communication. (The first call to these functions sets up the
 	IPC structures - which otherwise cause unneeded overhead.

Mon Jul 17 19:55:21 1995  Alexandre Julliard  <julliard@sunsite.unc.edu>

	* [controls/menu.c]
	Don't crash if a NULL string is passed to menu functions.

	* [memory/selector.c]
	We now use a bit in ldt_flags_copy to indicate free LDT entries.
	Fixed a bug in SELECTOR_ReallocBlock that could cause it to
	overwrite valid LDT entries when growing a block.

	* [miscemu/instr.c]
	Emulate int xx instruction by storing the interrupt vector in
	CS:IP and returning directly. This allows a program to install an
	interrupt vector.

	* [windows/win.c]
	Added function WIN_GetTopParent to get the top-level parent of a
	window.

Sun Jul  16 18:17:17 1995  Gregory Trubetskoy <grisha@mira.com>

        * [loader/resource.c]
        Added LoadIconHandler. It doesn't do anything yet, but now you
        can use borland help files with winhelp.exe.

Sun Jul 16 11:58:45 1995 Anand Kumria <akumria@ozemail.com.au>

	* [misc/main.c]
	Fixed to return 386 Enhanced mode correctly. Also return the same
 	type of CPU, for both Enhanced and Standard mode, namely a 386.

Sun Jul 16 00:02:04 1995    Martin von Loewis <loewis@informatik.hu-berlin.de>

	* [Configure] [include/options.h] [include/wineopts.h]
	  [misc/main.c][misc/spy.c]
	  Removed support of spy file. Redirected spy messages to stddeb.
	  Removed -spy option. Added -debugmsg +spy option.

	* [debugger/dbg.y][debugger/debug.l]
	Enabled segmented addresses (seg:offs) for break and x commands.

	* [if1632/gdi.spec] [objects/region.c] [windows/graphics.c]
	  [include/region.h]
	FrameRgn, REGION_FrameRgn: New functions

	* [if1632/kernel.spec]
	IsWinOldApTask: Return false

	* [if1632/mouse.spec]
	CplApplet: Removed

	* [if1632/user.spec] [windows/win.c]
	ShowOwnedPopups: New function

	* [if1632/winsock.spec] [misc/winsocket.c]
	inet_addr, select: New prototypes in relay code
	Fixed memory layout for netdb functions (getXbyY).
	WINSOCK_ioctlsocket: Translated FIONREAD, FIONBIO, and FIOASYNC

	* [objects/clipping.c]
	RectVisible: Fixed call to LPToDP

	* [rc/winerc.c]
	main: Removed extra argument to getopt for Linux.

Tue Jul 11 00:14:41 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>

        * [controls/listbox.c]
	Yet another fix for ListBoxDirectory().
	
	* [loader/module.c] [if1632/kernel.spec]
	Make GetModuleHandle() accept instance handles as parameter.

        * [if1632/relay.c] [loader/task.c]
	Put a magic cookie at the bottom of the 32 bit stack, and check on
	each return from a 32 bit function whether it's still there. Complain
	if it's not.

        * [if1632/user.spec]
	Wrong entry for CloseDriver().

	* [misc/dos_fs.c] [loader/task.c] [include/dos_fs.h] [misc/file.c]
	[miscemu/int21.c]
	Large parts of dos_fs.c simplified. Changed it to use one
	current drive/directory per task, which is set to the module path on
	task creation.
	Prevent CorelPaint from closing stdin.
	open() with O_CREAT set must be passed three parameters.
	DOS FindFirst()/FindNext() could crash when FA_LABEL was set. Fixed,
	it's in DOS_readdir() now.

	* [misc/profile.c]
	Some badly written software (Lotus Freelance Graphics) passes a bogus
	size parameter that caused Wine to write off the end of a segment.
	Fixed. (It's probably too paranoid now.)
	
	* [multimedia/mmsystem.c] [multimedia/time.c] [multimedia/joystick.c]
	[multimedia/Imakefile] [if1632/winprocs.spec]
	16 bit entry point for MMSysTimeCallback.
	Split off time.c and joystick.c from mmsystem.c.
	
	* [objects/dib.c]
	GetDIBits(): call XGetImage() via CallTo32_LargeStack.

        * [windows/cursor.c]
	DestroyCursor(): do nothing for builtin cursors.
	
	* [windows/mdi.c]
	Half of WM_MDISETMENU implemented.
	
	* [windows/win.c]
	EnumWindows() and EnumTaskWindows() never enumerated any windows.
	Fixed.

	* [windows/*.c]
	Fixed GetParent() to return correct values for owned windows.

	* [windows/message.c]
	Don't try to activate disabled top-level windows.

        * [windows/nonclient.c]
	Work around a bug in gcc-2.7.0.
	
	* [tools/build.c] [include/stackframe.h] [memory/global.c] 
	[loader/task.c] [memory/selector.c]
	Some Visual Basic programs (and possibly others, too) expect ES to be 
	preserved by a call to an API function, so we have to save it.
	In GlobalFree() and FreeSelector(), we must clear CURRENT_STACK16->es 
	to prevent segfaults if ES contained the selector to be freed.

Sun Jul  9 20:21:20 1995  Jon Tombs  <jon@gtex02.us.es>

	* [*/*]
	Added missing prototypes to header files and relevant includes
	to reduce compile time warnings.

Sun Jul  9 18:32:56 1995  Michael Patra  <micky@marie.physik.tu-berlin.de>

	* [configure.in] [include/config.h] [*/Makefile.in]
	New configuration scheme based on autoconf.

Sat Jul  8 14:12:45 1995  Morten Welinder  <terra+@cs.cmu.edu>

	* [miscemu/ioports.c]
	Revamp to have only one in- and one out- variant, both really
 	implemented.

	* [miscemu/instr.c]
	INSTR_EmulateInstruction: Use new ioport interface.  Implement
 	string io.  Correct instruction pointer for 32-bit code.

	* [include/miscemu.h]
	Update port function prototypes.

	* [include/registers.h]
	Defined FS and GS.

Sat Jul  8 13:38:54 1995  Hans de Graaff  <graaff@twi72.twi.tudelft.nl>

	* [misc/dos_fs.c]
	ChopOffSlash(): A path consisting off a single slash is left
 	intact, and multiple slashes are all removed.
diff --git a/loader/Imakefile b/loader/Imakefile
index befe47a..3ec199f 100644
--- a/loader/Imakefile
+++ b/loader/Imakefile
@@ -3,7 +3,6 @@
 MODULE = loader
 
 SRCS = \
-	dump.c \
 	main.c \
 	module.c \
 	ne_image.c \
diff --git a/loader/Makefile.in b/loader/Makefile.in
new file mode 100644
index 0000000..b9cd285
--- /dev/null
+++ b/loader/Makefile.in
@@ -0,0 +1,50 @@
+CC 	= @CC@
+CFLAGS 	= @CFLAGS@
+XINCL 	= @x_includes@
+TOPSRC  = @top_srcdir@
+DIVINCL = -I$(TOPSRC)/include
+LD	= @LD@
+LDCOMBINEFLAGS = @LDCOMBINEFLAGS@
+
+
+MODULE 	= loader
+
+SRCS 	= main.c module.c ne_image.c ne_resource.c pe_image.c \
+	pe_resource.c selector.c signal.c resource.c task.c
+ 
+OBJS = $(SRCS:.c=.o)
+
+.c.o:
+	$(CC) -c $(CFLAGS) $(XINCL) $(DIVINCL) -o $*.o $<
+
+all: $(MODULE).o
+
+$(MODULE).o: $(OBJS)
+	$(LD) $(LDCOMBINEFLAGS) $(OBJS) -o $(MODULE).o
+
+depend:
+	sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
+	$(CC) $(DIVINCL) $(XINCL) -MM *.c >> tmp_make
+	cp tmp_make Makefile
+	rm tmp_make
+
+clean:
+	rm -f *.o \#*\# *~ tmp_make
+
+distclean: clean
+	rm Makefile
+
+countryclean:
+
+NAMES = $(SRCS:.c=)
+
+winelibclean:
+	for i in $(NAMES); do \
+	if test `grep -c WINELIB $$i.c` -ne 0; then \
+	rm $$i.o; \
+	fi; \
+	done
+ 
+dummy:
+
+### Dependencies:
diff --git a/loader/dump.c b/loader/dump.c
deleted file mode 100644
index 39344e5..0000000
--- a/loader/dump.c
+++ /dev/null
@@ -1,75 +0,0 @@
-#ifndef WINELIB
-/*
-static char RCSId[] = "$Id: dump.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
-static char Copyright[] = "Copyright  Robert J. Amstadt, 1993";
-*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#ifdef linux
-#include <linux/unistd.h>
-#include <linux/head.h>
-#include <linux/ldt.h>
-#endif
-#include <errno.h>
-#include "neexe.h"
-#include "prototypes.h"
-
-/**********************************************************************
- *					PrintFileHeader
- */
-void
-PrintFileHeader(struct ne_header_s *ne_header)
-{
-    printf("ne_header: %c%c\n",
-           ne_header->ne_magic & 0xff,
-           ne_header->ne_magic >> 8 );
-    printf("linker version: %d.%d\n", ne_header->linker_version,
-	   ne_header->linker_revision);
-    printf("format flags: %04x\n", ne_header->format_flags);
-    printf("automatic data segment: %04x\n", ne_header->auto_data_seg);
-    printf("CS:IP  %04x:%04x\n", ne_header->cs, ne_header->ip);
-    printf("SS:SP  %04x:%04x\n", ne_header->ss, ne_header->sp);
-    printf("additional flags: %02x\n", ne_header->additional_flags);
-    printf("operating system: %02x\n", ne_header->operating_system);
-    printf("fast load offset: %04x\n", ne_header->fastload_offset);
-    printf("fast load length: %04x\n", ne_header->fastload_length);
-}
-
-/**********************************************************************
- *					PrintRelocationTable
- */
-void 
-PrintRelocationTable(char *exe_ptr, 
-		     struct ne_segment_table_entry_s *seg_entry_p,
-		     int segment)
-{
-    struct relocation_entry_s *rep;
-    int i;
-    int offset;
-    u_short n_entries, *sp;
-
-    printf("RELOCATION TABLE %d:\n", segment + 1);
-    
-    if (seg_entry_p->seg_data_offset == 0)
-	return;
-
-    offset = seg_entry_p->seg_data_length;
-    if (offset == 0)
-	offset = 0x10000;
-
-    sp = (u_short *) (exe_ptr + seg_entry_p->seg_data_offset * 512 + offset);
-    n_entries = *sp;
-
-    rep = (struct relocation_entry_s *) (sp + 1);
-    for (i = 0; i < n_entries; i++, rep++)
-    {
-	printf("  ADDR TYPE %d,  TYPE %d,  OFFSET %04x,",
-	       rep->address_type, rep->relocation_type, rep->offset);
-	printf("TARGET %04x %04x\n", rep->target1, rep->target2);
-    }
-}
-#endif /* ifndef WINELIB */
diff --git a/loader/main.c b/loader/main.c
index 7a2d435..0e301df 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -11,6 +11,18 @@
 #include <string.h>
 #include <errno.h>
 #include "windows.h"
+#include "module.h"
+#include "task.h"
+#include "selectors.h"
+#include "comm.h"
+#include "user.h"
+#include "menu.h"
+#include "atom.h"
+#include "dialog.h"
+#include "message.h"
+#include "syscolor.h"
+#include "sysmetrics.h"
+#include "gdi.h"
 #include "debugger.h"
 #include "dos_fs.h"
 #include "dlls.h"
@@ -18,6 +30,7 @@
 #include "neexe.h"
 #include "options.h"
 #include "task.h"
+#include "dce.h"
 #include "pe_image.h"
 #include "stddebug.h"
 #include "debug.h"
@@ -29,6 +42,7 @@
 int MAIN_Init(void)
 {
     extern BOOL RELAY_Init(void);
+    extern BOOL RELAY32_Init(void); 
 
     int queueSize;
 
@@ -103,14 +117,22 @@
 int _WinMain(int argc, char **argv)
 {
     int i;
+    HANDLE handle;
 
     if (!MAIN_Init()) return 0;
 
     for (i = 1; i < argc; i++)
     {
-        if (WinExec( argv[i], SW_SHOWNORMAL ) < 32)
+        if ((handle = WinExec( argv[i], SW_SHOWNORMAL )) < 32)
         {
-            fprintf(stderr, "wine: can't exec '%s'.\n", argv[i]);
+            fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
+            switch (handle)
+            {
+            case 2: fprintf( stderr, "file not found\n" ); break;
+            case 11: fprintf( stderr, "invalid exe file\n" ); break;
+            case 21: fprintf( stderr, "win32 executable\n" ); break;
+            default: fprintf( stderr, "error=%d\n", handle ); break;
+            }
             exit(1);
         }
     }
diff --git a/loader/module.c b/loader/module.c
index 01d2678..12cf6ba 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -21,7 +21,6 @@
 #include "task.h"
 #include "toolhelp.h"
 #include "stddebug.h"
-/* #define DEBUG_MODULE */
 #include "debug.h"
 
 
@@ -53,7 +52,7 @@
 
         hModule = GLOBAL_CreateBlock( GMEM_MOVEABLE, table->module_start,
                                       table->module_end - table->module_start,
-                                      0, FALSE, FALSE, FALSE );
+                                      0, FALSE, FALSE, FALSE, NULL );
         if (!hModule) return FALSE;
         FarSetOwner( hModule, hModule );
 
@@ -69,7 +68,7 @@
 
         pSegTable->selector = GLOBAL_CreateBlock(GMEM_FIXED, table->code_start,
                                                  pSegTable->minsize, hModule,
-                                                 TRUE, TRUE, FALSE );
+                                                 TRUE, TRUE, FALSE, NULL );
         if (!pSegTable->selector) return FALSE;
         pSegTable++;
 
@@ -99,35 +98,34 @@
 
     MODULE_SetEntryPoint( hModule, 183,  /* KERNEL.183: __0000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 193,  /* KERNEL.193: __0040H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x400,
-                                     0x100, hModule, FALSE, FALSE, FALSE ) );
+                                  0x100, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 174,  /* KERNEL.174: __A000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x10000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 181,  /* KERNEL.181: __B000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x20000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 182,  /* KERNEL.182: __B800H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x28000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 195,  /* KERNEL.195: __C000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x30000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 179,  /* KERNEL.179: __D000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x40000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 190,  /* KERNEL.190: __E000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x50000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 173,  /* KERNEL.173: __ROMBIOS */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x60000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     MODULE_SetEntryPoint( hModule, 194,  /* KERNEL.194: __F000H */
                           GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x60000,
-                                     0x10000, hModule, FALSE, FALSE, FALSE ) );
-
+                                0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
     return TRUE;
 }
 
@@ -304,15 +302,8 @@
     {
         minsize = pSegment->minsize ? pSegment->minsize : 0x10000;
         if (i == pModule->ss) minsize += pModule->stack_size;
-        if (i == pModule->dgroup)
-        {
-#if 0
-            /* FIXME: this is needed because heap growing is not implemented */
-            pModule->heap_size = 0x10000 - minsize;
-#endif
-            /* The DGROUP is allocated by MODULE_CreateInstance */
-            continue;
-        }
+	/* The DGROUP is allocated by MODULE_CreateInstance */
+        if (i == pModule->dgroup) continue;
         pSegment->selector = GLOBAL_Alloc( GMEM_ZEROINIT | GMEM_FIXED,
                                       minsize, hModule,
                                       !(pSegment->flags & NE_SEGFLAGS_DATA),
@@ -1013,6 +1004,12 @@
 /**********************************************************************
  *	    GetModuleHandle    (KERNEL.47)
  */
+HMODULE WIN16_GetModuleHandle( SEGPTR name )
+{
+    if (HIWORD(name) == 0) return GetExePtr( LOWORD(name) );
+    return MODULE_FindModule( PTR_SEG_TO_LIN(name) );
+}
+
 HMODULE GetModuleHandle( LPCSTR name )
 {
     return MODULE_FindModule( name );
diff --git a/loader/pe_image.c b/loader/pe_image.c
index ee1b119..2d284b5 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -197,7 +197,7 @@
 		      wpnt->fd, wpnt->pe->pe_seg[i].PointerToRawData);
 	}
 	if(result==-1){
-		fprintf(stderr,"Could not load section %x to desired address %x\n",
+		fprintf(stderr,"Could not load section %x to desired address %lx\n",
 			i, load_addr+wpnt->pe->pe_seg[i].Virtual_Address);
 		fprintf(stderr,"Need to implement relocations now\n");
 		exit(0);
diff --git a/loader/resource.c b/loader/resource.c
index 4cf44cf..4e6bbfc 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -32,6 +32,16 @@
     else \
         dprintf_resource( stddeb, "#%04x", LOWORD(name)); 
 
+
+/**********************************************************************
+ *	    LoadIconHandler    (USER.456)
+ */
+HICON LoadIconHandler( HANDLE hResource, BOOL bNew )
+{
+  return 0;
+}
+
+
 /**********************************************************************
  *	    FindResource    (KERNEL.60)
  */
diff --git a/loader/selector.c b/loader/selector.c
index d04e4f1..ab211bd 100644
--- a/loader/selector.c
+++ b/loader/selector.c
@@ -8,33 +8,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 
 #ifndef WINELIB
 
-#ifdef __linux__
-#include <sys/mman.h>
-#include <linux/unistd.h>
-#include <linux/head.h>
-#include <linux/mman.h>
-#include <linux/a.out.h>
-#include <linux/ldt.h>
-#endif
-#if defined(__NetBSD__) || defined(__FreeBSD__)
-#include <sys/mman.h>
-#include <machine/segments.h>
-#endif
-
 #include "windows.h"
-#include "ldt.h"
-#include "wine.h"
 #include "global.h"
-#include "dlls.h"
-#include "neexe.h"
-#include "prototypes.h"
 #include "module.h"
 #include "stddebug.h"
 /* #define DEBUG_SELECTORS */
diff --git a/loader/signal.c b/loader/signal.c
index e7c8381..4ede072 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -15,7 +15,6 @@
 #endif
 
 #include "debugger.h"
-#include "prototypes.h"
 #include "miscemu.h"
 #include "registers.h"
 #include "win.h"
@@ -24,6 +23,7 @@
 char * cstack[4096];
 #endif
 struct sigaction segv_act;
+struct sigaction usr2_act;
 
 #ifdef linux
 extern void ___sig_restore();
@@ -71,15 +71,21 @@
 
 void init_wine_signals(void)
 {
+        extern void stop_wait(int a);
 #ifdef linux
 	segv_act.sa_handler = (__sighandler_t) win_fault;
 	/* Point to the top of the stack, minus 4 just in case, and make
 	   it aligned  */
 	segv_act.sa_restorer = 
-		(void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
+	    (void (*)()) (((unsigned int)(cstack) + sizeof(cstack) - 4) & ~3);
+	usr2_act.sa_restorer= segv_act.sa_restorer;
+	usr2_act.sa_handler = (__sighandler_t) stop_wait;
+	/* Point to the top of the stack, minus 4 just in case, and make
+	   it aligned  */
 	wine_sigaction(SIGSEGV, &segv_act, NULL);
 	wine_sigaction(SIGILL, &segv_act, NULL);
 	wine_sigaction(SIGFPE, &segv_act, NULL);
+	wine_sigaction(SIGUSR2, &usr2_act, NULL);
 #ifdef SIGBUS
 	wine_sigaction(SIGBUS, &segv_act, NULL);
 #endif
@@ -126,6 +132,13 @@
                 perror("sigaction: SIGTRAP");
                 exit(1);
         }
+        usr2_act.sa_handler = (void (*)) stop_wait; /* For breakpoints */
+	usr2_act.sa_flags = SA_ONSTACK;
+        usr2_act.sa_mask = sig_mask;
+	if (sigaction(SIGUSR2, &usr2_act, NULL) < 0) {
+                perror("sigaction: SIGUSR2");
+                exit(1);
+        }
 #endif
 }
 
diff --git a/loader/task.c b/loader/task.c
index 222bd01..53d1006 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -21,6 +21,7 @@
 #include "toolhelp.h"
 #include "stddebug.h"
 #include "debug.h"
+#include "dde_proc.h"
 
   /* Min. number of thunks allocated when creating a new segment */
 #define MIN_THUNKS  32
@@ -247,7 +248,8 @@
     STACK16FRAME *frame16;
     STACK32FRAME *frame32;
     extern DWORD CALL16_RetAddr_word;
-
+    char filename[256];
+    
     if (!(pModule = (NE_MODULE *)GlobalLock( hModule ))) return 0;
     pSegTable = NE_SEG_TABLE( pModule );
 
@@ -258,6 +260,12 @@
     if (!hTask) return 0;
     pTask = (TDB *)GlobalLock( hTask );
 
+      /* get current directory */
+    
+    GetModuleFileName( hModule, filename, sizeof(filename) );
+    name = strrchr(filename, '\\');
+    if (name) *(name+1) = 0;
+
       /* Fill the task structure */
 
     pTask->nEvents       = 1;  /* So the task can be started */
@@ -268,10 +276,10 @@
     pTask->hPrevInstance = hPrevInstance;
     pTask->hModule       = hModule;
     pTask->hParent       = hCurrentTask;
-    pTask->curdrive      = 'C' - 'A' + 0x80;
+    pTask->curdrive      = filename[0] - 'A' + 0x80;
     pTask->magic         = TDB_MAGIC;
     pTask->nCmdShow      = cmdShow;
-    strcpy( pTask->curdir, "WINDOWS" );
+    strcpy( pTask->curdir, filename+2 );
 
       /* Create the thunks block */
 
@@ -302,13 +310,13 @@
       /* Allocate a selector for the PDB */
 
     pTask->hPDB = GLOBAL_CreateBlock( GMEM_FIXED, &pTask->pdb, sizeof(PDB),
-                                      hModule, FALSE, FALSE, FALSE );
+                                      hModule, FALSE, FALSE, FALSE, NULL );
 
       /* Allocate a code segment alias for the TDB */
 
     pTask->hCSAlias = GLOBAL_CreateBlock( GMEM_FIXED, (void *)pTask,
                                           sizeof(TDB), pTask->hPDB, TRUE,
-                                          FALSE, FALSE );
+                                          FALSE, FALSE, NULL );
 
       /* Set the owner of the environment block */
 
@@ -326,6 +334,7 @@
 
       /* Create the 32-bit stack frame */
 
+    *(DWORD *)GlobalLock(pTask->hStack32) = 0xDEADBEEF;
     stack32Top = (char*)GlobalLock(pTask->hStack32) + STACK32_SIZE;
     frame32 = (STACK32FRAME *)stack32Top - 1;
     frame32->saved_esp = (DWORD)stack32Top;
@@ -342,13 +351,13 @@
       /* Create the 16-bit stack frame */
 
     pTask->ss = hInstance;
-    pTask->sp = (pModule->sp != 0) ? pModule->sp :
-                pSegTable[pModule->ss-1].minsize + pModule->stack_size;
+    pTask->sp = ((pModule->sp != 0) ? pModule->sp :
+                 pSegTable[pModule->ss-1].minsize + pModule->stack_size) & ~1;
     stack16Top = (char *)PTR_SEG_OFF_TO_LIN( pTask->ss, pTask->sp );
     frame16 = (STACK16FRAME *)stack16Top - 1;
     frame16->saved_ss = pTask->ss;
     frame16->saved_sp = pTask->sp;
-    frame16->ds = pTask->hInstance;
+    frame16->ds = frame16->es = pTask->hInstance;
     frame16->entry_point = 0;
     frame16->ordinal_number = 24;  /* WINPROCS.24 is TASK_Reschedule */
     frame16->dll_id = 24; /* WINPROCS */
@@ -461,6 +470,7 @@
     TDB *pOldTask = NULL, *pNewTask;
     HTASK hTask = 0;
 
+    dde_reschedule();
       /* First check if there's a task to kill */
 
     if (hTaskToKill && (hTaskToKill != hCurrentTask))