Release 970824

Sat Aug 23 00:05:23 1997  Andreas Mohr <100.30936@germany.net>

	* [if1632/kernel.spec] [if1632/mmsystem.spec]
	Added some stubs.

	* [include/neexe.h] [loader/module.c]
	Added warning for OS/2 executables.

	* [multimedia/midi.c]
	Shortened MIDIOUT driver version string to be less than 31 chars.

	* [objects/gdiobj.c]
	Fixed DeleteObject32() to react properly when called with stock object.

Fri Aug 22 18:03:26 1997  Dimitrie O. Paun <dimi@cs.toronto.edu>

	* [controls/updown.c] [include/updown.h]
	First attempt at implementiong the UpDown class.

	* [controls/widgets.c]
	Added the UpDown class to be initialized by InitCommonControls().

Wed Aug 20 18:01:33 1997  Doug Ridgway <ridgway@routh.UCSD.EDU>

	* [graphics/*] [objects/*] [include/gdi.h]
	Made all GDI objects (except DCs) moveable.

Mon Aug 18 03:25:30 1997  Alex Korobka <alex@trantor.pharm.sunysb.edu>

	* [windows/event.c] [misc/winsock.c] [misc/winsock_dns.c]
	Removed IPC communication to speed up winsock services
	(tested only with 16-bit netscape 3.03).

	* [graphics/x11drv/xfont.c] [documentation/fonts]
	Miscellaneous improvements. Updated docs.

Sun Aug 17 20:39:55 1997  Ingo Schneider <schneidi@informatik.tu-muenchen.de>

	* [misc/comm.c]
	A couple of bug fixes.

Sun Aug 17 19:29:22 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [debugger/dbg.y]
	Display next instruction after stepi/nexti.

	* [if1632/relay.c] [include/callback.h] [tools/build.c]
	Replaced CallTo32_LargeStack with the CALL_LARGE_STACK macro for
	better Winelib support.

	* [include/sigcontext.h]
	Renamed to sig_context.h to avoid conflicts with libc.

	* [*/*]
	All API functions are now prefixed with WINAPI in prevision of
	future Winelib integration.

	* [loader/signal.c] [memory/ldt.c]
	Fixed assembly code to be -fPIC compatible.

Thu Aug 14 14:38:15 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [if1632/crtdll.spec][win32/except.c]
	_global_unwind, _local_unwind stub added.

	* [objects/dib.c]	
	Don't read memory you don't even need for the target bitmap (fixes
	one 'lazy' program).

	* [if1632/relay.c][if1632/thunk.c][if1632/kernel32.spec]
	  [win32/ordinals.c][memory/selector.c][memory/global.c]
	  [include/callback.h]
	Added/moved some more win95 ordinal stuff. Implemented QT_Thunk
	(not 100% correct yet) and some friends.

	* [loader/pe_image.c]
	Add possibility to break at the DLL entrypoint.

	* [controls/static.c][misc/commdlg.c][scheduler/thread.c]
	Misc bugfixes and additions.

	* [misc/registry.c]
	The registry seems to be case-preserving but case-insensitive.

	* [memory/global.c]	
	Adapted to new /proc/meminfo format.

	* [objects/font.c][graphics/x11drv/xfont.c]
	FONT_SelectObject and GetTextMetrics* get passed ranges in logical
 	and not device points (thanks to Marion Reyzl for pointing this
 	out).

	* [windows/caret.c]
	Use the windows own DC if present (The caret coordinates are
	logical coordinates based on it). Fixes another AMIPRO problem.

Wed Aug  6 18:22:22 1997  Morten Welinder  <terra@diku.dk>

	* [controls/menu.c]
	General clean-up and Win32 work: split item_flags into fType and
	fState; split item_id into wID and hSubMenu.  Improved
	debug-printing.  Implemented InsertMenuItem32[AW],
	SetMenuDefaultItem32, and SetMenuItemInfo32[AW].  Fixed
	GetMenuItemInfo32[AW].

	* [if1632/user32.spec]
	Define above new functions.

	* [include/windows.h]
	Define MF_DEFAULT and MF_RIGHTJUSTIFY.  Prototype above functions.

	* [include/menu.h]
	Don't prototype now-static MENU_InitSysMenuPopup.

	* [include/comm.h]
	Reduce MAX_PORTS to 9 (which the profile code can handle).

Tue Aug  5 20:16:22 1997  Victor Schneider <vischne@ibm.net>

	* [library/winestub.c] [libtest/expand.c]
	These patches let people porting Windows apps compile them using
	the same conventions regarding global _argc and _argv as those on
	Windows C/C++ compilers.
diff --git a/ANNOUNCE b/ANNOUNCE
index 73a0d1a..b22dffa 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,13 +1,15 @@
-This is release 970804 of Wine, the MS Windows emulator.  This is still a
+This is release 970824 of Wine, the MS Windows emulator.  This is still a
 developer's only release.  There are many bugs and many unimplemented API
 features.  Most applications still do not work correctly.
 
 Patches should be submitted to "julliard@lrc.epfl.ch".  Please don't
 forget to include a ChangeLog entry.
 
-WHAT'S NEW with Wine-970804: (see ChangeLog for details)
-	- Joystick support.
-	- More Win32 stuff.
+WHAT'S NEW with Wine-970824: (see ChangeLog for details)
+	- Better Win32 menu support.
+	- Improved Winsock.
+	- UpDown control.
+	- More undocumented Win95 hacks.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -16,10 +18,10 @@
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-  ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/development/Wine-970804.tar.gz
-  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-970804.tar.gz
-  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-970804.tar.gz
-  ftp://ftp.progsoc.uts.edu.au/pub/Wine/development/Wine-970804.tar.gz
+  ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/development/Wine-970824.tar.gz
+  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-970824.tar.gz
+  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-970824.tar.gz
+  ftp://ftp.progsoc.uts.edu.au/pub/Wine/development/Wine-970824.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/BUGS b/BUGS
index 74110a3..05f5253 100644
--- a/BUGS
+++ b/BUGS
@@ -42,9 +42,6 @@
 
  * "Cursor XXXX has more than 1 bpp!"
 
- * 32-bit Freecell segfaults when started from the Progman (looks like
-   a problem with cards.dll).
-
  * Margins in edit controls are too wide.
 
  * SGI window manager treats Wine windows as topmost.
diff --git a/ChangeLog b/ChangeLog
index f1264ad..94d3fd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,129 @@
 ----------------------------------------------------------------------
+Sat Aug 23 00:05:23 1997  Andreas Mohr <100.30936@germany.net>
+
+	* [if1632/kernel.spec] [if1632/mmsystem.spec]
+	Added some stubs.
+
+	* [include/neexe.h] [loader/module.c]
+	Added warning for OS/2 executables.
+
+	* [multimedia/midi.c]
+	Shortened MIDIOUT driver version string to be less than 31 chars.
+
+	* [objects/gdiobj.c]
+	Fixed DeleteObject32() to react properly when called with stock object.
+
+Fri Aug 22 18:03:26 1997  Dimitrie O. Paun <dimi@cs.toronto.edu>
+
+	* [controls/updown.c] [include/updown.h]
+	First attempt at implementiong the UpDown class.
+
+	* [controls/widgets.c]
+	Added the UpDown class to be initialized by InitCommonControls().
+
+Wed Aug 20 18:01:33 1997  Doug Ridgway <ridgway@routh.UCSD.EDU>
+
+	* [graphics/*] [objects/*] [include/gdi.h]
+	Made all GDI objects (except DCs) moveable.
+
+Mon Aug 18 03:25:30 1997  Alex Korobka <alex@trantor.pharm.sunysb.edu>
+
+	* [windows/event.c] [misc/winsock.c] [misc/winsock_dns.c]
+	Removed IPC communication to speed up winsock services
+	(tested only with 16-bit netscape 3.03).
+
+	* [graphics/x11drv/xfont.c] [documentation/fonts]
+	Miscellaneous improvements. Updated docs.
+
+Sun Aug 17 20:39:55 1997  Ingo Schneider <schneidi@informatik.tu-muenchen.de>
+
+	* [misc/comm.c]
+	A couple of bug fixes.
+
+Sun Aug 17 19:29:22 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>
+
+	* [debugger/dbg.y]
+	Display next instruction after stepi/nexti.
+
+	* [if1632/relay.c] [include/callback.h] [tools/build.c]
+	Replaced CallTo32_LargeStack with the CALL_LARGE_STACK macro for
+	better Winelib support.
+
+	* [include/sigcontext.h]
+	Renamed to sig_context.h to avoid conflicts with libc.
+
+	* [*/*]
+	All API functions are now prefixed with WINAPI in prevision of
+	future Winelib integration.
+
+	* [loader/signal.c] [memory/ldt.c]
+	Fixed assembly code to be -fPIC compatible.
+
+Thu Aug 14 14:38:15 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
+
+	* [if1632/crtdll.spec][win32/except.c]
+	_global_unwind, _local_unwind stub added.
+
+	* [objects/dib.c]	
+	Don't read memory you don't even need for the target bitmap (fixes
+	one 'lazy' program).
+
+	* [if1632/relay.c][if1632/thunk.c][if1632/kernel32.spec]
+	  [win32/ordinals.c][memory/selector.c][memory/global.c]
+	  [include/callback.h]
+	Added/moved some more win95 ordinal stuff. Implemented QT_Thunk
+	(not 100% correct yet) and some friends.
+
+	* [loader/pe_image.c]
+	Add possibility to break at the DLL entrypoint.
+
+	* [controls/static.c][misc/commdlg.c][scheduler/thread.c]
+	Misc bugfixes and additions.
+
+	* [misc/registry.c]
+	The registry seems to be case-preserving but case-insensitive.
+
+	* [memory/global.c]	
+	Adapted to new /proc/meminfo format.
+
+	* [objects/font.c][graphics/x11drv/xfont.c]
+	FONT_SelectObject and GetTextMetrics* get passed ranges in logical
+ 	and not device points (thanks to Marion Reyzl for pointing this
+ 	out).
+
+	* [windows/caret.c]
+	Use the windows own DC if present (The caret coordinates are
+	logical coordinates based on it). Fixes another AMIPRO problem.
+
+Wed Aug  6 18:22:22 1997  Morten Welinder  <terra@diku.dk>
+
+	* [controls/menu.c]
+	General clean-up and Win32 work: split item_flags into fType and
+	fState; split item_id into wID and hSubMenu.  Improved
+	debug-printing.  Implemented InsertMenuItem32[AW],
+	SetMenuDefaultItem32, and SetMenuItemInfo32[AW].  Fixed
+	GetMenuItemInfo32[AW].
+
+	* [if1632/user32.spec]
+	Define above new functions.
+
+	* [include/windows.h]
+	Define MF_DEFAULT and MF_RIGHTJUSTIFY.  Prototype above functions.
+
+	* [include/menu.h]
+	Don't prototype now-static MENU_InitSysMenuPopup.
+
+	* [include/comm.h]
+	Reduce MAX_PORTS to 9 (which the profile code can handle).
+
+Tue Aug  5 20:16:22 1997  Victor Schneider <vischne@ibm.net>
+
+	* [library/winestub.c] [libtest/expand.c]
+	These patches let people porting Windows apps compile them using
+	the same conventions regarding global _argc and _argv as those on
+	Windows C/C++ compilers.
+
+----------------------------------------------------------------------
 Sun Aug  3 14:03:43 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>
 
 	* [documentation/Makefile.in]
diff --git a/README b/README
index 25a81f6..01bc791 100644
--- a/README
+++ b/README
@@ -83,7 +83,8 @@
 
 The best place to get help or to report bugs is the Usenet newsgroup
 comp.emulators.ms-windows.wine. The Wine FAQ is posted there every
-month.
+month. Also, you may want to browse old messages on www.dejanews.com 
+to check whether your problem is already fixed. 
 
 If you add something, or fix a bug, please send a patch ('diff -u'
 format preferred) to julliard@lrc.epfl.ch for inclusion in the next
diff --git a/controls/Makefile.in b/controls/Makefile.in
index 3379b18..9d24345 100644
--- a/controls/Makefile.in
+++ b/controls/Makefile.in
@@ -16,6 +16,7 @@
 	scroll.c \
 	static.c \
 	status.c \
+	updown.c \
 	widgets.c
 
 all: $(MODULE).o
diff --git a/controls/button.c b/controls/button.c
index 07cc5e1..312282d 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -71,7 +71,8 @@
 /***********************************************************************
  *           ButtonWndProc
  */
-LRESULT ButtonWndProc(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI ButtonWndProc( HWND32 hWnd, UINT32 uMsg,
+                              WPARAM32 wParam, LPARAM lParam )
 {
     RECT16 rect;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
diff --git a/controls/combo.c b/controls/combo.c
index 3771933..3c3590f 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -83,30 +83,32 @@
  */
 static LRESULT COMBO_NCCreate(WND* wnd, LPARAM lParam)
 {
-  LPHEADCOMBO 		lphc;
+   LPHEADCOMBO 		lphc;
 
-  if ( wnd && COMBO_Init() &&
+   if ( wnd && COMBO_Init() &&
       (lphc = HeapAlloc(GetProcessHeap(), 0, sizeof(HEADCOMBO))) )
-  {
-       LPCREATESTRUCT32A     lpcs = (CREATESTRUCT32A*)lParam;
+   {
+	LPCREATESTRUCT32A     lpcs = (CREATESTRUCT32A*)lParam;
        
-       memset( lphc, 0, sizeof(HEADCOMBO) );
+	memset( lphc, 0, sizeof(HEADCOMBO) );
        *(LPHEADCOMBO*)wnd->wExtra = lphc;
 
        /* some braindead apps do try to use scrollbar/border flags */
 
-       lphc->dwStyle = (lpcs->style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL));
-       wnd->dwStyle &= ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
+	lphc->dwStyle = (lpcs->style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL));
+	wnd->dwStyle &= ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
 
-       if( !(lpcs->style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
-             lphc->dwStyle |= CBS_HASSTRINGS;
+	if( !(lpcs->style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
+              lphc->dwStyle |= CBS_HASSTRINGS;
+	if( !(wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) )
+	      lphc->wState |= CBF_NOTIFY;
 
-       dprintf_combo(stddeb, "COMBO_NCCreate: [0x%08x], style = %08x\n", 
-				              (UINT32)lphc, lphc->dwStyle );
+	dprintf_combo(stddeb, "COMBO_NCCreate: [0x%08x], style = %08x\n", 
+						(UINT32)lphc, lphc->dwStyle );
 
-       return (LRESULT)(UINT32)wnd->hwndSelf; 
-  }
-  return (LRESULT)FALSE;
+	return (LRESULT)(UINT32)wnd->hwndSelf; 
+    }
+    return (LRESULT)FALSE;
 }
 
 /***********************************************************************
@@ -1239,7 +1241,8 @@
  *
  * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
  */
-LRESULT ComboWndProc(HWND32 hwnd, UINT32 message, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI ComboWndProc( HWND32 hwnd, UINT32 message,
+                             WPARAM32 wParam, LPARAM lParam )
 {
     WND*	pWnd = WIN_FindWndPtr(hwnd);
    
diff --git a/controls/desktop.c b/controls/desktop.c
index 6708fb7..b1651f2 100644
--- a/controls/desktop.c
+++ b/controls/desktop.c
@@ -131,8 +131,8 @@
  *
  * Window procedure for the desktop window.
  */
-LRESULT DesktopWndProc( HWND32 hwnd, UINT32 message,
-                        WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI DesktopWndProc( HWND32 hwnd, UINT32 message,
+                               WPARAM32 wParam, LPARAM lParam )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
     DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
@@ -169,7 +169,7 @@
 /***********************************************************************
  *           SetDeskPattern   (USER.279)
  */
-BOOL16 SetDeskPattern(void)
+BOOL16 WINAPI SetDeskPattern(void)
 {
     char buffer[100];
     GetProfileString32A( "desktop", "Pattern", "(None)", buffer, 100 );
@@ -180,7 +180,7 @@
 /***********************************************************************
  *           SetDeskWallPaper16   (USER.285)
  */
-BOOL16 SetDeskWallPaper16( LPCSTR filename )
+BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
 {
     return SetDeskWallPaper32( filename );
 }
@@ -191,7 +191,7 @@
  *
  * FIXME: is there a unicode version?
  */
-BOOL32 SetDeskWallPaper32( LPCSTR filename )
+BOOL32 WINAPI SetDeskWallPaper32( LPCSTR filename )
 {
     HBITMAP32 hbitmap;
     HDC32 hdc;
diff --git a/controls/edit.c b/controls/edit.c
index 0a8a3d48..28373cd 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -148,7 +148,8 @@
 /*
  *	This is the only exported function
  */
-LRESULT EditWndProc(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam);
+LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg,
+                            WPARAM32 wParam, LPARAM lParam );
 /*
  *	Helper functions only valid for one type of control
  */
@@ -297,7 +298,8 @@
  *	names).
  *
  */
-LRESULT EditWndProc(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg,
+                            WPARAM32 wParam, LPARAM lParam )
 {
 	WND *wnd = WIN_FindWndPtr(hwnd);
 	EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra);
diff --git a/controls/icontitle.c b/controls/icontitle.c
index 1864086..b54801e 100644
--- a/controls/icontitle.c
+++ b/controls/icontitle.c
@@ -185,7 +185,8 @@
 /***********************************************************************
  *           IconTitleWndProc
  */
-LRESULT IconTitleWndProc( HWND32 hWnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI IconTitleWndProc( HWND32 hWnd, UINT32 msg,
+                                 WPARAM32 wParam, LPARAM lParam )
 {
     WND *wnd = WIN_FindWndPtr( hWnd );
 
diff --git a/controls/listbox.c b/controls/listbox.c
index 71f56be..5466abe 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -233,7 +233,8 @@
     {
         INT32 diff = (descr->top_item - index) / descr->page_size * descr->column_width;
         if (scroll && (abs(diff) < descr->width))
-            ScrollWindow32( wnd->hwndSelf, diff, 0, NULL, NULL );
+            ScrollWindowEx32( wnd->hwndSelf, diff, 0, NULL, NULL, 0, NULL, 
+				SW_INVALIDATE | SW_ERASE );
         else
             scroll = FALSE;
     }
@@ -259,7 +260,8 @@
             diff = (descr->top_item - index) * descr->item_height;
 
         if (abs(diff) < descr->height)
-            ScrollWindow32( wnd->hwndSelf, 0, diff, NULL, NULL );
+            ScrollWindowEx32( wnd->hwndSelf, 0, diff, NULL, NULL, 0, NULL,
+					SW_INVALIDATE | SW_ERASE );
         else
             scroll = FALSE;
     }
@@ -1006,7 +1008,8 @@
     descr->horz_pos = pos;
     LISTBOX_UpdateScroll( wnd, descr );
     if (abs(diff) < descr->width)
-        ScrollWindow32( wnd->hwndSelf, diff, 0, NULL, NULL );
+        ScrollWindowEx32( wnd->hwndSelf, diff, 0, NULL, NULL, 0, NULL,
+			SW_INVALIDATE | SW_ERASE );
     else
         InvalidateRect32( wnd->hwndSelf, NULL, TRUE );
 }
@@ -2019,6 +2022,8 @@
 
     *(LB_DESCR **)wnd->wExtra = descr;
 
+/*    if (wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) descr->style &= ~LBS_NOTIFY;
+ */
     if (descr->style & LBS_EXTENDEDSEL) descr->style |= LBS_MULTIPLESEL;
     if (descr->style & LBS_MULTICOLUMN) descr->style &= ~LBS_OWNERDRAWVARIABLE;
     if (descr->style & LBS_OWNERDRAWVARIABLE) descr->style |= LBS_NOINTEGRALHEIGHT;
@@ -2066,7 +2071,8 @@
 /***********************************************************************
  *           ListBoxWndProc
  */
-LRESULT ListBoxWndProc(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI ListBoxWndProc( HWND32 hwnd, UINT32 msg,
+                               WPARAM32 wParam, LPARAM lParam )
 {
     LRESULT ret;
     LB_DESCR *descr;
@@ -2491,7 +2497,8 @@
  *  NOTE: in Windows, winproc address of the ComboLBox is the same 
  *	  as that of the Listbox.
  */
-LRESULT ComboLBWndProc(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI ComboLBWndProc( HWND32 hwnd, UINT32 msg,
+                               WPARAM32 wParam, LPARAM lParam )
 {
     LRESULT lRet = 0;
     WND *wnd = WIN_FindWndPtr( hwnd );
diff --git a/controls/menu.c b/controls/menu.c
index 769084b..5a1e28c 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -51,26 +51,24 @@
 #define MM_SETMENUHANDLE	(WM_USER + 0)
 #define MM_GETMENUHANDLE	(WM_USER + 1)
 
-typedef struct
-{
-  HBITMAP32	hCheckBit;
-  HBITMAP32	hUnCheckBit;
-} CBITMAPS, *PCBITMAPS;
-
 /* Menu item structure */
-typedef struct
-{
-    UINT32      item_flags;    /* Item flags */
-    UINT32      item_id;       /* Item or popup id */
+typedef struct {
+    /* ----------- MENUITEMINFO Stuff ----------- */
+    UINT32 fType;		/* Item type. */
+    UINT32 fState;		/* Item state.  */
+    UINT32 wID;			/* Item id.  */
+    HMENU32 hSubMenu;		/* Pop-up menu.  */
+    HBITMAP32 hCheckBit;	/* Bitmap when checked.  */
+    HBITMAP32 hUnCheckBit;	/* Bitmap when unchecked.  */
+    LPSTR text;			/* Item text or bitmap handle.  */
+    DWORD dwItemData;		/* Application defined.  */
+    /* ----------- Wine stuff ----------- */
     RECT32      rect;          /* Item area (relative to menu window) */
     UINT32      xTab;          /* X position of text after Tab */
-    PCBITMAPS	pCB;	       /* checkmark bitmaps */
-    LPSTR       text;          /* Item text or bitmap handle */
 } MENUITEM;
 
 /* Popup menu structure */
-typedef struct
-{
+typedef struct {
     WORD        wFlags;       /* Menu flags (MF_POPUP, MF_SYSMENU) */
     WORD        wMagic;       /* Magic number */
     HQUEUE16    hTaskQ;       /* Task queue for this menu */
@@ -98,6 +96,7 @@
 } MTRACKER;
 
 #define MENU_MAGIC   0x554d  /* 'MU' */
+#define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
 
 #define ITEM_PREV		-1
 #define ITEM_NEXT		 1
@@ -112,24 +111,33 @@
 #define POPUP_YSHADE		4
 
   /* Space between 2 menu bar items */
-int MENU_BAR_ITEMS_SPACE = 12;
+#define MENU_BAR_ITEMS_SPACE 12
 
   /* Minimum width of a tab character */
-int MENU_TAB_SPACE = 8;
+#define MENU_TAB_SPACE 8
 
   /* Height of a separator item */
-int SEPARATOR_HEIGHT = 5;
+#define SEPARATOR_HEIGHT 5
 
   /* (other menu->FocusedItem values give the position of the focused item) */
 #define NO_SELECTED_ITEM  0xffff
 
-#define IS_STRING_ITEM(flags) \
-    (!((flags) & (MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR)))
+#define MENU_ITEM_TYPE(flags) \
+  ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
+
+#define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
+
 #define IS_SYSTEM_MENU(menu)  \
 	(!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
 #define IS_SYSTEM_POPUP(menu) \
 	((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
 
+#define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
+		   MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
+		   MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
+		   MF_POPUP | MF_SYSMENU | MF_HELP)
+#define STATE_MASK (~TYPE_MASK)
+
   /* Dimension of the menu bitmaps */
 static WORD check_bitmap_width = 0, check_bitmap_height = 0;
 static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
@@ -150,6 +158,92 @@
 
 
 /***********************************************************************
+ *           debug_print_menuitem
+ *
+ * Print a menuitem in readable form.
+ */
+
+#define MENUOUT(text) \
+  dprintf_menu (stddeb, "%s%s", (count++ ? "," : ""), (text))
+
+#define MENUFLAG(bit,text) \
+  do { \
+    if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
+  } while (0)
+
+static void debug_print_menuitem(const char *prefix, MENUITEM * mp, const char *postfix)
+{
+    dprintf_menu(stddeb, "%s", prefix);
+    if (mp) {
+	UINT32 flags = mp->fType;
+	int typ = MENU_ITEM_TYPE(flags);
+	dprintf_menu(stddeb, "{ ID=0x%x", mp->wID);
+	if (flags & MF_POPUP)
+	    dprintf_menu(stddeb, ", Sub=0x%x", mp->hSubMenu);
+	if (flags) {
+	    int count = 0;
+	    dprintf_menu(stddeb, ", Typ=");
+	    if (typ == MFT_STRING)
+		/* Nothing */ ;
+	    else if (typ == MFT_SEPARATOR)
+		MENUOUT("sep");
+	    else if (typ == MFT_OWNERDRAW)
+		MENUOUT("own");
+	    else if (typ == MFT_BITMAP)
+		MENUOUT("bit");
+	    else
+		MENUOUT("???");
+	    flags -= typ;
+
+	    MENUFLAG(MF_POPUP, "pop");
+	    MENUFLAG(MFT_MENUBARBREAK, "barbrk");
+	    MENUFLAG(MFT_MENUBREAK, "brk");
+	    MENUFLAG(MFT_RADIOCHECK, "radio");
+	    MENUFLAG(MFT_RIGHTORDER, "rorder");
+	    MENUFLAG(MF_SYSMENU, "sys");
+	    MENUFLAG(MFT_RIGHTJUSTIFY, "right");
+
+	    if (flags)
+		dprintf_menu(stddeb, "+0x%x", flags);
+	}
+	flags = mp->fState;
+	if (flags) {
+	    int count = 0;
+	    dprintf_menu(stddeb, ", State=");
+	    MENUFLAG(MFS_GRAYED, "grey");
+	    MENUFLAG(MFS_DISABLED, "dis");
+	    MENUFLAG(MFS_CHECKED, "check");
+	    MENUFLAG(MFS_HILITE, "hi");
+	    MENUFLAG(MF_USECHECKBITMAPS, "usebit");
+	    MENUFLAG(MF_MOUSESELECT, "mouse");
+	    if (flags)
+		dprintf_menu(stddeb, "+0x%x", flags);
+	}
+	if (mp->hCheckBit)
+	    dprintf_menu(stddeb, ", Chk=0x%x", mp->hCheckBit);
+	if (mp->hUnCheckBit)
+	    dprintf_menu(stddeb, ", Unc=0x%x", mp->hUnCheckBit);
+
+	if (typ == MFT_STRING) {
+	    if (mp->text)
+		dprintf_menu(stddeb, ", Text=\"%s\"", mp->text);
+	    else
+		dprintf_menu(stddeb, ", Text=Null");
+	} else if (mp->text == NULL)
+	    /* Nothing */ ;
+	else
+	    dprintf_menu(stddeb, ", Text=%p", mp->text);
+	dprintf_menu(stddeb, " }");
+    } else {
+	dprintf_menu(stddeb, "NULL");
+    }
+    dprintf_menu(stddeb, "%s", postfix);
+}
+
+#undef MENUOUT
+#undef MENUFLAG
+
+/***********************************************************************
  *           MENU_CopySysPopup
  *
  * Return the default system menu.
@@ -167,7 +261,7 @@
 	fprintf( stderr, "Unable to load default system menu\n" );
     }
 
-    dprintf_menu( stddeb, "MENU_CopySysPopup: returning %d.\n", hMenu );
+    dprintf_menu( stddeb, "MENU_CopySysPopup: returning %x.\n", hMenu );
 
     return hMenu;
 }
@@ -200,7 +294,8 @@
 	{
 	    InsertMenu32A( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
 
-	    menu->items[0].item_flags = MF_SYSMENU | MF_POPUP;
+            menu->items[0].fType = MF_SYSMENU | MF_POPUP;
+            menu->items[0].fState = 0;
 	    menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hPopupMenu);
 	    menu->wFlags |= MF_SYSMENU;
 
@@ -260,7 +355,7 @@
  *
  * Grey the appropriate items in System menu.
  */
-void MENU_InitSysMenuPopup( HMENU32 hmenu, DWORD style, DWORD clsStyle )
+static void MENU_InitSysMenuPopup( HMENU32 hmenu, DWORD style, DWORD clsStyle )
 {
     BOOL32 gray;
 
@@ -299,7 +394,7 @@
 	return i;
 
     for( ; i < menu->nItems; ++i ) {
-	if( menu->items[i].item_flags & MF_MENUBARBREAK )
+	if (menu->items[i].fType & MF_MENUBARBREAK)
 	    return i;
     }
 
@@ -329,14 +424,14 @@
     /* Find the start of the column */
 
     for(i = menu->FocusedItem; i != 0 &&
-	    !(menu->items[i].item_flags & MF_MENUBARBREAK);
+	 !(menu->items[i].fType & MF_MENUBARBREAK);
 	--i); /* empty */
 
     if(i == 0)
 	return NO_SELECTED_ITEM;
 
     for(--i; i != 0; --i) {
-	if(menu->items[i].item_flags & MF_MENUBARBREAK)
+	if (menu->items[i].fType & MF_MENUBARBREAK)
 	    break;
     }
 
@@ -369,14 +464,14 @@
         MENUITEM *item = menu->items;
 	for (i = 0; i < menu->nItems; i++, item++)
 	{
-	    if (item->item_id == *nPos)
+	    if (item->wID == *nPos)
 	    {
 		*nPos = i;
 		return item;
 	    }
-	    else if (item->item_flags & MF_POPUP)
+	    else if (item->fType & MF_POPUP)
 	    {
-		HMENU32 hsubmenu = (HMENU32)item->item_id;
+		HMENU32 hsubmenu = item->hSubMenu;
 		MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
 		if (subitem)
 		{
@@ -395,13 +490,8 @@
 static void MENU_FreeItemData( MENUITEM* item )
 {
     /* delete text */
-
-    if (IS_STRING_ITEM(item->item_flags) && item->text)
+    if (IS_STRING_ITEM(item->fType) && item->text)
         HeapFree( SystemHeap, 0, item->text );
-
-    /* delete checkmark stuff */
-
-    if (item->pCB) HeapFree( SystemHeap, 0, item->pCB );
 }
 
 /***********************************************************************
@@ -465,7 +555,7 @@
 	     key = toupper(key);
 	     for (i = 0; i < menu->nItems; i++, item++)
 	     {
-		if (IS_STRING_ITEM(item->item_flags))
+		if (IS_STRING_ITEM(item->fType))
 		{
 		    char *p = strchr( item->text, '&' );
 		    if (p && (p[1] != '&') && (toupper(p[1]) == key)) return i;
@@ -492,29 +582,29 @@
     DWORD dwSize;
     char *p;
 
-    dprintf_menu( stddeb, "MENU_CalcItemSize: HDC %p, item '%s', at "
-		  "(%d, %d) %s\n", (void *)hdc, lpitem->text, orgX, orgY,
-		  menuBar ? "(MenuBar)" : "" );
+    dprintf_menu(stddeb, "MENU_CalcItemSize: HDC 0x%x at (%d,%d): ",
+                 hdc, orgX, orgY);
+    debug_print_menuitem("", lpitem, (menuBar ? " (MenuBar)\n" : "\n"));
 
     SetRect32( &lpitem->rect, orgX, orgY, orgX, orgY );
 
-    if (lpitem->item_flags & MF_OWNERDRAW)
+    if (lpitem->fType & MF_OWNERDRAW)
     {
         MEASUREITEMSTRUCT32 mis;
         mis.CtlType    = ODT_MENU;
-        mis.itemID     = lpitem->item_id;
+        mis.itemID     = lpitem->wID;
         mis.itemData   = (DWORD)lpitem->text;
         mis.itemHeight = 16;
         mis.itemWidth  = 30;
         SendMessage32A( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
         lpitem->rect.bottom += mis.itemHeight;
         lpitem->rect.right  += mis.itemWidth;
-        dprintf_menu( stddeb, "DrawMenuItem: MeasureItem %04x %dx%d!\n",
-                      lpitem->item_id, mis.itemWidth, mis.itemHeight );
+        dprintf_menu(stddeb, "MENU_CalcItemSize: %08x %dx%d\n",
+                     lpitem->wID, mis.itemWidth, mis.itemHeight);
         return;
     } 
 
-    if (lpitem->item_flags & MF_SEPARATOR)
+    if (lpitem->fType & MF_SEPARATOR)
     {
 	lpitem->rect.bottom += SEPARATOR_HEIGHT;
 	return;
@@ -523,11 +613,11 @@
     if (!menuBar)
     {
 	lpitem->rect.right += 2 * check_bitmap_width;
-	if (lpitem->item_flags & MF_POPUP)
+	if (lpitem->fType & MF_POPUP)
 	    lpitem->rect.right += arrow_bitmap_width;
     }
 
-    if (lpitem->item_flags & MF_BITMAP)
+    if (lpitem->fType & MF_BITMAP)
     {
 	BITMAP32 bm;
         if (GetObject32A( (HBITMAP32)lpitem->text, sizeof(bm), &bm ))
@@ -540,7 +630,7 @@
     
     /* If we get here, then it must be a text item */
 
-    if (IS_STRING_ITEM( lpitem->item_flags ))
+    if (IS_STRING_ITEM( lpitem->fType ))
     {
         dwSize = GetTextExtent( hdc, lpitem->text, strlen(lpitem->text) );
         lpitem->rect.right  += LOWORD(dwSize);
@@ -595,19 +685,16 @@
 	for (i = start; i < lppop->nItems; i++, lpitem++)
 	{
 	    if ((i != start) &&
-		(lpitem->item_flags & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
+		(lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
 
-	    dprintf_menu( stddeb, "MENU_PopupMenuCalcSize: calling "
-			  "MENU_CalcItemSize on '%s', org=(%d, %d)\n",
-			  lpitem->text, orgX, orgY );
 	    if(TWEAK_Win95Look)
 		++orgY;
 
 	    MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
-            if (lpitem->item_flags & MF_MENUBARBREAK) orgX++;
+            if (lpitem->fType & MF_MENUBARBREAK) orgX++;
 	    maxX = MAX( maxX, lpitem->rect.right );
 	    orgY = lpitem->rect.bottom;
-	    if (IS_STRING_ITEM(lpitem->item_flags) && lpitem->xTab)
+	    if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
 	    {
 		maxTab = MAX( maxTab, lpitem->xTab );
 		maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
@@ -619,7 +706,7 @@
 	for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
 	{
 	    lpitem->rect.right = maxX;
-	    if (IS_STRING_ITEM(lpitem->item_flags) && lpitem->xTab)
+	    if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
                 lpitem->xTab = maxTab;
 	}
 	lppop->Height = MAX( lppop->Height, orgY );
@@ -663,9 +750,9 @@
 	  /* Parse items until line break or end of menu */
 	for (i = start; i < lppop->nItems; i++, lpitem++)
 	{
-	    if ((helpPos == -1) && (lpitem->item_flags & MF_HELP)) helpPos = i;
+	    if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
 	    if ((i != start) &&
-		(lpitem->item_flags & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
+		(lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
 
 
 	    dprintf_menu( stddeb, "MENU_MenuBarCalcSize: calling "
@@ -716,34 +803,36 @@
 {
     RECT32 rect;
 
-    if (lpitem->item_flags & MF_SYSMENU)
+    debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "\n");
+
+    if (lpitem->fType & MF_SYSMENU)
     {
 	if( !IsIconic32(hwnd) ) {
 	    if(TWEAK_Win95Look)
 		NC_DrawSysButton95( hwnd, hdc,
-				    lpitem->item_flags &
+				    lpitem->fState &
 				    (MF_HILITE | MF_MOUSESELECT) );
 	    else
 		NC_DrawSysButton( hwnd, hdc, 
-				  lpitem->item_flags &
+				  lpitem->fState &
 				  (MF_HILITE | MF_MOUSESELECT) );
 	}
 
 	return;
     }
 
-    if (lpitem->item_flags & MF_OWNERDRAW)
+    if (lpitem->fType & MF_OWNERDRAW)
     {
         DRAWITEMSTRUCT32 dis;
 
         dprintf_menu( stddeb, "DrawMenuItem: Ownerdraw!\n" );
         dis.CtlType   = ODT_MENU;
-        dis.itemID    = lpitem->item_id;
+        dis.itemID    = lpitem->wID;
         dis.itemData  = (DWORD)lpitem->text;
         dis.itemState = 0;
-        if (lpitem->item_flags & MF_CHECKED) dis.itemState |= ODS_CHECKED;
-        if (lpitem->item_flags & MF_GRAYED)  dis.itemState |= ODS_GRAYED;
-        if (lpitem->item_flags & MF_HILITE)  dis.itemState |= ODS_SELECTED;
+        if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
+        if (lpitem->fState & MF_GRAYED)  dis.itemState |= ODS_GRAYED;
+        if (lpitem->fState & MF_HILITE)  dis.itemState |= ODS_SELECTED;
         dis.itemAction = ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS;
         dis.hwndItem   = hwnd;
         dis.hDC        = hdc;
@@ -752,7 +841,7 @@
         return;
     }
 
-    if (menuBar && (lpitem->item_flags & MF_SEPARATOR)) return;
+    if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
     rect = lpitem->rect;
 
     /* Draw the background */
@@ -770,7 +859,7 @@
 	*/
     }
 
-    if (lpitem->item_flags & MF_HILITE) {
+    if (lpitem->fState & MF_HILITE) {
 	RECT32  r = rect;
 	r.top += MENU_HighlightTopNudge;
 	r.bottom += MENU_HighlightBottomNudge;
@@ -791,7 +880,7 @@
 
       /* Draw the separator bar (if any) */
 
-    if (!menuBar && (lpitem->item_flags & MF_MENUBARBREAK))
+    if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
     {
 	if(TWEAK_Win95Look)
 	    TWEAK_DrawMenuSeparatorVert95(hdc, rect.left - 1, 3, height - 3);
@@ -801,7 +890,7 @@
 	    LineTo32( hdc, rect.left, height );
 	}
     }
-    if (lpitem->item_flags & MF_SEPARATOR)
+    if (lpitem->fType & MF_SEPARATOR)
     {
 	if(TWEAK_Win95Look)
 	    TWEAK_DrawMenuSeparatorHoriz95(hdc, rect.left + 1,
@@ -818,9 +907,9 @@
 
       /* Setup colors */
 
-    if (lpitem->item_flags & MF_HILITE)
+    if (lpitem->fState & MF_HILITE)
     {
-	if (lpitem->item_flags & MF_GRAYED)
+	if (lpitem->fState & MF_GRAYED)
 	    SetTextColor32( hdc, GetSysColor32( COLOR_GRAYTEXT ) );
 	else
 	    SetTextColor32( hdc, GetSysColor32( COLOR_HIGHLIGHTTEXT ) );
@@ -828,7 +917,7 @@
     }
     else
     {
-	if (lpitem->item_flags & MF_GRAYED)
+	if (lpitem->fState & MF_GRAYED)
 	    SetTextColor32( hdc, GetSysColor32( COLOR_GRAYTEXT ) );
 	else
 	    SetTextColor32( hdc, GetSysColor32( COLOR_MENUTEXT ) );
@@ -846,18 +935,18 @@
 	   * is 1 for a white pixel and 0 for a black one. 
 	   */
 
-	if (lpitem->item_flags & MF_CHECKED)
-            GRAPH_DrawBitmap( hdc, lpitem->pCB ? lpitem->pCB->hCheckBit
+	if (lpitem->fState & MF_CHECKED)
+            GRAPH_DrawBitmap( hdc, lpitem->hCheckBit ? lpitem->hCheckBit
 			      : hStdCheck, rect.left, (y - check_bitmap_height) / 2, 
 			      0, 0, check_bitmap_width, check_bitmap_height, TRUE );
-	else if (lpitem->pCB)
-	    GRAPH_DrawBitmap( hdc, lpitem->pCB->hUnCheckBit, rect.left, 
+        else if (lpitem->hUnCheckBit)
+            GRAPH_DrawBitmap( hdc, lpitem->hUnCheckBit, rect.left,
 			      (y - check_bitmap_height) / 2, 0, 0,
 			      check_bitmap_width, check_bitmap_height, TRUE );
 
 	  /* Draw the popup-menu arrow */
 
-	if (lpitem->item_flags & MF_POPUP)
+	if (lpitem->fType & MF_POPUP)
 	{
 	    GRAPH_DrawBitmap( hdc, hStdMnArrow,
 			      rect.right-arrow_bitmap_width-1,
@@ -871,7 +960,7 @@
 
       /* Draw the item text or bitmap */
 
-    if (lpitem->item_flags & MF_BITMAP)
+    if (lpitem->fType & MF_BITMAP)
     {
 	GRAPH_DrawBitmap( hdc, (HBITMAP32)lpitem->text,
                           rect.left, rect.top, 0, 0,
@@ -879,7 +968,7 @@
 	return;
     }
     /* No bitmap - process text if present */
-    else if (IS_STRING_ITEM(lpitem->item_flags))
+    else if (IS_STRING_ITEM(lpitem->fType))
     {
 	register int i;
 
@@ -902,12 +991,13 @@
 	    rect.left += MENU_ItemLeftNudge;
 	}
 
-	if(!TWEAK_Win95Look || !(lpitem->item_flags & MF_GRAYED)) {
+	if(!TWEAK_Win95Look || !(lpitem->fState & MF_GRAYED)) {
 	    DrawText32A( hdc, lpitem->text, i, &rect,
 			 DT_LEFT | DT_VCENTER | DT_SINGLELINE );
 	}
 	else {
-	    if (!(lpitem->item_flags & MF_HILITE)) {
+	    if (!(lpitem->fState & MF_HILITE))
+            {
 		++rect.left;
 		++rect.top;
 		++rect.right;
@@ -1119,7 +1209,7 @@
     if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
     if (menu->FocusedItem != NO_SELECTED_ITEM)
     {
-	menu->items[menu->FocusedItem].item_flags &= ~(MF_HILITE|MF_MOUSESELECT);
+	menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
 	menu->FocusedItem = NO_SELECTED_ITEM;
     }
 
@@ -1220,7 +1310,7 @@
     if (!lppop->nItems) return;
 
     if ((wIndex != NO_SELECTED_ITEM) && 
-	(lppop->items[wIndex].item_flags & MF_SEPARATOR))
+	(lppop->items[wIndex].fType & MF_SEPARATOR))
 	wIndex = NO_SELECTED_ITEM;
 
     if (lppop->FocusedItem == wIndex) return;
@@ -1230,7 +1320,7 @@
       /* Clear previous highlighted item */
     if (lppop->FocusedItem != NO_SELECTED_ITEM) 
     {
-	lppop->items[lppop->FocusedItem].item_flags &=~(MF_HILITE|MF_MOUSESELECT);
+	lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
 	MENU_DrawMenuItem(lppop->hWnd,hdc,&lppop->items[lppop->FocusedItem],
                           lppop->Height, !(lppop->wFlags & MF_POPUP) );
     }
@@ -1239,13 +1329,16 @@
     lppop->FocusedItem = wIndex;
     if (lppop->FocusedItem != NO_SELECTED_ITEM) 
     {
-	lppop->items[lppop->FocusedItem].item_flags |= MF_HILITE;
+	lppop->items[lppop->FocusedItem].fState |= MF_HILITE;
 	MENU_DrawMenuItem( lppop->hWnd, hdc, &lppop->items[lppop->FocusedItem],
                            lppop->Height, !(lppop->wFlags & MF_POPUP) );
         if (sendMenuSelect)
-	    SendMessage16( hwndOwner, WM_MENUSELECT,
-                           lppop->items[lppop->FocusedItem].item_id,
-                           MAKELONG( lppop->items[lppop->FocusedItem].item_flags | MF_MOUSESELECT, hmenu));
+        {
+            MENUITEM *ip = &lppop->items[lppop->FocusedItem];
+	    SendMessage16( hwndOwner, WM_MENUSELECT, ip->wID,
+                           MAKELONG(ip->fType | (ip->fState | MF_MOUSESELECT),
+                                    hmenu) );
+        }
     }
     else if (sendMenuSelect)
         SendMessage16( hwndOwner, WM_MENUSELECT, hmenu,
@@ -1275,7 +1368,7 @@
 	if( menu->nItems == 1 ) return; else
 	for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems 
 					    ; i += offset)
-	    if (!(menu->items[i].item_flags & MF_SEPARATOR))
+	    if (!(menu->items[i].fType & MF_SEPARATOR))
 	    {
 		MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
 		return;
@@ -1284,7 +1377,7 @@
 
     for ( i = (offset > 0) ? 0 : menu->nItems - 1; 
 		  i >= 0 && i < menu->nItems ; i += offset)
-	if (!(menu->items[i].item_flags & MF_SEPARATOR))
+	if (!(menu->items[i].fType & MF_SEPARATOR))
 	{
 	    MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
 	    return;
@@ -1301,11 +1394,9 @@
 static BOOL32 MENU_SetItemData( MENUITEM *item, UINT32 flags, UINT32 id,
                                 LPCSTR str )
 {
-    LPSTR prevText = IS_STRING_ITEM(item->item_flags) ? item->text : NULL;
+    LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
 
-    dprintf_menu(stddeb,"SetItemData: %04x [%08x] '%s'  -> %04x [%08x] '%s'\n",
-		 item->item_flags, item->item_id, prevText ? prevText : "",
-		 flags, id, (IS_STRING_ITEM(flags) && str) ? str : "" );
+    debug_print_menuitem("MENU_SetItemData from: ", item, "\n");
 
     if (IS_STRING_ITEM(flags))
     {
@@ -1331,22 +1422,32 @@
     else if (flags & MF_OWNERDRAW) item->text = (LPSTR)str;
     else item->text = NULL;
 
-    if (item->item_flags & MF_POPUP && item->item_id != id )
-	DestroyMenu32( (HMENU32)item->item_id );   /* ModifyMenu() spec */
+    if (item->fType & MF_POPUP && item->hSubMenu != id )
+	DestroyMenu32( item->hSubMenu );   /* ModifyMenu() spec */
 
     if (flags & MF_POPUP)
     {
-	POPUPMENU*	menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
-	if( menu && menu->wMagic == MENU_MAGIC) menu->wFlags |= MF_POPUP;
+	POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
+        if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
 	else
-	    return (item->item_id = item->item_flags = FALSE);
+        {
+            item->wID = 0;
+            item->hSubMenu = 0;
+            item->fType = 0;
+            item->fState = 0;
+	    return FALSE;
+        }
     }
 
-    item->item_flags = flags & ~(MF_HILITE | MF_MOUSESELECT);
-    item->item_id    = id;
+    item->fType = flags & TYPE_MASK;
+    item->fState = (flags & STATE_MASK) &
+        ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
+    item->wID = item->hSubMenu = id;
 
     SetRectEmpty32( &item->rect );
     if (prevText) HeapFree( SystemHeap, 0, prevText );
+
+    debug_print_menuitem("MENU_SetItemData to  : ", item, "\n");
     return TRUE;
 }
 
@@ -1470,55 +1571,50 @@
  */
 static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU32 hMenu)
 {
-    DWORD flags;
-    DWORD state;
-    DWORD id;
-    LPCWSTR str;
     WORD resinfo;
+    do {
+	MENUITEMINFO32W mii;
 
-    do
-    {
-        /* printf ("%p:", res); */
-
-        flags = GET_DWORD(res);
+	mii.cbSize = sizeof(mii);
+	mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
+	mii.fType = GET_DWORD(res);
         res += sizeof(DWORD);
-        state = GET_DWORD(res);
+	mii.fState = GET_DWORD(res);
         res += sizeof(DWORD);
-        id = GET_DWORD(res);
+	mii.wID = GET_DWORD(res);
         res += sizeof(DWORD);
 	resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte.  */
         res += sizeof(WORD);
 	/* Align the text on a word boundary.  */
 	res += (~((int)res - 1)) & 1;
-        str = (LPCWSTR)res;
-        res += (1 + lstrlen32W (str)) * sizeof(WCHAR);
+	mii.dwTypeData = (LPWSTR) res;
+	res += (1 + lstrlen32W(mii.dwTypeData)) * sizeof(WCHAR);
 	/* Align the following fields on a dword boundary.  */
 	res += (~((int)res - 1)) & 3;
 
         /* FIXME: This is inefficient and cannot be optimised away by gcc.  */
 	{
-	  LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
-	  dprintf_menu (stddeb, "Menu item: [%08lx,%08lx,%04lx,%04x,%s]\n",
-			flags, state, id, resinfo, newstr);
+	    LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
+					   0, mii.dwTypeData);
+	    dprintf_menu(stddeb, "Menu item: [%08x,%08x,%04x,%04x,%s]\n",
+			 mii.fType, mii.fState, mii.wID, resinfo, newstr);
 	  HeapFree( GetProcessHeap(), 0, newstr );
 	}
 
-        if (resinfo & 1) /* Pop-up? */
-        {
+	if (resinfo & 1) {	/* Pop-up? */
 	    DWORD helpid = GET_DWORD(res); /* FIXME: use this.  */
-            HMENU32 hSubMenu = CreatePopupMenu32();
 	    res += sizeof(DWORD);
-            if (!hSubMenu) return NULL;
-            if (!(res = MENUEX_ParseResource( res, hSubMenu)))
+	    mii.hSubMenu = CreatePopupMenu32();
+	    if (!mii.hSubMenu)
+		return NULL;
+	    if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
+		DestroyMenu32(mii.hSubMenu);
                 return NULL;
-            AppendMenu32W( hMenu, flags | MF_POPUP /* HACK!  FIXME */,
-			   (UINT32)hSubMenu, (LPCWSTR)str );
         }
-        else  /* Not a popup */
-        {
-	  AppendMenu32W( hMenu, flags, id,
-			 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
+	    mii.fMask |= MIIM_SUBMENU;
+	    mii.fType |= MF_POPUP;
         }
+	InsertMenuItem32W(hMenu, -1, MF_BYPOSITION, &mii);
     } while (!(resinfo & MF_END));
     return res;
 }
@@ -1539,9 +1635,8 @@
     if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
 
     item = &menu->items[menu->FocusedItem];
-    if ((item->item_flags & (MF_POPUP | MF_MOUSESELECT))
-			 == (MF_POPUP | MF_MOUSESELECT))
-	return (HMENU32)item->item_id;
+    if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
+        return item->hSubMenu;
     return 0;
 }
 
@@ -1565,10 +1660,10 @@
 	if (menu->FocusedItem != NO_SELECTED_ITEM)
 	{
 	    item = &menu->items[menu->FocusedItem];
-	    if (!(item->item_flags & MF_POPUP) ||
-		!(item->item_flags & MF_MOUSESELECT)) return;
-	    item->item_flags &= ~MF_MOUSESELECT;
-	    hsubmenu = (HMENU32)item->item_id;
+	    if (!(item->fType & MF_POPUP) ||
+		!(item->fState & MF_MOUSESELECT)) return;
+	    item->fState &= ~MF_MOUSESELECT;
+	    hsubmenu = item->hSubMenu;
 	} else return;
 
 	submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
@@ -1609,17 +1704,18 @@
          (menu->FocusedItem == NO_SELECTED_ITEM)) return hmenu;
 
     item = &menu->items[menu->FocusedItem];
-    if (!(item->item_flags & MF_POPUP) ||
-         (item->item_flags & (MF_GRAYED | MF_DISABLED))) return hmenu;
-    item->item_flags |= MF_MOUSESELECT;
+    if (!(item->fType & MF_POPUP) ||
+         (item->fState & (MF_GRAYED | MF_DISABLED))) return hmenu;
+    item->fState |= MF_MOUSESELECT;
 
     if (IS_SYSTEM_MENU(menu))
     {
-	MENU_InitSysMenuPopup((HMENU16)item->item_id, wndPtr->dwStyle, wndPtr->class->style);
+	MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, wndPtr->class->style);
 
 	NC_GetSysPopupPos( wndPtr, &rect );
 	rect.top = rect.bottom;
-	rect.right = SYSMETRICS_CXSIZE; rect.bottom = SYSMETRICS_CYSIZE;
+	rect.right = SYSMETRICS_CXSIZE;
+        rect.bottom = SYSMETRICS_CYSIZE;
     }
     else
     {
@@ -1639,11 +1735,11 @@
 	}
     }
 
-    MENU_ShowPopup( hwndOwner, (HMENU16)item->item_id, menu->FocusedItem,
+    MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
 		    rect.left, rect.top, rect.right, rect.bottom );
     if (selectFirst)
-        MENU_MoveSelection( hwndOwner, (HMENU32)item->item_id, ITEM_NEXT );
-    return (HMENU32)item->item_id;
+        MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
+    return item->hSubMenu;
 }
 
 /***********************************************************************
@@ -1656,12 +1752,11 @@
    POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
    register UINT32 ht = menu->FocusedItem;
 
-#define HAS_POPUP(item)	(((item).item_flags & (MF_POPUP | MF_MOUSESELECT)) \
-			== (MF_POPUP | MF_MOUSESELECT))
    /* try subpopup first (if any) */
-   ht = (ht != NO_SELECTED_ITEM && HAS_POPUP(menu->items[ht]))
-	? (UINT32)MENU_PtMenu( menu->items[ht].item_id, pt ) : 0;
-#undef HAS_POPUP
+    ht = (ht != NO_SELECTED_ITEM &&
+          (menu->items[ht].fType & MF_POPUP) &&
+          (menu->items[ht].fState & MF_MOUSESELECT))
+        ? (UINT32) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
 
    if( !ht )	/* check the current window (avoiding WM_HITTEST) */
    {
@@ -1694,18 +1789,21 @@
 	(menu->FocusedItem == NO_SELECTED_ITEM)) return TRUE;
 
     item = &menu->items[menu->FocusedItem];
-    if (!(item->item_flags & MF_POPUP))
+
+    dprintf_menu(stddeb, "MENU_ExecFocusedItem: %08x %08x %08x\n",
+                 hMenu, item->wID, item->hSubMenu);
+
+    if (!(item->fType & MF_POPUP))
     {
-	if (!(item->item_flags & (MF_GRAYED | MF_DISABLED)))
+	if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
 	{
 	    if( menu->wFlags & MF_SYSMENU )
 	    {
-		PostMessage16( pmt->hOwnerWnd, WM_SYSCOMMAND, item->item_id,
+		PostMessage16( pmt->hOwnerWnd, WM_SYSCOMMAND, item->hSubMenu,
 			       MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
 	    }
 	    else
-		PostMessage16( pmt->hOwnerWnd, WM_COMMAND,
-					item->item_id, 0 );
+		PostMessage16( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
 	    return FALSE;
 	}
 	else return TRUE;
@@ -1765,9 +1863,9 @@
 	    if( ptmenu->FocusedItem == id )
 	    {
 		/* nothing to do with already selected non-popup */
-		if( !(item->item_flags & MF_POPUP) ) return TRUE;
+		if( !(item->fType & MF_POPUP) ) return TRUE;
 
-	        if( item->item_flags & MF_MOUSESELECT )
+	        if( item->fState & MF_MOUSESELECT )
 		{
 		    if( ptmenu->wFlags & MF_POPUP )
 		    {
@@ -1812,9 +1910,9 @@
 
 	if( ptmenu->FocusedItem == id )
 	{
-	    if( !(item->item_flags & MF_POPUP) )
+	    if( !(item->fType & MF_POPUP) )
 		return MENU_ExecFocusedItem( pmt, hPtMenu );
-	    hPtMenu = (HMENU32)item->item_id;
+	    hPtMenu = item->hSubMenu;
 	    if( hPtMenu == pmt->hCurrentMenu )
 	    {
 	        /* Select first item of sub-popup */    
@@ -2390,8 +2488,8 @@
 /**********************************************************************
  *           TrackPopupMenu16   (USER.416)
  */
-BOOL16 TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
-                         INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
+BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
+                           INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
 {
     RECT32 r;
     if (lpRect)
@@ -2404,8 +2502,8 @@
 /**********************************************************************
  *           TrackPopupMenu32   (USER32.548)
  */
-BOOL32 TrackPopupMenu32( HMENU32 hMenu, UINT32 wFlags, INT32 x, INT32 y,
-                         INT32 nReserved, HWND32 hWnd, const RECT32 *lpRect )
+BOOL32 WINAPI TrackPopupMenu32( HMENU32 hMenu, UINT32 wFlags, INT32 x, INT32 y,
+                           INT32 nReserved, HWND32 hWnd, const RECT32 *lpRect )
 {
     BOOL32 ret = FALSE;
 
@@ -2419,8 +2517,8 @@
 /**********************************************************************
  *           TrackPopupMenuEx   (USER32.549)
  */
-BOOL32 TrackPopupMenuEx( HMENU32 hMenu, UINT32 wFlags, INT32 x, INT32 y,
-			 HWND32 hWnd, LPTPMPARAMS lpTpm )
+BOOL32 WINAPI TrackPopupMenuEx( HMENU32 hMenu, UINT32 wFlags, INT32 x, INT32 y,
+                                HWND32 hWnd, LPTPMPARAMS lpTpm )
 {
     fprintf( stderr, "TrackPopupMenuEx: not fully implemented\n" );
     return TrackPopupMenu32( hMenu, wFlags, x, y, 0, hWnd,
@@ -2432,8 +2530,8 @@
  *
  * NOTE: Windows has totally different (and undocumented) popup wndproc.
  */
-LRESULT PopupMenuWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
-                          LPARAM lParam )
+LRESULT WINAPI PopupMenuWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                                 LPARAM lParam )
 {    
     WND* wndPtr = WIN_FindWndPtr(hwnd);
 
@@ -2517,7 +2615,7 @@
     WND *wndPtr;
     LPPOPUPMENU lppop;
 
-    dprintf_menu( stddeb, "MENU_GetMenuBarHeight: HWND 0x%lx, width %d, "
+    dprintf_menu( stddeb, "MENU_GetMenuBarHeight: HWND 0x%x, width %d, "
 		  "at (%d, %d).\n", hwnd, menubarWidth, orgX, orgY );
     
     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
@@ -2534,8 +2632,8 @@
 /*******************************************************************
  *         ChangeMenu16    (USER.153)
  */
-BOOL16 ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
-                     UINT16 id, UINT16 flags )
+BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
+                            UINT16 id, UINT16 flags )
 {
     dprintf_menu( stddeb,"ChangeMenu16: menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
                   hMenu, pos, (DWORD)data, id, flags );
@@ -2560,8 +2658,8 @@
 /*******************************************************************
  *         ChangeMenu32A    (USER32.22)
  */
-BOOL32 ChangeMenu32A( HMENU32 hMenu, UINT32 pos, LPCSTR data,
-                      UINT32 id, UINT32 flags )
+BOOL32 WINAPI ChangeMenu32A( HMENU32 hMenu, UINT32 pos, LPCSTR data,
+                             UINT32 id, UINT32 flags )
 {
     dprintf_menu( stddeb,"ChangeMenu32A: menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
                   hMenu, pos, (DWORD)data, id, flags );
@@ -2581,8 +2679,8 @@
 /*******************************************************************
  *         ChangeMenu32W    (USER32.23)
  */
-BOOL32 ChangeMenu32W( HMENU32 hMenu, UINT32 pos, LPCWSTR data,
-                      UINT32 id, UINT32 flags )
+BOOL32 WINAPI ChangeMenu32W( HMENU32 hMenu, UINT32 pos, LPCWSTR data,
+                             UINT32 id, UINT32 flags )
 {
     dprintf_menu( stddeb,"ChangeMenu32W: menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
                   hMenu, pos, (DWORD)data, id, flags );
@@ -2602,7 +2700,7 @@
 /*******************************************************************
  *         CheckMenuItem16    (USER.154)
  */
-BOOL16 CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
+BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
 {
     return (BOOL16)CheckMenuItem32( hMenu, id, flags );
 }
@@ -2611,16 +2709,16 @@
 /*******************************************************************
  *         CheckMenuItem32    (USER32.45)
  */
-DWORD CheckMenuItem32( HMENU32 hMenu, UINT32 id, UINT32 flags )
+DWORD WINAPI CheckMenuItem32( HMENU32 hMenu, UINT32 id, UINT32 flags )
 {
     MENUITEM *item;
     DWORD ret;
 
     dprintf_menu( stddeb,"CheckMenuItem: %04x %04x %04x\n", hMenu, id, flags );
     if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
-    ret = item->item_flags & MF_CHECKED;
-    if (flags & MF_CHECKED) item->item_flags |= MF_CHECKED;
-    else item->item_flags &= ~MF_CHECKED;
+    ret = item->fState & MF_CHECKED;
+    if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
+    else item->fState &= ~MF_CHECKED;
     return ret;
 }
 
@@ -2628,7 +2726,7 @@
 /**********************************************************************
  *         EnableMenuItem16    (USER.155)
  */
-BOOL16 EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
+BOOL16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
 {
     return EnableMenuItem32( hMenu, wItemID, wFlags );
 }
@@ -2637,7 +2735,7 @@
 /**********************************************************************
  *         EnableMenuItem32    (USER32.169)
  */
-BOOL32 EnableMenuItem32( HMENU32 hMenu, UINT32 wItemID, UINT32 wFlags )
+BOOL32 WINAPI EnableMenuItem32( HMENU32 hMenu, UINT32 wItemID, UINT32 wFlags )
 {
     BOOL32    bRet = FALSE;
     MENUITEM *item, *first = NULL;
@@ -2647,20 +2745,20 @@
 
     while( (item = MENU_FindItem( &hMenu, &wItemID, wFlags )) )
     {
-      if( !(item->item_flags & MF_POPUP) )
+      if( !(item->fType & MF_POPUP) )
       {
            /* We can't have MF_GRAYED and MF_DISABLED together */
            if (wFlags & MF_GRAYED)
            {
-  	     item->item_flags = (item->item_flags & ~MF_DISABLED) | MF_GRAYED;
+  	     item->fState = (item->fState & ~MF_DISABLED) | MF_GRAYED;
            }
            else if (wFlags & MF_DISABLED)
            {
-	     item->item_flags = (item->item_flags & ~MF_GRAYED) | MF_DISABLED;
+	     item->fState = (item->fState & ~MF_GRAYED) | MF_DISABLED;
            }
            else   /* MF_ENABLED */
            {
-	     item->item_flags &= ~(MF_GRAYED | MF_DISABLED);
+	     item->fState &= ~(MF_GRAYED | MF_DISABLED);
            } 
 	   bRet = TRUE;
 	   break;
@@ -2675,8 +2773,8 @@
 /*******************************************************************
  *         GetMenuString16    (USER.161)
  */
-INT16 GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
-                       LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
+INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
+                              LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
 {
     return GetMenuString32A( hMenu, wItemID, str, nMaxSiz, wFlags );
 }
@@ -2685,8 +2783,8 @@
 /*******************************************************************
  *         GetMenuString32A    (USER32.267)
  */
-INT32 GetMenuString32A( HMENU32 hMenu, UINT32 wItemID,
-                        LPSTR str, INT32 nMaxSiz, UINT32 wFlags )
+INT32 WINAPI GetMenuString32A( HMENU32 hMenu, UINT32 wItemID,
+                               LPSTR str, INT32 nMaxSiz, UINT32 wFlags )
 {
     MENUITEM *item;
 
@@ -2695,7 +2793,7 @@
     if (!str || !nMaxSiz) return 0;
     str[0] = '\0';
     if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
-    if (!IS_STRING_ITEM(item->item_flags)) return 0;
+    if (!IS_STRING_ITEM(item->fType)) return 0;
     lstrcpyn32A( str, item->text, nMaxSiz );
     dprintf_menu( stddeb, "GetMenuString32A: returning '%s'\n", str );
     return strlen(str);
@@ -2705,8 +2803,8 @@
 /*******************************************************************
  *         GetMenuString32W    (USER32.268)
  */
-INT32 GetMenuString32W( HMENU32 hMenu, UINT32 wItemID,
-                        LPWSTR str, INT32 nMaxSiz, UINT32 wFlags )
+INT32 WINAPI GetMenuString32W( HMENU32 hMenu, UINT32 wItemID,
+                               LPWSTR str, INT32 nMaxSiz, UINT32 wFlags )
 {
     MENUITEM *item;
 
@@ -2715,7 +2813,7 @@
     if (!str || !nMaxSiz) return 0;
     str[0] = '\0';
     if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
-    if (!IS_STRING_ITEM(item->item_flags)) return 0;
+    if (!IS_STRING_ITEM(item->fType)) return 0;
     lstrcpynAtoW( str, item->text, nMaxSiz );
     return lstrlen32W(str);
 }
@@ -2724,8 +2822,8 @@
 /**********************************************************************
  *         HiliteMenuItem16    (USER.162)
  */
-BOOL16 HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
-                         UINT16 wHilite )
+BOOL16 WINAPI HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
+                                UINT16 wHilite )
 {
     return HiliteMenuItem32( hWnd, hMenu, wItemID, wHilite );
 }
@@ -2734,8 +2832,8 @@
 /**********************************************************************
  *         HiliteMenuItem32    (USER32.317)
  */
-BOOL32 HiliteMenuItem32( HWND32 hWnd, HMENU32 hMenu, UINT32 wItemID,
-                         UINT32 wHilite )
+BOOL32 WINAPI HiliteMenuItem32( HWND32 hWnd, HMENU32 hMenu, UINT32 wItemID,
+                                UINT32 wHilite )
 {
     LPPOPUPMENU menu;
     dprintf_menu(stddeb,"HiliteMenuItem(%04x, %04x, %04x, %04x);\n", 
@@ -2752,7 +2850,7 @@
 /**********************************************************************
  *         GetMenuState16    (USER.250)
  */
-UINT16 GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
+UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
 {
     return GetMenuState32( hMenu, wItemID, wFlags );
 }
@@ -2761,31 +2859,32 @@
 /**********************************************************************
  *         GetMenuState32    (USER32.266)
  */
-UINT32 GetMenuState32( HMENU32 hMenu, UINT32 wItemID, UINT32 wFlags )
+UINT32 WINAPI GetMenuState32( HMENU32 hMenu, UINT32 wItemID, UINT32 wFlags )
 {
     MENUITEM *item;
     dprintf_menu(stddeb,"GetMenuState(%04x, %04x, %04x);\n", 
 		 hMenu, wItemID, wFlags);
     if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
-    if (item->item_flags & MF_POPUP)
+    if (item->fType & MF_POPUP)
     {
-	POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( (HMENU16)item->item_id );
+	POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( item->hSubMenu );
 	if (!menu) return -1;
 	else return (menu->nItems << 8) | (menu->wFlags & 0xff);
     }
     else
-      /* Non POPUP Menus only return flags in the lower byte */
-      return (item->item_flags & 0x00ff);
+        /* Non POPUP Menus only return flags in the lower byte */
+        /* XXX ??? */
+	return ((item->fType | item->fState) & 0x00ff);
 }
 
 
 /**********************************************************************
  *         GetMenuItemCount16    (USER.263)
  */
-INT16 GetMenuItemCount16( HMENU16 hMenu )
+INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
 {
     LPPOPUPMENU	menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
-    if (!menu || (menu->wMagic != MENU_MAGIC)) return -1;
+    if (!IS_A_MENU(menu)) return -1;
     dprintf_menu( stddeb,"GetMenuItemCount16(%04x) returning %d\n", 
                   hMenu, menu->nItems );
     return menu->nItems;
@@ -2795,10 +2894,10 @@
 /**********************************************************************
  *         GetMenuItemCount32    (USER32.261)
  */
-INT32 GetMenuItemCount32( HMENU32 hMenu )
+INT32 WINAPI GetMenuItemCount32( HMENU32 hMenu )
 {
     LPPOPUPMENU	menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
-    if (!menu || (menu->wMagic != MENU_MAGIC)) return -1;
+    if (!IS_A_MENU(menu)) return -1;
     dprintf_menu( stddeb,"GetMenuItemCount32(%04x) returning %d\n", 
                   hMenu, menu->nItems );
     return menu->nItems;
@@ -2808,36 +2907,37 @@
 /**********************************************************************
  *         GetMenuItemID16    (USER.264)
  */
-UINT16 GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
+UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
 {
     LPPOPUPMENU	menu;
 
     if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return -1;
     if ((nPos < 0) || ((UINT16) nPos >= menu->nItems)) return -1;
-    if (menu->items[nPos].item_flags & MF_POPUP) return -1;
-    return menu->items[nPos].item_id;
+    if (menu->items[nPos].fType & MF_POPUP) return -1;
+    return menu->items[nPos].wID;
 }
 
 
 /**********************************************************************
  *         GetMenuItemID32    (USER32.262)
  */
-UINT32 GetMenuItemID32( HMENU32 hMenu, INT32 nPos )
+UINT32 WINAPI GetMenuItemID32( HMENU32 hMenu, INT32 nPos )
 {
     LPPOPUPMENU	menu;
 
     if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return -1;
     if ((nPos < 0) || (nPos >= menu->nItems)) return -1;
-    if (menu->items[nPos].item_flags & MF_POPUP) return -1;
-    return menu->items[nPos].item_id;
+    /* FIXME: Now that submenus can have ids, is this still right?  */
+    if (menu->items[nPos].fType & MF_POPUP) return -1;
+    return menu->items[nPos].wID;
 }
 
 
 /*******************************************************************
  *         InsertMenu16    (USER.410)
  */
-BOOL16 InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
-                     UINT16 id, SEGPTR data )
+BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
+                            UINT16 id, SEGPTR data )
 {
     UINT32 pos32 = (UINT32)pos;
     if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT32)-1;
@@ -2851,8 +2951,8 @@
 /*******************************************************************
  *         InsertMenu32A    (USER32.321)
  */
-BOOL32 InsertMenu32A( HMENU32 hMenu, UINT32 pos, UINT32 flags,
-                      UINT32 id, LPCSTR str )
+BOOL32 WINAPI InsertMenu32A( HMENU32 hMenu, UINT32 pos, UINT32 flags,
+                             UINT32 id, LPCSTR str )
 {
     MENUITEM *item;
 
@@ -2875,7 +2975,8 @@
     if (flags & MF_POPUP)  /* Set the MF_POPUP flag on the popup-menu */
 	((POPUPMENU *)USER_HEAP_LIN_ADDR((HMENU16)id))->wFlags |= MF_POPUP;
 
-    item->pCB = NULL;
+    item->hCheckBit = item->hUnCheckBit = 0;
+    item->dwItemData = 0;
     return TRUE;
 }
 
@@ -2883,8 +2984,8 @@
 /*******************************************************************
  *         InsertMenu32W    (USER32.324)
  */
-BOOL32 InsertMenu32W( HMENU32 hMenu, UINT32 pos, UINT32 flags,
-                      UINT32 id, LPCWSTR str )
+BOOL32 WINAPI InsertMenu32W( HMENU32 hMenu, UINT32 pos, UINT32 flags,
+                             UINT32 id, LPCWSTR str )
 {
     BOOL32 ret;
 
@@ -2902,7 +3003,7 @@
 /*******************************************************************
  *         AppendMenu16    (USER.411)
  */
-BOOL16 AppendMenu16( HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data )
+BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
 {
     return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
 }
@@ -2911,7 +3012,8 @@
 /*******************************************************************
  *         AppendMenu32A    (USER32.4)
  */
-BOOL32 AppendMenu32A( HMENU32 hMenu, UINT32 flags, UINT32 id, LPCSTR data )
+BOOL32 WINAPI AppendMenu32A( HMENU32 hMenu, UINT32 flags,
+                             UINT32 id, LPCSTR data )
 {
     return InsertMenu32A( hMenu, -1, flags | MF_BYPOSITION, id, data );
 }
@@ -2920,7 +3022,8 @@
 /*******************************************************************
  *         AppendMenu32W    (USER32.5)
  */
-BOOL32 AppendMenu32W( HMENU32 hMenu, UINT32 flags, UINT32 id, LPCWSTR data )
+BOOL32 WINAPI AppendMenu32W( HMENU32 hMenu, UINT32 flags,
+                             UINT32 id, LPCWSTR data )
 {
     return InsertMenu32W( hMenu, -1, flags | MF_BYPOSITION, id, data );
 }
@@ -2929,7 +3032,7 @@
 /**********************************************************************
  *         RemoveMenu16    (USER.412)
  */
-BOOL16 RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
+BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
 {
     return RemoveMenu32( hMenu, nPos, wFlags );
 }
@@ -2938,7 +3041,7 @@
 /**********************************************************************
  *         RemoveMenu32    (USER32.440)
  */
-BOOL32 RemoveMenu32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags )
+BOOL32 WINAPI RemoveMenu32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags )
 {
     LPPOPUPMENU	menu;
     MENUITEM *item;
@@ -2974,7 +3077,7 @@
 /**********************************************************************
  *         DeleteMenu16    (USER.413)
  */
-BOOL16 DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
+BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
 {
     return DeleteMenu32( hMenu, nPos, wFlags );
 }
@@ -2983,11 +3086,11 @@
 /**********************************************************************
  *         DeleteMenu32    (USER32.128)
  */
-BOOL32 DeleteMenu32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags )
+BOOL32 WINAPI DeleteMenu32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags )
 {
     MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
     if (!item) return FALSE;
-    if (item->item_flags & MF_POPUP) DestroyMenu32( (HMENU32)item->item_id );
+    if (item->fType & MF_POPUP) DestroyMenu32( item->hSubMenu );
       /* nPos is now the position of the item */
     RemoveMenu32( hMenu, nPos, wFlags | MF_BYPOSITION );
     return TRUE;
@@ -2997,8 +3100,8 @@
 /*******************************************************************
  *         ModifyMenu16    (USER.414)
  */
-BOOL16 ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
-                     UINT16 id, SEGPTR data )
+BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
+                            UINT16 id, SEGPTR data )
 {
     if (IS_STRING_ITEM(flags))
         return ModifyMenu32A( hMenu, pos, flags, id,
@@ -3010,8 +3113,8 @@
 /*******************************************************************
  *         ModifyMenu32A    (USER32.396)
  */
-BOOL32 ModifyMenu32A( HMENU32 hMenu, UINT32 pos, UINT32 flags,
-                      UINT32 id, LPCSTR str )
+BOOL32 WINAPI ModifyMenu32A( HMENU32 hMenu, UINT32 pos, UINT32 flags,
+                             UINT32 id, LPCSTR str )
 {
     MENUITEM *item;
 
@@ -3035,8 +3138,8 @@
 /*******************************************************************
  *         ModifyMenu32W    (USER32.397)
  */
-BOOL32 ModifyMenu32W( HMENU32 hMenu, UINT32 pos, UINT32 flags,
-                      UINT32 id, LPCWSTR str )
+BOOL32 WINAPI ModifyMenu32W( HMENU32 hMenu, UINT32 pos, UINT32 flags,
+                             UINT32 id, LPCWSTR str )
 {
     BOOL32 ret;
 
@@ -3054,7 +3157,7 @@
 /**********************************************************************
  *         CreatePopupMenu16    (USER.415)
  */
-HMENU16 CreatePopupMenu16(void)
+HMENU16 WINAPI CreatePopupMenu16(void)
 {
     return CreatePopupMenu32();
 }
@@ -3063,7 +3166,7 @@
 /**********************************************************************
  *         CreatePopupMenu32    (USER32.81)
  */
-HMENU32 CreatePopupMenu32(void)
+HMENU32 WINAPI CreatePopupMenu32(void)
 {
     HMENU32 hmenu;
     POPUPMENU *menu;
@@ -3078,7 +3181,7 @@
 /**********************************************************************
  *         GetMenuCheckMarkDimensions    (USER.417) (USER32.257)
  */
-DWORD GetMenuCheckMarkDimensions(void)
+DWORD WINAPI GetMenuCheckMarkDimensions(void)
 {
     return MAKELONG( check_bitmap_width, check_bitmap_height );
 }
@@ -3087,8 +3190,8 @@
 /**********************************************************************
  *         SetMenuItemBitmaps16    (USER.418)
  */
-BOOL16 SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
-                             HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck )
+BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
+                                    HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
 {
     return SetMenuItemBitmaps32( hMenu, nPos, wFlags, hNewUnCheck, hNewCheck );
 }
@@ -3097,8 +3200,8 @@
 /**********************************************************************
  *         SetMenuItemBitmaps32    (USER32.489)
  */
-BOOL32 SetMenuItemBitmaps32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags,
-                             HBITMAP32 hNewUnCheck, HBITMAP32 hNewCheck )
+BOOL32 WINAPI SetMenuItemBitmaps32( HMENU32 hMenu, UINT32 nPos, UINT32 wFlags,
+                                    HBITMAP32 hNewUnCheck, HBITMAP32 hNewCheck)
 {
     MENUITEM *item;
     dprintf_menu(stddeb,"SetMenuItemBitmaps(%04x, %04x, %04x, %04x, %04x)\n",
@@ -3107,17 +3210,13 @@
 
     if (!hNewCheck && !hNewUnCheck)
     {
-	if( item->pCB ) HeapFree( SystemHeap, 0, item->pCB );
-	item->pCB = NULL;
-	item->item_flags &= ~MF_USECHECKBITMAPS;
+	item->fState &= ~MF_USECHECKBITMAPS;
     }
     else  /* Install new bitmaps */
     {
-	if( item->pCB == NULL ) 
-	    item->pCB = HeapAlloc( SystemHeap, 0, sizeof(CBITMAPS));
-	item->pCB->hCheckBit = hNewCheck;
-	item->pCB->hUnCheckBit = hNewUnCheck;
-	item->item_flags |= MF_USECHECKBITMAPS;
+	item->hCheckBit = hNewCheck;
+	item->hUnCheckBit = hNewUnCheck;
+	item->fState |= MF_USECHECKBITMAPS;
     }
     return TRUE;
 }
@@ -3126,7 +3225,7 @@
 /**********************************************************************
  *         CreateMenu16    (USER.151)
  */
-HMENU16 CreateMenu16(void)
+HMENU16 WINAPI CreateMenu16(void)
 {
     return CreateMenu32();
 }
@@ -3135,7 +3234,7 @@
 /**********************************************************************
  *         CreateMenu32    (USER32.80)
  */
-HMENU32 CreateMenu32(void)
+HMENU32 WINAPI CreateMenu32(void)
 {
     HMENU32 hMenu;
     LPPOPUPMENU menu;
@@ -3158,7 +3257,7 @@
 /**********************************************************************
  *         DestroyMenu16    (USER.152)
  */
-BOOL16 DestroyMenu16( HMENU16 hMenu )
+BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
 {
     return DestroyMenu32( hMenu );
 }
@@ -3167,7 +3266,7 @@
 /**********************************************************************
  *         DestroyMenu32    (USER32.133)
  */
-BOOL32 DestroyMenu32( HMENU32 hMenu )
+BOOL32 WINAPI DestroyMenu32( HMENU32 hMenu )
 {
     dprintf_menu(stddeb,"DestroyMenu(%04x)\n", hMenu);
 
@@ -3180,7 +3279,7 @@
 	if( pTopPopupWnd && (hMenu == *(HMENU32*)pTopPopupWnd->wExtra) )
 	  *(UINT32*)pTopPopupWnd->wExtra = 0;
 
-	if (lppop && (lppop->wMagic == MENU_MAGIC))
+	if (IS_A_MENU( lppop ))
 	{
 	    lppop->wMagic = 0;  /* Mark it as destroyed */
 
@@ -3194,8 +3293,7 @@
 	        MENUITEM *item = lppop->items;
 	        for (i = lppop->nItems; i > 0; i--, item++)
 	        {
-	            if (item->item_flags & MF_POPUP)
-	                DestroyMenu32( (HMENU32)item->item_id );
+	            if (item->fType & MF_POPUP) DestroyMenu32(item->hSubMenu);
 		    MENU_FreeItemData( item );
 	        }
 	        HeapFree( SystemHeap, 0, lppop->items );
@@ -3211,7 +3309,7 @@
 /**********************************************************************
  *         GetSystemMenu16    (USER.156)
  */
-HMENU16 GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
+HMENU16 WINAPI GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
 {
     return GetSystemMenu32( hWnd, bRevert );
 }
@@ -3220,7 +3318,7 @@
 /**********************************************************************
  *         GetSystemMenu32    (USER32.290)
  */
-HMENU32 GetSystemMenu32( HWND32 hWnd, BOOL32 bRevert )
+HMENU32 WINAPI GetSystemMenu32( HWND32 hWnd, BOOL32 bRevert )
 {
     WND *wndPtr = WIN_FindWndPtr( hWnd );
 
@@ -3237,8 +3335,8 @@
 	    {
 		POPUPMENU *menu = (POPUPMENU*) 
 			   USER_HEAP_LIN_ADDR(wndPtr->hSysMenu);
-		if( menu->items[0].item_id == MENU_DefSysPopup )
-		    menu->items[0].item_id = MENU_CopySysPopup();
+		if( menu->items[0].hSubMenu == MENU_DefSysPopup )
+		    menu->items[0].hSubMenu = MENU_CopySysPopup();
 	    }
 	}
 
@@ -3255,7 +3353,7 @@
 /*******************************************************************
  *         SetSystemMenu16    (USER.280)
  */
-BOOL16 SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
+BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
 {
     return SetSystemMenu32( hwnd, hMenu );
 }
@@ -3264,7 +3362,7 @@
 /*******************************************************************
  *         SetSystemMenu32    (USER32.507)
  */
-BOOL32 SetSystemMenu32( HWND32 hwnd, HMENU32 hMenu )
+BOOL32 WINAPI SetSystemMenu32( HWND32 hwnd, HMENU32 hMenu )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
 
@@ -3281,7 +3379,7 @@
 /**********************************************************************
  *         GetMenu16    (USER.157)
  */
-HMENU16 GetMenu16( HWND16 hWnd ) 
+HMENU16 WINAPI GetMenu16( HWND16 hWnd ) 
 {
     WND * wndPtr = WIN_FindWndPtr(hWnd);
     if (wndPtr && !(wndPtr->dwStyle & WS_CHILD)) 
@@ -3293,7 +3391,7 @@
 /**********************************************************************
  *         GetMenu32    (USER32.256)
  */
-HMENU32 GetMenu32( HWND32 hWnd ) 
+HMENU32 WINAPI GetMenu32( HWND32 hWnd ) 
 { 
     WND * wndPtr = WIN_FindWndPtr(hWnd);
     if (wndPtr && !(wndPtr->dwStyle & WS_CHILD)) 
@@ -3305,7 +3403,7 @@
 /**********************************************************************
  *         SetMenu16    (USER.158)
  */
-BOOL16 SetMenu16( HWND16 hWnd, HMENU16 hMenu )
+BOOL16 WINAPI SetMenu16( HWND16 hWnd, HMENU16 hMenu )
 {
     return SetMenu32( hWnd, hMenu );
 }
@@ -3314,7 +3412,7 @@
 /**********************************************************************
  *         SetMenu32    (USER32.486)
  */
-BOOL32 SetMenu32( HWND32 hWnd, HMENU32 hMenu )
+BOOL32 WINAPI SetMenu32( HWND32 hWnd, HMENU32 hMenu )
 {
     WND * wndPtr = WIN_FindWndPtr(hWnd);
 
@@ -3347,7 +3445,7 @@
 /**********************************************************************
  *         GetSubMenu16    (USER.159)
  */
-HMENU16 GetSubMenu16( HMENU16 hMenu, INT16 nPos )
+HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
 {
     return GetSubMenu32( hMenu, nPos );
 }
@@ -3356,21 +3454,21 @@
 /**********************************************************************
  *         GetSubMenu32    (USER32.287)
  */
-HMENU32 GetSubMenu32( HMENU32 hMenu, INT32 nPos )
+HMENU32 WINAPI GetSubMenu32( HMENU32 hMenu, INT32 nPos )
 {
     LPPOPUPMENU lppop;
 
     if (!(lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return 0;
     if ((UINT32)nPos >= lppop->nItems) return 0;
-    if (!(lppop->items[nPos].item_flags & MF_POPUP)) return 0;
-    return (HMENU32)lppop->items[nPos].item_id;
+    if (!(lppop->items[nPos].fType & MF_POPUP)) return 0;
+    return lppop->items[nPos].hSubMenu;
 }
 
 
 /**********************************************************************
  *         DrawMenuBar16    (USER.160)
  */
-void DrawMenuBar16( HWND16 hWnd )
+void WINAPI DrawMenuBar16( HWND16 hWnd )
 {
     DrawMenuBar32( hWnd );
 }
@@ -3379,7 +3477,7 @@
 /**********************************************************************
  *         DrawMenuBar32    (USER32.160)
  */
-BOOL32 DrawMenuBar32( HWND32 hWnd )
+BOOL32 WINAPI DrawMenuBar32( HWND32 hWnd )
 {
     LPPOPUPMENU lppop;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
@@ -3400,7 +3498,7 @@
 /***********************************************************************
  *           EndMenu   (USER.187) (USER32.174)
  */
-void EndMenu(void)
+void WINAPI EndMenu(void)
 {
     fEndMenu = TRUE;
 }
@@ -3409,7 +3507,7 @@
 /***********************************************************************
  *           LookupMenuHandle   (USER.217)
  */
-HMENU16 LookupMenuHandle( HMENU16 hmenu, INT16 id )
+HMENU16 WINAPI LookupMenuHandle( HMENU16 hmenu, INT16 id )
 {
     HMENU32 hmenu32 = hmenu;
     INT32 id32 = id;
@@ -3421,7 +3519,7 @@
 /**********************************************************************
  *	    LoadMenu16    (USER.150)
  */
-HMENU16 LoadMenu16( HINSTANCE16 instance, SEGPTR name )
+HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, SEGPTR name )
 {
     HRSRC16 hRsrc;
     HGLOBAL16 handle;
@@ -3454,7 +3552,7 @@
 /*****************************************************************
  *        LoadMenu32A   (USER32.370)
  */
-HMENU32 LoadMenu32A( HINSTANCE32 instance, LPCSTR name )
+HMENU32 WINAPI LoadMenu32A( HINSTANCE32 instance, LPCSTR name )
 {
     HRSRC32 hrsrc = FindResource32A( instance, name, (LPSTR)RT_MENU );
     if (!hrsrc) return 0;
@@ -3465,7 +3563,7 @@
 /*****************************************************************
  *        LoadMenu32W   (USER32.372)
  */
-HMENU32 LoadMenu32W( HINSTANCE32 instance, LPCWSTR name )
+HMENU32 WINAPI LoadMenu32W( HINSTANCE32 instance, LPCWSTR name )
 {
     HRSRC32 hrsrc = FindResource32W( instance, name, (LPWSTR)RT_MENU );
     if (!hrsrc) return 0;
@@ -3476,7 +3574,7 @@
 /**********************************************************************
  *	    LoadMenuIndirect16    (USER.220)
  */
-HMENU16 LoadMenuIndirect16( LPCVOID template )
+HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
 {
     HMENU16 hMenu;
     WORD version, offset;
@@ -3505,7 +3603,7 @@
 /**********************************************************************
  *	    LoadMenuIndirect32A    (USER32.370)
  */
-HMENU32 LoadMenuIndirect32A( LPCVOID template )
+HMENU32 WINAPI LoadMenuIndirect32A( LPCVOID template )
 {
     HMENU16 hMenu;
     WORD version, offset;
@@ -3547,7 +3645,7 @@
 /**********************************************************************
  *	    LoadMenuIndirect32W    (USER32.371)
  */
-HMENU32 LoadMenuIndirect32W( LPCVOID template )
+HMENU32 WINAPI LoadMenuIndirect32W( LPCVOID template )
 {
     /* FIXME: is there anything different between A and W? */
     return LoadMenuIndirect32A( template );
@@ -3557,11 +3655,20 @@
 /**********************************************************************
  *		IsMenu16    (USER.358)
  */
-BOOL16 IsMenu16( HMENU16 hmenu )
+BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
 {
-    LPPOPUPMENU menu;
-    if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
-    return (menu->wMagic == MENU_MAGIC);
+    LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
+    return IS_A_MENU(menu);
+}
+
+
+/**********************************************************************
+ *		IsMenu32    (USER32.345)
+ */
+BOOL32 WINAPI IsMenu32(HMENU32 hmenu)
+{
+    LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
+    return IS_A_MENU(menu);
 }
 
 /**********************************************************************
@@ -3574,40 +3681,48 @@
 					 BOOL32 unicode)
 {
   MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos);
-  if (!menu) return FALSE;
+    debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "\n");
+    if (!menu)
+	return FALSE;
 
-  if (lpmii->fMask && MIIM_TYPE)
-    {
-      lpmii->fType = menu->item_flags;
-      lpmii->dwTypeData = menu->text;
-      if (IS_STRING_ITEM (menu->item_flags))
-	{
-	  lpmii->cch = strlen (menu->text);
+    if (lpmii->fMask & MIIM_TYPE) {
+	lpmii->fType = menu->fType;
+	switch (MENU_ITEM_TYPE(menu->fType)) {
+	case MF_STRING:
+	    if (menu->text && lpmii->dwTypeData && lpmii->cch) {
 	  if (unicode)
-	    ; /* UGH! FIXME */
+		    lstrcpynAtoW((LPWSTR) lpmii->dwTypeData,
+				 menu->text,
+				 lpmii->cch);
+		else
+		    lstrcpyn32A(lpmii->dwTypeData,
+				menu->text,
+				lpmii->cch);
 	}
-      else
-	lpmii->cch = 0;
+	    break;
+	case MF_OWNERDRAW:
+	case MF_BITMAP:
+	    lpmii->dwTypeData = menu->text;
+	    break;
+	default:
+	    break;
     }
-
-  if (lpmii->fMask && MIIM_STATE)
-    lpmii->fState = 0; /* FIXME -- not saved.  */
-
-  if (lpmii->wID && MIIM_ID)
-    lpmii->fType = menu->item_id;
-
-  if (lpmii->fMask && MIIM_SUBMENU)
-    lpmii->hSubMenu = menu->item_id; /* FIXME: ??? */
-
-  if (lpmii->fMask && MIIM_CHECKMARKS)
-    {
-      PCBITMAPS pCB = menu->pCB;
-      lpmii->hbmpChecked = pCB ? pCB->hCheckBit : 0;
-      lpmii->hbmpUnchecked = pCB ? pCB->hUnCheckBit : 0;
     }
+    if (lpmii->fMask & MIIM_STATE)
+	lpmii->fState = menu->fState;
 
-  if (lpmii->fMask && MIIM_DATA)
-    lpmii->dwItemData = 0; /* FIXME -- not saved.  */
+    if (lpmii->fMask & MIIM_ID)
+	lpmii->wID = menu->wID;
+
+    if (lpmii->fMask & MIIM_SUBMENU)
+	lpmii->hSubMenu = menu->hSubMenu;
+
+    if (lpmii->fMask & MIIM_CHECKMARKS) {
+	lpmii->hbmpChecked = menu->hCheckBit;
+	lpmii->hbmpUnchecked = menu->hUnCheckBit;
+    }
+    if (lpmii->fMask & MIIM_DATA)
+	lpmii->dwItemData = menu->dwItemData;
 
   return TRUE;
 }
@@ -3615,8 +3730,8 @@
 /**********************************************************************
  *		GetMenuItemInfo32A    (USER32.263)
  */
-BOOL32 GetMenuItemInfo32A( HMENU32 hmenu, UINT32 item, BOOL32 bypos,
-			   LPMENUITEMINFO32A lpmii)
+BOOL32 WINAPI GetMenuItemInfo32A( HMENU32 hmenu, UINT32 item, BOOL32 bypos,
+                                  LPMENUITEMINFO32A lpmii)
 {
     return GetMenuItemInfo32_common (hmenu, item, bypos, lpmii, FALSE);
 }
@@ -3624,20 +3739,136 @@
 /**********************************************************************
  *		GetMenuItemInfo32W    (USER32.264)
  */
-BOOL32 GetMenuItemInfo32W( HMENU32 hmenu, UINT32 item, BOOL32 bypos,
-			   LPMENUITEMINFO32W lpmii)
+BOOL32 WINAPI GetMenuItemInfo32W( HMENU32 hmenu, UINT32 item, BOOL32 bypos,
+                                  LPMENUITEMINFO32W lpmii)
 {
     return GetMenuItemInfo32_common (hmenu, item, bypos,
                                      (LPMENUITEMINFO32A)lpmii, TRUE);
 }
 
+/**********************************************************************
+ *		SetMenuItemInfo32_common
+ */
+
+static BOOL32 SetMenuItemInfo32_common(MENUITEM * menu,
+				       const MENUITEMINFO32A *lpmii,
+				       BOOL32 unicode)
+{
+    if (!menu) return FALSE;
+
+    if (lpmii->fMask & MIIM_TYPE) {
+	/* Get rid of old string.  */
+	if (IS_STRING_ITEM(menu->fType) && menu->text)
+	    HeapFree(SystemHeap, 0, menu->text);
+
+	menu->fType = lpmii->fType;
+	menu->text = lpmii->dwTypeData;
+	if (IS_STRING_ITEM(menu->fType) && menu->text) {
+	    menu->text =
+		unicode
+		? HEAP_strdupWtoA(SystemHeap, 0,
+				  (LPWSTR) lpmii->dwTypeData)
+		: HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
+	}
+    }
+    if (lpmii->fMask & MIIM_STATE)
+	menu->fState = lpmii->fState;
+
+    if (lpmii->fMask & MIIM_ID)
+	menu->wID = lpmii->wID;
+
+    if (lpmii->fMask & MIIM_SUBMENU)
+	menu->hSubMenu = lpmii->hSubMenu;
+
+    if (lpmii->fMask & MIIM_CHECKMARKS)
+    {
+	menu->hCheckBit = lpmii->hbmpChecked;
+	menu->hUnCheckBit = lpmii->hbmpUnchecked;
+    }
+    if (lpmii->fMask & MIIM_DATA)
+	menu->dwItemData = lpmii->dwItemData;
+
+    debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "\n");
+    return TRUE;
+}
 
 /**********************************************************************
- *		IsMenu32    (USER32.345)
+ *		SetMenuItemInfo32A    (USER32.490)
  */
-BOOL32 IsMenu32( HMENU32 hmenu )
+BOOL32 WINAPI SetMenuItemInfo32A(HMENU32 hmenu, UINT32 item, BOOL32 bypos,
+                                 const MENUITEMINFO32A *lpmii) 
 {
-    LPPOPUPMENU menu;
-    if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
-    return (menu->wMagic == MENU_MAGIC);
+    return SetMenuItemInfo32_common(MENU_FindItem(&hmenu, &item, bypos),
+				    lpmii, FALSE);
+}
+
+/**********************************************************************
+ *		SetMenuItemInfo32W    (USER32.491)
+ */
+BOOL32 WINAPI SetMenuItemInfo32W(HMENU32 hmenu, UINT32 item, BOOL32 bypos,
+                                 const MENUITEMINFO32W *lpmii)
+{
+    return SetMenuItemInfo32_common(MENU_FindItem(&hmenu, &item, bypos),
+				    (const MENUITEMINFO32A*)lpmii, TRUE);
+}
+
+/**********************************************************************
+ *		SetMenuDefaultItem32    (USER32.488)
+ */
+BOOL32 WINAPI SetMenuDefaultItem32(HMENU32 hmenu, UINT32 item, BOOL32 bypos)
+{
+    MENUITEM *menu = MENU_FindItem(&hmenu, &item, bypos);
+    if (!menu) return FALSE;
+    debug_print_menuitem("SetMenuDefaultItem32: ", menu, "\n");
+    fprintf(stdnimp, "SetMenuDefaultItem32 (0x%x,%d,%d), empty stub!\n",
+	    hmenu, item, bypos);
+    return TRUE;
+}
+
+/*******************************************************************
+ *              InsertMenuItem16   (USER.441)
+ *
+ * FIXME: untested
+ */
+BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
+                                const MENUITEMINFO16 *mii )
+{
+    MENUITEMINFO32A miia;
+
+    miia.cbSize        = sizeof(miia);
+    miia.fMask         = mii->fMask;
+    miia.dwTypeData    = miia.dwTypeData;
+    miia.fType         = mii->fType;
+    miia.fState        = mii->fState;
+    miia.wID           = mii->wID;
+    miia.hSubMenu      = mii->hSubMenu;
+    miia.hbmpChecked   = mii->hbmpChecked;
+    miia.hbmpUnchecked = mii->hbmpUnchecked;
+    miia.dwItemData    = mii->dwItemData;
+    miia.cch           = mii->cch;
+    if (IS_STRING_ITEM(miia.fType))
+        miia.dwTypeData = PTR_SEG_TO_LIN(miia.dwTypeData);
+    return InsertMenuItem32A( hmenu, pos, byposition, &miia );
+}
+
+
+/**********************************************************************
+ *		InsertMenuItem32A    (USER32.322)
+ */
+BOOL32 WINAPI InsertMenuItem32A(HMENU32 hMenu, UINT32 uItem, BOOL32 bypos,
+                                const MENUITEMINFO32A *lpmii)
+{
+    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos);
+    return SetMenuItemInfo32_common(item, lpmii, FALSE);
+}
+
+
+/**********************************************************************
+ *		InsertMenuItem32W    (USER32.323)
+ */
+BOOL32 WINAPI InsertMenuItem32W(HMENU32 hMenu, UINT32 uItem, BOOL32 bypos,
+                                const MENUITEMINFO32W *lpmii)
+{
+    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos);
+    return SetMenuItemInfo32_common(item, (const MENUITEMINFO32A*)lpmii, TRUE);
 }
diff --git a/controls/scroll.c b/controls/scroll.c
index d2371f1..b8a3d4e 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -756,8 +756,8 @@
 /***********************************************************************
  *           ScrollBarWndProc
  */
-LRESULT ScrollBarWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
-                          LPARAM lParam )
+LRESULT WINAPI ScrollBarWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                                 LPARAM lParam )
 {
     switch(message)
     {
@@ -893,8 +893,8 @@
 /*************************************************************************
  *           SetScrollInfo16   (USER.475)
  */
-INT16 SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
-                       BOOL16 bRedraw )
+INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
+                              BOOL16 bRedraw )
 {
     return (INT16)SetScrollInfo32( hwnd, nBar, info, bRedraw );
 }
@@ -903,8 +903,8 @@
 /*************************************************************************
  *           SetScrollInfo32   (USER32.500)
  */
-INT32 SetScrollInfo32( HWND32 hwnd, INT32 nBar, const SCROLLINFO *info,
-                       BOOL32 bRedraw )
+INT32 WINAPI SetScrollInfo32( HWND32 hwnd, INT32 nBar, const SCROLLINFO *info,
+                              BOOL32 bRedraw )
 {
     SCROLLBAR_INFO *infoPtr;
     UINT32 new_flags;
@@ -1007,7 +1007,7 @@
 /*************************************************************************
  *           GetScrollInfo16   (USER.476)
  */
-BOOL16 GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
+BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
 {
     return GetScrollInfo32( hwnd, nBar, info );
 }
@@ -1016,7 +1016,7 @@
 /*************************************************************************
  *           GetScrollInfo32   (USER32.283)
  */
-BOOL32 GetScrollInfo32( HWND32 hwnd, INT32 nBar, LPSCROLLINFO info )
+BOOL32 WINAPI GetScrollInfo32( HWND32 hwnd, INT32 nBar, LPSCROLLINFO info )
 {
     SCROLLBAR_INFO *infoPtr;
 
@@ -1041,7 +1041,8 @@
 /*************************************************************************
  *           SetScrollPos16   (USER.62)
  */
-INT16 SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos, BOOL16 bRedraw )
+INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos,
+                             BOOL16 bRedraw )
 {
     return (INT16)SetScrollPos32( hwnd, nBar, nPos, bRedraw );
 }
@@ -1050,7 +1051,8 @@
 /*************************************************************************
  *           SetScrollPos32   (USER32.501)
  */
-INT32 SetScrollPos32( HWND32 hwnd, INT32 nBar, INT32 nPos, BOOL32 bRedraw )
+INT32 WINAPI SetScrollPos32( HWND32 hwnd, INT32 nBar, INT32 nPos,
+                             BOOL32 bRedraw )
 {
     SCROLLINFO info;
     SCROLLBAR_INFO *infoPtr;
@@ -1069,7 +1071,7 @@
 /*************************************************************************
  *           GetScrollPos16   (USER.63)
  */
-INT16 GetScrollPos16( HWND16 hwnd, INT16 nBar )
+INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
 {
     return (INT16)GetScrollPos32( hwnd, nBar );
 }
@@ -1078,7 +1080,7 @@
 /*************************************************************************
  *           GetScrollPos32   (USER32.284)
  */
-INT32 GetScrollPos32( HWND32 hwnd, INT32 nBar )
+INT32 WINAPI GetScrollPos32( HWND32 hwnd, INT32 nBar )
 {
     SCROLLBAR_INFO *infoPtr;
 
@@ -1090,8 +1092,8 @@
 /*************************************************************************
  *           SetScrollRange16   (USER.64)
  */
-void SetScrollRange16( HWND16 hwnd, INT16 nBar, INT16 MinVal, INT16 MaxVal,
-                       BOOL16 bRedraw )
+void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar,
+                              INT16 MinVal, INT16 MaxVal, BOOL16 bRedraw )
 {
     /* Invalid range -> range is set to (0,0) */
     if ((INT32)MaxVal - (INT32)MinVal > 0x7fff) MinVal = MaxVal = 0;
@@ -1102,8 +1104,8 @@
 /*************************************************************************
  *           SetScrollRange32   (USER32.502)
  */
-BOOL32 SetScrollRange32( HWND32 hwnd, INT32 nBar, INT32 MinVal, INT32 MaxVal,
-                         BOOL32 bRedraw )
+BOOL32 WINAPI SetScrollRange32( HWND32 hwnd, INT32 nBar,
+                                INT32 MinVal, INT32 MaxVal, BOOL32 bRedraw )
 {
     SCROLLINFO info;
 
@@ -1153,7 +1155,8 @@
 /*************************************************************************
  *           GetScrollRange16   (USER.65)
  */
-BOOL16 GetScrollRange16( HWND16 hwnd, INT16 nBar, LPINT16 lpMin, LPINT16 lpMax)
+BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar,
+                                LPINT16 lpMin, LPINT16 lpMax)
 {
     INT32 min, max;
     BOOL16 ret = GetScrollRange32( hwnd, nBar, &min, &max );
@@ -1166,7 +1169,8 @@
 /*************************************************************************
  *           GetScrollRange32   (USER32.285)
  */
-BOOL32 GetScrollRange32( HWND32 hwnd, INT32 nBar, LPINT32 lpMin, LPINT32 lpMax)
+BOOL32 WINAPI GetScrollRange32( HWND32 hwnd, INT32 nBar,
+                                LPINT32 lpMin, LPINT32 lpMax)
 {
     SCROLLBAR_INFO *infoPtr;
 
@@ -1185,7 +1189,7 @@
 /*************************************************************************
  *           ShowScrollBar16   (USER.267)
  */
-void ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
+void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
 {
     ShowScrollBar32( hwnd, nBar, fShow );
 }
@@ -1194,7 +1198,7 @@
 /*************************************************************************
  *           ShowScrollBar32   (USER32.531)
  */
-BOOL32 ShowScrollBar32( HWND32 hwnd, INT32 nBar, BOOL32 fShow )
+BOOL32 WINAPI ShowScrollBar32( HWND32 hwnd, INT32 nBar, BOOL32 fShow )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
@@ -1261,7 +1265,7 @@
 /*************************************************************************
  *           EnableScrollBar16   (USER.482)
  */
-BOOL16 EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
+BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
 {
     return EnableScrollBar32( hwnd, nBar, flags );
 }
@@ -1270,7 +1274,7 @@
 /*************************************************************************
  *           EnableScrollBar32   (USER32.170)
  */
-BOOL32 EnableScrollBar32( HWND32 hwnd, INT32 nBar, UINT32 flags )
+BOOL32 WINAPI EnableScrollBar32( HWND32 hwnd, INT32 nBar, UINT32 flags )
 {
     SCROLLBAR_INFO *infoPtr;
 
diff --git a/controls/static.c b/controls/static.c
index 6a547e2..ecd4a02 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -50,13 +50,17 @@
 {
     HICON16 prevIcon;
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
+    CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16( hicon ):NULL;
 
     if ((wndPtr->dwStyle & 0x0f) != SS_ICON) return 0;
+    if (hicon && !info) {
+	fprintf(stderr,"STATIC_SetIcon: huh? hicon!=0, but info=0???\n");
+    	return 0;
+    }
     prevIcon = infoPtr->hIcon;
     infoPtr->hIcon = hicon;
     if (hicon)
     {
-        CURSORICONINFO *info = (CURSORICONINFO *) GlobalLock16( hicon );
         SetWindowPos32( wndPtr->hwndSelf, 0, 0, 0, info->nWidth, info->nHeight,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
         GlobalUnlock16( hicon );
@@ -95,8 +99,8 @@
 /***********************************************************************
  *           StaticWndProc
  */
-LRESULT StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
-                       LPARAM lParam )
+LRESULT WINAPI StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
+                              LPARAM lParam )
 {
     LRESULT lResult = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
diff --git a/controls/status.c b/controls/status.c
index feef96c..0732664 100644
--- a/controls/status.c
+++ b/controls/status.c
@@ -38,7 +38,8 @@
 /***********************************************************************
  *           DrawStatusText32A   (COMCTL32.3)
  */
-void DrawStatusText32A( HDC32 hdc, LPRECT32 lprc, LPCSTR text, UINT32 style )
+void WINAPI DrawStatusText32A( HDC32 hdc, LPRECT32 lprc, LPCSTR text,
+                               UINT32 style )
 {
     RECT32		r, rt;
     int	oldbkmode;
@@ -435,8 +436,8 @@
     return 0;
 }
 
-LRESULT StatusWindowProc( HWND32 hwnd, UINT32 msg,
-                          WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI StatusWindowProc( HWND32 hwnd, UINT32 msg,
+                                 WPARAM32 wParam, LPARAM lParam )
 {
     STATUSWINDOWINFO *self;
 
@@ -480,8 +481,8 @@
 /***********************************************************************
  *           CreateStatusWindow32A   (COMCTL32.4)
  */
-HWND32 CreateStatusWindow32A( INT32 style, LPCSTR text, HWND32 parent,
-                              UINT32 wid )
+HWND32 WINAPI CreateStatusWindow32A( INT32 style, LPCSTR text, HWND32 parent,
+                                     UINT32 wid )
 {
     HWND32 ret;
     ATOM atom;
diff --git a/controls/updown.c b/controls/updown.c
new file mode 100644
index 0000000..a3a75ef
--- /dev/null
+++ b/controls/updown.c
@@ -0,0 +1,865 @@
+/*		
+ * Updown control
+ *
+ * Copyright 1997 Dimitrie O. Paun
+ *
+ * TODO:
+ *   - subclass the buddy window (in UPDOWN_SetBuddy) to process the
+ *     arrow keys
+ *   - I am not sure about the default values for the Min, Max, Pos
+ *     (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
+ * Testing:
+ *   Not much. The following  have not been tested at all:
+ *     - horizontal arrows
+ *     - listbox as buddy window
+ *     - acceleration
+ *     - base 16
+ *     - UDS_ALIGNLEFT, ~UDS_WRAP
+ *     - integers with thousand separators.
+ *   Even though the above list seems rather large, the control seems to
+ *   behave very well so I am confident it does work in most (all) of the
+ *   untested cases.
+ * Problems:
+ *   At the moment, the control will no draw itself very well because it
+ *   uses some features in DrawEdge that are not yet implemented. 
+ *   In other words, there is no known problem, exempt for the things in
+ *   the TODO list above.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include "windows.h"
+#include "winnls.h"
+#include "syscolor.h"
+#include "sysmetrics.h"
+#include "updown.h"
+#include "graphics.h"
+#include "heap.h"
+#include "win.h"
+#include "stddebug.h"
+/*#define  DEBUG_UPDOWN*/
+#include "debug.h"
+
+/* Control configuration constants */
+
+#define INITIAL_DELAY    500 /* initial timer until auto-increment kicks in */
+#define REPEAT_DELAY     50  /* delay between auto-increments */
+
+#define DEFAULT_WIDTH    10  /* default width of the ctrl */
+#define DEFAULT_XSEP     0   /* default separation between buddy and crtl */
+#define DEFAULT_ADDTOP   1   /* amount to extend above the buddy window */
+#define DEFAULT_ADDBOT   1   /* amount to extend below the buddy window */
+
+
+/* Work constants */
+
+#define FLAG_INCR        0x01
+#define FLAG_DECR        0x02
+#define FLAG_MOUSEIN     0x04
+#define FLAG_CLICKED     (FLAG_INCR | FLAG_DECR)
+
+#define TIMERID1         1
+#define TIMERID2         2
+
+static int accelIndex = -1;
+
+#define max(a,b) ((a)>(b)?(a):(b))
+#define min(a,b) ((a)<(b)?(a):(b))
+
+#define UNKNOWN_PARAM(msg, wParam, lParam) dprintf_updown(stddeb, \
+        "UpDown Ctrl: Unknown parameter(s) for message " #msg     \
+	"(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
+
+#define UPDOWN_GetInfoPtr(wndPtr) ((UPDOWN_INFO *)wndPtr->wExtra)
+
+/***********************************************************************
+ *           UPDOWN_InBounds
+ * Tests if a given value 'val' is between the Min&Max limits
+ */
+static BOOL32 UPDOWN_InBounds(WND *wndPtr, int val)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+
+  if(infoPtr->MaxVal > infoPtr->MinVal)
+    return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
+  else
+    return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
+}
+
+/***********************************************************************
+ *           UPDOWN_OffsetVal
+ * Tests if we can change the current value by delta. If so, it changes
+ * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
+ */
+static BOOL32 UPDOWN_OffsetVal(WND *wndPtr, int delta)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+
+  /* check if we can do the modification first */
+  if(!UPDOWN_InBounds(wndPtr, infoPtr->CurVal+delta)){
+    if(wndPtr->dwStyle & UDS_WRAP)
+      delta += (delta < 0 ? -1 : 1) *
+	(infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
+	(infoPtr->MinVal - infoPtr->MaxVal) +
+	(delta < 0 ? 1 : -1);
+    else
+      return FALSE;
+  }
+
+  infoPtr->CurVal += delta;
+  return TRUE;
+}
+
+/***********************************************************************
+ *           UPDOWN_GetArrawRect
+ * wndPtr   - pointer to the up-down wnd
+ * rect     - will hold the rectangle
+ * incr     - TRUE  get the "increment" rect (up or right)
+ *            FALSE get the "decrement" rect (down or left)
+ *          
+ */
+static void UPDOWN_GetArrowRect(WND *wndPtr, RECT32 *rect, BOOL32 incr)
+{
+  int len; /* will hold the width or height */
+
+  GetClientRect32(wndPtr->hwndSelf, rect);
+
+  if (wndPtr->dwStyle & UDS_HORZ) {
+    len = rect->right - rect->left; /* compute the width */
+    if (incr)
+      rect->left = len/2;
+    else
+      rect->right = len/2;
+  }
+  else {
+    len = rect->bottom - rect->top; /* compute the height */
+    if (incr)
+      rect->bottom = len/2;
+    else
+      rect->top = len/2;
+  }
+}
+
+/***********************************************************************
+ *           UPDOWN_GetArrowFromPoint
+ * Returns the rectagle (for the up or down arrow) that contains pt.
+ * If it returns the up rect, it returns TRUE.
+ * If it returns the down rect, it returns FALSE.
+ */
+static int UPDOWN_GetArrowFromPoint(WND *wndPtr, RECT32 *rect, POINT32 pt)
+{
+  UPDOWN_GetArrowRect(wndPtr, rect, TRUE);
+  if(PtInRect32(rect, pt))
+    return TRUE;
+
+  UPDOWN_GetArrowRect(wndPtr, rect, FALSE);
+  return FALSE;
+}
+
+
+/***********************************************************************
+ *           UPDOWN_GetThousandSep
+ * Returns the thousand sep. If an error occurs, it returns ','.
+ */
+static char UPDOWN_GetThousandSep()
+{
+  char sep[2];
+
+  if(GetLocaleInfo32A(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, 
+		      sep, sizeof(sep)) != 1)
+    return ',';
+
+  return sep[0];
+}
+
+/***********************************************************************
+ *           UPDOWN_GetBuddyInt
+ * Tries to read the pos from the buddy window and if it succeeds,
+ * it stores it in the control's CurVal
+ * returns:
+ *   TRUE  - if it read the integer from the buddy successfully
+ *   FALSE - if an error occured
+ */
+static BOOL32 UPDOWN_GetBuddyInt(WND *wndPtr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+  char txt[20], sep, *src, *dst;
+  int newVal;
+
+  if (!IsWindow32(infoPtr->Buddy))
+    return FALSE;
+
+  /*if the buddy is a list window, we must set curr index */
+  if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
+    newVal = SendMessage32A(infoPtr->Buddy, LB_GETCARETINDEX32, 0, 0);
+    if(newVal < 0)
+      return FALSE;
+  }
+  else{
+    /* we have a regural window, so will get the text */
+    if (!GetWindowText32A(infoPtr->Buddy, txt, sizeof(txt)))
+      return FALSE;
+
+    sep = UPDOWN_GetThousandSep(); 
+
+    /* now get rid of the separators */
+    for(src = dst = txt; *src; src++)
+      if(*src != sep)
+	*dst++ = *src;
+    *dst = 0;
+
+    /* try to convert the number and validate it */
+    newVal = strtol(txt, &src, infoPtr->Base);
+    if(*src || !UPDOWN_InBounds(wndPtr, newVal)) 
+      return FALSE;
+
+    dprintf_updown(stddeb, "UpDown Ctrl: new value(%d) read from buddy "
+		   "(old=%d)\n",  newVal, infoPtr->CurVal);
+  }
+  
+  infoPtr->CurVal = newVal;
+  return TRUE;
+}
+
+
+/***********************************************************************
+ *           UPDOWN_SetBuddyInt
+ * Tries to set the pos to the buddy window based on current pos
+ * returns:
+ *   TRUE  - if it set the caption of the  buddy successfully
+ *   FALSE - if an error occured
+ */
+static BOOL32 UPDOWN_SetBuddyInt(WND *wndPtr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+  char txt1[20], sep;
+  int len;
+
+  if (!IsWindow32(infoPtr->Buddy)) 
+    return FALSE;
+
+  dprintf_updown(stddeb, "UpDown Ctrl: set new value(%d) to buddy.\n",
+		 infoPtr->CurVal);
+
+  /*if the buddy is a list window, we must set curr index */
+  if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
+    SendMessage32A(infoPtr->Buddy, LB_SETCURSEL32, infoPtr->CurVal, 0);
+  }
+  else{ /* Regural window, so set caption to the number */
+    len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
+
+    sep = UPDOWN_GetThousandSep(); 
+
+    if (!(wndPtr->dwStyle & UDS_NOTHOUSANDS)) {
+      char txt2[20], *src = txt1, *dst = txt2;
+      if(len%3 > 0){
+	strncpy(dst, src, len%3);
+	dst += len%3;
+	src += len%3;
+      }
+      for(len=0; *src; len++,src++){
+	if(len%3==0)
+	  *dst++ = sep;
+	*dst++ = *src++;
+      }
+      *dst = 0;           /* null terminate it */
+      strcpy(txt1, txt2); /* move it to the proper place */
+    }
+    SetWindowText32A(infoPtr->Buddy, txt1);
+  }
+
+  return TRUE;
+} 
+
+/***********************************************************************
+ *           UPDOWN_DrawArraw
+ * Draw the arrows for the up-down control. The arrows are drawn with the
+ * current pen and filled with the current brush.
+ * Input:
+ * hdc      - the DC to draw on
+ * rect     - rectangle holding the arrow
+ * incr     - TRUE  if we draw the "increment" arrow
+ *            FALSE if we draw the "decrement" arrow
+ * pressed  - TRUE  if the arrow is pressed (clicked)
+ *            FALSE if the arrow is not pressed (clicked)
+ * horz     - TRUE  if the arrow is horizontal
+ *            FLASE if the arrow is vertical
+ */
+static void UPDOWN_DrawArrow(HDC32 hdc, RECT32 *rect, BOOL32 incr, 
+			     BOOL32 pressed, BOOL32 horz)
+{
+  const int w = rect->right - rect->left;
+  const int h = rect->bottom - rect->top;
+  int offset = pressed ? 1 : 0, tmp;
+  POINT32 pts[3];
+
+  if(horz){ /* horizontal arrows */
+    pts[0].x = rect->right  - max(2, w/3) + offset;
+    pts[0].y = rect->top    + max(2, h/4) + offset;
+    pts[1].x = pts[0].x;
+    pts[1].y = rect->bottom - max(2, h/4) + offset;
+    pts[2].x = rect->left + w/3 + offset;
+    pts[2].y = (pts[0].y + pts[1].y)/2;
+    if(pts[2].x-2<rect->left)
+      pts[2].x = rect->left + 2;
+    if(pts[2].x <= pts[0].x)
+      pts[2].x = pts[0].x - 1;
+
+    if(incr){
+      tmp = pts[2].x;
+      pts[2].x = pts[0].x;
+      pts[0].x = pts[1].x = tmp;
+    }
+  }
+  else{                   /* vertical arrows */
+    pts[0].x = rect->left + max(2, w/4) + offset;
+    pts[0].y = rect->top  + max(2, h/3) + offset;
+    pts[1].x = rect->right- max(2, w/4) + offset;
+    pts[1].y = pts[0].y;
+    pts[2].x = (pts[0].x + pts[1].x)/2;
+    pts[2].y = pts[0].y + h/3 + offset;
+    if(pts[2].y+2>rect->bottom)
+      pts[2].y = rect->bottom - 2;
+    if(pts[2].y <= pts[0].y)
+      pts[2].y = pts[0].y + 1;
+
+    if(incr){
+      tmp = pts[2].y;
+      pts[2].y = pts[0].y;
+      pts[0].y = pts[1].y = tmp;
+    }
+  }
+  Polygon32(hdc, pts, 3);
+
+}
+
+/***********************************************************************
+ *           UPDOWN_Paint
+ * Draw the arrows. The background need not be erased.
+ */
+static void UPDOWN_Paint(WND *wndPtr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+  PAINTSTRUCT32 ps;
+  BOOL32 prssed;
+  RECT32 rect;
+  HDC32 hdc;
+  HBRUSH32 oldBrush;
+
+  hdc = BeginPaint32( wndPtr->hwndSelf, &ps );
+
+  /*FIXME - this is just for test */
+  /*      - when DrawEdge works properly, this should dissapear 
+	  as DrawEdge will erase the background */
+/*oldBrush = SelectObject32(hdc, GetStockObject32(GRAY_BRUSH));
+  GetClientRect32(wndPtr->hwndSelf, &rect);
+  Rectangle32(hdc, rect.left, rect.top, rect.right, rect.bottom);
+  SelectObject32(hdc, oldBrush);*/
+
+  /* First select the proper brush */
+  oldBrush = wndPtr->dwStyle & WS_DISABLED ? GRAY_BRUSH : BLACK_BRUSH;
+  oldBrush = SelectObject32(hdc, GetStockObject32(oldBrush));
+
+  /* Draw the incr button */
+  UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
+  prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
+  DrawEdge32(hdc, &rect, prssed ? EDGE_SUNKEN : EDGE_RAISED, 
+	   BF_RECT | BF_SOFT | BF_MIDDLE);
+  UPDOWN_DrawArrow(hdc, &rect, TRUE, prssed, wndPtr->dwStyle & UDS_HORZ);
+		    
+  /* Draw the decr button */
+  UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
+  prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
+  DrawEdge32(hdc, &rect, prssed ? EDGE_SUNKEN : EDGE_RAISED, 
+	   BF_RECT | BF_SOFT | BF_MIDDLE);
+  UPDOWN_DrawArrow(hdc, &rect, FALSE, prssed, wndPtr->dwStyle & UDS_HORZ);
+
+  /* clean-up */  
+  SelectObject32(hdc, oldBrush);
+  EndPaint32( wndPtr->hwndSelf, &ps );
+}
+
+/***********************************************************************
+ *           UPDOWN_SetBuddy
+ * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
+ * Else, sets it as a new Buddy.
+ * Then, it should subclass the buddy 
+ * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
+ * process the UP/DOWN arrow keys.
+ * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
+ * the size/pos of the buddy and the control are adjusted accordingly.
+ */
+static BOOL32 UPDOWN_SetBuddy(WND *wndPtr, HWND32 hwndBud)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr); 
+  RECT32 budRect; /* new coord for the buddy */
+  int x;          /* new x position and width for the up-down */
+ 	  
+  /* Is is a valid bud? */
+  if(!IsWindow32(hwndBud))
+    return FALSE;
+
+  if(wndPtr->dwStyle & UDS_ARROWKEYS){
+    /* FIXME: we need to subclass the buddy to process the arrow keys. */
+    fprintf(stderr, "UpDown Ctrl: we should subclass the buddy window!\n");
+  }
+
+  /* do we need to do any adjustments? */
+  if(!(wndPtr->dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
+    return TRUE;
+
+  /* Get the rect of the buddy relative to its parent */
+  GetWindowRect32(infoPtr->Buddy, &budRect);
+  MapWindowPoints32(HWND_DESKTOP, GetParent32(infoPtr->Buddy),
+		  (POINT32 *)(&budRect.left), 2);
+	  
+  /* now do the positioning */
+  if(wndPtr->dwStyle & UDS_ALIGNRIGHT){
+    budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
+    x  = budRect.right+DEFAULT_XSEP;
+  }
+  else{ /* UDS_ALIGNLEFT */
+    x  = budRect.left;
+    budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
+  }
+
+  /* first adjust the buddy to accomodate the up/down */
+  SetWindowPos32(infoPtr->Buddy, 0, budRect.left, budRect.top,
+	       budRect.right  - budRect.left, budRect.bottom - budRect.top, 
+	       SWP_NOACTIVATE|SWP_NOZORDER);
+
+  /* now position the up/down */
+  /* Since the UDS_ALIGN* flags were used, */
+  /* we will pick the position and size of the window. */
+  SetWindowPos32(wndPtr->hwndSelf,0,x,budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
+		 (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
+		 SWP_NOACTIVATE|SWP_NOZORDER); 
+
+  return TRUE;
+}	  
+
+/***********************************************************************
+ *           UPDOWN_DoAction
+ *
+ * This function increments/decrements the CurVal by the 
+ * 'delta' amount according to the 'incr' flag
+ * It notifies the parent as required.
+ * It handles wraping and non-wraping correctly.
+ * It is assumed that delta>0
+ */
+static void UPDOWN_DoAction(WND *wndPtr, int delta, BOOL32 incr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr); 
+  int old_val = infoPtr->CurVal;
+  NM_UPDOWN ni;
+
+  dprintf_updown(stddeb, "UpDown Ctrl action: %s by %d\n",
+		 incr ? "inc" : "dec", delta);
+
+  /* check if we can do the modification first */
+  delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
+  if(!UPDOWN_OffsetVal(wndPtr, delta))
+    return;
+
+  /* so, if we can do the change, recompute delta and restore old value */
+  delta = infoPtr->CurVal - old_val;
+  infoPtr->CurVal = old_val;
+
+  /* We must notify parent now to obtain permission */
+  ni.iPos = infoPtr->CurVal;
+  ni.iDelta = delta;
+  ni.hdr.hwndFrom = wndPtr->hwndSelf;
+  ni.hdr.idFrom = wndPtr->wIDmenu;
+  ni.hdr.code = UDN_DELTAPOS; 
+  if(SendMessage32A(wndPtr->parent->hwndSelf, 
+		    WM_NOTIFY, wndPtr->wIDmenu, (LPARAM)&ni))
+    return; /* we are not allowed to change */
+  
+  /* Now adjust value with (maybe new) delta */
+  if(!UPDOWN_OffsetVal(wndPtr, ni.iDelta))
+    return;
+
+  /* Now take care about our buddy */
+  if(!IsWindow32(infoPtr->Buddy)) 
+    return; /* Nothing else to do */
+
+
+  if(wndPtr->dwStyle & UDS_SETBUDDYINT)
+    UPDOWN_SetBuddyInt(wndPtr);
+
+  /* Also, notify it */
+  /* FIXME: do we need to send the notification only if
+            we do not have the UDS_SETBUDDYINT style set? */
+  SendMessage32A(infoPtr->Buddy, 
+		 wndPtr->dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL, 
+		 MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
+		 wndPtr->hwndSelf);
+}
+
+/***********************************************************************
+ *           UPDOWN_IsEnabled
+ *
+ * Returns TRUE if it is enabled as well as its buddy (if any)
+ *         FALSE otherwise
+ */
+static BOOL32 UPDOWN_IsEnabled(WND *wndPtr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+
+  if(wndPtr->dwStyle & WS_DISABLED)
+    return FALSE;
+  return IsWindowEnabled32(infoPtr->Buddy);
+}
+
+/***********************************************************************
+ *           UPDOWN_CancelMode
+ *
+ * Deletes any timers, releases the mouse and does  redraw if necessary.
+ * If the control is not in "capture" mode, it does nothing.
+ * If the control was not in cancel mode, it returns FALSE. 
+ * If the control was in cancel mode, it returns TRUE.
+ */
+static BOOL32 UPDOWN_CancelMode(WND *wndPtr)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+ 
+  /* if not in 'capture' mode, do nothing */
+  if(!(infoPtr->Flags & FLAG_CLICKED))
+    return FALSE;
+
+  KillTimer32(wndPtr->hwndSelf, TIMERID1); /* kill all possible timers */
+  KillTimer32(wndPtr->hwndSelf, TIMERID2);
+  
+  if(GetCapture32() == wndPtr->hwndSelf)   /* let the mouse go         */
+    ReleaseCapture();          /* if we still have it      */  
+  
+  infoPtr->Flags = 0;          /* get rid of any flags     */
+  UPDOWN_Paint(wndPtr);        /* redraw the control just in case */
+  
+  return TRUE;
+}
+
+/***********************************************************************
+ *           UPDOWN_HandleMouseEvent
+ *
+ * Handle a mouse event for the updown.
+ * 'pt' is the location of the mouse event in client or
+ * windows coordinates. 
+ */
+static void UPDOWN_HandleMouseEvent(WND *wndPtr, UINT32 msg, POINT32 pt)
+{
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
+  RECT32 rect;
+  int temp;
+
+  switch(msg)
+    {
+    case WM_LBUTTONDOWN:  /* Initialise mouse tracking */
+      /* If we are already in the 'clicked' mode, then nothing to do */
+      if(infoPtr->Flags & FLAG_CLICKED)
+	return;
+
+      /* If the buddy is an edit, will set focus to it */
+      if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
+	SetFocus32(infoPtr->Buddy);
+
+      /* Now see which one is the 'active' arrow */
+      temp = UPDOWN_GetArrowFromPoint(wndPtr, &rect, pt);
+
+      /* Update the CurVal if necessary */
+      if(wndPtr->dwStyle & UDS_SETBUDDYINT)
+	UPDOWN_GetBuddyInt(wndPtr);
+	
+      /* Before we proceed, see if we can spin... */
+      if(!(wndPtr->dwStyle & UDS_WRAP))
+	if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
+	   (!temp && infoPtr->CurVal==infoPtr->MinVal))
+	  return;
+
+      /* Set up the correct flags */
+      infoPtr->Flags  = 0; 
+      infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
+      infoPtr->Flags |= FLAG_MOUSEIN;
+      
+      /* repaint the control */
+      UPDOWN_Paint(wndPtr);
+
+      /* process the click */
+      UPDOWN_DoAction(wndPtr, 1, infoPtr->Flags & FLAG_INCR);
+
+      /* now capture all mouse messages */
+      SetCapture32(wndPtr->hwndSelf);
+
+      /* and startup the first timer */
+      SetTimer32(wndPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0); 
+      break;
+
+    case WM_MOUSEMOVE:
+      /* If we are not in the 'clicked' mode, then nothing to do */
+      if(!(infoPtr->Flags & FLAG_CLICKED))
+	return;
+
+      /* save the flags to see if any got modified */
+      temp = infoPtr->Flags;
+
+      /* Now get the 'active' arrow rectangle */
+      if (infoPtr->Flags & FLAG_INCR)
+	UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
+      else
+	UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
+
+      /* Update the flags if we are in/out */
+      if(PtInRect32(&rect, pt))
+	infoPtr->Flags |=  FLAG_MOUSEIN;
+      else{
+	infoPtr->Flags &= ~FLAG_MOUSEIN;
+	if(accelIndex != -1) /* if we have accel info */
+	  accelIndex = 0;    /* reset it              */
+      }
+      /* If state changed, redraw the control */
+      if(temp != infoPtr->Flags)
+	UPDOWN_Paint(wndPtr);
+      break;
+
+      default:
+	fprintf(stderr, "UpDown: Impossible case in proc "
+		"UPDOWN_HandleMouseEvent");
+    }
+
+}
+
+/***********************************************************************
+ *           UpDownWndProc
+ */
+LRESULT WINAPI UpDownWindowProc(HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                                LPARAM lParam)
+{
+  WND *wndPtr = WIN_FindWndPtr(hwnd);
+  UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr); 
+  int temp;
+
+  switch(message)
+    {
+    case WM_CREATE:
+      /* initialize the info struct */
+      infoPtr->AccelCount=0; infoPtr->AccelVect=0; 
+      infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
+      infoPtr->Base  = 10; /* Default to base 10  */
+      infoPtr->Buddy = 0;  /* No buddy window yet */
+      infoPtr->Flags = 0;  /* And no flags        */
+
+      /* Do we pick the buddy win ourselves? */
+      if(wndPtr->dwStyle & UDS_AUTOBUDDY)
+	UPDOWN_SetBuddy(wndPtr, GetWindow32(wndPtr->hwndSelf, GW_HWNDPREV));
+	
+      dprintf_updown(stddeb, "UpDown Ctrl creation, hwnd=%04x\n", hwnd);
+      break;
+    
+    case WM_DESTROY:
+      if(infoPtr->AccelVect)
+	free(infoPtr->AccelVect);
+      dprintf_updown(stddeb, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
+      break;
+	
+    case WM_ENABLE:
+      if(wndPtr->dwStyle & WS_DISABLED)
+	UPDOWN_CancelMode(wndPtr);
+      UPDOWN_Paint(wndPtr);
+      break;
+
+    case WM_TIMER:
+      /* if initial timer, kill it and start the repeat timer */
+      if(wParam == TIMERID1){
+	KillTimer32(hwnd, TIMERID1);
+	/* if no accel info given, used default timer */
+	if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
+	  accelIndex = -1;
+	  temp = REPEAT_DELAY;
+	}
+	else{
+	  accelIndex = 0; /* otherwise, use it */
+	  temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
+	}
+	SetTimer32(hwnd, TIMERID2, temp, 0);
+      }
+
+      /* now, if the mouse is above us, do the thing...*/
+      if(infoPtr->Flags & FLAG_MOUSEIN){
+	temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
+	UPDOWN_DoAction(wndPtr, temp, infoPtr->Flags & FLAG_INCR);
+	
+	if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
+	  KillTimer32(hwnd, TIMERID2);
+	  accelIndex++; /* move to the next accel info */
+	  temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
+	  /* make sure we have at least 1ms intervals */
+	  SetTimer32(hwnd, TIMERID2, temp, 0);	    
+	}
+      }
+      break;
+
+    case WM_CANCELMODE:
+      UPDOWN_CancelMode(wndPtr);
+      break;
+
+    case WM_LBUTTONUP:
+      if(!UPDOWN_CancelMode(wndPtr))
+	break;
+      /*If we released the mouse and our buddy is an edit */
+      /* we must select all text in it.                   */
+      if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
+	SendMessage32A(infoPtr->Buddy, EM_SETSEL32, 0, MAKELONG(0, -1));
+      break;
+      
+    case WM_LBUTTONDOWN:
+    case WM_MOUSEMOVE:
+      if(UPDOWN_IsEnabled(wndPtr)){
+	POINT32 pt;
+	CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
+	UPDOWN_HandleMouseEvent( wndPtr, message, pt );
+      }
+    break;
+
+    case WM_KEYDOWN:
+      if((wndPtr->dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(wndPtr)){
+	switch(wParam){
+	case VK_UP:  
+	case VK_DOWN:
+	  UPDOWN_GetBuddyInt(wndPtr);
+	  UPDOWN_DoAction(wndPtr, 1, wParam==VK_UP);
+	  break;
+	}
+      }
+      break;
+      
+    case WM_PAINT:
+      UPDOWN_Paint(wndPtr);
+      break;
+    
+    case UDM_GETACCEL:
+      if (wParam==0 && lParam==0)    /*if both zero, */
+	return infoPtr->AccelCount;  /*just return the accel count*/
+      if (wParam || lParam){
+	UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
+	return 0;
+      }
+      temp = min(infoPtr->AccelCount, wParam);
+      memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
+      return temp;
+
+    case UDM_SETACCEL:
+      dprintf_updown(stddeb, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
+      if(infoPtr->AccelVect){
+	free(infoPtr->AccelVect);
+	infoPtr->AccelCount = 0;
+	infoPtr->AccelVect  = 0;
+      }
+      if(wParam==0)
+	return TRUE;
+      infoPtr->AccelVect = malloc(wParam*sizeof(UDACCEL));
+      if(infoPtr->AccelVect==0)
+	return FALSE;
+      memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
+      return TRUE;
+
+    case UDM_GETBASE:
+      if (wParam || lParam)
+	UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
+      return infoPtr->Base;
+
+    case UDM_SETBASE:
+      dprintf_updown(stddeb, "UpDown Ctrl new base(%d), hwnd=%04x\n", 
+		     wParam, hwnd);
+      if ( !(wParam==10 || wParam==16) || lParam)
+	UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
+      if (wParam==10 || wParam==16){
+	temp = infoPtr->Base;
+	infoPtr->Base = wParam;
+	return temp;       /* return the prev base */
+      }
+      break;
+
+    case UDM_GETBUDDY:
+      if (wParam || lParam)
+	UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
+      return infoPtr->Buddy;
+
+    case UDM_SETBUDDY:
+      if (lParam)
+	UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
+      temp = infoPtr->Buddy;
+      infoPtr->Buddy = wParam;
+      UPDOWN_SetBuddy(wndPtr, wParam);
+      dprintf_updown(stddeb, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n", 
+		     infoPtr->Buddy, hwnd);
+      return temp;
+
+    case UDM_GETPOS:
+      if (wParam || lParam)
+	UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
+      temp = UPDOWN_GetBuddyInt(wndPtr);
+      return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
+
+    case UDM_SETPOS:
+      if (wParam || HIWORD(lParam))
+	UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
+      temp = SLOWORD(lParam);
+      dprintf_updown(stddeb, "UpDown Ctrl new value(%d), hwnd=%04x\n",
+		     temp, hwnd);
+      if(!UPDOWN_InBounds(wndPtr, temp)){
+	if(temp < infoPtr->MinVal)  
+	  temp = infoPtr->MinVal;
+	if(temp > infoPtr->MaxVal)
+	  temp = infoPtr->MaxVal;
+      }
+      wParam = infoPtr->CurVal; /* save prev value   */
+      infoPtr->CurVal = temp;   /* set the new value */
+      if(wndPtr->dwStyle & UDS_SETBUDDYINT)
+	UPDOWN_SetBuddyInt(wndPtr);
+      return wParam;            /* return prev value */
+      
+    case UDM_GETRANGE:
+      if (wParam || lParam)
+	UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
+      return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
+
+    case UDM_SETRANGE:
+      if (wParam)
+	UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have:     */
+      infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
+      infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
+                                         /* |Max-Min| <= UD_MAXVAL        */
+      dprintf_updown(stddeb, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n", 
+		     infoPtr->MinVal, infoPtr->MaxVal, hwnd);
+      break;                             
+
+    default: 
+      if (message >= WM_USER) 
+	fprintf( stderr, "UpDown Ctrl: unknown msg %04x wp=%04x lp=%08lx\n", 
+		 message, wParam, lParam );
+      return DefWindowProc32A( hwnd, message, wParam, lParam ); 
+    } 
+
+    return 0;
+}
+
+/***********************************************************************
+ *           CreateUpDownControl  (COMCTL32.14)
+ */
+HWND32 WINAPI CreateUpDownControl( DWORD style, INT32 x, INT32 y,
+                                   INT32 cx, INT32 cy, HWND32 parent,
+                                   INT32 id, HINSTANCE32 inst, HWND32 buddy,
+                                   INT32 maxVal, INT32 minVal, INT32 curVal )
+{
+  HWND32 hUD = CreateWindow32A(UPDOWN_CLASS32A, 0, style, x, y, cx, cy,
+			       parent, id, inst, 0);
+  if(hUD){
+    SendMessage32A(hUD, UDM_SETBUDDY, buddy, 0);
+    SendMessage32A(hUD, UDM_SETRANGE, 0, MAKELONG(maxVal, minVal));
+    SendMessage32A(hUD, UDM_SETPOS, 0, MAKELONG(curVal, 0));     
+  }
+
+  return hUD;
+}
diff --git a/controls/widgets.c b/controls/widgets.c
index 20fe5a5..c8b9990 100644
--- a/controls/widgets.c
+++ b/controls/widgets.c
@@ -12,6 +12,7 @@
 #include "static.h"
 #include "status.h"
 #include "scroll.h"
+#include "updown.h"
 #include "desktop.h"
 #include "mdi.h"
 #include "gdi.h"
@@ -20,18 +21,18 @@
 
 /* Window procedures */
 
-extern LRESULT EditWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                            LPARAM lParam );
-extern LRESULT ComboWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                             LPARAM lParam );
-extern LRESULT ComboLBWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                               LPARAM lParam );
-extern LRESULT ListBoxWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                               LPARAM lParam );
-extern LRESULT PopupMenuWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                                 LPARAM lParam );
-extern LRESULT IconTitleWndProc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-				 LPARAM lParam );
+extern LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg,
+                                   WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI ComboWndProc( HWND32 hwnd, UINT32 msg,
+                                    WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI ComboLBWndProc( HWND32 hwnd, UINT32 msg,
+                                      WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI ListBoxWndProc( HWND32 hwnd, UINT32 msg,
+                                      WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI PopupMenuWndProc( HWND32 hwnd, UINT32 msg,
+                                        WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI IconTitleWndProc( HWND32 hwnd, UINT32 msg,
+                                        WPARAM32 wParam, LPARAM lParam );
 
 /* Win16 class info */
 
@@ -102,6 +103,8 @@
 {
     { CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW, StatusWindowProc, 0,
       sizeof(STATUSWINDOWINFO), 0, 0, 0, 0, 0, STATUSCLASSNAME32A },
+    { CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW, UpDownWindowProc, 0,
+      sizeof(UPDOWN_INFO), 0, 0, 0, 0, 0, UPDOWN_CLASS32A }
 };
 
 #define NB_COMMON_CONTROLS32 \
@@ -160,7 +163,7 @@
 /***********************************************************************
  *           InitCommonControls   (COMCTL32.15)
  */
-void InitCommonControls(void)
+void WINAPI InitCommonControls(void)
 {
     int i;
     char name[30];
diff --git a/debugger/dbg.y b/debugger/dbg.y
index cc6d35d..39541c1 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -504,8 +504,10 @@
 	    DEBUG_SilentBackTrace();
 	}
 
-	if( signal != SIGTRAP )
-	  {
+	if ((signal != SIGTRAP) ||
+            (dbg_exec_mode == EXEC_STEPI_OVER) ||
+            (dbg_exec_mode == EXEC_STEPI_INSTR))
+        {
 	    /* Show where we crashed */
 	    curr_frame = 0;
 	    DEBUG_PrintAddress( &addr, dbg_mode, TRUE );
@@ -515,7 +517,7 @@
 		DEBUG_Disasm( &addr, TRUE );
 		fprintf(stderr,"\n");
 	      }
-	  }
+        }
 
         ret_ok = 0;
         do
diff --git a/documentation/fonts b/documentation/fonts
index 00ef738..32ac06c 100644
--- a/documentation/fonts
+++ b/documentation/fonts
@@ -2,7 +2,7 @@
 How To Convert Windows Fonts
 ============================
 
-If you have access to Windows installation you should use 
+If you have access to a Windows installation you should use 
 fnt2bdf utility (found in the 'tools)' directory to convert
 bitmap fonts (VGASYS.FON, SSERIFE.FON, and SERIFE.FON) into 
 the format that X Window System can recognize. 
@@ -21,18 +21,21 @@
 	If you are already in X you should run 'xset fp rehash' 
         to make X server aware of the new fonts.
 
-Step 5. Edit wine.conf file to remove aliases for the fonts 
+Step 5. Edit WINE.CONF file to remove aliases for the fonts 
 	you've just installed.
 
-Wine can get by without these fonts but 'the look and feel'
-will be quite different. Also, some applications try to load
-their custom fonts on the fly (WinWord 6.0) and since Wine does
+WINE can get by without these fonts but 'the look and feel'
+may be quite different. Also, some applications try to load
+their custom fonts on the fly (WinWord 6.0) and since WINE does
 not implement this yet it instead prints out something like;
 
-STUB: AddFontResource( somefile.FON )
+STUB: AddFontResource( SOMEFILE.FON )
 
 You can convert this file too. Note that .FON file may not hold 
-any bitmap fonts and fnt2bdf will fail if this is the case.
+any bitmap fonts and fnt2bdf will fail if this is the case. Also
+note that although the above message will not disappear WINE will
+work around the problem by using the font you extracted from the
+SOMEFILE.FON.
 
 What to do with TrueType fonts? There are several commercial
 font tools that can convert them to the Type1 format but the 
@@ -44,53 +47,75 @@
 via FreeType renderer in the future (hint, hint :-)
 
 
-WINE.CONF And Font Mapper
-=========================
+How To Add Font Aliases To WINE.CONF
+====================================
 
 Many Windows applications assume that fonts included in original Windows 3.1 
-distribution (Arial, Times New Roman, MS Sans Serif, etc.) are always present. 
-In order to make font mapper choose a closely related font you can add aliases
-to the [fonts] section.
+distribution are always present. By default Wine creates a number of aliases
+that map them on the existing X fonts:
+
+Windows font		...is mapped to...	X font
+
+"MS Sans Serif"			->		"-adobe-helvetica-"
+"MS Serif"			->		"-bitstream-charter-"
+"Times New Roman"		->		"-adobe-times-"
+"Arial"				->		"-adobe-helvetica-"
+
+There is no default alias for the "System" font. Also, no aliases are 
+created for the fonts that applications install at runtime. The recommended 
+way to deal with this problem is to convert the missing font (see above). 
+If it proves impossible, like in the case with TrueType fonts, you can force 
+the font mapper to choose a closely related X font by adding an alias to the 
+[fonts] section. Make sure that the X font actually exists (with xfontsel
+tool).
 
 AliasN = [Windows font], [X font] <, optional "mask X font" flag>
 
 Example:
 
-Alias0 = System, --international-, mask
-Alias1 = Arial, -adobe-helvetica-
-Alias2 = Times New Roman, -adobe-times-
+Alias0 = System, --international-, subst
+Alias1 = ...
 ...
 
 Comments:
-    There must be no gaps in the sequence {0, ..., N} otherwise all aliases
+*   There must be no gaps in the sequence {0, ..., N} otherwise all aliases
     after the first gap won't be read.
 
-    Usually font mapper translates X font names into font names visible to
+*   Usually font mapper translates X font names into font names visible to
     Windows programs in the following fashion:
 
-    X font			Converted name
+    X font		...will show up as...		Extracted name
 
-    -adobe-helvetica-...	"Helvetica"
-    -adobe-utopia-...		"Utopia"
-    -misc-fixed-...		"Fixed"
+    --international-...		->			"International"
+    -adobe-helvetica-...	->			"Helvetica"
+    -adobe-utopia-...		->			"Utopia"
+    -misc-fixed-...		->			"Fixed"
     -...
-    -sony-fixed-...		"Sony Fixed"  (already have "Fixed")
+    -sony-fixed-...		->			"Sony Fixed" 
     -...
 
-    Only converted names appear in the font selection dialogs. However, 
-    if there is an alias with the "mask" flag set converted name will be 
-    replaced by this alias.
+    Note that since -misc-fixed- and -sony-fixed- are different fonts
+    Wine modified the second extracted name to make sure Windows programs
+    can distinguish them because only extracted names appear in the font 
+    selection dialogs. 
+ 
+*   "Masking" alias replaces the original extracted name so that in the 
+    example case we will have the following mapping:
 
-    --international-		"System"
+    --international-		->			"System"
 
-    Nonmasking aliases are translated only when program asks for a font
-    with the name that matches an alias.
+    "Nonmasking" aliases are transparent to the user and they do not 
+    replace extracted names.
 
-    If you do not have an access to Windows fonts mentioned in the first 
-    paragraph you should try to substitute them with similar X fonts.
+    Wine discards an alias when it sees that the native X font is
+    available.
+
+*   If you do not have access to Windows fonts mentioned in the first 
+    paragraph you should try to substitute the "System" font with 
+    nonmasking alias. 'xfontsel' will show you the fonts available to
+    X.
 
     Alias.. = System, ...bold font without serifs
-    Alias.. = MS Sans Serif, ...helvetica-like font
 
 Also, some Windows applications request fonts without specifying the 
 typeface name of the font. Font table starts with Arial in most Windows 
@@ -106,15 +131,16 @@
     It is better to have a scalable font family (bolds and italics included) 
     as the default choice because mapper checks all available fonts until 
     requested height and other attributes match perfectly or the end of the 
-    font table is reached.
+    font table is reached. Typical X installations have scalable fonts in
+    the ../fonts/Type1 and ../fonts/Speedo directories.
 
 
-Cached Font Metrics
-===================
+How To Manage Cached Font Metrics
+=================================
 
 WINE stores detailed information about available fonts in the ~/.wine/.cachedmetrics
 file. You can copy it elsewhere and add this entry to the [fonts] section 
-in the WINE.CONF:
+in your WINE.CONF:
 
 FontMetrics = <file with metrics>
 
@@ -122,3 +148,27 @@
 metrics from scratch and then it will overwrite ~/.wine/.cachedmetrics with 
 the new information. This process can take a while.
 
+
+Too Small Or Too Large Fonts
+============================
+
+Windows programs may ask WINE to render a font with the height specified
+in points. However, point-to-pixel ratio depends on the real physical size 
+of your display (15", 17", etc...). X tries to provide an estimate of that 
+but it can be quite different from the actual size. You can change this
+ratio by adding the following entry to the [fonts] section:
+
+Resolution = <integer value>
+
+In general, higher numbers give you larger fonts. Try to experiment with
+values in the 60 - 120 range. 96 is a good starting point.
+
+
+"FONT_Init: failed to load ..." Messages On Startup
+===================================================
+
+The most likely cause is a broken fonts.dir file in one of your font
+directories. You need to rerun 'mkfontdir' to rebuild this file. Read
+its manpage for more information.
+
+
diff --git a/documentation/wine.texinfo b/documentation/wine.texinfo
index a530871..1395c61 100644
--- a/documentation/wine.texinfo
+++ b/documentation/wine.texinfo
@@ -45,12 +45,14 @@
 
 @sp 4
 FIXME: UNIX and POSIX trademarks. @*
-DOS @*
 X11 @*
-MS-Windows, Windows-NT, Windows 95 are registered trademarks of
-Microsoft Corp. Postscript is a registered trademark of Adobe Systems
-Inc. All other product names mentioned herein are the trademarks of
-their respective owners.
+Microsoft, Windows, MS-Windows, Windows-NT, Windows 95, and MS-DOS are
+registered trademarks of Microsoft Corporation.
+NT is a trademark of Northern Telecom Limited.
+C++Builder is a trademark of Borland International, Inc.
+Postscript is a registered trademark of Adobe Systems Inc.
+Other trademarks are the property of their respective owners, which may
+be registered in certain jurisdictions.
 @end ifinfo
 
 @c begin chapters on right pages
@@ -60,7 +62,7 @@
 @sp 10
 
 @center @titlefont{The Wine Reference Manual}
-@center Edition 0.0.2, 21 July 1997
+@center Edition 0.0.3, 14 August 1997
 
 
 @c The following two commands start the copyright page.
@@ -81,10 +83,14 @@
 
 @sp 4
 FIXME: UNIX and POSIX trademarks. @*
-MS-Windows, Windows-NT, Windows 95 are registered trademarks of
-Microsoft Corp. Postscript is a registered trademark of Adobe Systems
-Inc. All other product names mentioned herein are the trademarks of
-their respective owners.
+X11 @*
+Microsoft, Windows, MS-Windows, Windows-NT, Windows 95, and MS-DOS are
+registered trademarks of Microsoft Corporation.
+NT is a trademark of Northern Telecom Limited.
+C++Builder is a trademark of Borland International, Inc.
+Postscript is a registered trademark of Adobe Systems Inc.
+Other trademarks are the property of their respective owners, which may
+be registered in certain jurisdictions.
 @end titlepage
 
 
@@ -95,12 +101,12 @@
 
 @c Edit this macro manually in the above parts of the document
 @macro winemanualversion
-0.0.2
+0.0.3
 @end macro
 
 @c Edit this macro manually in the above parts of the document
 @macro winemanualdate
-21 July 1997
+14 August 1997
 @end macro
 
 @c Edit this macro manually into the TeX titlepage
@@ -136,6 +142,11 @@
 @end macro
 
 @c FIXME: automatical trademark reference
+@macro WINNT40
+Windows NT 4.0
+@end macro
+
+@c FIXME: automatical trademark reference
 @macro WIN95
 Windows 95
 @end macro
@@ -409,12 +420,12 @@
 @file{RELEASE-NOTES}, @file{BUGS}, @file{LICENSE}, and @file{WARRANTY},
 in the root directory of the Wine distribution.
 
-The Wine FAQ, available from
-@url{ftp://ftp.asgardpro.com/wine/dave/Wine.FAQ},
-@url{ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/Wine.FAQ},
-@url{ftp://rtfm.mit.edu/pub/usenet-by-group/comp.emulators.ms-windows.wine/WINE_(WINdows_Emulator)_Frequently_Asked_Questions},
-@url{ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/Wine.FAQ},
-@url{http://www.asgardpro.com/wine/index.html},
+The Wine FAQ, available from @*
+@url{ftp://ftp.asgardpro.com/wine/dave/Wine.FAQ}, @*
+@url{ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/Wine.FAQ}, @*
+@url{ftp://rtfm.mit.edu/pub/usenet-by-group/comp.emulators.ms-windows.wine/WINE_(WINdows_Emulator)_Frequently_Asked_Questions}, @*
+@url{ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/Wine.FAQ}, @*
+@url{http://www.asgardpro.com/wine/index.html}, @*
 gives answer to a lot of questions.
 
 The Wine USENET newsgroup is interesting for developers. It discusses technical
@@ -702,8 +713,10 @@
 The file is a directory. (Wine value: 0x0010).
 @end defvr
 @defvr_cw32 FILE_ATTRIBUTE_ARCHIVE
-The file is an archive file. All non-directory files are reported by Wine 
-to have this attribute. (Wine value: 0x0020).
+The file is an archive file. Currently, all non-directory files are
+reported by Wine to have this attribute. This attribute is normally set
+by @mswindows{} to indicate that a file is to be archived; when the file
+is archived, the flag is cleared. (Wine value: 0x0020).
 @end defvr
 @defvr_cw32 FILE_ATTRIBUTE_NORMAL
 The file does not have any other attributes set. This value must be used
@@ -948,7 +961,21 @@
 name is the common usage, some program parts (notably DLL's themselves)
 sometimes refer to DLL entries by ordinal. Therefore, the ordinals
 cannot be chosen arbitrarily.
-@* FIXME: is that correct?
+
+Regular programs that are compiled and linked against @mswindows{} DLL's
+will import DLL functions by name. This is therefore the default
+behaviour. Most DLL functions will be imported by name in all cases.
+Apparently, the @WIN32{} DLL's even show some difference in the mapping
+of functions and ordinals on @WINNT{} and @WIN95{}. For most DLL
+functions, the ordinal number will not matter.
+
+There are some exceptions to that. Notable the KERNEL32 ordinals below
+100 are (presently) unnamed and undocumented functions which can only be
+imported by ordinal. These functions are called by some @mswindows{}
+programs. Also the @file{shell32.dll} functions are reported to be
+imported by ordinal in some other DLL's.
+
+@xref{Getting information on the API}, for sources of further information.
 
 @node Spec file header, Variable entry points, Ordinals, The spec files
 @subsubsection The header of a @file{.spec}-file
@@ -1034,7 +1061,8 @@
 @item register
 A function using CPU registers to pass arguments.
 @item stdcall
-A normal @WIN32{} function.
+A normal @WIN32{} function. @xref{Investigating the undocumented API},
+for an explanation of the stdcall calling convention.
 @item cdecl
 A @WIN32{} function using the C calling conventions. (This is presently
 only used for the built-in functions of the C runtime system).
@@ -1097,6 +1125,9 @@
 See the @code{wsprintf}* functions in @file{user.spec} and 
 @file{user32.spec} for an example.
 
+Sometimes it is not known how many arguments an undocumented DLL
+function takes. @xref{Getting information on the API}, for some hints on
+how to proceed in such a case.
 
 @node Special entries, , Function entry points, The spec files
 @subsubsection Special entries of @file{.spec}-files
@@ -1132,8 +1163,10 @@
 
 @var{ORDINAL} is replaced by the ordinal number corresponding to the
 function. @var{ARGLENGTH} is the number of bytes that need to be removed
-from the stack before returning to the caller. @var{RETVALUE} is the
-return value which will be passed back to the caller.
+from the stack before returning to the caller. @xref{Investigating the
+undocumented API}, for an explanation of the stdcall calling convention.
+@var{RETVALUE} is the return value which will be passed back to the
+caller.
 
 @strong{Extern ordinals}
 
@@ -1182,6 +1215,10 @@
 some suggestions. 
 
 @menu
+* Getting information on the API::      Official and unofficial sources
+                                        of information on the @WIN32{} API.
+* Investigating the undocumented API::  You can find out some API
+                                        information on your own.
 * Implementing an API type::            How to implement a data type
                                         of the API (a checklist).
 * Implementing an API function::        How to implement one function
@@ -1198,9 +1235,268 @@
 @xref{Debugging}, for advice on how to debug Wine.
 @xref{Applying patches}, for instructions on applying patches.
 
-FIXME: what is most urgently needed
 
-@node Implementing an API type, Implementing an API function, , The Wine Project
+@node Getting information on the API, Investigating the undocumented API, , The Wine Project
+@section Official and unofficial documentation on the @mswindows{} API
+@cindex documentation of API functions
+@cindex undocumented API functions
+
+
+@strong{Official documentation}
+
+For documentation on @WIN32{} API functions, you might try one of these
+sources:
+
+@itemize @bullet
+
+@item
+There is a free online version of the MSDN library (including
+documentation for the @WIN32{} API) on
+@url{http://www.microsoft.com/msdn/}.
+
+@item 
+The @WINNT{} DDK gives information about some kernel (``executive'')
+routines. Some of the function documentation might also apply to user
+accessible DLL's.
+@end itemize
+
+@strong{Unofficial documentation}
+
+Not all of the @WIN32{} API is well documented. Some functions are
+obscured, and undocumented. @xref{Ordinals}, for information about
+undocumented functions imported by ordinal. Getting to know what these
+functions do can be tiresome and tedious. Here is a quote from a
+news posting concerning two books that might help:
+@c From: vischne@ibm.net-nospam (root)
+@c Subject: Re: Functions
+@c Newsgroups: comp.emulators.ms-windows.wine
+@c Date: 24 Jul 97 16:45:11 GMT
+@c Organization: The Light
+@c NNTP-Posting-Host: 129.37.246.203
+@c Message-ID: <33d78697.0@news3.ibm.net>
+
+@quotation
+Well actually, there are at least _two_ books that address these problems.
+One is by Matt Pietrek, ``Windows 95 System Programming Secrets'', which
+gives some auxiliary programs for helping ferret out the information, and
+the other is by Shulman, ``Undocumented Windows 95''.
+@end quotation
+
+@xref{Ordinals}, for some notes on undocumented kernel functions.
+
+@itemize @bullet
+
+@item
+@cindex book on undocumented API features by Pietrik
+``Windows 95 System Programming Secrets'' @*
+by Matt Pietrek @*
+Book & Disk Edition @*
+Paperback, 778 pages @*
+Published by IDG Books Worldwide @*
+Publication date: November 1, 1995 @*
+Dimensions (in inches): 9.25 x 7.42 x 2.06 @*
+ISBN: 1568843186 @*
+
+@item
+@cindex book on undocumented API features by Schulman
+``Undocumented Windows; A Programmers Guide
+to Reserved Microsoft Windows API Functions'' @*
+by Andrew Schulman @*
+Paperback, 715 pages @*
+Published by Addison-Wesley Pub Co @*
+Publication date: February 1, 1994 @*
+Dimensions (in inches): 9.11 x 7.37 x 1.53 @*
+ISBN: 0201608340  @*
+
+@item
+More books on these topics (including Schulman and Pietrik): @*
+@url{http://www.sonic.net/~undoc/bookstore.html}
+
+@item
+More details about calling undocumented functions can be found at
+@url{http://ftp.uni-mannheim.de/info/OReilly/windows/win95.update/dirty.html}.
+
+@item
+In 1993 Dr. Dobbs Journal published a column called ``Undocumented
+Corner''.
+@item
+You might want to check out BYTE from December 1983 as well.
+@* FIXME: is that to be taken seriously?
+@item
+And you might try to find out something on your own. @xref{Investigating
+the undocumented API}, for details.
+@end itemize
+
+But, all in all, @url{news:comp.emulators.ms-windows.wine} says
+@c From: dacut@henry.ece.cmu.edu (David A. Cuthbert)
+@c Subject: Re: Getting Internet Explorer to work
+@c Newsgroups: comp.emulators.ms-windows.wine
+@c Date: 24 Jul 1997 03:10:30 GMT
+@c Organization: Electrical & Computer Engineering, Carnegie Mellon University
+@c Reply-To: henry.ece.cmu.edu!dacut
+@c Message-ID: <5r6h36$86c@fs7.ece.cmu.edu>
+@c NNTP-Posting-Host: henry.ece.cmu.edu
+
+@quotation
+Unfortunately, short of getting something like NuMega's SoftIce, I
+don't think there's a ``good'' reference on the mystery <100 ordinals in
+KERNEL32.DLL.
+@end quotation
+
+
+@node Investigating the undocumented API, Implementing an API type, Getting information on the API, The Wine Project
+@section Investigating the undocumented API
+@cindex undocumented API investigation
+@cindex parameters of undocumented API functions
+@cindex stdcall calling convention
+@cindex C calling convention
+@cindex API function parameters investigation
+@cindex stack handling under stdcall calling
+
+Besides reading the documentation in @ref{Getting information on the API},
+you can find out some properties of API functions on your own.
+
+Sometimes it is not known how many arguments an undocumented DLL
+function takes. Here is a text from a news posting that gives some
+hints on how you might proceed in this case.
+
+@c The following text is closely quoted from:
+@c From: dacut@henry.ece.cmu.edu (David A. Cuthbert)
+@c Subject: Win32 stub functions (Claus Fischer, please read)
+@c Newsgroups: comp.emulators.ms-windows.wine
+@c Date: 7 Aug 1997 22:33:09 GMT
+@c Organization: Electrical & Computer Engineering, Carnegie Mellon University
+@c Reply-To: henry.ece.cmu.edu!dacut
+@c Message-ID: <5sdif5$qt3@fs7.ece.cmu.edu>
+
+The problem with implementing stubs for @WIN32{} functions is that it is
+not sufficient to return a default value (usually 0) and leave the
+stack the way we found it. For most @WIN32{} functions -- those that use
+the @dfn{stdcall} calling convention -- the arguments sent to the function
+are removed from the stack.
+
+Some background:  On the i386 class of machines, stack entries are
+usually dword (4 bytes) in size, little-endian.  The stack grows
+downward in memory.  The stack pointer, maintained in the @samp{esp}
+register, points to the last valid entry; thus, the operation of
+pushing a value onto the stack involves decrementing @samp{esp} and then
+moving the value into the memory pointed to by esp (i.e., @code{push p}
+in assembly resembles @code{*(--esp) = p;} in C).  Removing (popping)
+values off the stack is the reverse (i.e., @code{pop p} corresponds to
+@code{p = *(esp++);}).
+
+In the @dfn{stdcall} calling convention, arguments are pushed onto the
+stack right-to-left.  For example, the C call
+
+@example
+    myfunction(40, 20, 70, 30);
+@end example
+
+is expressed in Intel assembly as:
+
+@example
+    push 30
+    push 70
+    push 20
+    push 40
+    call myfunction
+@end example
+
+In addition, the called function is responsible for removing the
+arguments off the stack.  Thus, before the call to myfunction, the
+stack would look like:
+
+@example
+             [local variable or temporary]
+             [local variable or temporary]
+              30
+              70
+              20
+    esp ->    40
+@end example
+
+After the call returns, it should look like:
+
+@example
+             [local variable or temporary]
+    esp ->   [local variable or temporary]
+@end example
+
+To restore the stack to this state, the called function must know how
+many arguments to remove (which is the number of arguments it takes).
+This is a problem if the function is undocumented.
+
+One way to attempt to document the number of arguments each function
+takes is to create a wrapper around that function that detects the
+stack offset.  @file{WinRelay} (see below) was written to create such
+wrappers. Essentially, each wrapper assumes that the function will take
+a large number of arguments (by default, 64 in @file{WinRelay}).  The
+wrapper copies each of these arguments into its stack, calls the actual
+function, and then calculates the number of arguments by checking esp
+before and after the call.
+
+@cindex bsod (blue screen of death)
+@cindex blue screen of death
+The main problem with this scheme is that the function must actually
+be called from another program.  Many of these functions are seldom
+used.  An attempt was made to aggressively query each function in a
+given library (@file{ntdll.dll}) by passing 64 arguments, all 0, to each
+function.  Unfortunately, @WINNT40{} quickly goes to a blue screen
+of death (@dfn{bsod}), even if the program is run from a
+non-administrator account.
+
+Another method that has been much more successful is to attempt to
+figure out how many arguments each function is removing from the
+stack.  This instruction, @code{ret hhll} (where @samp{hhll} is the
+number of bytes to remove, i.e. the number of arguments times 4), contains
+the bytes @samp{0xc2 ll hh} in memory.  It is a reasonable assumption
+that few, if any, functions take more than 16 arguments; therefore,
+@samp{hh} is 0x0 and @samp{ll} is less than 0x40.  This utility,
+@file{MakeSpec} (see below), simply queries the address of a function
+and looks for the first occurrence of the bytes @samp{0xc2 ll 0x0},
+where @math{@samp{ll} <= 0x40}.
+
+Of course, this is not without errors. @code{ret 00ll} is not the only
+instruction that can have the byte sequence @samp{0xc2 ll 0x0}; for
+example, @code{push 0x000040c2} has the byte sequence
+@samp{0x68 0xc2 0x40 0x0 0x0}, which matches the above.  Properly, the
+utility should look for this sequence only on an instruction boundary;
+unfortunately, finding instruction boundaries on an i386 requires
+implementing a full disassemble -- quite a daunting task.  Besides,
+the probability of having such a byte sequence that is not the actual
+return instruction is fairly low.
+
+Much more troublesome is the non-linear flow of a function.  For
+example, consider the following two functions:
+
+@example
+    somefunction1:
+        jmp  somefunction1_impl
+
+    somefunction2:
+        ret  0004
+
+    somefunction1_impl:
+        ret  0008
+@end example
+
+@file{MakeSpec} would incorrectly list both @code{somefunction1} and
+@code{somefunction2} as taking only a single argument, whereas
+@code{somefunction1} really takes two arguments.
+
+With these limitations in mind, it is possible to implement more stubs
+in Wine and, eventually, the functions themselves.
+
+@c end of quote
+
+The program @file{WinRelay} can be downloaded from
+@url{http://www.ece.cmu.edu/afs/ece/usr/dacut/www/src},
+and @file{MakeSpec} will be available from the same location. You can
+compile them with Borland's C++Builder; you should not optimize when
+compiling (@file{WinRelay} needs the stack frames).
+
+
+@node Implementing an API type, Implementing an API function, Investigating the undocumented API, The Wine Project
 @section Implementing an API type
 
 Here is a checklist that should help you writing your first API type. It
@@ -1279,6 +1575,11 @@
 @xref{API function and type naming}, for details.
 
 @item
+Find out what the function should do. This may be tricky for
+undocumented functions. @xref{Getting information on the API}, for some
+hints.
+
+@item
 Find out where the function should go:
 @enumerate
 @item
diff --git a/files/directory.c b/files/directory.c
index 6bc5c45..ba6a2aa 100644
--- a/files/directory.c
+++ b/files/directory.c
@@ -179,7 +179,7 @@
 /***********************************************************************
  *           GetTempPath32A   (KERNEL32.292)
  */
-UINT32 GetTempPath32A( UINT32 count, LPSTR path )
+UINT32 WINAPI GetTempPath32A( UINT32 count, LPSTR path )
 {
     if (path) lstrcpyn32A( path, DIR_TempDosDir, count );
     return strlen( DIR_TempDosDir );
@@ -189,7 +189,7 @@
 /***********************************************************************
  *           GetTempPath32W   (KERNEL32.293)
  */
-UINT32 GetTempPath32W( UINT32 count, LPWSTR path )
+UINT32 WINAPI GetTempPath32W( UINT32 count, LPWSTR path )
 {
     if (path) lstrcpynAtoW( path, DIR_TempDosDir, count );
     return strlen( DIR_TempDosDir );
@@ -240,14 +240,14 @@
 /***********************************************************************
  *           GetTempDrive   (KERNEL.92)
  */
-BYTE GetTempDrive( BYTE ignored )
+BYTE WINAPI GetTempDrive( BYTE ignored )
 {
     /* FIXME: apparently Windows does something with the ignored byte */
     return DIR_TempDosDir[0];
 }
 
 
-UINT32 WIN16_GetTempDrive( BYTE ignored )
+UINT32 WINAPI WIN16_GetTempDrive( BYTE ignored )
 {
     /* A closer look at krnl386.exe shows what the SDK doesn't mention:
      *
@@ -264,7 +264,7 @@
 /***********************************************************************
  *           GetWindowsDirectory16   (KERNEL.134)
  */
-UINT16 GetWindowsDirectory16( LPSTR path, UINT16 count )
+UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
 {
     return (UINT16)GetWindowsDirectory32A( path, count );
 }
@@ -273,7 +273,7 @@
 /***********************************************************************
  *           GetWindowsDirectory32A   (KERNEL32.311)
  */
-UINT32 GetWindowsDirectory32A( LPSTR path, UINT32 count )
+UINT32 WINAPI GetWindowsDirectory32A( LPSTR path, UINT32 count )
 {
     if (path) lstrcpyn32A( path, DIR_WindowsDosDir, count );
     return strlen( DIR_WindowsDosDir );
@@ -283,7 +283,7 @@
 /***********************************************************************
  *           GetWindowsDirectory32W   (KERNEL32.312)
  */
-UINT32 GetWindowsDirectory32W( LPWSTR path, UINT32 count )
+UINT32 WINAPI GetWindowsDirectory32W( LPWSTR path, UINT32 count )
 {
     if (path) lstrcpynAtoW( path, DIR_WindowsDosDir, count );
     return strlen( DIR_WindowsDosDir );
@@ -293,7 +293,7 @@
 /***********************************************************************
  *           GetSystemDirectory16   (KERNEL.135)
  */
-UINT16 GetSystemDirectory16( LPSTR path, UINT16 count )
+UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
 {
     return (UINT16)GetSystemDirectory32A( path, count );
 }
@@ -302,7 +302,7 @@
 /***********************************************************************
  *           GetSystemDirectory32A   (KERNEL32.282)
  */
-UINT32 GetSystemDirectory32A( LPSTR path, UINT32 count )
+UINT32 WINAPI GetSystemDirectory32A( LPSTR path, UINT32 count )
 {
     if (path) lstrcpyn32A( path, DIR_SystemDosDir, count );
     return strlen( DIR_SystemDosDir );
@@ -312,7 +312,7 @@
 /***********************************************************************
  *           GetSystemDirectory32W   (KERNEL32.283)
  */
-UINT32 GetSystemDirectory32W( LPWSTR path, UINT32 count )
+UINT32 WINAPI GetSystemDirectory32W( LPWSTR path, UINT32 count )
 {
     if (path) lstrcpynAtoW( path, DIR_SystemDosDir, count );
     return strlen( DIR_SystemDosDir );
@@ -322,7 +322,7 @@
 /***********************************************************************
  *           CreateDirectory16   (KERNEL.144)
  */
-BOOL16 CreateDirectory16( LPCSTR path, LPVOID dummy )
+BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
 {
     dprintf_file( stddeb,"CreateDirectory16(%s,%p)\n", path, dummy );
     return (BOOL16)CreateDirectory32A( path, NULL );
@@ -332,7 +332,8 @@
 /***********************************************************************
  *           CreateDirectory32A   (KERNEL32.39)
  */
-BOOL32 CreateDirectory32A( LPCSTR path, LPSECURITY_ATTRIBUTES lpsecattribs )
+BOOL32 WINAPI CreateDirectory32A( LPCSTR path,
+                                  LPSECURITY_ATTRIBUTES lpsecattribs )
 {
     DOS_FULL_NAME full_name;
     LPCSTR unixName;
@@ -357,7 +358,8 @@
 /***********************************************************************
  *           CreateDirectory32W   (KERNEL32.42)
  */
-BOOL32 CreateDirectory32W( LPCWSTR path, LPSECURITY_ATTRIBUTES lpsecattribs )
+BOOL32 WINAPI CreateDirectory32W( LPCWSTR path,
+                                  LPSECURITY_ATTRIBUTES lpsecattribs )
 {
     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
     BOOL32 ret = CreateDirectory32A( xpath, lpsecattribs );
@@ -369,8 +371,8 @@
 /***********************************************************************
  *           CreateDirectoryEx32A   (KERNEL32.40)
  */
-BOOL32 CreateDirectoryEx32A( LPCSTR template, LPCSTR path,
-                             LPSECURITY_ATTRIBUTES lpsecattribs)
+BOOL32 WINAPI CreateDirectoryEx32A( LPCSTR template, LPCSTR path,
+                                    LPSECURITY_ATTRIBUTES lpsecattribs)
 {
     return CreateDirectory32A(path,lpsecattribs);
 }
@@ -379,8 +381,8 @@
 /***********************************************************************
  *           CreateDirectoryEx32W   (KERNEL32.41)
  */
-BOOL32 CreateDirectoryEx32W( LPCWSTR template, LPCWSTR path,
-                             LPSECURITY_ATTRIBUTES lpsecattribs)
+BOOL32 WINAPI CreateDirectoryEx32W( LPCWSTR template, LPCWSTR path,
+                                    LPSECURITY_ATTRIBUTES lpsecattribs)
 {
     return CreateDirectory32W(path,lpsecattribs);
 }
@@ -389,7 +391,7 @@
 /***********************************************************************
  *           RemoveDirectory16   (KERNEL)
  */
-BOOL16 RemoveDirectory16( LPCSTR path )
+BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
 {
     return (BOOL16)RemoveDirectory32A( path );
 }
@@ -398,7 +400,7 @@
 /***********************************************************************
  *           RemoveDirectory32A   (KERNEL32.437)
  */
-BOOL32 RemoveDirectory32A( LPCSTR path )
+BOOL32 WINAPI RemoveDirectory32A( LPCSTR path )
 {
     DOS_FULL_NAME full_name;
     LPCSTR unixName;
@@ -424,7 +426,7 @@
 /***********************************************************************
  *           RemoveDirectory32W   (KERNEL32.438)
  */
-BOOL32 RemoveDirectory32W( LPCWSTR path )
+BOOL32 WINAPI RemoveDirectory32W( LPCWSTR path )
 {
     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
     BOOL32 ret = RemoveDirectory32A( xpath );
@@ -583,8 +585,8 @@
 /***********************************************************************
  *           SearchPath32A   (KERNEL32.447)
  */
-DWORD SearchPath32A( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
-                     LPSTR buffer, LPSTR *lastpart )
+DWORD WINAPI SearchPath32A( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
+                            LPSTR buffer, LPSTR *lastpart )
 {
     LPSTR p, res;
     DOS_FULL_NAME full_name;
@@ -604,8 +606,8 @@
 /***********************************************************************
  *           SearchPath32W   (KERNEL32.448)
  */
-DWORD SearchPath32W( LPCWSTR path, LPCWSTR name, LPCWSTR ext, DWORD buflen,
-                     LPWSTR buffer, LPWSTR *lastpart )
+DWORD WINAPI SearchPath32W( LPCWSTR path, LPCWSTR name, LPCWSTR ext,
+                            DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
 {
     LPWSTR p;
     LPSTR res;
diff --git a/files/dos_fs.c b/files/dos_fs.c
index 014b41e..74f6cf2 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -764,7 +764,8 @@
 /***********************************************************************
  *           GetShortPathName32A   (KERNEL32.271)
  */
-DWORD GetShortPathName32A( LPCSTR longpath, LPSTR shortpath, DWORD shortlen )
+DWORD WINAPI GetShortPathName32A( LPCSTR longpath, LPSTR shortpath,
+                                  DWORD shortlen )
 {
     DOS_FULL_NAME full_name;
 
@@ -778,7 +779,8 @@
 /***********************************************************************
  *           GetShortPathName32W   (KERNEL32.272)
  */
-DWORD GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
+DWORD WINAPI GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath,
+                                  DWORD shortlen )
 {
     DOS_FULL_NAME full_name;
     DWORD ret = 0;
@@ -877,7 +879,8 @@
 /***********************************************************************
  *           GetFullPathName32A   (KERNEL32.272)
  */
-DWORD GetFullPathName32A(LPCSTR name, DWORD len, LPSTR buffer, LPSTR *lastpart)
+DWORD WINAPI GetFullPathName32A( LPCSTR name, DWORD len, LPSTR buffer,
+                                 LPSTR *lastpart )
 {
     DWORD ret = DOSFS_DoGetFullPathName( name, len, buffer, FALSE );
     if (ret && lastpart)
@@ -893,8 +896,8 @@
 /***********************************************************************
  *           GetFullPathName32W   (KERNEL32.273)
  */
-DWORD GetFullPathName32W( LPCWSTR name, DWORD len, LPWSTR buffer,
-                          LPWSTR *lastpart )
+DWORD WINAPI GetFullPathName32W( LPCWSTR name, DWORD len, LPWSTR buffer,
+                                 LPWSTR *lastpart )
 {
     LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     DWORD ret = DOSFS_DoGetFullPathName( nameA, len, (LPSTR)buffer, TRUE );
@@ -1044,7 +1047,7 @@
 /*************************************************************************
  *           FindFirstFile16   (KERNEL.413)
  */
-HANDLE16 FindFirstFile16( LPCSTR path, WIN32_FIND_DATA32A *data )
+HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATA32A *data )
 {
     DOS_FULL_NAME full_name;
     HGLOBAL16 handle;
@@ -1076,7 +1079,7 @@
 /*************************************************************************
  *           FindFirstFile32A   (KERNEL32.123)
  */
-HANDLE32 FindFirstFile32A( LPCSTR path, WIN32_FIND_DATA32A *data )
+HANDLE32 WINAPI FindFirstFile32A( LPCSTR path, WIN32_FIND_DATA32A *data )
 {
     HANDLE32 handle = FindFirstFile16( path, data );
     if (handle == INVALID_HANDLE_VALUE16) return INVALID_HANDLE_VALUE32;
@@ -1087,7 +1090,7 @@
 /*************************************************************************
  *           FindFirstFile32W   (KERNEL32.124)
  */
-HANDLE32 FindFirstFile32W( LPCWSTR path, WIN32_FIND_DATA32W *data )
+HANDLE32 WINAPI FindFirstFile32W( LPCWSTR path, WIN32_FIND_DATA32W *data )
 {
     WIN32_FIND_DATA32A dataA;
     LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
@@ -1111,7 +1114,7 @@
 /*************************************************************************
  *           FindNextFile16   (KERNEL.414)
  */
-BOOL16 FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data )
+BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data )
 {
     FIND_FIRST_INFO *info;
     int count;
@@ -1143,7 +1146,7 @@
 /*************************************************************************
  *           FindNextFile32A   (KERNEL32.126)
  */
-BOOL32 FindNextFile32A( HANDLE32 handle, WIN32_FIND_DATA32A *data )
+BOOL32 WINAPI FindNextFile32A( HANDLE32 handle, WIN32_FIND_DATA32A *data )
 {
     return FindNextFile16( handle, data );
 }
@@ -1152,7 +1155,7 @@
 /*************************************************************************
  *           FindNextFile32W   (KERNEL32.127)
  */
-BOOL32 FindNextFile32W( HANDLE32 handle, WIN32_FIND_DATA32W *data )
+BOOL32 WINAPI FindNextFile32W( HANDLE32 handle, WIN32_FIND_DATA32W *data )
 {
     WIN32_FIND_DATA32A dataA;
     if (!FindNextFile32A( handle, &dataA )) return FALSE;
@@ -1171,7 +1174,7 @@
 /*************************************************************************
  *           FindClose16   (KERNEL.415)
  */
-BOOL16 FindClose16( HANDLE16 handle )
+BOOL16 WINAPI FindClose16( HANDLE16 handle )
 {
     FIND_FIRST_INFO *info;
 
@@ -1191,7 +1194,7 @@
 /*************************************************************************
  *           FindClose32   (KERNEL32.119)
  */
-BOOL32 FindClose32( HANDLE32 handle )
+BOOL32 WINAPI FindClose32( HANDLE32 handle )
 {
     return FindClose16( (HANDLE16)handle );
 }
@@ -1419,7 +1422,7 @@
 /***********************************************************************
  *           DosDateTimeToFileTime   (KERNEL32.76)
  */
-BOOL32 DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft )
+BOOL32 WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
 {
     struct tm newtm;
 
@@ -1437,8 +1440,8 @@
 /***********************************************************************
  *           FileTimeToDosDateTime   (KERNEL32.111)
  */
-BOOL32 FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
-                              LPWORD fattime )
+BOOL32 WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
+                                     LPWORD fattime )
 {
     time_t unixtime = DOSFS_FileTimeToUnixTime( ft, NULL );
     struct tm *tm = localtime( &unixtime );
@@ -1454,7 +1457,8 @@
 /***********************************************************************
  *           LocalFileTimeToFileTime   (KERNEL32.373)
  */
-BOOL32 LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
+BOOL32 WINAPI LocalFileTimeToFileTime( const FILETIME *localft,
+                                       LPFILETIME utcft )
 {
     struct tm *xtm;
     DWORD remainder;
@@ -1470,7 +1474,8 @@
 /***********************************************************************
  *           FileTimeToLocalFileTime   (KERNEL32.112)
  */
-BOOL32 FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
+BOOL32 WINAPI FileTimeToLocalFileTime( const FILETIME *utcft,
+                                       LPFILETIME localft )
 {
     struct tm *xtm;
     DWORD remainder;
@@ -1486,7 +1491,7 @@
 /***********************************************************************
  *           FileTimeToSystemTime   (KERNEL32.113)
  */
-BOOL32 FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
+BOOL32 WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
 {
     struct tm *xtm;
     DWORD remainder;
@@ -1508,8 +1513,7 @@
  *
  * returns array of strings terminated by \0, terminated by \0
  */
-DWORD
-QueryDosDevice32A(LPCSTR devname,LPSTR target,DWORD bufsize)
+DWORD WINAPI QueryDosDevice32A(LPCSTR devname,LPSTR target,DWORD bufsize)
 {
     LPSTR s;
     char  buffer[200];
@@ -1537,8 +1541,7 @@
  *
  * returns array of strings terminated by \0, terminated by \0
  */
-DWORD
-QueryDosDevice32W(LPCWSTR devname,LPWSTR target,DWORD bufsize)
+DWORD WINAPI QueryDosDevice32W(LPCWSTR devname,LPWSTR target,DWORD bufsize)
 {
     LPSTR devnameA = devname?HEAP_strdupWtoA(GetProcessHeap(),0,devname):NULL;
     LPSTR targetA = (LPSTR)HEAP_xalloc(GetProcessHeap(),0,bufsize);
@@ -1554,7 +1557,7 @@
 /***********************************************************************
  *           SystemTimeToFileTime   (KERNEL32.526)
  */
-BOOL32 SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
+BOOL32 WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
 {
     struct tm xtm;
 
diff --git a/files/drive.c b/files/drive.c
index c4a88de..cee484a 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -538,9 +538,9 @@
 /***********************************************************************
  *           GetDiskFreeSpace16   (KERNEL.422)
  */
-BOOL16 GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
-                           LPDWORD sector_bytes, LPDWORD free_clusters,
-                           LPDWORD total_clusters )
+BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
+                                  LPDWORD sector_bytes, LPDWORD free_clusters,
+                                  LPDWORD total_clusters )
 {
     return GetDiskFreeSpace32A( root, cluster_sectors, sector_bytes,
                                 free_clusters, total_clusters );
@@ -550,9 +550,9 @@
 /***********************************************************************
  *           GetDiskFreeSpace32A   (KERNEL32.206)
  */
-BOOL32 GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
-                            LPDWORD sector_bytes, LPDWORD free_clusters,
-                            LPDWORD total_clusters )
+BOOL32 WINAPI GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
+                                   LPDWORD sector_bytes, LPDWORD free_clusters,
+                                   LPDWORD total_clusters )
 {
     int	drive;
     DWORD size,available;
@@ -583,9 +583,9 @@
 /***********************************************************************
  *           GetDiskFreeSpace32W   (KERNEL32.207)
  */
-BOOL32 GetDiskFreeSpace32W( LPCWSTR root, LPDWORD cluster_sectors,
-                            LPDWORD sector_bytes, LPDWORD free_clusters,
-                            LPDWORD total_clusters )
+BOOL32 WINAPI GetDiskFreeSpace32W( LPCWSTR root, LPDWORD cluster_sectors,
+                                   LPDWORD sector_bytes, LPDWORD free_clusters,
+                                   LPDWORD total_clusters )
 {
     LPSTR xroot;
     BOOL32 ret;
@@ -601,7 +601,7 @@
 /***********************************************************************
  *           GetDriveType16   (KERNEL.136)
  */
-UINT16 GetDriveType16( UINT16 drive )
+UINT16 WINAPI GetDriveType16( UINT16 drive )
 {
     dprintf_dosfs( stddeb, "GetDriveType16(%c:)\n", 'A' + drive );
     switch(DRIVE_GetType(drive))
@@ -619,7 +619,7 @@
 /***********************************************************************
  *           GetDriveType32A   (KERNEL32.208)
  */
-UINT32 GetDriveType32A( LPCSTR root )
+UINT32 WINAPI GetDriveType32A( LPCSTR root )
 {
     dprintf_dosfs( stddeb, "GetDriveType32A(%s)\n", root );
     if (root[1] != ':')
@@ -642,7 +642,7 @@
 /***********************************************************************
  *           GetDriveType32W   (KERNEL32.209)
  */
-UINT32 GetDriveType32W( LPCWSTR root )
+UINT32 WINAPI GetDriveType32W( LPCWSTR root )
 {
     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
     UINT32 ret = GetDriveType32A( xpath );
@@ -654,7 +654,7 @@
 /***********************************************************************
  *           GetCurrentDirectory16   (KERNEL.411)
  */
-UINT16 GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
+UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
 {
     return (UINT16)GetCurrentDirectory32A( buflen, buf );
 }
@@ -665,7 +665,7 @@
  *
  * Returns "X:\\path\\etc\\".
  */
-UINT32 GetCurrentDirectory32A( UINT32 buflen, LPSTR buf )
+UINT32 WINAPI GetCurrentDirectory32A( UINT32 buflen, LPSTR buf )
 {
     char *pref = "A:\\";
     const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
@@ -684,7 +684,7 @@
 /***********************************************************************
  *           GetCurrentDirectory32W   (KERNEL32.197)
  */
-UINT32 GetCurrentDirectory32W( UINT32 buflen, LPWSTR buf )
+UINT32 WINAPI GetCurrentDirectory32W( UINT32 buflen, LPWSTR buf )
 {
     LPSTR xpath = HeapAlloc( GetProcessHeap(), 0, buflen+1 );
     UINT32 ret = GetCurrentDirectory32A( buflen, xpath );
@@ -697,7 +697,7 @@
 /***********************************************************************
  *           SetCurrentDirectory   (KERNEL.412)
  */
-BOOL16 SetCurrentDirectory16( LPCSTR dir )
+BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir )
 {
     return SetCurrentDirectory32A( dir );
 }
@@ -706,7 +706,7 @@
 /***********************************************************************
  *           SetCurrentDirectory32A   (KERNEL32.479)
  */
-BOOL32 SetCurrentDirectory32A( LPCSTR dir )
+BOOL32 WINAPI SetCurrentDirectory32A( LPCSTR dir )
 {
     int drive = DRIVE_GetCurrentDrive();
 
@@ -730,7 +730,7 @@
 /***********************************************************************
  *           SetCurrentDirectory32W   (KERNEL32.480)
  */
-BOOL32 SetCurrentDirectory32W( LPCWSTR dirW )
+BOOL32 WINAPI SetCurrentDirectory32W( LPCWSTR dirW )
 {
     LPSTR dir = HEAP_strdupWtoA( GetProcessHeap(), 0, dirW );
     BOOL32 res = SetCurrentDirectory32A( dir );
@@ -742,7 +742,7 @@
 /***********************************************************************
  *           GetLogicalDriveStrings32A   (KERNEL32.231)
  */
-UINT32 GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
+UINT32 WINAPI GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
 {
     int drive, count;
 
@@ -768,7 +768,7 @@
 /***********************************************************************
  *           GetLogicalDriveStrings32W   (KERNEL32.232)
  */
-UINT32 GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
+UINT32 WINAPI GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
 {
     int drive, count;
 
@@ -794,7 +794,7 @@
 /***********************************************************************
  *           GetLogicalDrives   (KERNEL32.233)
  */
-DWORD GetLogicalDrives(void)
+DWORD WINAPI GetLogicalDrives(void)
 {
     DWORD ret = 0;
     int drive;
@@ -808,9 +808,10 @@
 /***********************************************************************
  *           GetVolumeInformation32A   (KERNEL32.309)
  */
-BOOL32 GetVolumeInformation32A( LPCSTR root, LPSTR label, DWORD label_len,
-                                DWORD *serial, DWORD *filename_len,
-                                DWORD *flags, LPSTR fsname, DWORD fsname_len )
+BOOL32 WINAPI GetVolumeInformation32A( LPCSTR root, LPSTR label,
+                                       DWORD label_len, DWORD *serial,
+                                       DWORD *filename_len, DWORD *flags,
+                                       LPSTR fsname, DWORD fsname_len )
 {
     int drive;
 
@@ -843,9 +844,10 @@
 /***********************************************************************
  *           GetVolumeInformation32W   (KERNEL32.310)
  */
-BOOL32 GetVolumeInformation32W( LPCWSTR root, LPWSTR label, DWORD label_len,
-                                DWORD *serial, DWORD *filename_len,
-                                DWORD *flags, LPWSTR fsname, DWORD fsname_len)
+BOOL32 WINAPI GetVolumeInformation32W( LPCWSTR root, LPWSTR label,
+                                       DWORD label_len, DWORD *serial,
+                                       DWORD *filename_len, DWORD *flags,
+                                       LPWSTR fsname, DWORD fsname_len )
 {
     LPSTR xroot    = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
     LPSTR xvolname = label ? HeapAlloc(GetProcessHeap(),0,label_len) : NULL;
diff --git a/files/file.c b/files/file.c
index 742d518..540446a 100644
--- a/files/file.c
+++ b/files/file.c
@@ -376,8 +376,8 @@
 /***********************************************************************
  *             GetFileInformationByHandle   (KERNEL32.219)
  */
-DWORD GetFileInformationByHandle( HFILE32 hFile,
-                                  BY_HANDLE_FILE_INFORMATION *info )
+DWORD WINAPI GetFileInformationByHandle( HFILE32 hFile,
+                                         BY_HANDLE_FILE_INFORMATION *info )
 {
     FILE_OBJECT *file;
     DWORD ret = 0;
@@ -400,7 +400,7 @@
 /**************************************************************************
  *           GetFileAttributes16   (KERNEL.420)
  */
-DWORD GetFileAttributes16( LPCSTR name )
+DWORD WINAPI GetFileAttributes16( LPCSTR name )
 {
     return GetFileAttributes32A( name );
 }
@@ -409,7 +409,7 @@
 /**************************************************************************
  *           GetFileAttributes32A   (KERNEL32.217)
  */
-DWORD GetFileAttributes32A( LPCSTR name )
+DWORD WINAPI GetFileAttributes32A( LPCSTR name )
 {
     DOS_FULL_NAME full_name;
     BY_HANDLE_FILE_INFORMATION info;
@@ -425,7 +425,7 @@
 /**************************************************************************
  *           GetFileAttributes32W   (KERNEL32.218)
  */
-DWORD GetFileAttributes32W( LPCWSTR name )
+DWORD WINAPI GetFileAttributes32W( LPCWSTR name )
 {
     LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     DWORD res = GetFileAttributes32A( nameA );
@@ -437,7 +437,7 @@
 /***********************************************************************
  *           GetFileSize   (KERNEL32.220)
  */
-DWORD GetFileSize( HFILE32 hFile, LPDWORD filesizehigh )
+DWORD WINAPI GetFileSize( HFILE32 hFile, LPDWORD filesizehigh )
 {
     BY_HANDLE_FILE_INFORMATION info;
     if (!GetFileInformationByHandle( hFile, &info )) return 0;
@@ -449,8 +449,9 @@
 /***********************************************************************
  *           GetFileTime   (KERNEL32.221)
  */
-BOOL32 GetFileTime( HFILE32 hFile, FILETIME *lpCreationTime,
-                    FILETIME *lpLastAccessTime, FILETIME *lpLastWriteTime )
+BOOL32 WINAPI GetFileTime( HFILE32 hFile, FILETIME *lpCreationTime,
+                           FILETIME *lpLastAccessTime,
+                           FILETIME *lpLastWriteTime )
 {
     BY_HANDLE_FILE_INFORMATION info;
     if (!GetFileInformationByHandle( hFile, &info )) return FALSE;
@@ -463,7 +464,7 @@
 /***********************************************************************
  *           CompareFileTime   (KERNEL32.28)
  */
-INT32 CompareFileTime( LPFILETIME x, LPFILETIME y )
+INT32 WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
 {
         if (!x || !y) return -1;
 
@@ -517,8 +518,8 @@
 /***********************************************************************
  *           GetTempFileName16   (KERNEL.97)
  */
-UINT16 GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
-                          LPSTR buffer )
+UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
+                                 LPSTR buffer )
 {
     char temppath[144];
 
@@ -544,8 +545,8 @@
 /***********************************************************************
  *           GetTempFileName32A   (KERNEL32.290)
  */
-UINT32 GetTempFileName32A( LPCSTR path, LPCSTR prefix, UINT32 unique,
-                           LPSTR buffer)
+UINT32 WINAPI GetTempFileName32A( LPCSTR path, LPCSTR prefix, UINT32 unique,
+                                  LPSTR buffer)
 {
     DOS_FULL_NAME full_name;
     int i;
@@ -603,8 +604,8 @@
 /***********************************************************************
  *           GetTempFileName32W   (KERNEL32.291)
  */
-UINT32 GetTempFileName32W( LPCWSTR path, LPCWSTR prefix, UINT32 unique,
-                           LPWSTR buffer )
+UINT32 WINAPI GetTempFileName32W( LPCWSTR path, LPCWSTR prefix, UINT32 unique,
+                                  LPWSTR buffer )
 {
     LPSTR   patha,prefixa;
     char    buffera[144];
@@ -758,7 +759,7 @@
 /***********************************************************************
  *           OpenFile16   (KERNEL.74)
  */
-HFILE16 OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
+HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
 {
     return FILE_DoOpenFile( name, ofs, mode, FALSE );
 }
@@ -767,7 +768,7 @@
 /***********************************************************************
  *           OpenFile32   (KERNEL32.396)
  */
-HFILE32 OpenFile32( LPCSTR name, OFSTRUCT *ofs, UINT32 mode )
+HFILE32 WINAPI OpenFile32( LPCSTR name, OFSTRUCT *ofs, UINT32 mode )
 {
     return FILE_DoOpenFile( name, ofs, mode, TRUE );
 }
@@ -776,7 +777,7 @@
 /***********************************************************************
  *           _lclose16   (KERNEL.81)
  */
-HFILE16 _lclose16( HFILE16 hFile )
+HFILE16 WINAPI _lclose16( HFILE16 hFile )
 {
     dprintf_file( stddeb, "_lclose16: handle %d\n", hFile );
     return CloseHandle( hFile ) ? 0 : HFILE_ERROR16;
@@ -786,7 +787,7 @@
 /***********************************************************************
  *           _lclose32   (KERNEL32.592)
  */
-HFILE32 _lclose32( HFILE32 hFile )
+HFILE32 WINAPI _lclose32( HFILE32 hFile )
 {
     dprintf_file( stddeb, "_lclose32: handle %d\n", hFile );
     return CloseHandle( hFile ) ? 0 : HFILE_ERROR32;
@@ -796,7 +797,7 @@
 /***********************************************************************
  *           WIN16_hread
  */
-LONG WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
+LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
 {
     LONG maxlen;
 
@@ -813,7 +814,7 @@
 /***********************************************************************
  *           WIN16_lread
  */
-UINT16 WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
+UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
 {
     return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
 }
@@ -822,7 +823,7 @@
 /***********************************************************************
  *           _lread32   (KERNEL32.596)
  */
-UINT32 _lread32( HFILE32 hFile, LPVOID buffer, UINT32 count )
+UINT32 WINAPI _lread32( HFILE32 hFile, LPVOID buffer, UINT32 count )
 {
     FILE_OBJECT *file;
     UINT32 result;
@@ -840,7 +841,7 @@
 /***********************************************************************
  *           _lread16   (KERNEL.82)
  */
-UINT16 _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
+UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
 {
     return (UINT16)_lread32( hFile, buffer, (LONG)count );
 }
@@ -849,7 +850,7 @@
 /***********************************************************************
  *           _lcreat16   (KERNEL.83)
  */
-HFILE16 _lcreat16( LPCSTR path, INT16 attr )
+HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
 {
     int mode = (attr & 1) ? 0444 : 0666;
     dprintf_file( stddeb, "_lcreat16: %s %02x\n", path, attr );
@@ -860,7 +861,7 @@
 /***********************************************************************
  *           _lcreat32   (KERNEL32.593)
  */
-HFILE32 _lcreat32( LPCSTR path, INT32 attr )
+HFILE32 WINAPI _lcreat32( LPCSTR path, INT32 attr )
 {
     int mode = (attr & 1) ? 0444 : 0666;
     dprintf_file( stddeb, "_lcreat32: %s %02x\n", path, attr );
@@ -882,8 +883,8 @@
 /***********************************************************************
  *           SetFilePointer   (KERNEL32.492)
  */
-DWORD SetFilePointer( HFILE32 hFile, LONG distance, LONG *highword,
-                      DWORD method )
+DWORD WINAPI SetFilePointer( HFILE32 hFile, LONG distance, LONG *highword,
+                             DWORD method )
 {
     FILE_OBJECT *file;
     int origin, result;
@@ -915,7 +916,7 @@
 /***********************************************************************
  *           _llseek16   (KERNEL.84)
  */
-LONG _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
+LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
 {
     return SetFilePointer( hFile, lOffset, NULL, nOrigin );
 }
@@ -924,7 +925,7 @@
 /***********************************************************************
  *           _llseek32   (KERNEL32.594)
  */
-LONG _llseek32( HFILE32 hFile, LONG lOffset, INT32 nOrigin )
+LONG WINAPI _llseek32( HFILE32 hFile, LONG lOffset, INT32 nOrigin )
 {
     return SetFilePointer( hFile, lOffset, NULL, nOrigin );
 }
@@ -933,7 +934,7 @@
 /***********************************************************************
  *           _lopen16   (KERNEL.85)
  */
-HFILE16 _lopen16( LPCSTR path, INT16 mode )
+HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
 {
     return _lopen32( path, mode );
 }
@@ -942,7 +943,7 @@
 /***********************************************************************
  *           _lopen32   (KERNEL32.595)
  */
-HFILE32 _lopen32( LPCSTR path, INT32 mode )
+HFILE32 WINAPI _lopen32( LPCSTR path, INT32 mode )
 {
     INT32 unixMode;
 
@@ -968,7 +969,7 @@
 /***********************************************************************
  *           _lwrite16   (KERNEL.86)
  */
-UINT16 _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
+UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
 {
     return (UINT16)_hwrite32( hFile, buffer, (LONG)count );
 }
@@ -976,7 +977,7 @@
 /***********************************************************************
  *           _lwrite32   (KERNEL.86)
  */
-UINT32 _lwrite32( HFILE32 hFile, LPCSTR buffer, UINT32 count )
+UINT32 WINAPI _lwrite32( HFILE32 hFile, LPCSTR buffer, UINT32 count )
 {
     return (UINT32)_hwrite32( hFile, buffer, (LONG)count );
 }
@@ -985,7 +986,7 @@
 /***********************************************************************
  *           _hread16   (KERNEL.349)
  */
-LONG _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
+LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
 {
     return _lread32( hFile, buffer, count );
 }
@@ -994,7 +995,7 @@
 /***********************************************************************
  *           _hread32   (KERNEL32.590)
  */
-LONG _hread32( HFILE32 hFile, LPVOID buffer, LONG count)
+LONG WINAPI _hread32( HFILE32 hFile, LPVOID buffer, LONG count)
 {
     return _lread32( hFile, buffer, count );
 }
@@ -1003,7 +1004,7 @@
 /***********************************************************************
  *           _hwrite16   (KERNEL.350)
  */
-LONG _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
+LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
 {
     return _hwrite32( hFile, buffer, count );
 }
@@ -1012,7 +1013,7 @@
 /***********************************************************************
  *           _hwrite32   (KERNEL32.591)
  */
-LONG _hwrite32( HFILE32 hFile, LPCSTR buffer, LONG count )
+LONG WINAPI _hwrite32( HFILE32 hFile, LPCSTR buffer, LONG count )
 {
     FILE_OBJECT *file;
     LONG result;
@@ -1042,7 +1043,7 @@
 /***********************************************************************
  *           SetHandleCount16   (KERNEL.199)
  */
-UINT16 SetHandleCount16( UINT16 count )
+UINT16 WINAPI SetHandleCount16( UINT16 count )
 {
     HGLOBAL16 hPDB = GetCurrentPDB();
     PDB *pdb = (PDB *)GlobalLock16( hPDB );
@@ -1094,7 +1095,7 @@
 /*************************************************************************
  *           SetHandleCount32   (KERNEL32.494)
  */
-UINT32 SetHandleCount32( UINT32 count )
+UINT32 WINAPI SetHandleCount32( UINT32 count )
 {
     return MIN( 256, count );
 }
@@ -1103,7 +1104,7 @@
 /***********************************************************************
  *           FlushFileBuffers   (KERNEL32.133)
  */
-BOOL32 FlushFileBuffers( HFILE32 hFile )
+BOOL32 WINAPI FlushFileBuffers( HFILE32 hFile )
 {
     FILE_OBJECT *file;
     BOOL32 ret;
@@ -1124,7 +1125,7 @@
 /**************************************************************************
  *           SetEndOfFile   (KERNEL32.483)
  */
-BOOL32 SetEndOfFile( HFILE32 hFile )
+BOOL32 WINAPI SetEndOfFile( HFILE32 hFile )
 {
     FILE_OBJECT *file;
     BOOL32 ret = TRUE;
@@ -1145,7 +1146,7 @@
 /***********************************************************************
  *           DeleteFile16   (KERNEL.146)
  */
-BOOL16 DeleteFile16( LPCSTR path )
+BOOL16 WINAPI DeleteFile16( LPCSTR path )
 {
     return DeleteFile32A( path );
 }
@@ -1154,7 +1155,7 @@
 /***********************************************************************
  *           DeleteFile32A   (KERNEL32.71)
  */
-BOOL32 DeleteFile32A( LPCSTR path )
+BOOL32 WINAPI DeleteFile32A( LPCSTR path )
 {
     DOS_FULL_NAME full_name;
     const char *unixName;
@@ -1181,7 +1182,7 @@
 /***********************************************************************
  *           DeleteFile32W   (KERNEL32.72)
  */
-BOOL32 DeleteFile32W( LPCWSTR path )
+BOOL32 WINAPI DeleteFile32W( LPCWSTR path )
 {
     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
     BOOL32 ret = RemoveDirectory32A( xpath );
@@ -1218,13 +1219,6 @@
 
     if (!file)
     {
-	/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
-#ifdef MAP_SHARED
-	flags &= ~MAP_SHARED;
-#endif
-#ifdef MAP_PRIVATE
-	flags |= MAP_PRIVATE;
-#endif
 #ifdef MAP_ANON
         flags |= MAP_ANON;
 #else
@@ -1240,6 +1234,13 @@
         }
         fd = fdzero;
 #endif  /* MAP_ANON */
+	/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
+#ifdef MAP_SHARED
+	flags &= ~MAP_SHARED;
+#endif
+#ifdef MAP_PRIVATE
+	flags |= MAP_PRIVATE;
+#endif
     }
     else fd = file->unix_handle;
 
@@ -1250,7 +1251,7 @@
 /***********************************************************************
  *           GetFileType   (KERNEL32.222)
  */
-DWORD GetFileType( HFILE32 hFile )
+DWORD WINAPI GetFileType( HFILE32 hFile )
 {
     FILE_OBJECT *file = FILE_GetFile(hFile);
     if (!file) return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
@@ -1264,7 +1265,7 @@
  *
  * 
  */
-BOOL32 MoveFileEx32A( LPCSTR fn1, LPCSTR fn2, DWORD flag )
+BOOL32 WINAPI MoveFileEx32A( LPCSTR fn1, LPCSTR fn2, DWORD flag )
 {
     DOS_FULL_NAME full_name1, full_name2;
     int mode=0; /* mode == 1: use copy */
@@ -1348,7 +1349,7 @@
 /**************************************************************************
  *           MoveFileEx32W   (KERNEL32.???)
  */
-BOOL32 MoveFileEx32W( LPCWSTR fn1, LPCWSTR fn2, DWORD flag )
+BOOL32 WINAPI MoveFileEx32W( LPCWSTR fn1, LPCWSTR fn2, DWORD flag )
 {
     LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
     LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
@@ -1364,7 +1365,7 @@
  *
  *  Move file or directory
  */
-BOOL32 MoveFile32A( LPCSTR fn1, LPCSTR fn2 )
+BOOL32 WINAPI MoveFile32A( LPCSTR fn1, LPCSTR fn2 )
 {
     DOS_FULL_NAME full_name1, full_name2;
     struct stat fstat;
@@ -1408,7 +1409,7 @@
 /**************************************************************************
  *           MoveFile32W   (KERNEL32.390)
  */
-BOOL32 MoveFile32W( LPCWSTR fn1, LPCWSTR fn2 )
+BOOL32 WINAPI MoveFile32W( LPCWSTR fn1, LPCWSTR fn2 )
 {
     LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
     LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
@@ -1422,7 +1423,7 @@
 /**************************************************************************
  *           CopyFile32A   (KERNEL32.36)
  */
-BOOL32 CopyFile32A( LPCSTR source, LPCSTR dest, BOOL32 fail_if_exists )
+BOOL32 WINAPI CopyFile32A( LPCSTR source, LPCSTR dest, BOOL32 fail_if_exists )
 {
     HFILE32 h1, h2;
     BY_HANDLE_FILE_INFORMATION info;
@@ -1465,7 +1466,7 @@
 /**************************************************************************
  *           CopyFile32W   (KERNEL32.37)
  */
-BOOL32 CopyFile32W( LPCWSTR source, LPCWSTR dest, BOOL32 fail_if_exists )
+BOOL32 WINAPI CopyFile32W( LPCWSTR source, LPCWSTR dest, BOOL32 fail_if_exists)
 {
     LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, source );
     LPSTR destA   = HEAP_strdupWtoA( GetProcessHeap(), 0, dest );
@@ -1479,10 +1480,10 @@
 /***********************************************************************
  *              SetFileTime   (KERNEL32.493)
  */
-BOOL32 SetFileTime( HFILE32 hFile,
-                    const FILETIME *lpCreationTime,
-                    const FILETIME *lpLastAccessTime,
-                    const FILETIME *lpLastWriteTime )
+BOOL32 WINAPI SetFileTime( HFILE32 hFile,
+                           const FILETIME *lpCreationTime,
+                           const FILETIME *lpLastAccessTime,
+                           const FILETIME *lpLastWriteTime )
 {
     FILE_OBJECT *file = FILE_GetFile(hFile);
     struct utimbuf utimbuf;
@@ -1596,7 +1597,7 @@
 /**************************************************************************
  *           LockFile   (KERNEL32.511)
  */
-BOOL32 LockFile(
+BOOL32 WINAPI LockFile(
 	HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
 	DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh )
 {
@@ -1647,7 +1648,7 @@
 /**************************************************************************
  *           UnlockFile   (KERNEL32.703)
  */
-BOOL32 UnlockFile(
+BOOL32 WINAPI UnlockFile(
 	HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
 	DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh )
 {
diff --git a/files/profile.c b/files/profile.c
index 6fac8eb..eb15ace 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -766,15 +766,14 @@
 
     for (lpchX = start, lpch = NULL; *lpchX != '\0'; lpchX++ )
     {
-        if( isspace( *lpchX ) ) lpch = lpch ? lpch : lpchX;
-        else lpch = NULL;
-
         if( *lpchX == ',' )
         {
             if( lpch ) *lpch = '\0'; else *lpchX = '\0';
             while( *(++lpchX) )
                 if( !isspace(*lpchX) ) return lpchX;
         }
+	else if( isspace( *lpchX ) && !lpch ) lpch = lpchX;
+	     else lpch = NULL;
     }
     if( lpch ) *lpch = '\0';
     return NULL;
@@ -786,7 +785,7 @@
 /***********************************************************************
  *           GetProfileInt16   (KERNEL.57)
  */
-UINT16 GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
+UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
 {
     return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
 }
@@ -795,7 +794,7 @@
 /***********************************************************************
  *           GetProfileInt32A   (KERNEL32.264)
  */
-UINT32 GetProfileInt32A( LPCSTR section, LPCSTR entry, INT32 def_val )
+UINT32 WINAPI GetProfileInt32A( LPCSTR section, LPCSTR entry, INT32 def_val )
 {
     return GetPrivateProfileInt32A( section, entry, def_val, "win.ini" );
 }
@@ -803,7 +802,7 @@
 /***********************************************************************
  *           GetProfileInt32W   (KERNEL32.264)
  */
-UINT32 GetProfileInt32W( LPCWSTR section, LPCWSTR entry, INT32 def_val )
+UINT32 WINAPI GetProfileInt32W( LPCWSTR section, LPCWSTR entry, INT32 def_val )
 {
     if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
     return GetPrivateProfileInt32W( section, entry, def_val, wininiW );
@@ -812,8 +811,8 @@
 /***********************************************************************
  *           GetProfileString16   (KERNEL.58)
  */
-INT16 GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
-                          LPSTR buffer, INT16 len )
+INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
+                                 LPSTR buffer, INT16 len )
 {
     return GetPrivateProfileString16( section, entry, def_val,
                                       buffer, len, "win.ini" );
@@ -822,8 +821,8 @@
 /***********************************************************************
  *           GetProfileString32A   (KERNEL32.268)
  */
-INT32 GetProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR def_val,
-                           LPSTR buffer, INT32 len )
+INT32 WINAPI GetProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR def_val,
+                                  LPSTR buffer, INT32 len )
 {
     return GetPrivateProfileString32A( section, entry, def_val,
                                        buffer, len, "win.ini" );
@@ -832,8 +831,8 @@
 /***********************************************************************
  *           GetProfileString32W   (KERNEL32.269)
  */
-INT32 GetProfileString32W( LPCWSTR section,LPCWSTR entry,LPCWSTR def_val,
-                           LPWSTR buffer, INT32 len )
+INT32 WINAPI GetProfileString32W( LPCWSTR section, LPCWSTR entry,
+                                  LPCWSTR def_val, LPWSTR buffer, INT32 len )
 {
     if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
     return GetPrivateProfileString32W( section, entry, def_val,
@@ -844,7 +843,8 @@
 /***********************************************************************
  *           WriteProfileString16   (KERNEL.59)
  */
-BOOL16 WriteProfileString16( LPCSTR section, LPCSTR entry, LPCSTR string )
+BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry,
+                                    LPCSTR string )
 {
     return WritePrivateProfileString16( section, entry, string, "win.ini" );
 }
@@ -852,7 +852,8 @@
 /***********************************************************************
  *           WriteProfileString32A   (KERNEL32.587)
  */
-BOOL32 WriteProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR string )
+BOOL32 WINAPI WriteProfileString32A( LPCSTR section, LPCSTR entry,
+                                     LPCSTR string )
 {
     return WritePrivateProfileString32A( section, entry, string, "win.ini" );
 }
@@ -860,7 +861,8 @@
 /***********************************************************************
  *           WriteProfileString32W   (KERNEL32.588)
  */
-BOOL32 WriteProfileString32W( LPCWSTR section, LPCWSTR entry, LPCWSTR string )
+BOOL32 WINAPI WriteProfileString32W( LPCWSTR section, LPCWSTR entry,
+                                     LPCWSTR string )
 {
     if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
     return WritePrivateProfileString32W( section, entry, string, wininiW );
@@ -870,8 +872,8 @@
 /***********************************************************************
  *           GetPrivateProfileInt16   (KERNEL.127)
  */
-UINT16 GetPrivateProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val,
-                               LPCSTR filename )
+UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
+                                      INT16 def_val, LPCSTR filename )
 {
     long result=(long)GetPrivateProfileInt32A(section,entry,def_val,filename);
 
@@ -884,8 +886,8 @@
 /***********************************************************************
  *           GetPrivateProfileInt32A   (KERNEL32.251)
  */
-UINT32 GetPrivateProfileInt32A( LPCSTR section, LPCSTR entry, INT32 def_val,
-                                LPCSTR filename )
+UINT32 WINAPI GetPrivateProfileInt32A( LPCSTR section, LPCSTR entry,
+                                       INT32 def_val, LPCSTR filename )
 {
     char buffer[20];
     char *p;
@@ -902,8 +904,8 @@
 /***********************************************************************
  *           GetPrivateProfileInt32W   (KERNEL32.252)
  */
-UINT32 GetPrivateProfileInt32W( LPCWSTR section, LPCWSTR entry, INT32 def_val,
-                                LPCWSTR filename )
+UINT32 WINAPI GetPrivateProfileInt32W( LPCWSTR section, LPCWSTR entry,
+                                       INT32 def_val, LPCWSTR filename )
 {
     LPSTR sectionA  = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
     LPSTR entryA    = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
@@ -918,8 +920,9 @@
 /***********************************************************************
  *           GetPrivateProfileString16   (KERNEL.128)
  */
-INT16 GetPrivateProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
-                                 LPSTR buffer, INT16 len, LPCSTR filename )
+INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
+                                        LPCSTR def_val, LPSTR buffer,
+                                        INT16 len, LPCSTR filename )
 {
     return GetPrivateProfileString32A(section,entry,def_val,buffer,len,filename);
 }
@@ -927,8 +930,9 @@
 /***********************************************************************
  *           GetPrivateProfileString32A   (KERNEL32.255)
  */
-INT32 GetPrivateProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR def_val,
-                                  LPSTR buffer, INT32 len, LPCSTR filename )
+INT32 WINAPI GetPrivateProfileString32A( LPCSTR section, LPCSTR entry,
+                                         LPCSTR def_val, LPSTR buffer,
+                                         INT32 len, LPCSTR filename )
 {
     if (PROFILE_Open( filename ))
         return PROFILE_GetString( section, entry, def_val, buffer, len );
@@ -939,9 +943,9 @@
 /***********************************************************************
  *           GetPrivateProfileString32W   (KERNEL32.256)
  */
-INT32 GetPrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
-                                  LPCWSTR def_val, LPWSTR buffer,
-                                  INT32 len, LPCWSTR filename )
+INT32 WINAPI GetPrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
+                                         LPCWSTR def_val, LPWSTR buffer,
+                                         INT32 len, LPCWSTR filename )
 {
     LPSTR sectionA  = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
     LPSTR entryA    = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
@@ -964,8 +968,8 @@
 /***********************************************************************
  *           WritePrivateProfileString16   (KERNEL.129)
  */
-BOOL16 WritePrivateProfileString16(LPCSTR section,LPCSTR entry,LPCSTR string,
-                                   LPCSTR filename)
+BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry,
+                                           LPCSTR string, LPCSTR filename )
 {
     return WritePrivateProfileString32A(section,entry,string,filename);
 }
@@ -973,8 +977,8 @@
 /***********************************************************************
  *           WritePrivateProfileString32A   (KERNEL32.582)
  */
-BOOL32 WritePrivateProfileString32A(LPCSTR section,LPCSTR entry,LPCSTR string,
-                                    LPCSTR filename )
+BOOL32 WINAPI WritePrivateProfileString32A( LPCSTR section, LPCSTR entry,
+                                            LPCSTR string, LPCSTR filename )
 {
     if (!PROFILE_Open( filename )) return FALSE;
     if (!section) return PROFILE_FlushFile();
@@ -984,8 +988,8 @@
 /***********************************************************************
  *           WritePrivateProfileString32W   (KERNEL32.583)
  */
-BOOL32 WritePrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
-                                     LPCWSTR string, LPCWSTR filename )
+BOOL32 WINAPI WritePrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
+                                            LPCWSTR string, LPCWSTR filename )
 {
     LPSTR sectionA  = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
     LPSTR entryA    = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
@@ -1004,7 +1008,7 @@
 /***********************************************************************
  *           WriteOutProfiles   (KERNEL.315)
  */
-void WriteOutProfiles(void)
+void WINAPI WriteOutProfiles(void)
 {
     PROFILE_FlushFile();
 }
diff --git a/graphics/bitblt.c b/graphics/bitblt.c
index eda13f4..2356de8 100644
--- a/graphics/bitblt.c
+++ b/graphics/bitblt.c
@@ -12,8 +12,8 @@
 /***********************************************************************
  *           PatBlt16    (GDI.29)
  */
-BOOL16 PatBlt16( HDC16 hdc, INT16 left, INT16 top,
-                 INT16 width, INT16 height, DWORD rop)
+BOOL16 WINAPI PatBlt16( HDC16 hdc, INT16 left, INT16 top,
+                        INT16 width, INT16 height, DWORD rop)
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc || !dc->funcs->pPatBlt) return FALSE;
@@ -27,8 +27,8 @@
 /***********************************************************************
  *           PatBlt32    (GDI32.260)
  */
-BOOL32 PatBlt32( HDC32 hdc, INT32 left, INT32 top,
-                 INT32 width, INT32 height, DWORD rop)
+BOOL32 WINAPI PatBlt32( HDC32 hdc, INT32 left, INT32 top,
+                        INT32 width, INT32 height, DWORD rop)
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc || !dc->funcs->pPatBlt) return FALSE;
@@ -42,8 +42,9 @@
 /***********************************************************************
  *           BitBlt16    (GDI.34)
  */
-BOOL16 BitBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst, INT16 width,
-                 INT16 height, HDC16 hdcSrc, INT16 xSrc, INT16 ySrc, DWORD rop)
+BOOL16 WINAPI BitBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst, INT16 width,
+                        INT16 height, HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
+                        DWORD rop )
 {
     DC *dcDst, *dcSrc;
 
@@ -63,8 +64,9 @@
 /***********************************************************************
  *           BitBlt32    (GDI32.10)
  */
-BOOL32 BitBlt32( HDC32 hdcDst, INT32 xDst, INT32 yDst, INT32 width,
-                 INT32 height, HDC32 hdcSrc, INT32 xSrc, INT32 ySrc, DWORD rop)
+BOOL32 WINAPI BitBlt32( HDC32 hdcDst, INT32 xDst, INT32 yDst, INT32 width,
+                        INT32 height, HDC32 hdcSrc, INT32 xSrc, INT32 ySrc,
+                        DWORD rop )
 {
     DC *dcDst, *dcSrc;
 
@@ -84,10 +86,10 @@
 /***********************************************************************
  *           StretchBlt16    (GDI.35)
  */
-BOOL16 StretchBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst,
-                     INT16 widthDst, INT16 heightDst,
-                     HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
-                     INT16 widthSrc, INT16 heightSrc, DWORD rop )
+BOOL16 WINAPI StretchBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst,
+                            INT16 widthDst, INT16 heightDst,
+                            HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
+                            INT16 widthSrc, INT16 heightSrc, DWORD rop )
 {
     DC *dcDst, *dcSrc;
 
@@ -109,10 +111,10 @@
 /***********************************************************************
  *           StretchBlt32    (GDI32.350)
  */
-BOOL32 StretchBlt32( HDC32 hdcDst, INT32 xDst, INT32 yDst,
-                     INT32 widthDst, INT32 heightDst,
-                     HDC32 hdcSrc, INT32 xSrc, INT32 ySrc,
-                     INT32 widthSrc, INT32 heightSrc, DWORD rop )
+BOOL32 WINAPI StretchBlt32( HDC32 hdcDst, INT32 xDst, INT32 yDst,
+                            INT32 widthDst, INT32 heightDst,
+                            HDC32 hdcSrc, INT32 xSrc, INT32 ySrc,
+                            INT32 widthSrc, INT32 heightSrc, DWORD rop )
 {
     DC *dcDst, *dcSrc;
 
@@ -134,8 +136,8 @@
 /***********************************************************************
  *           FastWindowFrame    (GDI.400)
  */
-BOOL16 FastWindowFrame( HDC16 hdc, const RECT16 *rect,
-                        INT16 width, INT16 height, DWORD rop )
+BOOL16 WINAPI FastWindowFrame( HDC16 hdc, const RECT16 *rect,
+                               INT16 width, INT16 height, DWORD rop )
 {
     HBRUSH32 hbrush = SelectObject32( hdc, GetStockObject32( GRAY_BRUSH ) );
     PatBlt32( hdc, rect->left, rect->top,
diff --git a/graphics/escape.c b/graphics/escape.c
index d742fc1..b60b9a8 100644
--- a/graphics/escape.c
+++ b/graphics/escape.c
@@ -9,19 +9,24 @@
 #include "gdi.h"
 #include "dc.h"
 
-INT16 Escape16( HDC16 hdc, INT16 nEscape, INT16 cbInput,
-                SEGPTR lpszInData, SEGPTR lpvOutData )
+INT16 WINAPI Escape16( HDC16 hdc, INT16 nEscape, INT16 cbInput,
+                       SEGPTR lpszInData, SEGPTR lpvOutData )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc || !dc->funcs->pEscape) return 0;
     return dc->funcs->pEscape( dc, nEscape, cbInput, lpszInData, lpvOutData );
 }
 
-INT32 Escape32( HDC32 hdc, INT32 nEscape, INT32 cbInput,
-                LPVOID lpszInData, LPVOID lpvOutData )
+INT32 WINAPI Escape32( HDC32 hdc, INT32 nEscape, INT32 cbInput,
+                       LPVOID lpszInData, LPVOID lpvOutData )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc || !dc->funcs->pEscape) return 0;
+    switch (nEscape) {
+    case GETSCALINGFACTOR:
+         return 1;
+    	
+    }
     return dc->funcs->pEscape( dc, nEscape, cbInput,
                                (SEGPTR)lpszInData, (SEGPTR)lpvOutData );
 }
diff --git a/graphics/fontengine.c b/graphics/fontengine.c
index 376b7f7..4dd6e1f 100644
--- a/graphics/fontengine.c
+++ b/graphics/fontengine.c
@@ -8,23 +8,20 @@
 #include "windows.h"
 
 /* GDI 300 */
-WORD 
-EngineEnumerateFont(LPSTR fontname, FARPROC16 proc, DWORD data )
+WORD WINAPI EngineEnumerateFont(LPSTR fontname, FARPROC16 proc, DWORD data )
 {
     printf("In engineEnumerateFont for %s\n",(fontname)?fontname:"NULL");
     return 0;
 }
 #ifdef NOTDEF
 /* GDI 301 */
-WORD 
-EngineDeleteFont(LPFONTINFO16 lpFontInfo)
+WORD WINAPI EngineDeleteFont(LPFONTINFO16 lpFontInfo)
 {
     return 0
 }
 #endif
 /* GDI 302 */
-WORD
-EngineRealizeFont(LPLOGFONT16 lplogFont, LPTEXTXFORM16 lptextxform, LPFONTINFO16 lpfontInfo)
+WORD WINAPI EngineRealizeFont(LPLOGFONT16 lplogFont, LPTEXTXFORM16 lptextxform, LPFONTINFO16 lpfontInfo)
 {
     printf("In EngineRealizeFont\n");
     
@@ -32,27 +29,23 @@
 }
 #ifdef NOTDEF
 /* GDI 303 */
-WORD 
-EngineGetCharWidth(LPFONTINFO16 lpFontInfo, BYTE, BYTE, LPINT16)
+WORD WINAPI EngineGetCharWidth(LPFONTINFO16 lpFontInfo, BYTE, BYTE, LPINT16)
 {
     return 0;
 }
 
 /* GDI 304 */
-WORD 
-EngineSetFontContext(LPFONTINFO lpFontInfo, WORD data)
+WORD WINAPI EngineSetFontContext(LPFONTINFO lpFontInfo, WORD data)
 {
 }
 /* GDI 305 */
-WORD 
-EngineGetGlyphBMP(WORD word, LPFONTINFO lpFontInfo, WORD, WORD, LPSTR string, DWORD dword, LPBITMAPMETRICS16 metrics)
+WORD WINAPI EngineGetGlyphBMP(WORD word, LPFONTINFO lpFontInfo, WORD, WORD, LPSTR string, DWORD dword, LPBITMAPMETRICS16 metrics)
 {
     return 0;
 }
 
 /* GDI 306 */
-DWORD 
-EngineMakeFontDir(HDC16 hdc, LPFONTDIR fontdir, LPCSTR string)
+DWORD WINAPI EngineMakeFontDir(HDC16 hdc, LPFONTDIR fontdir, LPCSTR string)
 {
     return 0;
     
@@ -60,8 +53,7 @@
 
 /* GDI 314 */
 
-WORD 
-EngineExtTextOut()
+WORD WINAPI EngineExtTextOut()
 {
 }
 
diff --git a/graphics/mapping.c b/graphics/mapping.c
index e70c1e5..576eb34 100644
--- a/graphics/mapping.c
+++ b/graphics/mapping.c
@@ -37,7 +37,7 @@
 /***********************************************************************
  *           DPtoLP16    (GDI.67)
  */
-BOOL16 DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
+BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
@@ -55,7 +55,7 @@
 /***********************************************************************
  *           DPtoLP32    (GDI32.65)
  */
-BOOL32 DPtoLP32( HDC32 hdc, LPPOINT32 points, INT32 count )
+BOOL32 WINAPI DPtoLP32( HDC32 hdc, LPPOINT32 points, INT32 count )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
@@ -73,7 +73,7 @@
 /***********************************************************************
  *           LPtoDP16    (GDI.99)
  */
-BOOL16 LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
+BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
@@ -91,7 +91,7 @@
 /***********************************************************************
  *           LPtoDP32    (GDI32.247)
  */
-BOOL32 LPtoDP32( HDC32 hdc, LPPOINT32 points, INT32 count )
+BOOL32 WINAPI LPtoDP32( HDC32 hdc, LPPOINT32 points, INT32 count )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
@@ -109,7 +109,7 @@
 /***********************************************************************
  *           SetMapMode16    (GDI.3)
  */
-INT16 SetMapMode16( HDC16 hdc, INT16 mode )
+INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
 {
     return SetMapMode32( hdc, mode );
 }
@@ -118,7 +118,7 @@
 /***********************************************************************
  *           SetMapMode32    (GDI32.321)
  */
-INT32 SetMapMode32( HDC32 hdc, INT32 mode )
+INT32 WINAPI SetMapMode32( HDC32 hdc, INT32 mode )
 {
     INT32 prevMode;
     DC * dc = DC_GetDCPtr( hdc );
@@ -199,7 +199,7 @@
 /***********************************************************************
  *           SetViewportExt    (GDI.14)
  */
-DWORD SetViewportExt( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetViewportExt( HDC16 hdc, INT16 x, INT16 y )
 {
     SIZE32 size;
     if (!SetViewportExtEx32( hdc, x, y, &size )) return 0;
@@ -210,7 +210,7 @@
 /***********************************************************************
  *           SetViewportExtEx16    (GDI.479)
  */
-BOOL16 SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
+BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
 {
     SIZE32 size32;
     BOOL16 ret = SetViewportExtEx32( hdc, x, y, &size32 );
@@ -222,7 +222,7 @@
 /***********************************************************************
  *           SetViewportExtEx32    (GDI32.340)
  */
-BOOL32 SetViewportExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
+BOOL32 WINAPI SetViewportExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -246,7 +246,7 @@
 /***********************************************************************
  *           SetViewportOrg    (GDI.13)
  */
-DWORD SetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     POINT32 pt;
     if (!SetViewportOrgEx32( hdc, x, y, &pt )) return 0;
@@ -257,7 +257,7 @@
 /***********************************************************************
  *           SetViewportOrgEx16    (GDI.480)
  */
-BOOL16 SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
+BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
 {
     POINT32 pt32;
     BOOL16 ret = SetViewportOrgEx32( hdc, x, y, &pt32 );
@@ -269,7 +269,7 @@
 /***********************************************************************
  *           SetViewportOrgEx32    (GDI32.341)
  */
-BOOL32 SetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
+BOOL32 WINAPI SetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -289,7 +289,7 @@
 /***********************************************************************
  *           SetWindowExt    (GDI.12)
  */
-DWORD SetWindowExt( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetWindowExt( HDC16 hdc, INT16 x, INT16 y )
 {
     SIZE32 size;
     if (!SetWindowExtEx32( hdc, x, y, &size )) return 0;
@@ -300,7 +300,7 @@
 /***********************************************************************
  *           SetWindowExtEx16    (GDI.481)
  */
-BOOL16 SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
+BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
 {
     SIZE32 size32;
     BOOL16 ret = SetWindowExtEx32( hdc, x, y, &size32 );
@@ -312,7 +312,7 @@
 /***********************************************************************
  *           SetWindowExtEx32    (GDI32.344)
  */
-BOOL32 SetWindowExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
+BOOL32 WINAPI SetWindowExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -335,7 +335,7 @@
 /***********************************************************************
  *           SetWindowOrg    (GDI.11)
  */
-DWORD SetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     POINT32 pt;
     if (!SetWindowOrgEx32( hdc, x, y, &pt )) return 0;
@@ -346,7 +346,7 @@
 /***********************************************************************
  *           SetWindowOrgEx16    (GDI.482)
  */
-BOOL16 SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
+BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
 {
     POINT32 pt32;
     BOOL16 ret = SetWindowOrgEx32( hdc, x, y, &pt32 );
@@ -358,7 +358,7 @@
 /***********************************************************************
  *           SetWindowOrgEx32    (GDI32.345)
  */
-BOOL32 SetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
+BOOL32 WINAPI SetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -377,7 +377,7 @@
 /***********************************************************************
  *           OffsetViewportOrg    (GDI.17)
  */
-DWORD OffsetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI OffsetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     POINT32 pt;
     if (!OffsetViewportOrgEx32( hdc, x, y, &pt )) return 0;
@@ -388,7 +388,7 @@
 /***********************************************************************
  *           OffsetViewportOrgEx16    (GDI.476)
  */
-BOOL16 OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
+BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
 {
     POINT32 pt32;
     BOOL16 ret = OffsetViewportOrgEx32( hdc, x, y, &pt32 );
@@ -400,7 +400,7 @@
 /***********************************************************************
  *           OffsetViewportOrgEx32    (GDI32.257)
  */
-BOOL32 OffsetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
+BOOL32 WINAPI OffsetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt)
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -420,7 +420,7 @@
 /***********************************************************************
  *           OffsetWindowOrg    (GDI.15)
  */
-DWORD OffsetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI OffsetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     POINT32 pt;
     if (!OffsetWindowOrgEx32( hdc, x, y, &pt )) return 0;
@@ -431,7 +431,7 @@
 /***********************************************************************
  *           OffsetWindowOrgEx16    (GDI.477)
  */
-BOOL16 OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
+BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
 {
     POINT32 pt32;
     BOOL16 ret = OffsetWindowOrgEx32( hdc, x, y, &pt32 );
@@ -443,7 +443,7 @@
 /***********************************************************************
  *           OffsetWindowOrgEx32    (GDI32.258)
  */
-BOOL32 OffsetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
+BOOL32 WINAPI OffsetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -463,8 +463,8 @@
 /***********************************************************************
  *           ScaleViewportExt    (GDI.18)
  */
-DWORD ScaleViewportExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
-                        INT16 yNum, INT16 yDenom )
+DWORD WINAPI ScaleViewportExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
+                               INT16 yNum, INT16 yDenom )
 {
     SIZE32 size;
     if (!ScaleViewportExtEx32( hdc, xNum, xDenom, yNum, yDenom, &size ))
@@ -476,8 +476,8 @@
 /***********************************************************************
  *           ScaleViewportExtEx16    (GDI.484)
  */
-BOOL16 ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
-                             INT16 yNum, INT16 yDenom, LPSIZE16 size )
+BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
+                                    INT16 yNum, INT16 yDenom, LPSIZE16 size )
 {
     SIZE32 size32;
     BOOL16 ret = ScaleViewportExtEx32( hdc, xNum, xDenom, yNum, yDenom,
@@ -490,8 +490,8 @@
 /***********************************************************************
  *           ScaleViewportExtEx32    (GDI32.293)
  */
-BOOL32 ScaleViewportExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
-                             INT32 yNum, INT32 yDenom, LPSIZE32 size )
+BOOL32 WINAPI ScaleViewportExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
+                                    INT32 yNum, INT32 yDenom, LPSIZE32 size )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
@@ -517,8 +517,8 @@
 /***********************************************************************
  *           ScaleWindowExt    (GDI.16)
  */
-DWORD ScaleWindowExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
-		      INT16 yNum, INT16 yDenom )
+DWORD WINAPI ScaleWindowExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
+                             INT16 yNum, INT16 yDenom )
 {
     SIZE32 size;
     if (!ScaleWindowExtEx32( hdc, xNum, xDenom, yNum, yDenom, &size ))
@@ -530,8 +530,8 @@
 /***********************************************************************
  *           ScaleWindowExtEx16    (GDI.485)
  */
-BOOL16 ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
-                           INT16 yNum, INT16 yDenom, LPSIZE16 size )
+BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
+                                  INT16 yNum, INT16 yDenom, LPSIZE16 size )
 {
     SIZE32 size32;
     BOOL16 ret = ScaleWindowExtEx32( hdc, xNum, xDenom, yNum, yDenom,
@@ -544,8 +544,8 @@
 /***********************************************************************
  *           ScaleWindowExtEx32    (GDI32.294)
  */
-BOOL32 ScaleWindowExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
-                           INT32 yNum, INT32 yDenom, LPSIZE32 size )
+BOOL32 WINAPI ScaleWindowExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
+                                  INT32 yNum, INT32 yDenom, LPSIZE32 size )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc) return FALSE;
diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c
index a5ffa69..b187bce 100644
--- a/graphics/metafiledrv/init.c
+++ b/graphics/metafiledrv/init.c
@@ -138,7 +138,7 @@
 /**********************************************************************
  *	     CreateMetafile16   (GDI.125)
  */
-HDC16 CreateMetaFile16( LPCSTR filename )
+HDC16 WINAPI CreateMetaFile16( LPCSTR filename )
 {
     DC *dc;
     METAFILEDRV_PDEVICE *physDev;
@@ -177,7 +177,7 @@
 /******************************************************************
  *	     CloseMetafile16   (GDI.126)
  */
-HMETAFILE16 CloseMetaFile16( HDC16 hdc )
+HMETAFILE16 WINAPI CloseMetaFile16( HDC16 hdc )
 {
     DC *dc;
     HMETAFILE16 hmf;
@@ -231,7 +231,7 @@
 /******************************************************************
  *	     DeleteMetafile16   (GDI.127)
  */
-BOOL16 DeleteMetaFile16( HMETAFILE16 hmf )
+BOOL16 WINAPI DeleteMetaFile16( HMETAFILE16 hmf )
 {
     return !GlobalFree16( hmf );
 }
diff --git a/graphics/metafiledrv/objects.c b/graphics/metafiledrv/objects.c
index 2c1aa22..dcb096d 100644
--- a/graphics/metafiledrv/objects.c
+++ b/graphics/metafiledrv/objects.c
@@ -83,6 +83,7 @@
 HGDIOBJ32 MFDRV_SelectObject( DC *dc, HGDIOBJ32 handle )
 {
     GDIOBJHDR * ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
+    HGDIOBJ32 ret = 0;
 
     if (!ptr) return 0;
     dprintf_gdi(stddeb, "SelectObject: hdc=%04x %04x\n", dc->hSelf, handle );
@@ -90,15 +91,21 @@
     switch(ptr->wMagic)
     {
       case PEN_MAGIC:
-	  return MFDRV_PEN_SelectObject( dc, handle, (PENOBJ *)ptr );
+	  ret = MFDRV_PEN_SelectObject( dc, handle, (PENOBJ *)ptr );
+	  break;
       case BRUSH_MAGIC:
-	  return MFDRV_BRUSH_SelectObject( dc, handle, (BRUSHOBJ *)ptr );
+	  ret = MFDRV_BRUSH_SelectObject( dc, handle, (BRUSHOBJ *)ptr );
+	  break;
       case BITMAP_MAGIC:
-	  return MFDRV_BITMAP_SelectObject( dc, handle, (BITMAPOBJ *)ptr );
+	  ret = MFDRV_BITMAP_SelectObject( dc, handle, (BITMAPOBJ *)ptr );
+	  break;
       case FONT_MAGIC:
-	  return MFDRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+	  ret = MFDRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+	  break;
       case REGION_MAGIC:
-	  return (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	  ret = (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	  break;
     }
-    return 0;
+    GDI_HEAP_UNLOCK( handle );
+    return ret;
 }
diff --git a/graphics/painting.c b/graphics/painting.c
index ed96464..efd785a 100644
--- a/graphics/painting.c
+++ b/graphics/painting.c
@@ -29,7 +29,7 @@
 /***********************************************************************
  *           LineTo16    (GDI.19)
  */
-BOOL16 LineTo16( HDC16 hdc, INT16 x, INT16 y )
+BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
 {
     return LineTo32( hdc, x, y );
 }
@@ -38,7 +38,7 @@
 /***********************************************************************
  *           LineTo32    (GDI32.249)
  */
-BOOL32 LineTo32( HDC32 hdc, INT32 x, INT32 y )
+BOOL32 WINAPI LineTo32( HDC32 hdc, INT32 x, INT32 y )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -50,7 +50,7 @@
 /***********************************************************************
  *           MoveTo    (GDI.20)
  */
-DWORD MoveTo( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI MoveTo( HDC16 hdc, INT16 x, INT16 y )
 {
     POINT16	pt;
 
@@ -63,7 +63,7 @@
 /***********************************************************************
  *           MoveToEx16    (GDI.483)
  */
-BOOL16 MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
+BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
 {
     POINT32 pt32;
 
@@ -77,7 +77,7 @@
 /***********************************************************************
  *           MoveToEx32    (GDI32.254)
  */
-BOOL32 MoveToEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
+BOOL32 WINAPI MoveToEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -89,8 +89,9 @@
 /***********************************************************************
  *           Arc16    (GDI.23)
  */
-BOOL16 Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right, INT16 bottom,
-              INT16 xstart, INT16 ystart, INT16 xend, INT16 yend )
+BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
+                     INT16 bottom, INT16 xstart, INT16 ystart,
+                     INT16 xend, INT16 yend )
 {
     return Arc32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
    		  (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
@@ -101,8 +102,9 @@
 /***********************************************************************
  *           Arc32    (GDI32.7)
  */
-BOOL32 Arc32( HDC32 hdc, INT32 left, INT32 top, INT32 right, INT32 bottom,
-              INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
+BOOL32 WINAPI Arc32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
+                     INT32 bottom, INT32 xstart, INT32 ystart,
+                     INT32 xend, INT32 yend )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -114,8 +116,9 @@
 /***********************************************************************
  *           Pie16    (GDI.26)
  */
-BOOL16 Pie16( HDC16 hdc, INT16 left, INT16 top, INT16 right, INT16 bottom,
-              INT16 xstart, INT16 ystart, INT16 xend, INT16 yend )
+BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
+                     INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
+                     INT16 xend, INT16 yend )
 {
     return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
    		  (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
@@ -126,8 +129,9 @@
 /***********************************************************************
  *           Pie32   (GDI32.262)
  */
-BOOL32 Pie32( HDC32 hdc, INT32 left, INT32 top, INT32 right, INT32 bottom,
-              INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
+BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
+                     INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
+                     INT32 xend, INT32 yend )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -139,8 +143,9 @@
 /***********************************************************************
  *           Chord16    (GDI.348)
  */
-BOOL16 Chord16( HDC16 hdc, INT16 left, INT16 top, INT16 right, INT16 bottom,
-                INT16 xstart, INT16 ystart, INT16 xend, INT16 yend )
+BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
+                       INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
+                       INT16 xend, INT16 yend )
 {
     return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
 }
@@ -149,8 +154,9 @@
 /***********************************************************************
  *           Chord32    (GDI32.14)
  */
-BOOL32 Chord32( HDC32 hdc, INT32 left, INT32 top, INT32 right, INT32 bottom,
-                INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
+BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
+                       INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
+                       INT32 xend, INT32 yend )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -162,7 +168,8 @@
 /***********************************************************************
  *           Ellipse16    (GDI.24)
  */
-BOOL16 Ellipse16( HDC16 hdc, INT16 left, INT16 top, INT16 right, INT16 bottom )
+BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
+                         INT16 right, INT16 bottom )
 {
     return Ellipse32( hdc, left, top, right, bottom );
 }
@@ -171,7 +178,8 @@
 /***********************************************************************
  *           Ellipse32    (GDI32.75)
  */
-BOOL32 Ellipse32( HDC32 hdc, INT32 left, INT32 top, INT32 right, INT32 bottom )
+BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
+                         INT32 right, INT32 bottom )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -183,7 +191,8 @@
 /***********************************************************************
  *           Rectangle16    (GDI.27)
  */
-BOOL16 Rectangle16(HDC16 hdc, INT16 left, INT16 top, INT16 right, INT16 bottom)
+BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
+                           INT16 right, INT16 bottom )
 {
     return Rectangle32( hdc, left, top, right, bottom );
 }
@@ -192,7 +201,8 @@
 /***********************************************************************
  *           Rectangle32    (GDI32.283)
  */
-BOOL32 Rectangle32(HDC32 hdc, INT32 left, INT32 top, INT32 right, INT32 bottom)
+BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
+                           INT32 right, INT32 bottom )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -204,8 +214,8 @@
 /***********************************************************************
  *           RoundRect16    (GDI.28)
  */
-BOOL16 RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
-                    INT16 bottom, INT16 ell_width, INT16 ell_height )
+BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
+                           INT16 bottom, INT16 ell_width, INT16 ell_height )
 {
     return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
 }
@@ -214,8 +224,8 @@
 /***********************************************************************
  *           RoundRect32    (GDI32.291)
  */
-BOOL32 RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
-                    INT32 bottom, INT32 ell_width, INT32 ell_height )
+BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
+                           INT32 bottom, INT32 ell_width, INT32 ell_height )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -227,7 +237,7 @@
 /***********************************************************************
  *           FillRect16    (USER.81)
  */
-INT16 FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
+INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
 {
     HBRUSH16 prevBrush;
 
@@ -246,7 +256,7 @@
 /***********************************************************************
  *           FillRect32    (USER32.196)
  */
-INT32 FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
+INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
 {
     HBRUSH32 prevBrush;
 
@@ -261,7 +271,7 @@
 /***********************************************************************
  *           InvertRect16    (USER.82)
  */
-void InvertRect16( HDC16 hdc, const RECT16 *rect )
+void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
 {
     PatBlt32( hdc, rect->left, rect->top,
               rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
@@ -271,7 +281,7 @@
 /***********************************************************************
  *           InvertRect32    (USER32.329)
  */
-void InvertRect32( HDC32 hdc, const RECT32 *rect )
+void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
 {
     PatBlt32( hdc, rect->left, rect->top,
               rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
@@ -281,7 +291,7 @@
 /***********************************************************************
  *           FrameRect16    (USER.83)
  */
-INT16 FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
+INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
 {
     HBRUSH16 prevBrush;
     int left, top, right, bottom;
@@ -316,7 +326,7 @@
 /***********************************************************************
  *           FrameRect32    (USER32.202)
  */
-INT32 FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
+INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
 {
     RECT16 rect16;
     CONV_RECT32TO16( rect, &rect16 );
@@ -327,7 +337,7 @@
 /***********************************************************************
  *           SetPixel16    (GDI.31)
  */
-COLORREF SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
+COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
 {
     return SetPixel32( hdc, x, y, color );
 }
@@ -336,7 +346,7 @@
 /***********************************************************************
  *           SetPixel32    (GDI32.327)
  */
-COLORREF SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
+COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
 {
     DC * dc = DC_GetDCPtr( hdc );
   
@@ -348,7 +358,7 @@
 /***********************************************************************
  *           GetPixel16    (GDI.83)
  */
-COLORREF GetPixel16( HDC16 hdc, INT16 x, INT16 y )
+COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
 {
     return GetPixel32( hdc, x, y );
 }
@@ -357,7 +367,7 @@
 /***********************************************************************
  *           GetPixel32    (GDI32.211)
  */
-COLORREF GetPixel32( HDC32 hdc, INT32 x, INT32 y )
+COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -376,7 +386,7 @@
 /***********************************************************************
  *           PaintRgn16    (GDI.43)
  */
-BOOL16 PaintRgn16( HDC16 hdc, HRGN16 hrgn )
+BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
 {
     return PaintRgn32( hdc, hrgn );
 }
@@ -385,7 +395,7 @@
 /***********************************************************************
  *           PaintRgn32    (GDI32.259)
  */
-BOOL32 PaintRgn32( HDC32 hdc, HRGN32 hrgn )
+BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -397,7 +407,7 @@
 /***********************************************************************
  *           FillRgn16    (GDI.40)
  */
-BOOL16 FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
+BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
 {
     return FillRgn32( hdc, hrgn, hbrush );
 }
@@ -406,7 +416,7 @@
 /***********************************************************************
  *           FillRgn32    (GDI32.101)
  */
-BOOL32 FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
+BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
 {
     BOOL32 retval;
     HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
@@ -420,8 +430,8 @@
 /***********************************************************************
  *           FrameRgn16     (GDI.41)
  */
-BOOL16 FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
-                   INT16 nWidth, INT16 nHeight )
+BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
+                          INT16 nWidth, INT16 nHeight )
 {
     return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
 }
@@ -430,8 +440,8 @@
 /***********************************************************************
  *           FrameRgn32     (GDI32.105)
  */
-BOOL32 FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
-                   INT32 nWidth, INT32 nHeight )
+BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
+                          INT32 nWidth, INT32 nHeight )
 {
     HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
     if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
@@ -444,7 +454,7 @@
 /***********************************************************************
  *           InvertRgn16    (GDI.42)
  */
-BOOL16 InvertRgn16( HDC16 hdc, HRGN16 hrgn )
+BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
 {
     return InvertRgn32( hdc, hrgn );
 }
@@ -453,7 +463,7 @@
 /***********************************************************************
  *           InvertRgn32    (GDI32.246)
  */
-BOOL32 InvertRgn32( HDC32 hdc, HRGN32 hrgn )
+BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
 {
     HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
     INT32 prevROP = SetROP232( hdc, R2_NOT );
@@ -467,7 +477,7 @@
 /***********************************************************************
  *           DrawFocusRect16    (USER.466)
  */
-void DrawFocusRect16( HDC16 hdc, const RECT16* rc )
+void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
 {
     RECT32 rect32;
     CONV_RECT16TO32( rc, &rect32 );
@@ -480,7 +490,7 @@
  *
  * FIXME: PatBlt(PATINVERT) with background brush.
  */
-void DrawFocusRect32( HDC32 hdc, const RECT32* rc )
+void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
 {
     HPEN32 hOldPen;
     INT32 oldDrawMode, oldBkMode;
@@ -515,7 +525,7 @@
 /**********************************************************************
  *          Polyline16  (GDI.37)
  */
-BOOL16 Polyline16( HDC16 hdc, LPPOINT16 pt, INT16 count )
+BOOL16 WINAPI Polyline16( HDC16 hdc, LPPOINT16 pt, INT16 count )
 {
     register int i;
     LPPOINT32 pt32 = (LPPOINT32)xmalloc(count*sizeof(POINT32));
@@ -531,7 +541,7 @@
 /**********************************************************************
  *          Polyline32   (GDI32.276)
  */
-BOOL32 Polyline32( HDC32 hdc, const LPPOINT32 pt, INT32 count )
+BOOL32 WINAPI Polyline32( HDC32 hdc, const LPPOINT32 pt, INT32 count )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -543,7 +553,7 @@
 /**********************************************************************
  *          Polygon16  (GDI.36)
  */
-BOOL16 Polygon16( HDC16 hdc, LPPOINT16 pt, INT16 count )
+BOOL16 WINAPI Polygon16( HDC16 hdc, LPPOINT16 pt, INT16 count )
 {
     register int i;
     LPPOINT32 pt32 = (LPPOINT32)xmalloc(count*sizeof(POINT32));
@@ -560,7 +570,7 @@
 /**********************************************************************
  *          Polygon32  (GDI32.275)
  */
-BOOL32 Polygon32( HDC32 hdc, LPPOINT32 pt, INT32 count )
+BOOL32 WINAPI Polygon32( HDC32 hdc, LPPOINT32 pt, INT32 count )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -572,7 +582,8 @@
 /**********************************************************************
  *          PolyPolygon16  (GDI.450)
  */
-BOOL16 PolyPolygon16( HDC16 hdc, LPPOINT16 pt, LPINT16 counts, UINT16 polygons)
+BOOL16 WINAPI PolyPolygon16( HDC16 hdc, LPPOINT16 pt, LPINT16 counts,
+                             UINT16 polygons )
 {
     int		i,nrpts;
     LPPOINT32	pt32;
@@ -597,7 +608,8 @@
 /**********************************************************************
  *          PolyPolygon32  (GDI.450)
  */
-BOOL32 PolyPolygon32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts, UINT32 polygons)
+BOOL32 WINAPI PolyPolygon32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts,
+                             UINT32 polygons )
 {
     DC * dc = DC_GetDCPtr( hdc );
 
@@ -608,8 +620,8 @@
 /**********************************************************************
  *          ExtFloodFill16   (GDI.372)
  */
-BOOL16 ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
-                       UINT16 fillType )
+BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
+                              UINT16 fillType )
 {
     return ExtFloodFill32( hdc, x, y, color, fillType );
 }
@@ -618,8 +630,8 @@
 /**********************************************************************
  *          ExtFloodFill32   (GDI32.96)
  */
-BOOL32 ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
-                       UINT32 fillType )
+BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
+                              UINT32 fillType )
 {
     DC *dc = DC_GetDCPtr( hdc );
 
@@ -631,7 +643,7 @@
 /**********************************************************************
  *          FloodFill16   (GDI.25)
  */
-BOOL16 FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
+BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
 {
     return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
 }
@@ -640,7 +652,7 @@
 /**********************************************************************
  *          FloodFill32   (GDI32.104)
  */
-BOOL32 FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
+BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
 {
     return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
 }
@@ -649,7 +661,7 @@
 /**********************************************************************
  *          DrawEdge16   (USER.659)
  */
-BOOL16 DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
+BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
 {
     RECT32 rect32;
     BOOL32 ret;
@@ -664,7 +676,7 @@
 /**********************************************************************
  *          DrawEdge32   (USER32.154)
  */
-BOOL32 DrawEdge32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
+BOOL32 WINAPI DrawEdge32( HDC32 hdc, LPRECT32 rc, UINT32 edge, UINT32 flags )
 {
     HBRUSH32 hbrushOld;
 
@@ -747,7 +759,8 @@
 /**********************************************************************
  *          DrawFrameControl16  (USER.656)
  */
-BOOL16 DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
+BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType,
+                                  UINT16 uState )
 {
     fprintf( stdnimp,"DrawFrameControl16(%x,%p,%d,%x), empty stub!\n",
              hdc,rc,uType,uState );
@@ -758,7 +771,8 @@
 /**********************************************************************
  *          DrawFrameControl32  (USER32.157)
  */
-BOOL32 DrawFrameControl32( HDC32 hdc, LPRECT32 rc, UINT32 uType, UINT32 uState )
+BOOL32 WINAPI DrawFrameControl32( HDC32 hdc, LPRECT32 rc, UINT32 uType,
+                                  UINT32 uState )
 {
     fprintf( stdnimp,"DrawFrameControl32(%x,%p,%d,%x), empty stub!\n",
              hdc,rc,uType,uState );
@@ -768,10 +782,22 @@
 /**********************************************************************
  *          DrawFrameControl32  (USER32.152)
  */
-BOOL32 DrawAnimatedRects32( HWND32 hwnd, int idAni,
-                           const LPRECT32 lprcFrom, const LPRECT32 lprcTo )
+BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
+                                   const LPRECT32 lprcFrom,
+                                   const LPRECT32 lprcTo )
 {
     fprintf( stdnimp,"DrawAnimatedRects32(%x,%d,%p,%p), empty stub!\n",
              hwnd, idAni, lprcFrom, lprcTo );
     return TRUE;
 }
+
+BOOL32 WINAPI DrawState32A(
+	HDC32 hdc,HBRUSH32 hbrush,DRAWSTATEPROC drawstateproc,
+	LPARAM lparam,WPARAM32 wparam,INT32 x,INT32 y,INT32 z,INT32 a,UINT32 b
+) {
+	fprintf(stderr,"DrawStateA(%x,%x,%p,0x%08lx,0x%08lx,%d,%d,%d,%d,%d),stub\n",
+		hdc,hbrush,drawstateproc,lparam,wparam,x,y,z,a,b
+	);
+	return TRUE;
+}
+
diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c
index 9fc2086..4611105 100644
--- a/graphics/win16drv/init.c
+++ b/graphics/win16drv/init.c
@@ -173,8 +173,9 @@
  * 	1) Just count the number of fonts available.
  * 	2) Store all font data passed.
  */
-WORD WineEnumDFontCallback(LPLOGFONT16 lpLogFont, LPTEXTMETRIC16 lpTextMetrics, 
-			   WORD wFontType, LONG lpvClientData) 
+WORD WINAPI WineEnumDFontCallback(LPLOGFONT16 lpLogFont,
+                                  LPTEXTMETRIC16 lpTextMetrics,
+                                  WORD wFontType, LONG lpvClientData) 
 {
     int wRet = 0;
     WEPFC *pWEPFC = (WEPFC *)lpvClientData; 
@@ -325,6 +326,12 @@
 				  (void *)&wepfc);
                 numFonts = wepfc.nCount;
 	    }
+            else
+            {
+                /* If the number of fonts returned are zero we can not continue */
+                fprintf( stderr, "No fonts? Aborting CreateDC...\n");
+                return FALSE;
+            }
 	}
     }
 		
@@ -476,20 +483,17 @@
 
 static struct hpq *hpqueue;
 
-HPQ 
-CreatePQ(int size) 
+HPQ WINAPI CreatePQ(int size) 
 {
     printf("CreatePQ: %d\n",size);
     return 1;
 }
-int 
-DeletePQ(HPQ hPQ) 
+int WINAPI DeletePQ(HPQ hPQ) 
 {
     printf("DeletePQ: %x\n", hPQ);
     return 0;
 }
-int 
-ExtractPQ(HPQ hPQ) 
+int WINAPI ExtractPQ(HPQ hPQ) 
 { 
     struct hpq *queue, *prev, *current, *currentPrev;
     int key = 0, tag = -1;
@@ -527,8 +531,7 @@
     return tag;
 }
 
-int 
-InsertPQ(HPQ hPQ, int tag, int key) 
+int WINAPI InsertPQ(HPQ hPQ, int tag, int key) 
 {
     struct hpq *queueItem = malloc(sizeof(struct hpq));
     queueItem->next = hpqueue;
@@ -539,14 +542,12 @@
     printf("InsertPQ: %x %d %d\n", hPQ, tag, key);
     return TRUE;
 }
-int
-MinPQ(HPQ hPQ) 
+int WINAPI MinPQ(HPQ hPQ) 
 {
     printf("MinPQ: %x\n", hPQ); 
     return 0;
 }
-int
-SizePQ(HPQ hPQ, int sizechange) 
+int WINAPI SizePQ(HPQ hPQ, int sizechange) 
 {  
     printf("SizePQ: %x %d\n", hPQ, sizechange); 
     return -1; 
@@ -656,7 +657,7 @@
     return nRet;
 }
 
-HANDLE16 OpenJob(LPSTR lpOutput, LPSTR lpTitle, HDC16 hDC)
+HANDLE16 WINAPI OpenJob(LPSTR lpOutput, LPSTR lpTitle, HDC16 hDC)
 {
     HANDLE16 hHandle = SP_ERROR;
     PPRINTJOB pPrintJob;
@@ -690,7 +691,7 @@
     return hHandle;
 }
 
-int CloseJob(HANDLE16 hJob)
+int WINAPI CloseJob(HANDLE16 hJob)
 {
     int nRet = SP_ERROR;
     PPRINTJOB pPrintJob = NULL;
@@ -708,7 +709,7 @@
     return nRet;
 }
 
-int WriteSpool(HANDLE16 hJob, LPSTR lpData, WORD cch)
+int WINAPI WriteSpool(HANDLE16 hJob, LPSTR lpData, WORD cch)
 {
     int nRet = SP_ERROR;
     PPRINTJOB pPrintJob = NULL;
@@ -726,7 +727,7 @@
     return nRet;
 }
 
-int WriteDialog(HANDLE16 hJob, LPSTR lpMsg, WORD cchMsg)
+int WINAPI WriteDialog(HANDLE16 hJob, LPSTR lpMsg, WORD cchMsg)
 {
     int nRet = 0;
 
@@ -736,7 +737,7 @@
     return nRet;
 }
 
-int DeleteJob(HANDLE16 hJob, WORD wNotUsed)
+int WINAPI DeleteJob(HANDLE16 hJob, WORD wNotUsed)
 {
     int nRet;
 
@@ -751,20 +752,20 @@
  * when it has been processed.  For simplicity they havn't been implemented.
  * This means a whole job has to be processed before it is sent to the printer.
  */
-int StartSpoolPage(HANDLE16 hJob)
+int WINAPI StartSpoolPage(HANDLE16 hJob)
 {
     dprintf_win16drv(stddeb, "StartSpoolPage GDI.246 unimplemented\n");
     return 1;
 
 }
-int EndSpoolPage(HANDLE16 hJob)
+int WINAPI EndSpoolPage(HANDLE16 hJob)
 {
     dprintf_win16drv(stddeb, "EndSpoolPage GDI.247 unimplemented\n");
     return 1;
 }
 
 
-DWORD GetSpoolJob(int nOption, LONG param)
+DWORD WINAPI GetSpoolJob(int nOption, LONG param)
 {
     DWORD retval = 0;
     dprintf_win16drv(stddeb, "In GetSpoolJob param 0x%lx noption %d\n",param, nOption);
diff --git a/graphics/win16drv/objects.c b/graphics/win16drv/objects.c
index c865790..ee54724 100644
--- a/graphics/win16drv/objects.c
+++ b/graphics/win16drv/objects.c
@@ -24,11 +24,12 @@
 
 
 /***********************************************************************
- *           X11DRV_SelectObject
+ *           WIN16DRV_SelectObject
  */
 HGDIOBJ32 WIN16DRV_SelectObject( DC *dc, HGDIOBJ32 handle )
 {
     GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
+    HGDIOBJ32 ret = 0;
 
     if (!ptr) return 0;
     dprintf_gdi(stddeb, "SelectObject: hdc=%04x %04x\n", dc->hSelf, handle );
@@ -37,17 +38,17 @@
     {
     case PEN_MAGIC:
         fprintf(stderr, "WIN16DRV_SelectObject for PEN not implemented\n");
-        return 0;
     case BRUSH_MAGIC:
         fprintf(stderr, "WIN16DRV_SelectObject for BRUSH not implemented\n");
-        return 0;
     case BITMAP_MAGIC:
         fprintf(stderr, "WIN16DRV_SelectObject for BITMAP not implemented\n");
-        return 0;
     case FONT_MAGIC:
-        return WIN16DRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+        ret = WIN16DRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+	break;
     case REGION_MAGIC:
-	  return (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	ret = (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	break;
     }
-    return 0;
+    GDI_HEAP_UNLOCK( handle );
+    return ret;
 }
diff --git a/graphics/wing.c b/graphics/wing.c
index 90321e5..58be554 100644
--- a/graphics/wing.c
+++ b/graphics/wing.c
@@ -66,7 +66,7 @@
 /***********************************************************************
  *          WinGCreateDC16	(WING.1001)
  */
-HDC16 WinGCreateDC16(void)
+HDC16 WINAPI WinGCreateDC16(void)
 {
   __initWinG();
 
@@ -78,7 +78,7 @@
 /***********************************************************************
  *  WinGRecommendDIBFormat16    (WING.1002)
  */
-BOOL16 WinGRecommendDIBFormat16(BITMAPINFO *fmt)
+BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *fmt)
 {
   fprintf(stdnimp,"WinGRecommendDIBFormat()\n");
 
@@ -93,7 +93,8 @@
 /***********************************************************************
  *        WinGCreateBitmap16    (WING.1003)
  */
-HBITMAP16 WinGCreateBitmap16(HDC16 winDC, BITMAPINFO *header, void **bits)
+HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 winDC, BITMAPINFO *header,
+                                    void **bits)
 {
   fprintf(stdnimp,"WinGCreateBitmap: empty stub! (expect failure)\n");
   if( __WinGOK > 0 && header )
@@ -126,7 +127,7 @@
 	    if (hbitmap)
 	    {
 	      __ShmBitmapCtl* p = (__ShmBitmapCtl*)xmalloc(sizeof(__ShmBitmapCtl));
-		BITMAPOBJ* 	 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
+		BITMAPOBJ* 	 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
 
 		bmpObjPtr->size.cx = 0;
 		bmpObjPtr->size.cy = 0;
@@ -170,6 +171,7 @@
 		    hbitmap = 0;
 		}
 	    }
+	    GDI_HEAP_UNLOCK( hbitmap );
 	    return hbitmap;
 	}
     }
@@ -181,7 +183,7 @@
 /***********************************************************************
  *  WinGGetDIBPointer   (WING.1004)
  */
-SEGPTR WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
+SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
 {
 #ifdef PRELIMINARY_WING16_SUPPORT
   BITMAPOBJ*	bmp = (BITMAPOBJ *) GDI_GetObjPtr( hWinGBitmap, BITMAP_MAGIC );
@@ -192,6 +194,7 @@
     if( p )
     {
       if( bmpi ) memcpy( bmpi, &__bmpiWinG, sizeof(BITMAPINFOHEADER));
+      GDI_HEAP_UNLOCK( hWinGBitmap );
       return p->bits;
     }
   }
@@ -202,7 +205,8 @@
 /***********************************************************************
  *  WinGSetDIBColorTable   (WING.1004)
  */
-UINT16 WinGSetDIBColorTable16(HDC16 hWinGDC, UINT16 start, UINT16 num, RGBQUAD* pColor)
+UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hWinGDC, UINT16 start, UINT16 num,
+                                     RGBQUAD* pColor)
 {
         fprintf(stdnimp,"WinGSetDIBColorTable: empty stub!\n");
         return num;
@@ -211,8 +215,8 @@
 /***********************************************************************
  *  WinGGetDIBColorTable16   (WING.1005)
  */
-UINT16 WinGGetDIBColorTable16(HDC16 winDC, UINT16 start, UINT16 numentry,
-                            RGBQUAD* colors)
+UINT16 WINAPI WinGGetDIBColorTable16(HDC16 winDC, UINT16 start,
+                                     UINT16 numentry, RGBQUAD* colors)
 {
 	fprintf(stdnimp,"WinGGetDIBColorTable: empty stub!\n");
 	return 0;
@@ -221,7 +225,7 @@
 /***********************************************************************
  *  WinGCreateHalfTonePalette16   (WING.1007)
  */
-HPALETTE16 WinGCreateHalfTonePalette16(void)
+HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
 {
         fprintf(stdnimp,"WinGCreateHalfTonePalette: empty stub!\n");
 	return 0;
@@ -230,7 +234,8 @@
 /***********************************************************************
  *  WinGCreateHalfToneBrush16   (WING.1008)
  */
-HPALETTE16 WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col, WING_DITHER_TYPE type)
+HPALETTE16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
+                                            WING_DITHER_TYPE type)
 {
         fprintf(stdnimp,"WinGCreateHalfToneBrush: empty stub!\n");
 	return 0;
@@ -239,9 +244,10 @@
 /***********************************************************************
  *  WinGStretchBlt16   (WING.1009)
  */
-BOOL16 WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest, INT16 widDest,
-                        INT16 heiDest, HDC16 srcDC, INT16 xSrc, INT16 ySrc,
-                        INT16 widSrc, INT16 heiSrc)
+BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
+                               INT16 widDest, INT16 heiDest,
+                               HDC16 srcDC, INT16 xSrc, INT16 ySrc,
+                               INT16 widSrc, INT16 heiSrc)
 {
 
         return StretchBlt16(destDC, xDest, yDest, widDest, heiDest, srcDC, xSrc, ySrc, widSrc, heiSrc, SRCCOPY);
@@ -252,8 +258,9 @@
 /***********************************************************************
  *  WinGBitBlt16   (WING.1010)
  */
-BOOL16 WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest, INT16 widDest,
-                    INT16 heiDest, HDC16 srcDC, INT16 xSrc, INT16 ySrc)
+BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
+                           INT16 widDest, INT16 heiDest, HDC16 srcDC,
+                           INT16 xSrc, INT16 ySrc)
 {
     /* destDC is a display DC, srcDC is a memory DC */
 
diff --git a/graphics/x11drv/bitblt.c b/graphics/x11drv/bitblt.c
index 1fbd3c5..a497ce2 100644
--- a/graphics/x11drv/bitblt.c
+++ b/graphics/x11drv/bitblt.c
@@ -1341,6 +1341,34 @@
     return TRUE;
 }
 
+struct StretchBlt_params
+{
+    DC   *dcDst;
+    INT32 xDst;
+    INT32 yDst;
+    INT32 widthDst;
+    INT32 heightDst;
+    DC   *dcSrc;
+    INT32 xSrc;
+    INT32 ySrc;
+    INT32 widthSrc;
+    INT32 heightSrc;
+    DWORD rop;
+};
+
+/***********************************************************************
+ *           BITBLT_DoStretchBlt
+ *
+ * Wrapper function for BITBLT_InternalStretchBlt
+ * to use with CALL_LARGE_STACK.
+ */
+static int BITBLT_DoStretchBlt( const struct StretchBlt_params *p )
+{
+    return (int)BITBLT_InternalStretchBlt( p->dcDst, p->xDst, p->yDst,
+                                           p->widthDst, p->heightDst,
+                                           p->dcSrc, p->xSrc, p->ySrc,
+                                           p->widthSrc, p->heightSrc, p->rop );
+}
 
 /***********************************************************************
  *           X11DRV_PatBlt
@@ -1348,9 +1376,9 @@
 BOOL32 X11DRV_PatBlt( DC *dc, INT32 left, INT32 top,
                       INT32 width, INT32 height, DWORD rop )
 {
-    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
-                                 dc, left, top, width, height,
-                                 NULL, 0, 0, 0, 0, rop );
+    struct StretchBlt_params params = { dc, left, top, width, height,
+                                        NULL, 0, 0, 0, 0, rop };
+    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
 }
 
 
@@ -1361,9 +1389,9 @@
                       INT32 width, INT32 height, DC *dcSrc,
                       INT32 xSrc, INT32 ySrc, DWORD rop )
 {
-    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
-                                dcDst, xDst, yDst, width, height,
-                                dcSrc, xSrc, ySrc, width, height, rop );
+    struct StretchBlt_params params = { dcDst, xDst, yDst, width, height,
+                                        dcSrc, xSrc, ySrc, width, height, rop};
+    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
 }
 
 
@@ -1375,7 +1403,8 @@
                           DC *dcSrc, INT32 xSrc, INT32 ySrc,
                           INT32 widthSrc, INT32 heightSrc, DWORD rop )
 {
-    return CallTo32_LargeStack( (int(*)())BITBLT_InternalStretchBlt, 11,
-                                dcDst, xDst, yDst, widthDst, heightDst,
-                                dcSrc, xSrc, ySrc, widthSrc, heightSrc, rop );
+    struct StretchBlt_params params = { dcDst, xDst, yDst, widthDst, heightDst,
+                                        dcSrc, xSrc, ySrc, widthSrc, heightSrc,
+                                        rop };
+    return (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
 }
diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c
index 1fe88da..a162ad7 100644
--- a/graphics/x11drv/brush.c
+++ b/graphics/x11drv/brush.c
@@ -179,6 +179,7 @@
 	dc->u.x.brush.fillStyle = FillOpaqueStippled;
 	dc->u.x.brush.pixel = -1;  /* Special case (see DC_SetupGCForBrush) */
     }
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
diff --git a/graphics/x11drv/clipping.c b/graphics/x11drv/clipping.c
index ddc9183..7645e68 100644
--- a/graphics/x11drv/clipping.c
+++ b/graphics/x11drv/clipping.c
@@ -31,4 +31,5 @@
     {
         XSetClipRectangles( display, dc->u.x.gc, 0, 0, NULL, 0, 0 );
     }
+    GDI_HEAP_UNLOCK( dc->w.hGCClipRgn );
 }
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index 2619425..ec80312 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -631,16 +631,29 @@
  *
  * Main flood-fill routine.
  */
-static BOOL32 X11DRV_DoFloodFill( DC *dc, RECT32 *rect, INT32 x, INT32 y,
-                                 COLORREF color, UINT32 fillType )
+
+struct FloodFill_params
+{
+    DC      *dc;
+    INT32    x;
+    INT32    y;
+    COLORREF color;
+    UINT32   fillType;
+};
+
+static BOOL32 X11DRV_DoFloodFill( const struct FloodFill_params *params )
 {
     XImage *image;
+    RECT32 rect;
+    DC *dc = params->dc;
+
+    if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
 
     if (!(image = XGetImage( display, dc->u.x.drawable,
-                             dc->w.DCOrgX + rect->left,
-                             dc->w.DCOrgY + rect->top,
-                             rect->right - rect->left,
-                             rect->bottom - rect->top,
+                             dc->w.DCOrgX + rect.left,
+                             dc->w.DCOrgY + rect.top,
+                             rect.right - rect.left,
+                             rect.bottom - rect.top,
                              AllPlanes, ZPixmap ))) return FALSE;
 
     if (DC_SetupGCForBrush( dc ))
@@ -648,11 +661,12 @@
           /* ROP mode is always GXcopy for flood-fill */
         XSetFunction( display, dc->u.x.gc, GXcopy );
         X11DRV_InternalFloodFill(image, dc,
-                                 XLPTODP(dc,x) - rect->left,
-                                 YLPTODP(dc,y) - rect->top,
-                                 dc->w.DCOrgX + rect->left,
-                                 dc->w.DCOrgY + rect->top,
-                                 COLOR_ToPhysical( dc, color ), fillType );
+                                 XLPTODP(dc,params->x) - rect.left,
+                                 YLPTODP(dc,params->y) - rect.top,
+                                 dc->w.DCOrgX + rect.left,
+                                 dc->w.DCOrgY + rect.top,
+                                 COLOR_ToPhysical( dc, params->color ),
+                                 params->fillType );
     }
 
     XDestroyImage( image );
@@ -667,15 +681,11 @@
 X11DRV_ExtFloodFill( DC *dc, INT32 x, INT32 y, COLORREF color,
                      UINT32 fillType )
 {
-    RECT32 rect;
-    HDC32	hdc = dc->hSelf; /* FIXME */
+    struct FloodFill_params params = { dc, x, y, color, fillType };
 
     dprintf_graphics( stddeb, "X11DRV_ExtFloodFill %d,%d %06lx %d\n",
                       x, y, color, fillType );
 
-    if (!PtVisible32( hdc, x, y )) return FALSE;
-    if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
-
-    return CallTo32_LargeStack( (int(*)())X11DRV_DoFloodFill, 6,
-                                dc, &rect, x, y, color, fillType );
+    if (!PtVisible32( dc->hSelf, x, y )) return FALSE;
+    return CALL_LARGE_STACK( X11DRV_DoFloodFill, &params );
 }
diff --git a/graphics/x11drv/init.c b/graphics/x11drv/init.c
index 0d7496f..6cfd5a1 100644
--- a/graphics/x11drv/init.c
+++ b/graphics/x11drv/init.c
@@ -136,6 +136,8 @@
 	X11DRV_DevCaps.rasterCaps |= RC_PALETTE;
 	X11DRV_DevCaps.sizePalette = DefaultVisual(display,DefaultScreen(display))->map_entries;
     }
+ 
+    /* Resolution will be adjusted during the font init */
 
     X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
     X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
@@ -177,6 +179,7 @@
         dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
         dc->w.hVisRgn      = CreateRectRgn32( 0, 0, bmp->bitmap.bmWidth,
                                               bmp->bitmap.bmHeight );
+	GDI_HEAP_UNLOCK( dc->w.hBitmap );
     }
     else
     {
diff --git a/graphics/x11drv/objects.c b/graphics/x11drv/objects.c
index fb2f0b8..c665b07 100644
--- a/graphics/x11drv/objects.c
+++ b/graphics/x11drv/objects.c
@@ -29,6 +29,7 @@
 HGDIOBJ32 X11DRV_SelectObject( DC *dc, HGDIOBJ32 handle )
 {
     GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
+    HGDIOBJ32 ret = 0;
 
     if (!ptr) return 0;
     dprintf_gdi(stddeb, "SelectObject: hdc=%04x %04x\n", dc->hSelf, handle );
@@ -36,15 +37,21 @@
     switch(ptr->wMagic)
     {
       case PEN_MAGIC:
-	  return X11DRV_PEN_SelectObject( dc, handle, (PENOBJ *)ptr );
+	  ret = X11DRV_PEN_SelectObject( dc, handle, (PENOBJ *)ptr );
+	  break;
       case BRUSH_MAGIC:
-	  return X11DRV_BRUSH_SelectObject( dc, handle, (BRUSHOBJ *)ptr );
+	  ret = X11DRV_BRUSH_SelectObject( dc, handle, (BRUSHOBJ *)ptr );
+	  break;
       case BITMAP_MAGIC:
-	  return X11DRV_BITMAP_SelectObject( dc, handle, (BITMAPOBJ *)ptr );
+	  ret = X11DRV_BITMAP_SelectObject( dc, handle, (BITMAPOBJ *)ptr );
+	  break;
       case FONT_MAGIC:
-	  return X11DRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+	  ret = X11DRV_FONT_SelectObject( dc, handle, (FONTOBJ *)ptr );	  
+	  break;
       case REGION_MAGIC:
-	  return (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	  ret = (HGDIOBJ16)SelectClipRgn16( dc->hSelf, handle );
+	  break;
     }
-    return 0;
+    GDI_HEAP_UNLOCK( handle );
+    return ret;
 }
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index f12d89f..4b112e2 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -48,11 +48,44 @@
   struct __fontAlias*	next;
 } fontAlias;
 
+typedef struct
+{
+  LPSTR                 fatResource;
+  LPSTR                 fatAlias;
+} aliasTemplate;
+
+/* Font alias table - these 2 aliases are always present */
+
 static fontAlias aliasTable[2] = { 
 			{ "Helvetica", "Helv", &aliasTable[1] },
 			{ "Times", "Tms Rmn", NULL } 
 			};
 
+/* Optional built-in aliases, they are installed only when X
+ * cannot supply us with original MS fonts */
+
+static int	     faTemplateNum = 4;
+static aliasTemplate faTemplate[4] = {
+			  { "-adobe-helvetica-", "MS Sans Serif" },
+			  { "-bitstream-charter-", "MS Serif" },
+			  { "-adobe-times-", "Times New Roman" },
+			  { "-adobe-helvetica-", "Arial" }
+			  };
+
+/* Charset translation table, cp125-.. encoded fonts are produced by
+ * the fnt2bdf */
+
+static int	 numCPTranslation = 8;
+static BYTE	 CPTranslation[] = { EE_CHARSET,	/* cp125-0 */
+				     RUSSIAN_CHARSET,	/* cp125-1 */
+				     ANSI_CHARSET,	/* cp125-2 */
+				     GREEK_CHARSET,	/* cp125-3 */
+				     TURKISH_CHARSET,	/* cp125-4 */
+				     HEBREW_CHARSET,	/* cp125-5 */
+				     ARABIC_CHARSET,	/* cp125-6 */
+				     BALTIC_CHARSET	/* cp125-7 */
+				   }; 
+
 UINT16			XTextCaps = TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
 				    TC_SA_DOUBLE | TC_SA_INTEGER | TC_SA_CONTIN |
 			 	    TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE;
@@ -64,14 +97,17 @@
 static const char*	INIFontSection = "fonts";
 static const char*	INISubSection = "Alias";
 static const char*	INIDefault = "Default";
+static const char*	INIResolution = "Resolution";
+static const char*	INIGlobalMetrics = "FontMetrics";
 
 static const char*	LFDSeparator = "*-";
+static const char*	localMSEncoding = "cp125-";
 static const char*	iso8859Encoding = "iso8859-";
 static const char*	iso646Encoding = "iso646.1991-";
 static const char*	ansiEncoding = "ansi-";
-static fontResource*	fontList = NULL; 	
 static unsigned		DefResolution = 0;
 
+static fontResource*	fontList = NULL;
 static fontObject*      fontCache = NULL;		/* array */
 static int		fontCacheSize = FONTCACHE;
 static int		fontLF = -1, fontMRU = -1;	/* last free, most recently used */
@@ -317,28 +353,32 @@
   *(lpch - 1) = LFDSeparator[1];
 
 /* charset registry, charset encoding - */
-   if( strstr(lpch, "jisx") || strstr(lpch, "ksc") ) return FALSE;	/* 2-byte stuff */
+   if( strstr(lpch, "jisx") || 
+       strstr(lpch, "ksc") || 
+       strstr(lpch, "gb2312") ) return FALSE;	/* 2-byte stuff */
 
+   fi->df.dfCharSet = ANSI_CHARSET;
    if( strstr(lpch, iso8859Encoding) )
-   {
      fi->fi_flags |= FI_ENC_ISO8859;
-     fi->df.dfCharSet = ANSI_CHARSET;
-   }
    else if( strstr(lpch, iso646Encoding) )
-   {
      fi->fi_flags |= FI_ENC_ISO646;
-     fi->df.dfCharSet = ANSI_CHARSET;
-   }
-   else if( strstr(lpch, ansiEncoding) )	/* font2bdf produces -ansi-0 LFD */
-   {
+   else if( strstr(lpch, ansiEncoding) )	/* fnt2bdf produces -ansi-0 LFD */
      fi->fi_flags |= FI_ENC_ANSI;
-     fi->df.dfCharSet = ANSI_CHARSET;
+   else						/* ... and -cp125-x */
+   {
+	fi->df.dfCharSet = OEM_CHARSET;
+	if( !strncasecmp(lpch, localMSEncoding, 6) )
+	{
+	    lpch = LFD_Advance( lpch, 1 );
+	    if( lpch && (i = atoi( lpch )) < numCPTranslation )
+	    {
+		fi->fi_flags |= FI_ENC_MSCODEPAGE;
+		fi->df.dfCharSet = CPTranslation[i];
+	    }
+	}
+	else if( strstr(lpch, "fontspecific") )
+	    fi->df.dfCharSet = SYMBOL_CHARSET;
    }
-   else if( strstr(lpch, "fontspecific") )
-     fi->df.dfCharSet = SYMBOL_CHARSET;
-   else
-     fi->df.dfCharSet = OEM_CHARSET;		/* FIXME: -cp126-.. from fnt2bdf */
-   
    return TRUE;					
 }
 
@@ -348,7 +388,7 @@
 static BOOL32  LFD_ComposeLFD( fontObject* fo, 
 			       INT32 height, LPSTR lpLFD, UINT32 uRelax )
 {
-   int		h, w, ch, point = 0;
+   int		h, w, ch, enc_ch, point = 0;
    char*	lpch; 
    const char*  lpEncoding = NULL;
 
@@ -400,9 +440,12 @@
    if( fo->fo_flags & FO_SYNTH_HEIGHT ) h = fo->fi->lfd_height;
    else h = (fo->fi->lfd_height * height) / fo->fi->df.dfPixHeight;
 
-   if( fo->lf.lfWidth && (XTextCaps & TC_SF_X_YINDEP) 
-	              && !(fo->fo_flags & FO_SYNTH_WIDTH) )
-       point = (fo->fi->lfd_decipoints * fo->lf.lfWidth) / fo->fi->df.dfAvgWidth;
+   if( XTextCaps & TC_SF_X_YINDEP ) 
+	if( fo->lf.lfWidth && !(fo->fo_flags & FO_SYNTH_WIDTH) )
+	    point = (fo->fi->lfd_decipoints * fo->lf.lfWidth) / fo->fi->df.dfAvgWidth;
+	else 
+	if( fo->fi->fi_flags & FI_SCALABLE ) /* adjust h/w ratio */
+	    point = h * 72 * 10 / fo->fi->lfd_resolution;
 
 /* spacing and width */
 
@@ -411,16 +454,35 @@
    else 
        w = ( fo->fi->fi_flags & FI_VARIABLEPITCH ) ? 'p' : LFDSeparator[0]; 
 
-/* encoding, not quite there yet */
+/* encoding */
 
+   enc_ch = '*';
    if( fo->fi->df.dfCharSet == ANSI_CHARSET )
    {
 	if( fo->fi->fi_flags & FI_ENC_ISO8859 )
 	     lpEncoding = iso8859Encoding;
 	else if( fo->fi->fi_flags & FI_ENC_ISO646 )
 	     lpEncoding = iso646Encoding;
+	else if( fo->fi->fi_flags & FI_ENC_MSCODEPAGE )
+	{
+	     enc_ch = '2';
+	     lpEncoding = localMSEncoding;
+	}
 	else lpEncoding = ansiEncoding;
-   } else    lpEncoding = LFDSeparator;
+   } 
+   else if( fo->fi->fi_flags & FI_ENC_MSCODEPAGE )
+   {
+	int i;
+
+	lpEncoding = localMSEncoding;
+	for( i = 0; i < numCPTranslation; i++ )
+	     if( CPTranslation[i] == fo->fi->df.dfCharSet )
+	     {
+		enc_ch = '0' + i;
+		break;
+	     }
+   }
+   else lpEncoding = LFDSeparator;	/* whatever */
 
    lpch = lpLFD + lstrlen32A(lpLFD);
    ch = (fo->fi->fi_flags & FI_SCALABLE) ? '0' : LFDSeparator[0];
@@ -433,20 +495,20 @@
        case 0: 
 	    if( point )
 	    {
-	        sprintf( lpch, "%i-%i-%i-%c-%c-*-%s*", h, point, 
-			 fo->fi->lfd_resolution, ch, w, lpEncoding );
+	        sprintf( lpch, "%i-%i-%i-%c-%c-*-%s%c", h, point, 
+			 fo->fi->lfd_resolution, ch, w, lpEncoding, enc_ch );
 	        break;
 	    }
 	    /* fall through */
 
        case 1: 
-	    sprintf( lpch, "%i-*-%i-%c-%c-*-%s*", h, 
-			fo->fi->lfd_resolution, ch, w, lpEncoding );
+	    sprintf( lpch, "%i-*-%i-%c-%c-*-%s%c", h, 
+			fo->fi->lfd_resolution, ch, w, lpEncoding, enc_ch );
 	    break;
 
        case 2:
-	    sprintf( lpch, "%i-*-%i-%c-*-*-%s*",
-			h, fo->fi->lfd_resolution, ch, lpEncoding );
+	    sprintf( lpch, "%i-*-%i-%c-*-*-%s%c",
+			h, fo->fi->lfd_resolution, ch, lpEncoding, enc_ch );
 	    break;
 
        case 3:
@@ -668,7 +730,8 @@
                     return FF_SWISS;
                   break;
         case 'c':
-        case 'C': if(!lstrcmpi32A(lfFaceName, "Courier") )
+        case 'C': if(!lstrcmpi32A(lfFaceName, "Courier") ||
+		     !lstrcmpi32A(lfFaceName, "Charter") )
                     return FF_ROMAN;
                   break;
         case 'p':
@@ -692,6 +755,18 @@
 
 
 /***********************************************************************
+ *           XFONT_CheckResourceName
+ */
+static BOOL32 XFONT_CheckResourceName( LPSTR resource, LPCSTR name, INT32 n )
+{
+    resource = LFD_Advance( resource, 2 );
+    if( resource )
+	return (!lstrncmpi32A( resource, name, n ));
+    return FALSE;
+}
+
+
+/***********************************************************************
  *           XFONT_WindowsNames
  *
  * Build generic Windows aliases for X font names.
@@ -711,17 +786,13 @@
 	if( fr->fr_flags & FR_NAMESET ) continue;     /* skip already assigned */
 
 	lpstr = LFD_Advance(fr->resource, 2);
-	i = lpstr - LFD_Advance( lpstr, 1 );
+	i = LFD_Advance( lpstr, 1 ) - lpstr;
 
 	for( pfr = fontList; pfr != fr ; pfr = pfr->next )
 	    if( pfr->fr_flags & FR_NAMESET )
-	    {
-		lpch = LFD_Advance(pfr->resource, 2);
+		if( XFONT_CheckResourceName( pfr->resource, lpstr, i ) )
+		    break;
 
-		/* check if already have the same face name */
-
-		if( !lstrncmp32A(lpch, lpstr, i) ) break;
-	    }
 	if( pfr != fr )  /* prepend vendor name */
 	    lpstr = fr->resource + 1;
 
@@ -781,10 +852,24 @@
  */
 static fontAlias* XFONT_CreateAlias( LPCSTR lpTypeFace, LPCSTR lpAlias )
 {
+    int j;
     fontAlias* pfa = aliasTable;
-    int j = lstrlen32A(lpTypeFace) + 1;
 
-    while( pfa->next ) pfa = pfa->next;
+    while( 1 ) 
+    {
+	/* check if we already got one */
+	if( !lstrcmpi32A( pfa->faTypeFace, lpAlias ) )
+	{
+#ifdef DEBUG_FONT_INIT
+	    dprintf_font(stddeb,"\tredundant alias '%s' -> '%s'\n", lpAlias, lpTypeFace );
+#endif
+	    return NULL;
+	} 
+	if( pfa->next ) pfa = pfa->next;
+	else break;
+    }
+
+    j = lstrlen32A(lpTypeFace) + 1;
     pfa->next = HeapAlloc( SystemHeap, 0, sizeof(fontAlias) +
 					  j + lstrlen32A(lpAlias) + 1 );
     if((pfa = pfa->next))
@@ -814,54 +899,79 @@
  *   Alias0 = Arial, -adobe-helvetica- 
  *   Alias1 = Times New Roman, -bitstream-courier-, 1
  *   ...
+ *
+ * Note that from 081797 and on we have built-in alias templates that take
+ * care of the necessary Windows typefaces.
  */
 static void XFONT_LoadAliases( char** buffer, int buf_size )
 {
+    char* lpResource, *lpAlias;
     char  subsection[32];
-    int	  i = 0;
+    int	  i = 0, j = 0;
+    BOOL32 bHaveAlias = TRUE, bSubst = FALSE;
 
     if( buf_size < 128 )
 	*buffer = HeapReAlloc(SystemHeap, 0, *buffer, 256 );
     do
     {
-	wsprintf32A( subsection, "%s%i", INISubSection, i++ );
-
-	if( PROFILE_GetWineIniString( INIFontSection, subsection, "", *buffer, 128 ) )
+	if( j < faTemplateNum )
 	{
-	    char* lpchX, *lpchW = *buffer;
+	    /* built-in templates first */
 
-	    while( isspace(*lpchW) ) lpchW++;
-	    lpchX = PROFILE_GetStringItem( lpchW );
+	    lpResource = faTemplate[j].fatResource;
+	    lpAlias = faTemplate[j].fatAlias;
+	    j++;
+	}
+	else
+	{
+	    /* then WINE.CONF */
 
-	    if( lpchX )
+	    wsprintf32A( subsection, "%s%i", INISubSection, i++ );
+
+	    if( (bHaveAlias = PROFILE_GetWineIniString( INIFontSection, 
+					subsection, "", *buffer, 128 )) )
 	    {
-		fontResource* fr;
+		lpAlias = *buffer;
+		while( isspace(*lpAlias) ) lpAlias++;
+		lpResource = PROFILE_GetStringItem( lpAlias );
+		bSubst = (PROFILE_GetStringItem( lpResource )) ? TRUE : FALSE;
+	    }
+	}
+
+	if( bHaveAlias )
+	{
+	    int length;
+
+	    length = lstrlen32A( lpAlias );
+	    if( lpResource && length )
+	    {
+		fontResource* fr, *frMatch = NULL;
 
 		for (fr = fontList; fr ; fr = fr->next)
 		{
-		    int j;
-
-		    j = lstrlen32A( fr->resource );
-
-		    if( !lstrncmpi32A( fr->resource, lpchX, j) )
+		    if( !lstrcmpi32A( fr->resource, lpResource ) ) frMatch = fr;
+		    if( XFONT_CheckResourceName( fr->resource, lpAlias, length ) )
 		    {
-			char* lpch = PROFILE_GetStringItem( lpchX );
+			/* alias is not needed since the real font is present */
+			frMatch = NULL; break;
+		    }
+		}
 
-			if( lpch )
-			{
+		if( frMatch )
+		{
+		    if( bSubst )
+		    {
 #ifdef DEBUG_FONT_INIT
-                            dprintf_font(stddeb, "\tsubstituted '%s' with %s\n",
-							fr->lfFaceName, lpchW );
+                        dprintf_font(stddeb, "\tsubstituted '%s' with %s\n",
+						frMatch->lfFaceName, lpAlias );
 #endif
-			    lstrcpyn32A( fr->lfFaceName, lpchW, LF_FACESIZE );
-			    fr->fr_flags |= FR_NAMESET;
-			}
-		        else
-			{
-			    /* create new entry in the alias table */
-			    XFONT_CreateAlias(fr->lfFaceName, lpchW);
-			}
-			break;
+			lstrcpyn32A( frMatch->lfFaceName, lpAlias, LF_FACESIZE );
+			frMatch->fr_flags |= FR_NAMESET;
+		    }
+		    else
+		    {
+			/* create new entry in the alias table */
+			XFONT_CreateAlias( frMatch->lfFaceName, lpAlias );
 		    }
 		}
 	    }
@@ -883,8 +993,10 @@
     pwd = getpwuid(getuid());
     if( pwd && pwd->pw_dir )
     {
-	int i = lstrlen32A( pwd->pw_dir ) + lstrlen32A( INIWinePrefix ) + lstrlen32A( INIFontMetrics ) + 2;
-	if( i > *buf_size ) buffer = (char*) HeapReAlloc( SystemHeap, 0, buffer, *buf_size = i );
+	int i = lstrlen32A( pwd->pw_dir ) + lstrlen32A( INIWinePrefix ) + 
+					    lstrlen32A( INIFontMetrics ) + 2;
+	if( i > *buf_size ) 
+	    buffer = (char*) HeapReAlloc( SystemHeap, 0, buffer, *buf_size = i );
 	lstrcpy32A( buffer, pwd->pw_dir );
 	strcat( buffer, INIWinePrefix );
 	strcat( buffer, INIFontMetrics );
@@ -896,7 +1008,7 @@
 /***********************************************************************
  *           XFONT_ReadCachedMetrics
  */
-static BOOL32 XFONT_ReadCachedMetrics( int fd, unsigned x_checksum, int x_count )
+static BOOL32 XFONT_ReadCachedMetrics( int fd, int res, unsigned x_checksum, int x_count )
 {
     if( fd >= 0 )
     {
@@ -938,6 +1050,9 @@
 			      (int)(pfi->next) != j++ ) goto fail;
 
 			   pfi->df.dfFace = pfr->lfFaceName;
+			   pfi->df.dfHorizRes = pfi->df.dfVertRes = res;
+			   pfi->df.dfPoints = (INT16)(((INT32)(pfi->df.dfPixHeight -
+					pfi->df.dfInternalLeading) * 72) / res );
 			   pfi->next = pfi + 1;
 
 			   if( j > pfr->count ) break;
@@ -1059,6 +1174,108 @@
 }
 
 /***********************************************************************
+ *           XFONT_CheckIniSection
+ *
+ *   Examines wine.conf for old/invalid font entries and recommend changes to
+ *   the user.
+ *
+ *   Revision history
+ *        05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
+ *             Original implementation.
+ */
+static void XFONT_CheckIniCallback(char const *, char const *, void *);
+
+static char const  *fontmsgprologue =
+"Wine warning:\n"
+"   The following entries in the [fonts] section of the wine.conf file are\n"
+"   obsolete or invalid:\n";
+
+static char const  *fontmsgepilogue =
+"   These entries should be eliminated or updated.\n"
+"   See the documentation/fonts file for more information.\n";
+
+static int XFONT_CheckIniSection()
+{
+    int  found = 0;
+
+    PROFILE_EnumerateWineIniSection("Fonts", &XFONT_CheckIniCallback,
+                    (void *)&found);
+    if(found)
+    fprintf(stderr, fontmsgepilogue);
+
+    return 1;
+}
+
+static void  XFONT_CheckIniCallback(
+    char const  *key,
+    char const  *value,
+    void  *found)
+{
+    /* Ignore any keys that start with potential comment characters "'", '#',
+       or ';'. */
+    if(key[0] == '\'' || key[0] == '#' || key[0] == ';' || key[0] == '\0')
+    return;
+
+    /* Make sure this is a valid key */
+    if((strncasecmp(key, INISubSection, 5) == 0) ||
+       (strcasecmp(key, INIDefault) == 0) ||
+       (strcasecmp(key, INIGlobalMetrics) == 0) ||
+       (strcasecmp(key, INIResolution) == 0) ) 
+    {
+	/* Valid key; make sure the value doesn't contain a wildcard */
+	if(strchr(value, '*')) {
+	    if(*(int *)found == 0) {
+		fprintf(stderr, fontmsgprologue);
+		++*(int *)found;
+	    }
+
+	    fprintf(stderr, "     %s=%s [no wildcards allowed]\n", key, value);
+	}
+    }
+    else {
+	/* Not a valid key */
+	if(*(int *)found == 0) {
+	    fprintf(stderr, fontmsgprologue);
+	    ++*(int *)found;
+    }
+
+	fprintf(stderr, "     %s=%s [obsolete]\n", key, value);
+    }
+
+    return;
+}
+
+/***********************************************************************
+ *           XFONT_GetPointResolution()
+ *
+ * Here we initialize DefResolution which is used in the
+ * XFONT_Match() penalty function. We also load the point
+ * resolution value (higher values result in larger fonts).
+ */
+static int XFONT_GetPointResolution( DeviceCaps* pDevCaps )
+{
+    int i, j, point_resolution, num = 3; 
+    int allowed_xfont_resolutions[3] = { 72, 75, 100 };
+    int best = 0, best_diff = 65536;
+
+    DefResolution = point_resolution = PROFILE_GetWineIniInt( INIFontSection, INIResolution, 0 );
+    if( !DefResolution ) DefResolution = point_resolution = pDevCaps->logPixelsY;
+    else pDevCaps->logPixelsX = pDevCaps->logPixelsY = DefResolution;
+
+    for( i = best = 0; i < num; i++ )
+    {
+	j = abs( DefResolution - allowed_xfont_resolutions[i] );
+	if( j < best_diff )
+	{
+	    best = i;
+		best_diff = j;
+	}
+    }
+    DefResolution = allowed_xfont_resolutions[best];
+    return point_resolution;
+}
+
+/***********************************************************************
  *           X11DRV_FONT_Init
  *
  * Initialize font resource list and allocate font cache.
@@ -1069,24 +1286,18 @@
   fontResource* fr, *pfr;
   fontInfo*	fi, *pfi;
   unsigned	x_checksum;
-  int		i, j, k, x_count, fd = -1, buf_size = 0;
+  int		i, j, res, x_count, fd = -1, buf_size = 0;
   char*		lpstr, *lpch, *lpmetrics, *buffer;
   char**	x_pattern;
 
-  DefResolution = PROFILE_GetWineIniInt( INIFontSection, "Resolution", 0 );
-  if( !DefResolution ) DefResolution = pDevCaps->logPixelsY;
+  XFONT_CheckIniSection();
 
-  i = abs(DefResolution - 72);
-  j = abs(DefResolution - 75);
-  k = abs(DefResolution - 100);
-
-  if( i < j ) DefResolution = ( i < k ) ? 72 : 100;
-  else DefResolution = ( j < k ) ? 75 : 100;
+  res = XFONT_GetPointResolution( pDevCaps );
       
   x_pattern = XListFonts(display, "*", MAX_FONT_FAMILIES * 16, &x_count );
 
-  dprintf_font(stddeb,"Font Mapper: initializing %i fonts [LPY=%i, DR=%i]\n", 
-				    x_count, pDevCaps->logPixelsY, DefResolution);
+  dprintf_font(stddeb,"Font Mapper: initializing %i fonts [LPY=%i, XDR=%i, DR=%i]\n", 
+				    x_count, pDevCaps->logPixelsY, DefResolution, res);
   for( i = x_checksum = 0; i < x_count; i++ )
   {
 #if 0
@@ -1104,17 +1315,17 @@
 
   /* deal with systemwide font metrics cache */
 
-  if( PROFILE_GetWineIniString( INIFontSection, "FontMetrics", "", buffer, 128 ) )
+  if( PROFILE_GetWineIniString( INIFontSection, INIGlobalMetrics, "", buffer, 128 ) )
       fd = open( buffer, O_RDONLY );
 
-  if( XFONT_ReadCachedMetrics(fd, x_checksum, x_count) == FALSE )
+  if( XFONT_ReadCachedMetrics(fd, res, x_checksum, x_count) == FALSE )
   {
       /* try per-user */
       buffer = XFONT_UserMetricsCache( buffer, &buf_size );
       if( buffer[0] )
       {
 	  fd = open( buffer, O_RDONLY );
-	  if( XFONT_ReadCachedMetrics(fd, x_checksum, x_count) == FALSE )
+	  if( XFONT_ReadCachedMetrics(fd, res, x_checksum, x_count) == FALSE )
 	      lpmetrics = HEAP_strdupA( SystemHeap, 0, buffer ); /* update later on */
       }
   }
@@ -1196,8 +1407,7 @@
 
 	if( (x_fs = XLoadQueryFont(display, lpstr)) )
 	{
-	   fi->df.dfHorizRes = pDevCaps->logPixelsX;
-           fi->df.dfVertRes = pDevCaps->logPixelsY;
+	   fi->df.dfHorizRes = fi->df.dfVertRes = res;
 
 	   XFONT_SetFontMetric( fi, fr, x_fs );
            XFreeFont( display, x_fs );
@@ -1301,7 +1511,7 @@
  *      weight, italics, underlines, strikeouts
  *
  * NOTE: you can experiment with different penalty weights to see what happens.
- * http://premium.microsoft.com/msdn/library/techart/f30/f34/f40/d4d/sa8bf.htm
+ * http://premium.microsoft.com/msdn/library/techart/f365/f36b/f37b/d38b/sa8bf.htm
  */
 static UINT32 XFONT_Match( fontMatch* pfm )
 {
@@ -1354,7 +1564,7 @@
 	   else 	/* expand only in integer multiples */
 	   {
 	       pfm->height = height - height%pfi->df.dfPixHeight;
-	       penalty += (height - pfm->height) * pfm->height / height;
+	       penalty += (height - pfm->height + 1) * height / pfi->df.dfPixHeight;
 	   }
        }
        else /* can't be scaled at all */
@@ -1432,18 +1642,6 @@
 }
 
 /***********************************************************************
- *            XFONT_CheckAliasTable
- */
-static LPSTR XFONT_CheckAliasTable( LPSTR lpAlias )
-{
-    fontAlias* fa;
-
-    for( fa = aliasTable; fa; fa = fa->next )
-	if( !lstrcmpi32A( fa->faAlias, lpAlias ) ) return fa->faTypeFace;
-    return NULL;
-}
-
-/***********************************************************************
  *            XFONT_CheckFIList
  *
  * REMOVE_SUBSETS - attach new fi and purge subsets
@@ -1515,9 +1713,17 @@
     fontMatch           fm = *pfm;
 
     pfm->pfi = NULL;
-    if( fm.plf->lfFaceName[0] )
+    if( fm.plf->lfFaceName[0] ) 
     {
-	LPSTR str = XFONT_CheckAliasTable( fm.plf->lfFaceName );
+	fontAlias* fa;
+	LPSTR str = NULL;
+
+	for( fa = aliasTable; fa; fa = fa->next )
+	     if( !lstrcmpi32A( fa->faAlias, fm.plf->lfFaceName ) ) 
+	     {
+		str = fa->faTypeFace;
+		break;
+	     }
         fm.pfr = XFONT_FindFIList( start, str ? str : fm.plf->lfFaceName );
     }
 
@@ -1827,11 +2033,17 @@
 HFONT32 X11DRV_FONT_SelectObject( DC* dc, HFONT32 hfont, FONTOBJ* font )
 {
     HFONT32 hPrevFont = 0;
+    LOGFONT16	lf;
 
     if( CHECK_PFONT(dc->u.x.font) ) 
         XFONT_ReleaseCacheEntry( __PFONT(dc->u.x.font) );
 
-    dc->u.x.font = XFONT_RealizeFont( &font->logfont );
+    /* FIXME: do we need to pass anything back from here? */
+    memcpy(&lf,&font->logfont,sizeof(lf));
+    lf.lfWidth	= font->logfont.lfWidth * dc->vportExtX/dc->wndExtX;
+    lf.lfHeight	= font->logfont.lfHeight* dc->vportExtY/dc->wndExtY;
+
+    dc->u.x.font = XFONT_RealizeFont( &lf );
     hPrevFont = dc->w.hFont;
     dc->w.hFont = hfont;
 
@@ -1966,7 +2178,7 @@
  *	   the pfr->resource field) with FR_SOFTFONT/FR_SOFTRESOURCE 
  *	   flag set. 
  */
-INT16 AddFontResource16( LPCSTR filename )
+INT16 WINAPI AddFontResource16( LPCSTR filename )
 {
     return AddFontResource32A( filename );
 }
@@ -1975,7 +2187,7 @@
 /***********************************************************************
  *           AddFontResource32A    (GDI32.2)
  */
-INT32 AddFontResource32A( LPCSTR str )
+INT32 WINAPI AddFontResource32A( LPCSTR str )
 {
     if (HIWORD(str))	/* font file */
         fprintf( stdnimp, "STUB: AddFontResource('%s')\n", str );
@@ -1988,7 +2200,7 @@
 /***********************************************************************
  *           AddFontResource32W    (GDI32.4)
  */
-INT32 AddFontResource32W( LPCWSTR str )
+INT32 WINAPI AddFontResource32W( LPCWSTR str )
 {
     fprintf( stdnimp, "STUB: AddFontResource32W(%p)\n", str );
     return 1;
@@ -1997,7 +2209,7 @@
 /***********************************************************************
  *           RemoveFontResource16    (GDI.136)
  */
-BOOL16 RemoveFontResource16( SEGPTR str )
+BOOL16 WINAPI RemoveFontResource16( SEGPTR str )
 {
     if (HIWORD(str))
         fprintf( stdnimp, "STUB: RemoveFontResource('%s')\n",
@@ -2011,7 +2223,7 @@
 /***********************************************************************
  *           RemoveFontResource32A    (GDI32.284)
  */
-BOOL32 RemoveFontResource32A( LPCSTR str )
+BOOL32 WINAPI RemoveFontResource32A( LPCSTR str )
 {
     if (HIWORD(str))
         fprintf( stdnimp, "STUB: RemoveFontResource('%s')\n", str );
@@ -2024,7 +2236,7 @@
 /***********************************************************************
  *           RemoveFontResource32W    (GDI32.286)
  */
-BOOL32 RemoveFontResource32W( LPCWSTR str )
+BOOL32 WINAPI RemoveFontResource32W( LPCWSTR str )
 {
     fprintf( stdnimp, "STUB: RemoveFontResource32W(%p)\n", str );
     return TRUE;
diff --git a/if1632/builtin.c b/if1632/builtin.c
index ebe48ad..6cc4527 100644
--- a/if1632/builtin.c
+++ b/if1632/builtin.c
@@ -154,7 +154,7 @@
     { &GDI32_Descriptor,    0 },
     { &KERNEL32_Descriptor, DLL_FLAG_ALWAYS_USED },
     { &LZ32_Descriptor,     0 },
-    { &MPR_Descriptor,      0 },
+    { &MPR_Descriptor,      DLL_FLAG_NOT_USED },
     { &NTDLL_Descriptor,    0 },
     { &SHELL32_Descriptor,  0 },
     { &USER32_Descriptor,   0 },
diff --git a/if1632/comctl32.spec b/if1632/comctl32.spec
index be6c101..d2f1efa 100644
--- a/if1632/comctl32.spec
+++ b/if1632/comctl32.spec
@@ -20,7 +20,7 @@
 11 stub MakeDragList
 12 stub LBItemFromPt
 13 stub DrawInsert
-14 stub CreateUpDownControl
+14 stdcall CreateUpDownControl(long long long long long long long long long long long long) CreateUpDownControl
 15 stdcall InitCommonControls() InitCommonControls
 16 stub CreateStatusWindow
 17 stub CreateStatusWindowW
diff --git a/if1632/crtdll.spec b/if1632/crtdll.spec
index 42a8805..5a61f97 100644
--- a/if1632/crtdll.spec
+++ b/if1632/crtdll.spec
@@ -131,7 +131,7 @@
 126 stub _getpid
 127 stub _getsystime
 128 stub _getw
-129 stub _global_unwind2
+129 register _global_unwind2(ptr) CRTDLL__global_unwind2
 130 stub _heapchk
 131 stub _heapmin
 132 stub _heapset
@@ -175,7 +175,7 @@
 170 stub _kbhit
 171 stub _lfind
 172 stub _loaddll
-173 stub _local_unwind2
+173 register _local_unwind2(ptr long) CRTDLL__local_unwind2
 174 stub _locking
 175 stub _logb
 176 stub _lrotl
@@ -461,7 +461,7 @@
 456 cdecl sin(long) CRTDLL_sin
 457 cdecl sinh(long) CRTDLL_sinh
 458 cdecl sprintf() CRTDLL_sprintf
-459 cdecl sqrt(long) CRTDLL_sqrt
+459 cdecl sqrt(long long) CRTDLL_sqrt
 460 cdecl srand(long) CRTDLL_srand
 461 cdecl sscanf() CRTDLL_sscanf
 462 cdecl strcat(ptr ptr) strcat
diff --git a/if1632/dummy.c b/if1632/dummy.c
index abc792e..dbf23c8 100644
--- a/if1632/dummy.c
+++ b/if1632/dummy.c
@@ -1,47 +1,49 @@
 #include <stdio.h>
-long stub_GDI_379(void) { fprintf(stderr, "Warning: GDI_379:STARTPAGE unimplemented stub\n"); return 1; }
-long stub_GDI_380(void) { fprintf(stderr, "Warning: GDI_380:ENDPAGE unimplemented stub\n"); return 1; }
-long stub_GDI_381(void) { fprintf(stderr, "Warning: GDI_381:SETABORTPROC unimplemented stub\n"); return 1; }
-long stub_GDI_382(void) { fprintf(stderr, "Warning: GDI_382:ABORTPROC unimplemented stub\n"); return 1; }
-long stub_GDI_530(void) { fprintf(stderr, "Warning: GDI_530: unimplemented stub\n"); return 0; }
-long stub_GDI_531(void) { fprintf(stderr, "Warning: GDI_531: unimplemented stub\n"); return 0; }
-long stub_GDI_532(void) { fprintf(stderr, "Warning: GDI_532: unimplemented stub\n"); return 0; }
-long stub_GDI_536(void) { fprintf(stderr, "Warning: GDI_536: unimplemented stub\n"); return 0; }
-long stub_GDI_538(void) { fprintf(stderr, "Warning: GDI_538: unimplemented stub\n"); return 0; }
-long stub_GDI_540(void) { fprintf(stderr, "Warning: GDI_540: unimplemented stub\n"); return 0; }
-long stub_GDI_543(void) { fprintf(stderr, "Warning: GDI_543: unimplemented stub\n"); return 0; }
-long stub_GDI_555(void) { fprintf(stderr, "Warning: GDI_555: unimplemented stub\n"); return 0; }
-long stub_GDI_560(void) { fprintf(stderr, "Warning: GDI_560: unimplemented stub\n"); return 0; }
-long stub_GDI_561(void) { fprintf(stderr, "Warning: GDI_561: unimplemented stub\n"); return 0; }
-long stub_GDI_564(void) { fprintf(stderr, "Warning: GDI_564: unimplemented stub\n"); return 0; }
-long stub_GDI_565(void) { fprintf(stderr, "Warning: GDI_565: unimplemented stub\n"); return 0; }
-long stub_GDI_566(void) { fprintf(stderr, "Warning: GDI_566: unimplemented stub\n"); return 0; }
-long stub_GDI_571(void) { fprintf(stderr, "Warning: GDI_571: unimplemented stub\n"); return 0; }
-long stub_GDI_572(void) { fprintf(stderr, "Warning: GDI_572: unimplemented stub\n"); return 0; }
-long stub_GDI_573(void) { fprintf(stderr, "Warning: GDI_573: unimplemented stub\n"); return 0; }
-long stub_GDI_556(void) { fprintf(stderr, "Warning: GDI_556: unimplemented stub\n"); return 0; }
-long stub_GDI_558(void) { fprintf(stderr, "Warning: GDI_558: unimplemented stub\n"); return 0; }
-long stub_GDI_569(void) { fprintf(stderr, "Warning: GDI_569: unimplemented stub\n"); return 0; }
-long stub_KERNEL_450(void) { fprintf(stderr, "Warning: KERNEL_450: unimplemented stub\n"); return 0; }
-long stub_USER_489(void) { fprintf(stderr, "Warning: USER_489: unimplemented stub\n"); return 0; }
-long stub_USER_490(void) { fprintf(stderr, "Warning: USER_490: unimplemented stub\n"); return 0; }
-long stub_USER_492(void) { fprintf(stderr, "Warning: USER_492: unimplemented stub\n"); return 0; }
-long stub_USER_496(void) { fprintf(stderr, "Warning: USER_496: unimplemented stub\n"); return 0; }
-long stub_USER_902(void) { fprintf(stderr, "Warning: USER_902: unimplemented stub\n"); return 0; }
-long stub_USER_905(void) { fprintf(stderr, "Warning: USER_905: unimplemented stub\n"); return 0; }
-long stub_USER_906(void) { fprintf(stderr, "Warning: USER_906: unimplemented stub\n"); return 0; }
-long stub_USER_907(void) { fprintf(stderr, "Warning: USER_907: unimplemented stub\n"); return 0; }
-long stub_USER_909(void) { fprintf(stderr, "Warning: USER_909: unimplemented stub\n"); return 0; }
-long stub_USER_910(void) { fprintf(stderr, "Warning: USER_910: unimplemented stub\n"); return 0; }
-long stub_USER_911(void) { fprintf(stderr, "Warning: USER_911: unimplemented stub\n"); return 0; }
-long stub_USER_912(void) { fprintf(stderr, "Warning: USER_912: unimplemented stub\n"); return 0; }
-long stub_USER_913(void) { fprintf(stderr, "Warning: USER_913: unimplemented stub\n"); return 0; }
-long stub_USER_914(void) { fprintf(stderr, "Warning: USER_914: unimplemented stub\n"); return 0; }
-long stub_USER_915(void) { fprintf(stderr, "Warning: USER_915: unimplemented stub\n"); return 0; }
-long stub_USER_916(void) { fprintf(stderr, "Warning: USER_916: unimplemented stub\n"); return 0; }
-long stub_USER_918(void) { fprintf(stderr, "Warning: USER_918: unimplemented stub\n"); return 0; }
-long stub_USER_919(void) { fprintf(stderr, "Warning: USER_919: unimplemented stub\n"); return 0; }
-long stub_USER_920(void) { fprintf(stderr, "Warning: USER_920: unimplemented stub\n"); return 0; }
-long stub_USER_922(void) { fprintf(stderr, "Warning: USER_922: unimplemented stub\n"); return 0; }
-long stub_USER_923(void) { fprintf(stderr, "Warning: USER_923: unimplemented stub\n"); return 0; }
-long stub_KERNEL_700(void) { fprintf(stderr, "Warning: KERNEL_700: unimplemented stub\n"); return 1; }
+#include "wintypes.h"
+long WINAPI stub_GDI_379(void) { fprintf(stderr, "Warning: GDI_379:STARTPAGE unimplemented stub\n"); return 1; }
+long WINAPI stub_GDI_380(void) { fprintf(stderr, "Warning: GDI_380:ENDPAGE unimplemented stub\n"); return 1; }
+long WINAPI stub_GDI_381(void) { fprintf(stderr, "Warning: GDI_381:SETABORTPROC unimplemented stub\n"); return 1; }
+long WINAPI stub_GDI_382(void) { fprintf(stderr, "Warning: GDI_382:ABORTPROC unimplemented stub\n"); return 1; }
+long WINAPI stub_GDI_530(void) { fprintf(stderr, "Warning: GDI_530: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_531(void) { fprintf(stderr, "Warning: GDI_531: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_532(void) { fprintf(stderr, "Warning: GDI_532: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_536(void) { fprintf(stderr, "Warning: GDI_536: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_538(void) { fprintf(stderr, "Warning: GDI_538: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_540(void) { fprintf(stderr, "Warning: GDI_540: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_543(void) { fprintf(stderr, "Warning: GDI_543: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_555(void) { fprintf(stderr, "Warning: GDI_555: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_560(void) { fprintf(stderr, "Warning: GDI_560: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_561(void) { fprintf(stderr, "Warning: GDI_561: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_564(void) { fprintf(stderr, "Warning: GDI_564: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_565(void) { fprintf(stderr, "Warning: GDI_565: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_566(void) { fprintf(stderr, "Warning: GDI_566: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_571(void) { fprintf(stderr, "Warning: GDI_571: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_572(void) { fprintf(stderr, "Warning: GDI_572: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_573(void) { fprintf(stderr, "Warning: GDI_573: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_556(void) { fprintf(stderr, "Warning: GDI_556: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_558(void) { fprintf(stderr, "Warning: GDI_558: unimplemented stub\n"); return 0; }
+long WINAPI stub_GDI_569(void) { fprintf(stderr, "Warning: GDI_569: unimplemented stub\n"); return 0; }
+long WINAPI stub_KERNEL_450(void) { fprintf(stderr, "Warning: KERNEL_450: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_489(void) { fprintf(stderr, "Warning: USER_489: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_490(void) { fprintf(stderr, "Warning: USER_490: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_492(void) { fprintf(stderr, "Warning: USER_492: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_496(void) { fprintf(stderr, "Warning: USER_496: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_902(void) { fprintf(stderr, "Warning: USER_902: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_905(void) { fprintf(stderr, "Warning: USER_905: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_906(void) { fprintf(stderr, "Warning: USER_906: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_907(void) { fprintf(stderr, "Warning: USER_907: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_909(void) { fprintf(stderr, "Warning: USER_909: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_910(void) { fprintf(stderr, "Warning: USER_910: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_911(void) { fprintf(stderr, "Warning: USER_911: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_912(void) { fprintf(stderr, "Warning: USER_912: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_913(void) { fprintf(stderr, "Warning: USER_913: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_914(void) { fprintf(stderr, "Warning: USER_914: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_915(void) { fprintf(stderr, "Warning: USER_915: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_916(void) { fprintf(stderr, "Warning: USER_916: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_918(void) { fprintf(stderr, "Warning: USER_918: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_919(void) { fprintf(stderr, "Warning: USER_919: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_920(void) { fprintf(stderr, "Warning: USER_920: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_922(void) { fprintf(stderr, "Warning: USER_922: unimplemented stub\n"); return 0; }
+long WINAPI stub_USER_923(void) { fprintf(stderr, "Warning: USER_923: unimplemented stub\n"); return 0; }
+long WINAPI stub_KERNEL_700(void) { fprintf(stderr, "Warning: KERNEL_700: unimplemented stub\n"); return 1; }
+long WINAPI stub_KERNEL_449(void) { fprintf(stderr, "Warning: KERNEL_449: unimplemented stub\n"); return 0; }
diff --git a/if1632/gdi.spec b/if1632/gdi.spec
index e407b44..1b0f157 100644
--- a/if1632/gdi.spec
+++ b/if1632/gdi.spec
@@ -314,7 +314,7 @@
              ScaleViewportExtEx16
 485 pascal16 ScaleWindowExtEx(word s_word s_word s_word s_word ptr)
              ScaleWindowExtEx16
-486 stub GETASPECTRATIOFILTEREX
+486 pascal16 GetAspectRatioFilterEx(word ptr) GetAspectRatioFilterEx16
 489 stub CreateDIBSection
 490 stub CloseEnhMetafile
 491 stub CopyEnhMetafile
diff --git a/if1632/gdi32.spec b/if1632/gdi32.spec
index 5cf890a..fd5c543 100644
--- a/if1632/gdi32.spec
+++ b/if1632/gdi32.spec
@@ -391,7 +391,7 @@
 0379 stub GdiWinWatchOpen
 0380 stub GetGlyphOutlineWow
 0381 stub GetTextCharsetInfo
-0382 stub TranslateCharsetInfo
+0382 stdcall TranslateCharsetInfo(ptr ptr long) TranslateCharSetInfo
 0383 stub UpdateICMRegKeyA
 0384 stub UpdateICMRegKeyW
 0385 stub gdiPlaySpoolStream
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index 39a6b41..e17ff9c 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -243,6 +243,7 @@
 318 stub FatalExitHook
 319 stub FlushCachedFileHandle
 320 pascal16 IsTask(word) IsTask
+321 stub KERNEL_321
 323 return IsRomModule 2 0
 324 pascal16 LogError(word ptr) LogError
 325 pascal16 LogParamError(word ptr ptr) LogParamError
@@ -304,7 +305,7 @@
 445 stub KERNEL_445
 446 stub KERNEL_446
 447 stub KERNEL_447
-449 stub KERNEL_449
+449 pascal KERNEL_449() stub_KERNEL_449
 450 pascal16 KERNEL_450() stub_KERNEL_450
 454 stub KERNEL_454
 455 stub KERNEL_455
@@ -321,7 +322,7 @@
 513 pascal   LoadLibraryEx32W(ptr long long) LoadLibraryEx32W16
 514 pascal16 FreeLibrary32W(long) FreeLibrary32
 515 pascal   GetProcAddress32W(long ptr) GetProcAddress32
-516 stub GetVDMPointer32W
+516 pascal GetVDMPointer32W(segptr long) GetVDMPointer32W
 517 pascal CallProc32W() WIN16_CallProc32W
 518 stub CallProcEx32W
 519 stub KERNEL_519
@@ -334,7 +335,7 @@
 612 stub KERNEL_612
 613 stub KERNEL_613
 614 stub KERNEL_614
-619 stub KERNEL_619
+619 pascal KERNEL_619(word long long) _KERNEL_619
 621 stub KERNEL_621
 627 stub IsBadFlatReadWritePtr
 630 stub KERNEL_630
diff --git a/if1632/kernel32.spec b/if1632/kernel32.spec
index b858d62..695a564 100644
--- a/if1632/kernel32.spec
+++ b/if1632/kernel32.spec
@@ -35,7 +35,7 @@
 40  stdcall _KERNEL32_41(long long long long long) _KERNEL32_41
 41  stub _KERNEL32_42
 42  stdcall _KERNEL32_43(long ptr long ptr ptr) _KERNEL32_43
-44  register _KERNEL32_45(long) _KERNEL32_45 
+44  register _KERNEL32_45() _KERNEL32_45 
 45  stdcall _KERNEL32_46(long long long long long) _KERNEL32_46
 46  stub _KERNEL32_47
  
@@ -44,7 +44,7 @@
 51  register _KERNEL32_52(long) _KERNEL32_52
 
 # WOW calls
-53  stub WOWCallback16
+53  stdcall WOWCallback16(long long) WOWCallback16
 54  stub WOWCallback16Ex
 55  stdcall WOWGetVDMPointer(long long long) WOWGetVDMPointer
 56  stub WOWHandle32
@@ -53,7 +53,7 @@
 59  stub WOWGlobalLock16
 60  stub WOWGlobalUnlock16
 61  stub WOWGlobalFree16
-62  stub WOWGlobalAllocLock16
+62  stdcall WOWGlobalAllocLock16(long long ptr) WOWGlobalAllocLock16
 63  stub WOWGlobalUnlockFree16
 64  stub WOWGlobalLockSize16
 65  stub WOWYield16
@@ -78,10 +78,10 @@
 84  stub RtlConvertUlongToLargeInteger
 
 86  stdcall _KERNEL32_87() _KERNEL32_87
-87  cdecl _KERNEL32_88(long long ptr) _KERNEL32_88
+87  cdecl _KERNEL32_88() _KERNEL32_88
 88  stub _KERNEL32_89
-89  stub _KERNEL32_90
-90  register _KERNEL32_91() _KERNEL32_91
+89  register _KERNEL32_90() _KERNEL32_90
+90  stub _KERNEL32_91
 91  stub _KERNEL32_92
 92  stdcall GETPWIN16LOCK(ptr) GetPWinLock
 96  stub ENTERSYSLEVEL
@@ -137,7 +137,7 @@
 144   stub ConnectNamedPipe
 145   stdcall ContinueDebugEvent(long long long) ContinueDebugEvent
 146   stub ConvertDefaultLocale
-147   stub ConvertToGlobalHandle
+147   stdcall ConvertToGlobalHandle(long) ConvertToGlobalHandle
 148   stdcall CopyFileA(ptr ptr long) CopyFile32A
 149   stdcall CopyFileW(ptr ptr long) CopyFile32W
 150   stub CreateConsoleScreenBuffer
@@ -285,6 +285,7 @@
 292   stdcall GetComputerNameA(ptr ptr) GetComputerName32A
 293   stdcall GetComputerNameW(ptr ptr) GetComputerName32W
 294   stdcall GetConsoleCP() GetConsoleCP
+295   stub GetConsoleCursorInfo
 296   stdcall GetConsoleMode(long ptr) GetConsoleMode
 297   stdcall GetConsoleOutputCP() GetConsoleOutputCP
 298   stdcall GetConsoleScreenBufferInfo(long ptr) GetConsoleScreenBufferInfo
@@ -368,7 +369,7 @@
 376   stub GetProcessShutdownParameters
 377   stdcall GetProcessTimes(long ptr ptr ptr ptr) GetProcessTimes
 378   stdcall GetProcessVersion(long) GetProcessVersion
-379   stub GetProcessWorkingSetSize
+379   stdcall GetProcessWorkingSetSize(long ptr ptr) GetProcessWorkingSetSize
 380   stub GetProductName
 381   stdcall GetProfileIntA(ptr ptr long) GetProfileInt32A
 382   stdcall GetProfileIntW(ptr ptr long) GetProfileInt32W
@@ -407,7 +408,7 @@
 415   stdcall GetThreadContext(long ptr) GetThreadContext
 416   stdcall GetThreadLocale() GetThreadLocale
 417   stdcall GetThreadPriority(long) GetThreadPriority
-418   stub GetThreadSelectorEntry
+418   stdcall GetThreadSelectorEntry(long long ptr) GetThreadSelectorEntry
 419   stub GetThreadTimes
 420   stdcall GetTickCount() GetTickCount
 421   stub GetTimeFormatA
@@ -454,6 +455,7 @@
 462   stdcall HeapFree(long long ptr) HeapFree
 463   stdcall HeapLock(long) HeapLock
 464   stdcall HeapReAlloc(long long ptr long) HeapReAlloc
+465   stub HeapSetFlags
 466   stdcall HeapSize(long long ptr) HeapSize
 467   stdcall HeapUnlock(long) HeapUnlock
 468   stdcall HeapValidate(long long ptr) HeapValidate
@@ -461,10 +463,10 @@
 470   stub InitAtomTable
 471   stdcall InitializeCriticalSection(ptr) InitializeCriticalSection
 472   stdcall InterlockedDecrement(ptr) InterlockedDecrement
-473   stdcall InterlockedExchange(ptr) InterlockedExchange
+473   stdcall InterlockedExchange(ptr long) InterlockedExchange
 474   stdcall InterlockedIncrement(ptr) InterlockedIncrement
 475   stub InvalidateNLSCache
-476   stdcall IsBadCodePtr(ptr long) IsBadCodePtr32
+476   stdcall IsBadCodePtr(ptr) IsBadCodePtr32
 477   stdcall IsBadHugeReadPtr(ptr long) IsBadHugeReadPtr32
 478   stdcall IsBadHugeWritePtr(ptr long) IsBadHugeWritePtr32
 479   stdcall IsBadReadPtr(ptr long) IsBadReadPtr32
@@ -483,7 +485,7 @@
 492   stub LCMapStringW
 493   stdcall LeaveCriticalSection(ptr)	LeaveCriticalSection
 494   stdcall LoadLibraryA(ptr) LoadLibrary32A
-495   stub LoadLibraryExA
+495   stdcall LoadLibraryExA(ptr long long) LoadLibraryEx32A
 496   stub LoadLibraryExW
 497   stdcall LoadLibraryW(ptr) LoadLibrary32W
 498   stub LoadModule
@@ -510,9 +512,8 @@
 519   stub MapHModuleLS
 520   stub MapHModuleSL
 521   stdcall MapLS(ptr) MapLS
-643   stdcall MapSL(long) MapSL
+522   stdcall MapSL(long) MapSL
 523   stub MapSLFix
-522   stub MapSL
 524   stdcall MapViewOfFile(long long long long long) MapViewOfFile
 525   stdcall MapViewOfFileEx(long long long long long ptr) MapViewOfFileEx
 526   stub Module32First
@@ -523,6 +524,7 @@
 531   stdcall MoveFileW(ptr ptr) MoveFile32W
 532   stdcall MulDiv(long long long) MulDiv32
 533   stdcall MultiByteToWideChar(long long ptr long ptr long) MultiByteToWideChar
+534   stub NotifyNLSUserCache
 535   stdcall OpenEventA(long long ptr) OpenEvent32A
 536   stdcall OpenEventW(long long ptr) OpenEvent32W
 537   stdcall OpenFile(ptr ptr long) OpenFile32
@@ -546,7 +548,7 @@
 555   stub Process32Next
 556   stub PulseEvent
 557   stub PurgeComm
-558   stub QT_Thunk
+558   register QT_Thunk() QT_Thunk
 559   stdcall QueryDosDeviceA(ptr ptr long) QueryDosDevice32A
 560   stdcall QueryDosDeviceW(ptr ptr long) QueryDosDevice32W
 561   stub QueryNumberOfEventLogRecords
@@ -566,7 +568,7 @@
 575   stdcall ReadConsoleW(long ptr long ptr ptr) ReadConsole32W
 576   stdcall ReadFile(long ptr long ptr ptr) ReadFile
 577   stub ReadFileEx
-578   stub ReadProcessMemory
+578   stdcall ReadProcessMemory(long ptr ptr long ptr) ReadProcessMemory
 579   stub RegisterServiceProcess
 580   stdcall ReinitializeCriticalSection(ptr) ReinitializeCriticalSection
 581   stdcall ReleaseMutex(long) ReleaseMutex
@@ -579,16 +581,16 @@
 588   stdcall RtlMoveMemory(ptr ptr long) RtlMoveMemory
 589   register RtlUnwind(ptr long ptr long) RtlUnwind
 590   stdcall RtlZeroMemory(ptr long) RtlZeroMemory
-591   stub SMapLS
-592   stub SMapLS_IP_EBP_12
-593   stub SMapLS_IP_EBP_16
-594   stub SMapLS_IP_EBP_20
-595   stub SMapLS_IP_EBP_24
-596   stub SMapLS_IP_EBP_28
-597   stub SMapLS_IP_EBP_32
-598   stub SMapLS_IP_EBP_36
-599   stub SMapLS_IP_EBP_40
-600   stub SMapLS_IP_EBP_8
+591   register SMapLS() SMapLS
+592   register SMapLS_IP_EBP_12() SMapLS_IP_EBP_12
+593   register SMapLS_IP_EBP_16() SMapLS_IP_EBP_16
+594   register SMapLS_IP_EBP_20() SMapLS_IP_EBP_20
+595   register SMapLS_IP_EBP_24() SMapLS_IP_EBP_24
+596   register SMapLS_IP_EBP_28() SMapLS_IP_EBP_28
+597   register SMapLS_IP_EBP_32() SMapLS_IP_EBP_32
+598   register SMapLS_IP_EBP_36() SMapLS_IP_EBP_36
+599   register SMapLS_IP_EBP_40() SMapLS_IP_EBP_40
+600   register SMapLS_IP_EBP_8() SMapLS_IP_EBP_8
 601   stub SUnMapLS
 602   stub SUnMapLS_IP_EBP_12
 603   stub SUnMapLS_IP_EBP_16
@@ -648,8 +650,8 @@
 657   stub SetMailslotInfo
 658   stub SetNamedPipeHandleState
 659   stdcall SetPriorityClass(long long) SetPriorityClass
-660   stub SetProcessShutdownParameters
-661   stub SetProcessWorkingSetSize
+660   stdcall SetProcessShutdownParameters(long long) SetProcessShutdownParameters
+661   stdcall SetProcessWorkingSetSize(long long long) SetProcessWorkingSetSize
 662   stdcall SetStdHandle(long long) SetStdHandle
 663   stdcall SetSystemPowerState(long long) SetSystemPowerState
 664   stdcall SetSystemTime(ptr) SetSystemTime
@@ -672,11 +674,12 @@
 681   stdcall SystemTimeToFileTime(ptr ptr) SystemTimeToFileTime
 682   stub SystemTimeToTzSpecificLocalTime
 683   stub TerminateProcess
-684   stub TerminateThread
+684   stdcall TerminateThread(long long) TerminateThread
 685   stub Thread32First
 686   stub Thread32Next
 687   stdcall ThunkConnect32(ptr ptr ptr ptr ptr ptr) ThunkConnect32
 688   stdcall TlsAlloc()	TlsAlloc
+689   stub TlsAllocInternal
 690   stdcall TlsFree(long) TlsFree
 691   stub TlsFreeInternal
 692   stdcall TlsGetValue(long) TlsGetValue
@@ -710,7 +713,7 @@
 720   stub WaitForMultipleObjects
 721   stub WaitForMultipleObjectsEx
 722   stdcall WaitForSingleObject(long long) WaitForSingleObject
-723   stub WaitForSingleObjectEx
+723   stdcall WaitForSingleObjectEx(long long long) WaitForSingleObjectEx
 724   stub WaitNamedPipeA
 725   stub WaitNamedPipeW
 726   stdcall WideCharToMultiByte(long long ptr long ptr long ptr ptr)	WideCharToMultiByte
@@ -798,8 +801,6 @@
 805   stub GetConsoleCommandHistoryLengthA
 806   stub GetConsoleCommandHistoryLengthW
 807   stub GetConsoleCommandHistoryW
-808   stub GetConsoleCursorInfo
-809   stub GetConsoleCursorInfo
 810   stub GetConsoleDisplayMode
 811   stub GetConsoleFontInfo
 812   stub GetConsoleFontSize
@@ -812,12 +813,10 @@
 819   stub HeapCreateTagsW
 820   stub HeapExtend
 821   stub HeapQueryTagW
-822   stub HeapSetFlags
 823   stub HeapSummary
 824   stub HeapUsage
 825   stub InvalidateConsoleDIBits
 826   stub IsDebuggerPresent
-827   stub NotifyNLSUserCache
 828   stub OpenConsoleW
 829   stub QueryWin31IniFilesMappedToRegistry
 830   stub RegisterConsoleVDM
diff --git a/if1632/mmsystem.spec b/if1632/mmsystem.spec
index 910f246..68b3a60 100644
--- a/if1632/mmsystem.spec
+++ b/if1632/mmsystem.spec
@@ -42,6 +42,7 @@
 305    pascal  MIDIINCLOSE(word) midiInClose
 306    pascal  MIDIINPREPAREHEADER(word segptr word) midiInPrepareHeader
 307    pascal  MIDIINUNPREPAREHEADER(word segptr word) midiInUnprepareHeader
+308    pascal  MIDIINADDBUFFER(word segptr word) midiInAddBuffer
 309    pascal  MIDIINSTART(word) midiInStart
 310    pascal  MIDIINSTOP(word) midiInStop
 311    pascal  MIDIINRESET(word) midiInReset
diff --git a/if1632/ntdll.spec b/if1632/ntdll.spec
index eeee134..08d3941 100644
--- a/if1632/ntdll.spec
+++ b/if1632/ntdll.spec
@@ -874,20 +874,20 @@
 870 stub _snwprintf
 871 stub _splitpath
 872 stub _strcmpi
-873 stub _stricmp
+873 stdcall _stricmp(ptr ptr) lstrcmpi32A
 874 stub _strlwr
 875 stub _strnicmp
 876 stdcall _strupr(ptr) CRTDLL__strupr
 877 stub _ultoa
 878 stub _vsnprintf
 879 stdcall _wcsicmp(ptr ptr) lstrcmpi32W
-880 stub _wcslwr
-881 stub _wcsnicmp
-882 stub _wcsupr
+880 stdcall _wcslwr(ptr) CRTDLL__wcslwr
+881 stdcall _wcsnicmp(ptr ptr long) lstrncmpi32W
+882 stdcall _wcsupr(ptr) CRTDLL__wcsupr
 883 stub abs
 884 stub atan
 885 stdcall atoi(ptr) CRTDLL_atoi
-886 stub atol
+886 stdcall atol(ptr) CRTDLL_atol
 887 stub ceil
 888 stub cos
 889 stub fabs
@@ -917,10 +917,10 @@
 913 stdcall sscanf() CRTDLL_sscanf
 914 stub strcat
 915 stdcall strchr(ptr long) strchr
-916 stub strcmp
-917 stub strcpy
+916 stdcall strcmp(ptr ptr) lstrcmp32A
+917 stdcall strcpy(ptr ptr) lstrcpy32A
 918 stub strcspn
-919 stub strlen
+919 stdcall strlen(ptr) lstrlen32A
 920 stub strncat
 921 stub strncmp
 922 stub strncpy
diff --git a/if1632/relay.c b/if1632/relay.c
index 06bf036..f8e98c4 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -35,6 +35,7 @@
 
     extern void CALLTO16_Start(), CALLTO16_End();
     extern void CALLTO16_Ret_word(), CALLTO16_Ret_long();
+    extern int CALLTO32_LargeStack();
     extern DWORD CALLTO16_RetAddr_word, CALLTO16_RetAddr_long;
 
     codesel = GLOBAL_CreateBlock( GMEM_FIXED, (void *)CALLTO16_Start,
@@ -49,6 +50,10 @@
     CALLTO16_RetAddr_long=MAKELONG( (int)CALLTO16_Ret_long-(int)CALLTO16_Start,
                                     codesel );
 
+    /* Set the CallLargeStack function pointer */
+
+    IF1632_CallLargeStack = CALLTO32_LargeStack;
+
     /* Initialize thunking */
 
     return THUNK_Init();
@@ -326,7 +331,7 @@
 /**********************************************************************
  *	     Catch    (KERNEL.55)
  */
-INT16 Catch( LPCATCHBUF lpbuf )
+INT16 WINAPI Catch( LPCATCHBUF lpbuf )
 {
     STACK16FRAME *pFrame = CURRENT_STACK16;
 
@@ -363,7 +368,7 @@
 /**********************************************************************
  *	     Throw    (KERNEL.56)
  */
-INT16 Throw( LPCATCHBUF lpbuf, INT16 retval )
+INT16 WINAPI Throw( LPCATCHBUF lpbuf, INT16 retval )
 {
     STACK16FRAME *pFrame;
     WORD es = CURRENT_STACK16->es;
@@ -394,8 +399,8 @@
 /**********************************************************************
  *	     CallProc32W    (KERNEL.56)
  */
-DWORD
-WIN16_CallProc32W() {
+DWORD /*WINAPI*/ WIN16_CallProc32W()
+{
 	DWORD *win_stack = (DWORD *)CURRENT_STACK16->args;
 	DWORD	nrofargs = win_stack[0];
 	DWORD	argconvmask = win_stack[1];
@@ -429,6 +434,10 @@
 		break;
 	case 5:	ret = CallTo32_5(proc32,args[0],args[1],args[2],args[3],args[4]);
 		break;
+	case 6:	ret = CallTo32_6(proc32,args[0],args[1],args[2],args[3],args[4],args[5]);
+		break;
+	case 7:	ret = CallTo32_7(proc32,args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
+		break;
 	default:
 		/* FIXME: should go up to 32  arguments */
 		fprintf(stderr,"CallProc32W: unsupported number of arguments %ld, please report.\n",nrofargs);
diff --git a/if1632/shell32.spec b/if1632/shell32.spec
index 4498271..14f5deb 100644
--- a/if1632/shell32.spec
+++ b/if1632/shell32.spec
@@ -17,6 +17,7 @@
   39 stdcall DragAcceptFiles(long long) DragAcceptFiles
   40 stub DragFinish
   42 stub DragQueryFile
+  47 stub SHELL32_47
   48 stub DragQueryFileA
   51 stub DragQueryFileAorW
   52 stub DragQueryFileW
@@ -31,9 +32,15 @@
  136 stub ExtractIconExA
  146 stub ExtractIconResInfoA
  148 stub ExtractIconResInfoW
+ 154 stub SHELL32_154
+ 155 stub SHELL32_155
+ 156 stub SHELL32_156
+ 158 stub SHELL32_158
  178 stub ExtractIconW
  180 stub ExtractVersionResource16W
- 184 stub FindExecutableA
+ 182 stub SHELL32_182
+ 183 stub SHELL32_183
+ 184 stdcall FindExecutableA(ptr ptr ptr) FindExecutable32A
  185 stub FindExecutableW
  186 return FreeIconList 4 0
  187 stub InternalExtractIconListA
diff --git a/if1632/signal.c b/if1632/signal.c
index 58f0c0b..62a6395 100644
--- a/if1632/signal.c
+++ b/if1632/signal.c
@@ -28,7 +28,7 @@
 
 #include "debugger.h"
 #include "options.h"
-#include "sigcontext.h"
+#include "sig_context.h"
 #include "miscemu.h"
 
 
diff --git a/if1632/thunk.c b/if1632/thunk.c
index 39cf091..a28c665 100644
--- a/if1632/thunk.c
+++ b/if1632/thunk.c
@@ -1,7 +1,8 @@
 /*
- * Emulator thunks
+ * Emulator and Win95 thunks
  *
  * Copyright 1996 Alexandre Julliard
+ * Copyright 1997 Marcus Meissner
  */
 
 #include "windows.h"
@@ -134,8 +135,8 @@
 /***********************************************************************
  *           THUNK_EnumObjects16   (GDI.71)
  */
-INT16 THUNK_EnumObjects16( HDC16 hdc, INT16 nObjType,
-                           GOBJENUMPROC16 func, LPARAM lParam )
+INT16 WINAPI THUNK_EnumObjects16( HDC16 hdc, INT16 nObjType,
+                                  GOBJENUMPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_ll );
     return EnumObjects16( hdc, nObjType, (GOBJENUMPROC16)&thunk, lParam );
@@ -145,8 +146,8 @@
 /***********************************************************************
  *           THUNK_EnumObjects32   (GDI32.89)
  */
-INT32 THUNK_EnumObjects32( HDC32 hdc, INT32 nObjType,
-                           GOBJENUMPROC32 func, LPARAM lParam )
+INT32 WINAPI THUNK_EnumObjects32( HDC32 hdc, INT32 nObjType,
+                                  GOBJENUMPROC32 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_2 );
     return EnumObjects32( hdc, nObjType, (GOBJENUMPROC32)&thunk, lParam );
@@ -156,8 +157,8 @@
 /*************************************************************************
  *           THUNK_EnumFonts16   (GDI.70)
  */
-INT16 THUNK_EnumFonts16( HDC16 hdc, LPCSTR lpFaceName,
-                         FONTENUMPROC16 func, LPARAM lParam )
+INT16 WINAPI THUNK_EnumFonts16( HDC16 hdc, LPCSTR lpFaceName,
+                                FONTENUMPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_llwl );
     return EnumFonts16( hdc, lpFaceName, (FONTENUMPROC16)&thunk, lParam );
@@ -166,8 +167,8 @@
 /*************************************************************************
  *           THUNK_EnumFonts32A   (GDI32.84)
  */
-INT32 THUNK_EnumFonts32A( HDC32 hdc, LPCSTR lpFaceName,
-                          FONTENUMPROC32A func, LPARAM lParam )
+INT32 WINAPI THUNK_EnumFonts32A( HDC32 hdc, LPCSTR lpFaceName,
+                                 FONTENUMPROC32A func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFonts32A( hdc, lpFaceName, (FONTENUMPROC32A)&thunk, lParam );
@@ -176,8 +177,8 @@
 /*************************************************************************
  *           THUNK_EnumFonts32W   (GDI32.85)
  */
-INT32 THUNK_EnumFonts32W( HDC32 hdc, LPCWSTR lpFaceName,
-                          FONTENUMPROC32W func, LPARAM lParam )
+INT32 WINAPI THUNK_EnumFonts32W( HDC32 hdc, LPCWSTR lpFaceName,
+                                 FONTENUMPROC32W func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFonts32W( hdc, lpFaceName, (FONTENUMPROC32W)&thunk, lParam );
@@ -186,8 +187,8 @@
 /******************************************************************
  *           THUNK_EnumMetaFile16   (GDI.175)
  */
-BOOL16 THUNK_EnumMetaFile16( HDC16 hdc, HMETAFILE16 hmf,
-                             MFENUMPROC16 func, LPARAM lParam )
+BOOL16 WINAPI THUNK_EnumMetaFile16( HDC16 hdc, HMETAFILE16 hmf,
+                                    MFENUMPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wllwl );
     return EnumMetaFile16( hdc, hmf, (MFENUMPROC16)&thunk, lParam );
@@ -197,8 +198,8 @@
 /*************************************************************************
  *           THUNK_EnumFontFamilies16   (GDI.330)
  */
-INT16 THUNK_EnumFontFamilies16( HDC16 hdc, LPCSTR lpszFamily,
-                                FONTENUMPROC16 func, LPARAM lParam )
+INT16 WINAPI THUNK_EnumFontFamilies16( HDC16 hdc, LPCSTR lpszFamily,
+                                       FONTENUMPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_llwl );
     return EnumFontFamilies16(hdc, lpszFamily, (FONTENUMPROC16)&thunk, lParam);
@@ -208,8 +209,8 @@
 /*************************************************************************
  *           THUNK_EnumFontFamilies32A   (GDI32.80)
  */
-INT32 THUNK_EnumFontFamilies32A( HDC32 hdc, LPCSTR lpszFamily,
-                                 FONTENUMPROC32A func, LPARAM lParam )
+INT32 WINAPI THUNK_EnumFontFamilies32A( HDC32 hdc, LPCSTR lpszFamily,
+                                        FONTENUMPROC32A func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFontFamilies32A(hdc,lpszFamily,(FONTENUMPROC32A)&thunk,lParam);
@@ -219,8 +220,8 @@
 /*************************************************************************
  *           THUNK_EnumFontFamilies32W   (GDI32.83)
  */
-INT32 THUNK_EnumFontFamilies32W( HDC32 hdc, LPCWSTR lpszFamily,
-                                 FONTENUMPROC32W func, LPARAM lParam )
+INT32 WINAPI THUNK_EnumFontFamilies32W( HDC32 hdc, LPCWSTR lpszFamily,
+                                        FONTENUMPROC32W func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFontFamilies32W(hdc,lpszFamily,(FONTENUMPROC32W)&thunk,lParam);
@@ -229,9 +230,9 @@
 /*************************************************************************
  *           THUNK_EnumFontFamiliesEx16   (GDI.613)
  */
-INT16 THUNK_EnumFontFamiliesEx16( HDC16 hdc, LPLOGFONT16 lpLF,
-                                  FONTENUMPROCEX16 func, LPARAM lParam,
-                                  DWORD reserved )
+INT16 WINAPI THUNK_EnumFontFamiliesEx16( HDC16 hdc, LPLOGFONT16 lpLF,
+                                         FONTENUMPROCEX16 func, LPARAM lParam,
+                                         DWORD reserved )
 {
     DECL_THUNK( thunk, func, CallTo16_word_llwl );
     return EnumFontFamiliesEx16( hdc, lpLF, (FONTENUMPROCEX16)&thunk,
@@ -242,9 +243,9 @@
 /*************************************************************************
  *           THUNK_EnumFontFamiliesEx32A   (GDI32.81)
  */
-INT32 THUNK_EnumFontFamiliesEx32A( HDC32 hdc, LPLOGFONT32A lpLF,
-                                   FONTENUMPROCEX32A func, LPARAM lParam,
-                                   DWORD reserved)
+INT32 WINAPI THUNK_EnumFontFamiliesEx32A( HDC32 hdc, LPLOGFONT32A lpLF,
+                                          FONTENUMPROCEX32A func, LPARAM lParam,
+                                          DWORD reserved)
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFontFamiliesEx32A( hdc, lpLF, (FONTENUMPROCEX32A)&thunk,
@@ -255,9 +256,9 @@
 /*************************************************************************
  *           THUNK_EnumFontFamiliesEx32W   (GDI32.82)
  */
-INT32 THUNK_EnumFontFamiliesEx32W( HDC32 hdc, LPLOGFONT32W lpLF,
-                                   FONTENUMPROCEX32W func, LPARAM lParam,
-                                   DWORD reserved )
+INT32 WINAPI THUNK_EnumFontFamiliesEx32W( HDC32 hdc, LPLOGFONT32W lpLF,
+                                          FONTENUMPROCEX32W func, LPARAM lParam,
+                                          DWORD reserved )
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumFontFamiliesEx32W( hdc, lpLF, (FONTENUMPROCEX32W)&thunk,
@@ -268,8 +269,8 @@
 /**********************************************************************
  *           THUNK_LineDDA16   (GDI.100)
  */
-void THUNK_LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd, INT16 nYEnd,
-                      LINEDDAPROC16 func, LPARAM lParam )
+void WINAPI THUNK_LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd,
+                             INT16 nYEnd, LINEDDAPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wwl );
     LineDDA16( nXStart, nYStart, nXEnd, nYEnd, (LINEDDAPROC16)&thunk, lParam );
@@ -279,8 +280,8 @@
 /**********************************************************************
  *           THUNK_LineDDA32   (GDI32.248)
  */
-BOOL32 THUNK_LineDDA32( INT32 nXStart, INT32 nYStart, INT32 nXEnd, INT32 nYEnd,
-                        LINEDDAPROC32 func, LPARAM lParam )
+BOOL32 WINAPI THUNK_LineDDA32( INT32 nXStart, INT32 nYStart, INT32 nXEnd,
+                               INT32 nYEnd, LINEDDAPROC32 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     return LineDDA32( nXStart, nYStart, nXEnd, nYEnd,
@@ -291,7 +292,7 @@
 /*******************************************************************
  *           THUNK_EnumWindows16   (USER.54)
  */
-BOOL16 THUNK_EnumWindows16( WNDENUMPROC16 func, LPARAM lParam )
+BOOL16 WINAPI THUNK_EnumWindows16( WNDENUMPROC16 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wl );
     return EnumWindows16( (WNDENUMPROC16)&thunk, lParam );
@@ -301,7 +302,7 @@
 /*******************************************************************
  *           THUNK_EnumWindows32   (USER32.192)
  */
-BOOL32 THUNK_EnumWindows32( WNDENUMPROC32 func, LPARAM lParam )
+BOOL32 WINAPI THUNK_EnumWindows32( WNDENUMPROC32 func, LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_2 );
     return EnumWindows32( (WNDENUMPROC32)&thunk, lParam );
@@ -311,8 +312,8 @@
 /**********************************************************************
  *           THUNK_EnumChildWindows16   (USER.55)
  */
-BOOL16 THUNK_EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func,
-                                 LPARAM lParam )
+BOOL16 WINAPI THUNK_EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func,
+                                        LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wl );
     return EnumChildWindows16( parent, (WNDENUMPROC16)&thunk, lParam );
@@ -322,8 +323,8 @@
 /**********************************************************************
  *           THUNK_EnumChildWindows32   (USER32.177)
  */
-BOOL32 THUNK_EnumChildWindows32( HWND32 parent, WNDENUMPROC32 func,
-                                 LPARAM lParam )
+BOOL32 WINAPI THUNK_EnumChildWindows32( HWND32 parent, WNDENUMPROC32 func,
+                                        LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_2 );
     return EnumChildWindows32( parent, (WNDENUMPROC32)&thunk, lParam );
@@ -333,8 +334,8 @@
 /**********************************************************************
  *           THUNK_EnumTaskWindows16   (USER.225)
  */
-BOOL16 THUNK_EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func,
-                                LPARAM lParam )
+BOOL16 WINAPI THUNK_EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func,
+                                       LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wl );
     return EnumTaskWindows16( hTask, (WNDENUMPROC16)&thunk, lParam );
@@ -344,7 +345,8 @@
 /**********************************************************************
  *           THUNK_EnumThreadWindows   (USER32.189)
  */
-BOOL32 THUNK_EnumThreadWindows( DWORD id, WNDENUMPROC32 func, LPARAM lParam )
+BOOL32 WINAPI THUNK_EnumThreadWindows( DWORD id, WNDENUMPROC32 func,
+                                       LPARAM lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_2 );
     return EnumThreadWindows( id, (WNDENUMPROC32)&thunk, lParam );
@@ -354,7 +356,7 @@
 /***********************************************************************
  *           THUNK_EnumProps16   (USER.27)
  */
-INT16 THUNK_EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
+INT16 WINAPI THUNK_EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wlw );
     return EnumProps16( hwnd, (PROPENUMPROC16)&thunk );
@@ -364,7 +366,7 @@
 /***********************************************************************
  *           THUNK_EnumProps32A   (USER32.185)
  */
-INT32 THUNK_EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
+INT32 WINAPI THUNK_EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     return EnumProps32A( hwnd, (PROPENUMPROC32A)&thunk );
@@ -374,7 +376,7 @@
 /***********************************************************************
  *           THUNK_EnumProps32W   (USER32.188)
  */
-INT32 THUNK_EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
+INT32 WINAPI THUNK_EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     return EnumProps32W( hwnd, (PROPENUMPROC32W)&thunk );
@@ -384,7 +386,8 @@
 /***********************************************************************
  *           THUNK_EnumPropsEx32A   (USER32.186)
  */
-INT32 THUNK_EnumPropsEx32A( HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam)
+INT32 WINAPI THUNK_EnumPropsEx32A( HWND32 hwnd, PROPENUMPROCEX32A func,
+                                   LPARAM lParam)
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumPropsEx32A( hwnd, (PROPENUMPROCEX32A)&thunk, lParam );
@@ -394,7 +397,8 @@
 /***********************************************************************
  *           THUNK_EnumPropsEx32W   (USER32.187)
  */
-INT32 THUNK_EnumPropsEx32W( HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam)
+INT32 WINAPI THUNK_EnumPropsEx32W( HWND32 hwnd, PROPENUMPROCEX32W func,
+                                   LPARAM lParam)
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumPropsEx32W( hwnd, (PROPENUMPROCEX32W)&thunk, lParam );
@@ -404,7 +408,8 @@
 /***********************************************************************
  *           THUNK_EnumSystemCodePages32A	(KERNEL32.92)
  */
-BOOL32 THUNK_EnumSystemCodePages32A( CODEPAGE_ENUMPROC32A func, DWORD flags )
+BOOL32 WINAPI THUNK_EnumSystemCodePages32A( CODEPAGE_ENUMPROC32A func,
+                                            DWORD flags )
 {
     DECL_THUNK( thunk, func, CallTo32_1 );
     return EnumSystemCodePages32A( (CODEPAGE_ENUMPROC32A)&thunk, flags );
@@ -414,7 +419,8 @@
 /***********************************************************************
  *           THUNK_EnumSystemCodePages32W	(KERNEL32.93)
  */
-BOOL32 THUNK_EnumSystemCodePages32W( CODEPAGE_ENUMPROC32W func, DWORD flags )
+BOOL32 WINAPI THUNK_EnumSystemCodePages32W( CODEPAGE_ENUMPROC32W func,
+                                            DWORD flags )
 {
     DECL_THUNK( thunk, func, CallTo32_1 );
     return EnumSystemCodePages32W( (CODEPAGE_ENUMPROC32W)&thunk, flags );
@@ -423,7 +429,7 @@
 /***********************************************************************
  *           THUNK_EnumSystemLocales32A   (KERNEL32.92)
  */
-BOOL32 THUNK_EnumSystemLocales32A( LOCALE_ENUMPROC32A func, DWORD flags )
+BOOL32 WINAPI THUNK_EnumSystemLocales32A( LOCALE_ENUMPROC32A func, DWORD flags)
 {
     DECL_THUNK( thunk, func, CallTo32_1 );
     return EnumSystemLocales32A( (LOCALE_ENUMPROC32A)&thunk, flags );
@@ -433,7 +439,7 @@
 /***********************************************************************
  *           THUNK_EnumSystemLocales32W   (KERNEL32.93)
  */
-BOOL32 THUNK_EnumSystemLocales32W( LOCALE_ENUMPROC32W func, DWORD flags )
+BOOL32 WINAPI THUNK_EnumSystemLocales32W( LOCALE_ENUMPROC32W func, DWORD flags)
 {
     DECL_THUNK( thunk, func, CallTo32_1 );
     return EnumSystemLocales32W( (LOCALE_ENUMPROC32W)&thunk, flags );
@@ -442,7 +448,10 @@
 /***********************************************************************
  *           THUNK_EnumResourceLanguages32W   (KERNEL32.87)
  */
-BOOL32 THUNK_EnumResourceLanguages32W( HMODULE32 hmod,LPCWSTR type,LPCWSTR name,ENUMRESLANGPROC32W func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceLanguages32W( HMODULE32 hmod, LPCWSTR type,
+                                              LPCWSTR name,
+                                              ENUMRESLANGPROC32W func,
+                                              LONG lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_5 );
     return EnumResourceLanguages32W( hmod,type,name,(ENUMRESLANGPROC32W)&thunk, lParam );
@@ -451,7 +460,10 @@
 /***********************************************************************
  *           THUNK_EnumResourceLanguages32A   (KERNEL32.86)
  */
-BOOL32 THUNK_EnumResourceLanguages32A( HMODULE32 hmod,LPCSTR type,LPCSTR name,ENUMRESLANGPROC32A func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceLanguages32A( HMODULE32 hmod, LPCSTR type,
+                                              LPCSTR name,
+                                              ENUMRESLANGPROC32A func,
+                                              LONG lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_5 );
     return EnumResourceLanguages32A( hmod,type,name,(ENUMRESLANGPROC32A)&thunk, lParam );
@@ -460,8 +472,8 @@
 /***********************************************************************
  *           THUNK_EnumResourceNames32A   (KERNEL32.88)
  */
-BOOL32 THUNK_EnumResourceNames32A( HMODULE32 hmod, LPCSTR type,
-                                   ENUMRESNAMEPROC32A func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceNames32A( HMODULE32 hmod, LPCSTR type,
+                                          ENUMRESNAMEPROC32A func, LONG lParam)
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumResourceNames32A( hmod,type,(ENUMRESNAMEPROC32A)&thunk,lParam );
@@ -470,8 +482,8 @@
 /***********************************************************************
  *           THUNK_EnumResourceNames32W   (KERNEL32.89)
  */
-BOOL32 THUNK_EnumResourceNames32W( HMODULE32 hmod, LPCWSTR type,
-                                   ENUMRESNAMEPROC32W func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceNames32W( HMODULE32 hmod, LPCWSTR type,
+                                          ENUMRESNAMEPROC32W func, LONG lParam)
 {
     DECL_THUNK( thunk, func, CallTo32_4 );
     return EnumResourceNames32W( hmod,type,(ENUMRESNAMEPROC32W)&thunk, lParam);
@@ -480,7 +492,8 @@
 /***********************************************************************
  *           THUNK_EnumResourceTypes32A   (KERNEL32.90)
  */
-BOOL32 THUNK_EnumResourceTypes32A( HMODULE32 hmod,ENUMRESTYPEPROC32A func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceTypes32A( HMODULE32 hmod,
+                                          ENUMRESTYPEPROC32A func, LONG lParam)
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     return EnumResourceTypes32A( hmod,(ENUMRESTYPEPROC32A)&thunk, lParam );
@@ -489,7 +502,9 @@
 /***********************************************************************
  *           THUNK_EnumResourceTypes32W   (KERNEL32.91)
  */
-BOOL32 THUNK_EnumResourceTypes32W( HMODULE32 hmod,ENUMRESTYPEPROC32W func, LONG lParam )
+BOOL32 WINAPI THUNK_EnumResourceTypes32W( HMODULE32 hmod,
+                                          ENUMRESTYPEPROC32W func,
+                                          LONG lParam )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     return EnumResourceTypes32W( hmod,(ENUMRESTYPEPROC32W)&thunk, lParam );
@@ -499,9 +514,10 @@
 /***********************************************************************
  *           THUNK_GrayString16   (USER.185)
  */
-BOOL16 THUNK_GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 func,
-                           LPARAM lParam, INT16 cch, INT16 x, INT16 y,
-                           INT16 cx, INT16 cy )
+BOOL16 WINAPI THUNK_GrayString16( HDC16 hdc, HBRUSH16 hbr,
+                                  GRAYSTRINGPROC16 func, LPARAM lParam,
+                                  INT16 cch, INT16 x, INT16 y,
+                                  INT16 cx, INT16 cy )
 {
     DECL_THUNK( thunk, func, CallTo16_word_wlw );
     if (!func)
@@ -515,9 +531,10 @@
 /***********************************************************************
  *           THUNK_GrayString32A   (USER32.314)
  */
-BOOL32 THUNK_GrayString32A( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 func,
-                            LPARAM lParam, INT32 cch, INT32 x, INT32 y,
-                            INT32 cx, INT32 cy )
+BOOL32 WINAPI THUNK_GrayString32A( HDC32 hdc, HBRUSH32 hbr,
+                                   GRAYSTRINGPROC32 func, LPARAM lParam,
+                                   INT32 cch, INT32 x, INT32 y,
+                                   INT32 cx, INT32 cy )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     if (!func)
@@ -531,9 +548,10 @@
 /***********************************************************************
  *           THUNK_GrayString32W   (USER32.315)
  */
-BOOL32 THUNK_GrayString32W( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 func,
-                            LPARAM lParam, INT32 cch, INT32 x, INT32 y,
-                            INT32 cx, INT32 cy )
+BOOL32 WINAPI THUNK_GrayString32W( HDC32 hdc, HBRUSH32 hbr,
+                                   GRAYSTRINGPROC32 func,
+                                   LPARAM lParam, INT32 cch, INT32 x, INT32 y,
+                                   INT32 cx, INT32 cy )
 {
     DECL_THUNK( thunk, func, CallTo32_3 );
     if (!func)
@@ -547,7 +565,7 @@
 /***********************************************************************
  *           THUNK_SetWindowsHook16   (USER.121)
  */
-FARPROC16 THUNK_SetWindowsHook16( INT16 id, HOOKPROC16 proc )
+FARPROC16 WINAPI THUNK_SetWindowsHook16( INT16 id, HOOKPROC16 proc )
 {
     HINSTANCE16 hInst = FarGetOwner( HIWORD(proc) );
     HTASK16 hTask = (id == WH_MSGFILTER) ? GetCurrentTask() : 0;
@@ -560,7 +578,7 @@
 /***********************************************************************
  *           THUNK_UnhookWindowsHook16   (USER.234)
  */
-BOOL16 THUNK_UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
+BOOL16 WINAPI THUNK_UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
 {
     BOOL16 ret;
     THUNK *thunk = THUNK_Find( (FARPROC16)proc );
@@ -574,8 +592,8 @@
 /***********************************************************************
  *           THUNK_SetWindowsHookEx16   (USER.291)
  */
-HHOOK THUNK_SetWindowsHookEx16( INT16 id, HOOKPROC16 proc, HINSTANCE16 hInst,
-                                HTASK16 hTask )
+HHOOK WINAPI THUNK_SetWindowsHookEx16( INT16 id, HOOKPROC16 proc,
+                                       HINSTANCE16 hInst, HTASK16 hTask )
 {
     THUNK *thunk = THUNK_Alloc( (FARPROC16)proc, (RELAY)CallTo16_long_wwl );
     if (!thunk) return 0;
@@ -586,7 +604,7 @@
 /***********************************************************************
  *           THUNK_UnhookWindowHookEx16   (USER.292)
  */
-BOOL16 THUNK_UnhookWindowsHookEx16( HHOOK hhook )
+BOOL16 WINAPI THUNK_UnhookWindowsHookEx16( HHOOK hhook )
 {
     THUNK *thunk = (THUNK *)HOOK_GetProc16( hhook );
     BOOL16 ret = UnhookWindowsHookEx16( hhook );
@@ -598,7 +616,7 @@
 /***********************************************************************
  *           THUNK_CreateSystemTimer   (SYSTEM.2)
  */
-WORD THUNK_CreateSystemTimer( WORD rate, FARPROC16 callback )
+WORD WINAPI THUNK_CreateSystemTimer( WORD rate, FARPROC16 callback )
 {
     THUNK *thunk = THUNK_Alloc( callback, (RELAY)CallTo16_word_ );
     if (!thunk) return 0;
@@ -609,7 +627,7 @@
 /***********************************************************************
  *           THUNK_KillSystemTimer   (SYSTEM.3)
  */
-WORD THUNK_KillSystemTimer( WORD timer )
+WORD WINAPI THUNK_KillSystemTimer( WORD timer )
 {
     extern WORD SYSTEM_KillSystemTimer( WORD timer );  /* misc/system.c */
     extern FARPROC16 SYSTEM_GetTimerProc( WORD timer );  /* misc/system.c */
@@ -624,7 +642,7 @@
 /***********************************************************************
  *            THUNK_SetUnhandledExceptionFilter   (KERNEL32.516)
  */
-LPTOP_LEVEL_EXCEPTION_FILTER THUNK_SetUnhandledExceptionFilter(
+LPTOP_LEVEL_EXCEPTION_FILTER WINAPI THUNK_SetUnhandledExceptionFilter(
                                           LPTOP_LEVEL_EXCEPTION_FILTER filter )
 {
     LPTOP_LEVEL_EXCEPTION_FILTER old;
@@ -644,7 +662,7 @@
 /***********************************************************************
  *           THUNK_SetDCHook   (GDI.190)
  */
-BOOL16 THUNK_SetDCHook( HDC16 hdc, FARPROC16 proc, DWORD dwHookData )
+BOOL16 WINAPI THUNK_SetDCHook( HDC16 hdc, FARPROC16 proc, DWORD dwHookData )
 {
     THUNK *thunk, *oldThunk;
 
@@ -669,7 +687,7 @@
 /***********************************************************************
  *           THUNK_GetDCHook   (GDI.191)
  */
-DWORD THUNK_GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
+DWORD WINAPI THUNK_GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
 {
     THUNK *thunk = NULL;
     DWORD ret = GetDCHook( hdc, (FARPROC16 *)&thunk );
@@ -687,19 +705,81 @@
     return ret;
 }
 
+/***********************************************************************
+ *                                                                     *
+ *                 Win95 internal thunks                               *
+ *                                                                     *
+ ***********************************************************************/
 
+/***********************************************************************
+ * Generates a FT_Prolog call.
+ *	
+ *  0FB6D1                  movzbl edx,cl
+ *  8B1495xxxxxxxx	    mov edx,[4*edx + xxxxxxxx]
+ *  68xxxxxxxx		    push FT_Prolog
+ *  C3			    lret
+ */
+static void _write_ftprolog(LPBYTE start,DWORD thunkstart) {
+	LPBYTE	x;
+
+	x	= start;
+	*x++	= 0x0f;*x++=0xb6;*x++=0xd1; /* movzbl edx,cl */
+	*x++	= 0x8B;*x++=0x14;*x++=0x95;*(DWORD*)x= thunkstart;
+	x+=4;	/* mov edx, [4*edx + thunkstart] */
+	*x++	= 0x68; *(DWORD*)x = (DWORD)GetProcAddress32(WIN32_GetModuleHandleA("KERNEL32"),"FT_Prolog");
+	x+=4; 	/* push FT_Prolog */
+	*x++	= 0xC3;		/* lret */
+	/* fill rest with 0xCC / int 3 */
+}
+
+/***********************************************************************
+ * Generates a QT_Thunk style call.
+ *	
+ *  33C9                    xor ecx, ecx
+ *  8A4DFC                  mov cl , [ebp-04]
+ *  8B148Dxxxxxxxx          mov edx, [4*ecx + (EAX+EDX)]
+ *  B8yyyyyyyy              mov eax, QT_Thunk
+ *  FFE0                    jmp eax
+ */
+static void _write_qtthunk(LPBYTE start,DWORD thunkstart) {
+	LPBYTE	x;
+
+	x	= start;
+	*x++	= 0x33;*x++=0xC9; /* xor ecx,ecx */
+	*x++	= 0x8A;*x++=0x4D;*x++=0xFC; /* movb cl,[ebp-04] */
+	*x++	= 0x8B;*x++=0x14;*x++=0x8D;*(DWORD*)x= thunkstart;
+	x+=4;	/* mov edx, [4*ecx + (EAX+EDX) */
+	*x++	= 0xB8; *(DWORD*)x = (DWORD)GetProcAddress32(WIN32_GetModuleHandleA("KERNEL32"),"QT_Thunk");
+	x+=4; 	/* mov eax , QT_Thunk */
+	*x++	= 0xFF; *x++ = 0xE0;	/* jmp eax */
+	/* should fill the rest of the 32 bytes with 0xCC */
+}
+
+/***********************************************************************
+ *		ThunkConnect32		(KERNEL32)
+ * Connects a 32bit and a 16bit thunkbuffer.
+ */
 struct thunkstruct
 {
 	char	magic[4];
-	DWORD	x1;
-	DWORD	x2;
+	DWORD	length;
+	DWORD	ptr;
+	DWORD	x0C;
+
+	DWORD	x10;
+	DWORD	x14;
+	DWORD	x18;
+	DWORD	x1C;
+	DWORD	x20;
 };
 
-UINT32 ThunkConnect32( struct thunkstruct *ths, LPSTR thunkfun16,
-                       LPSTR module16, LPSTR module32, HMODULE32 hmod32,
-                       DWORD dllinitarg1 )
+UINT32 WINAPI ThunkConnect32( struct thunkstruct *ths, LPSTR thunkfun16,
+                              LPSTR module16, LPSTR module32, HMODULE32 hmod32,
+                              DWORD dllinitarg1 )
 {
 	HINSTANCE16	hmm;
+	SEGPTR		thkbuf;
+	struct	thunkstruct	*ths16;
 
 	fprintf(stdnimp,"ThunkConnect32(<struct>,%s,%s,%s,%x,%lx)\n",
 		thunkfun16,module32,module16,hmod32,dllinitarg1
@@ -710,8 +790,402 @@
 		ths->magic[2],
 		ths->magic[3]
 	);
-	fprintf(stdnimp,"	x1 = %lx\n",ths->x1);
-	fprintf(stdnimp,"	x2 = %lx\n",ths->x2);
+	fprintf(stdnimp,"	length = %lx\n",ths->length);
+	if (lstrncmp32A(ths->magic,"SL01",4)&&lstrncmp32A(ths->magic,"LS01",4))
+		return 0;
 	hmm=LoadModule16(module16,NULL);
+	if (hmm<=32)
+		return 0;
+	thkbuf=(SEGPTR)WIN32_GetProcAddress16(hmm,thunkfun16);
+	if (!thkbuf)
+		return 0;
+	ths16=(struct thunkstruct*)PTR_SEG_TO_LIN(thkbuf);
+	if (lstrncmp32A(ths16->magic,ths->magic,4))
+		return 0;
+
+	if (!lstrncmp32A(ths->magic,"SL01",4))  {
+		if (ths16->length != ths->length)
+			return 0;
+		ths->x0C = (DWORD)ths16;
+
+		fprintf(stderr,"	ths16 magic is 0x%08lx\n",*(DWORD*)ths16->magic);
+		if (*((DWORD*)ths16->magic) != 0x0000304C)
+			return 0;
+		if (!*(WORD*)(((LPBYTE)ths16)+0x12))
+			return 0;
+		
+	}
+	if (!lstrncmp32A(ths->magic,"LS01",4))  {
+		if (ths16->length != ths->length)
+			return 0;
+		ths->ptr = (DWORD)PTR_SEG_TO_LIN(ths16->ptr);
+		/* code offset for QT_Thunk is at 0x1C...  */
+		_write_qtthunk (((LPBYTE)ths) + ths->x1C,ths->ptr);
+		/* code offset for FT_Prolog is at 0x20...  */
+		_write_ftprolog(((LPBYTE)ths) + ths->x20,ths->ptr);
+		return 1;
+	}
 	return TRUE;
 }
+
+
+/**********************************************************************
+ * The infamous and undocumented QT_Thunk procedure.
+ *
+ * We get arguments in [EBP+8] up to [EBP+38].
+ * We have to set up a frame in the 16 bit stackframe.
+ *	saved_ss_sp:	bp+0x40
+ *			bp+0x3c
+ *			...
+ *		bp:	bp+0x00
+ *		sp:	
+ *		
+ */
+extern DWORD IF1632_Saved16_ss_sp;
+VOID WINAPI QT_Thunk(CONTEXT *context)
+{
+	CONTEXT	context16;
+	LPBYTE	curstack;
+	DWORD	ret;
+
+	fprintf(stderr,"QT_Thunk(%08lx) ..",EDX_reg(context));
+	fprintf(stderr,"	argsize probably ebp-esp=%ld\n",
+		EBP_reg(context)-ESP_reg(context)
+	);
+	memcpy(&context16,context,sizeof(context16));
+
+	curstack = PTR_SEG_TO_LIN(IF1632_Saved16_ss_sp);
+	memcpy(curstack-0x40,(LPBYTE)EBP_reg(context),0x40);
+	EBP_reg(&context16)	 = LOWORD(IF1632_Saved16_ss_sp)-0x40;
+	IF1632_Saved16_ss_sp	-= 0x3c;
+
+	CS_reg(&context16)	 = HIWORD(EDX_reg(context));
+	IP_reg(&context16)	 = LOWORD(EDX_reg(context));
+#ifndef WINELIB
+	ret = CallTo16_regs_(&context16);
+#endif
+	fprintf(stderr,". returned %08lx\n",ret);
+	EAX_reg(context) 	 = ret;
+	IF1632_Saved16_ss_sp	+= 0x3c;
+}
+
+
+/**********************************************************************
+ *           WOWCallback16 (KERNEL32.62)
+ */
+DWORD WINAPI WOWCallback16(FARPROC16 fproc,DWORD arg)
+{
+	DWORD	ret;
+	fprintf(stderr,"WOWCallback16(%p,0x%08lx) ",fproc,arg);
+	ret =  CallTo16_long_l(fproc,arg);
+	fprintf(stderr,"... returns %ld\n",ret);
+	return ret;
+}
+
+/***********************************************************************
+ *           _KERNEL32_52    (KERNEL32.52)
+ * FIXME: what does it really do?
+ */
+VOID WINAPI _KERNEL32_52(DWORD arg1,CONTEXT *regs)
+{
+	fprintf(stderr,"_KERNE32_52(arg1=%08lx,%08lx)\n",arg1,EDI_reg(regs));
+
+	EAX_reg(regs) = (DWORD)WIN32_GetProcAddress16(EDI_reg(regs),"ThkBuf");
+
+	fprintf(stderr,"	GetProcAddress16(\"ThkBuf\") returns %08lx\n",
+			EAX_reg(regs)
+	);
+}
+
+/***********************************************************************
+ * 		_KERNEL32_43 	(KERNEL32.42)
+ * A thunkbuffer link routine 
+ * The thunkbuf looks like:
+ *
+ *	00: DWORD	length		? don't know exactly
+ *	04: SEGPTR	ptr		? where does it point to?
+ * The pointer ptr is written into the first DWORD of 'thunk'.
+ * (probably correct implemented)
+ */
+BOOL32 WINAPI _KERNEL32_43(LPDWORD thunk,LPCSTR thkbuf,DWORD len,
+                           LPCSTR dll16,LPCSTR dll32)
+{
+	HINSTANCE16	hmod;
+	LPDWORD		addr;
+	SEGPTR		segaddr;
+
+	fprintf(stderr,"_KERNEL32_43(%p,%s,0x%08lx,%s,%s)\n",thunk,thkbuf,len,dll16,dll32);
+
+	hmod = LoadLibrary16(dll16);
+	if (hmod<32) {
+		fprintf(stderr,"->failed to load 16bit DLL %s, error %d\n",dll16,hmod);
+		return NULL;
+	}
+	segaddr = (DWORD)WIN32_GetProcAddress16(hmod,(LPSTR)thkbuf);
+	if (!segaddr) {
+		fprintf(stderr,"->no %s exported from %s!\n",thkbuf,dll16);
+		return NULL;
+	}
+	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
+	if (addr[0] != len) {
+		fprintf(stderr,"->thkbuf length mismatch? %ld vs %ld\n",len,addr[0]);
+		return NULL;
+	}
+	if (!addr[1])
+		return 0;
+	fprintf(stderr,"	addr[1] is %08lx\n",addr[1]);
+	*(DWORD*)thunk = addr[1];
+	return addr[1];
+}
+
+/***********************************************************************
+ * 		_KERNEL32_45 	(KERNEL32.44)
+ * Looks like another 32->16 thunk. Dunno why they need two of them.
+ * calls the win16 address in EAX with the current stack.
+ *
+ * FIXME: doesn't seem to work correctly yet...
+ */
+VOID WINAPI _KERNEL32_45(CONTEXT *context)
+{
+	CONTEXT	context16;
+	LPBYTE	curstack;
+	DWORD	ret,stacksize;
+
+	fprintf(stderr,"KERNEL32_45(%%eax=0x%08lx(%%cx=0x%04lx,%%edx=0x%08lx))\n",
+		(DWORD)EAX_reg(context),(DWORD)CX_reg(context),(DWORD)EDX_reg(context)
+	);
+	stacksize = EBP_reg(context)-ESP_reg(context);
+	fprintf(stderr,"	stacksize = %ld\n",stacksize);
+
+	memcpy(&context16,context,sizeof(context16));
+
+	curstack = PTR_SEG_TO_LIN(IF1632_Saved16_ss_sp);
+	memcpy(curstack-stacksize,(LPBYTE)EBP_reg(context),stacksize);
+	fprintf(stderr,"IF1632_Saved16_ss_sp is 0x%08lx\n",IF1632_Saved16_ss_sp);
+	EBP_reg(&context16)	 = LOWORD(IF1632_Saved16_ss_sp)-stacksize;
+	IF1632_Saved16_ss_sp	-= stacksize;
+
+	DI_reg(&context16)	 = CX_reg(context);
+	CS_reg(&context16)	 = HIWORD(EAX_reg(context));
+	IP_reg(&context16)	 = LOWORD(EAX_reg(context));
+	/* some more registers spronged locally, but I don't think they are
+	 * needed
+	 */
+#ifndef WINELIB
+	ret = CallTo16_regs_(&context16);
+#endif
+	fprintf(stderr,". returned %08lx\n",ret);
+	EAX_reg(context) 	 = ret;
+	IF1632_Saved16_ss_sp	+= stacksize;
+
+}
+
+/***********************************************************************
+ *		(KERNEL32.40)
+ * A thunk setup routine.
+ * Expects a pointer to a preinitialized thunkbuffer in the first argument
+ * looking like:
+ *	00..03:		unknown	(pointer, check _41, _43, _46)
+ *	04: EB1E		jmp +0x20
+ *
+ *	06..23:		unknown (space for replacement code, check .90)
+ *
+ *	24:>E800000000		call offset 29
+ *	29:>58			pop eax		   ( target of call )
+ *	2A: 2D25000000		sub eax,0x00000025 ( now points to offset 4 )
+ *	2F: BAxxxxxxxx		mov edx,xxxxxxxx
+ *	34: 68yyyyyyyy		push KERNEL32.90
+ *	39: C3			ret
+ *
+ *	3A: EB1E		jmp +0x20
+ *	3E ... 59:	unknown (space for replacement code?)
+ *	5A: E8xxxxxxxx		call <32bitoffset xxxxxxxx>
+ *	5F: 5A			pop edx
+ *	60: 81EA25xxxxxx	sub edx, 0x25xxxxxx
+ *	66: 52			push edx
+ *	67: 68xxxxxxxx		push xxxxxxxx
+ *	6C: 68yyyyyyyy		push KERNEL32.89
+ *	71: C3			ret
+ *	72: end?
+ * This function checks if the code is there, and replaces the yyyyyyyy entries
+ * by the functionpointers.
+ * The thunkbuf looks like:
+ *
+ *	00: DWORD	length		? don't know exactly
+ *	04: SEGPTR	ptr		? where does it point to?
+ * The segpointer ptr is written into the first DWORD of 'thunk'.
+ * (probably correct implemented)
+ */
+
+LPVOID WINAPI _KERNEL32_41(LPBYTE thunk,LPCSTR thkbuf,DWORD len,LPCSTR dll16,
+                           LPCSTR dll32)
+{
+	HMODULE32	hkrnl32 = WIN32_GetModuleHandleA("KERNEL32");
+	HMODULE16	hmod;
+	LPDWORD		addr,addr2;
+	DWORD		segaddr;
+
+	fprintf(stderr,"KERNEL32_41(%p,%s,%ld,%s,%s)\n",
+		thunk,thkbuf,len,dll16,dll32
+	);
+
+	/* FIXME: add checks for valid code ... */
+	/* write pointers to kernel32.89 and kernel32.90 (+ordinal base of 1) */
+	*(DWORD*)(thunk+0x35) = (DWORD)GetProcAddress32(hkrnl32,(LPSTR)90);
+	*(DWORD*)(thunk+0x6D) = (DWORD)GetProcAddress32(hkrnl32,(LPSTR)89);
+
+	
+	hmod = LoadLibrary16(dll16);
+	if (hmod<32) {
+		fprintf(stderr,"->failed to load 16bit DLL %s, error %d\n",dll16,hmod);
+		return NULL;
+	}
+	segaddr = (DWORD)WIN32_GetProcAddress16(hmod,(LPSTR)thkbuf);
+	if (!segaddr) {
+		fprintf(stderr,"->no %s exported from %s!\n",thkbuf,dll16);
+		return NULL;
+	}
+	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
+	if (addr[0] != len) {
+		fprintf(stderr,"->thkbuf length mismatch? %ld vs %ld\n",len,addr[0]);
+		return NULL;
+	}
+	addr2 = PTR_SEG_TO_LIN(addr[1]);
+	fprintf(stderr,"	addr2 is %08lx:%p\n",addr[1],addr2);
+	if (HIWORD(addr2))
+		*(DWORD*)thunk = (DWORD)addr2;
+	return addr2;
+}
+
+/***********************************************************************
+ *							(KERNEL32.91)
+ * Thunk priming? function
+ * Rewrites the first part of the thunk to use the QT_Thunk interface
+ * and jumps to the start of that code.
+ */
+VOID WINAPI _KERNEL32_90(CONTEXT *context)
+{
+	fprintf(stderr,"_KERNEL32_90(eax=0x%08lx,edx=0x%08lx,ebp[-4]=0x%02x,target = %08lx, *target =%08lx)\n",
+		EAX_reg(context),EDX_reg(context),((BYTE*)EBP_reg(context))[-4],
+		(*(DWORD*)(EAX_reg(context)+EDX_reg(context)))+4*(((BYTE*)EBP_reg(context))[-4]),
+		*(DWORD*)((*(DWORD*)(EAX_reg(context)+EDX_reg(context)))+4*(((BYTE*)EBP_reg(context))[-4]))
+	);
+	_write_qtthunk((LPBYTE)EAX_reg(context),*(DWORD*)(EAX_reg(context)+EDX_reg(context)));
+	/* we just call the real QT_Thunk right now 
+	 * we can bypass the relaycode, for we already have the registercontext
+	 */
+	EDX_reg(context) = *(DWORD*)((*(DWORD*)(EAX_reg(context)+EDX_reg(context)))+4*(((BYTE*)EBP_reg(context))[-4]));
+	return QT_Thunk(context);
+}
+
+/***********************************************************************
+ *							(KERNEL32.45)
+ * Another thunkbuf link routine.
+ * The start of the thunkbuf looks like this:
+ * 	00: DWORD	length
+ *	04: SEGPTR	address for thunkbuffer pointer
+ */
+VOID WINAPI _KERNEL32_46(LPBYTE thunk,LPSTR thkbuf,DWORD len,LPSTR dll16,
+                         LPSTR dll32)
+{
+	LPDWORD		addr;
+	HMODULE16	hmod;
+	SEGPTR		segaddr;
+
+	fprintf(stderr,"KERNEL32_46(%p,%s,%lx,%s,%s)\n",
+		thunk,thkbuf,len,dll16,dll32
+	);
+	hmod = LoadLibrary16(dll16);
+	if (hmod < 32) {
+		fprintf(stderr,"->couldn't load %s, error %d\n",dll16,hmod);
+		return;
+	}
+	segaddr = (SEGPTR)WIN32_GetProcAddress16(hmod,thkbuf);
+	if (!segaddr) {
+		fprintf(stderr,"-> haven't found %s in %s!\n",thkbuf,dll16);
+		return;
+	}
+	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
+	if (addr[0] != len) {
+		fprintf(stderr,"-> length of thkbuf differs from expected length! (%ld vs %ld)\n",addr[0],len);
+		return;
+	}
+	*(DWORD*)PTR_SEG_TO_LIN(addr[1]) = (DWORD)thunk;
+}
+
+/**********************************************************************
+ *           _KERNEL32_87
+ * Check if thunking is initialized (ss selector set up etc.)
+ */
+BOOL32 WINAPI _KERNEL32_87()
+{
+    fprintf(stderr,"KERNEL32_87 stub, returning TRUE\n");
+    return TRUE;
+}
+
+/**********************************************************************
+ *           _KERNEL32_88
+ * One of the real thunking functions. This one seems to be for 32<->32
+ * thunks. It should probably be capable of crossing processboundaries.
+ *
+ * And YES, I've seen nr=48 (somewhere in the Win95 32<->16 OLE coupling)
+ */
+DWORD WINAPI _KERNEL32_88(DWORD *args)
+{
+    DWORD	nr = args[0];
+    DWORD	flags = args[1];
+    FARPROC32	fun = (FARPROC32)args[2];
+    DWORD	i,ret;
+
+    fprintf(stderr,"KERNEL32_88(%ld,0x%08lx,%p,[ ",nr,flags,fun);
+    for (i=0;i<nr/4;i++)
+    	fprintf(stderr,"0x%08lx,",args[3+i]);
+    fprintf(stderr,"])");
+#ifndef WINELIB
+    switch (nr) {
+    case 0:	ret = CallTo32_0(fun);
+		break;
+    case 4:	ret = CallTo32_1(fun,args[3]);
+		break;
+    case 8:	ret = CallTo32_2(fun,args[3],args[4]);
+		break;
+    case 12:	ret = CallTo32_3(fun,args[3],args[4],args[5]);
+		break;
+    case 16:	ret = CallTo32_4(fun,args[3],args[4],args[5],args[6]);
+		break;
+    case 20:	ret = CallTo32_5(fun,args[3],args[4],args[5],args[6],args[7]);
+		break;
+    case 24:	ret = CallTo32_6(fun,args[3],args[4],args[5],args[6],args[7],args[8]);
+		break;
+    case 28:	ret = CallTo32_7(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
+		break;
+    case 32:	ret = CallTo32_8(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]);
+		break;
+    case 36:	ret = CallTo32_9(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]);
+		break;
+    case 40:	ret = CallTo32_10(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12]);
+		break;
+    case 44:	ret = CallTo32_11(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13]);
+		break;
+    case 48:	ret = CallTo32_12(fun,args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13],args[14]);
+		break;
+    default:
+	fprintf(stderr,"    unsupported nr of arguments, %ld\n",nr);
+	ret = 0;
+	break;
+
+    }
+#endif
+    fprintf(stderr," returning %ld ...\n",ret);
+    return ret;
+}
+
+/**********************************************************************
+ * 		KERNEL_619		(KERNEL)
+ * Seems to store y and z depending on x in some internal lists...
+ */
+WORD WINAPI _KERNEL_619(WORD x,DWORD y,DWORD z)
+{
+    fprintf(stderr,"KERNEL_619(0x%04x,0x%08lx,0x%08lx)\n",x,y,z);
+    return x;
+}
diff --git a/if1632/user.spec b/if1632/user.spec
index 5f2dce1..6465424 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -283,7 +283,7 @@
 276 stub LockMyTask
 277 pascal16 GetDlgCtrlID(word) GetDlgCtrlID16
 278 pascal16 GetDesktopHwnd() GetDesktopHwnd
-279 stub OldSetDeskPattern
+279 pascal16 OldSetDeskPattern() SetDeskPattern
 280 pascal16 SetSystemMenu(word word) SetSystemMenu16
 281 pascal16 GetSysColorBrush(word) GetSysColorBrush16
 282 pascal16 SelectPalette(word word word) SelectPalette16
@@ -382,12 +382,12 @@
 431 pascal   AnsiUpper(segstr) AnsiUpper16
 432 pascal   AnsiLower(segstr) AnsiLower16
 433 pascal16 IsCharAlpha(byte) IsCharAlpha16
-434 pascal16 IsCharAlphanumeric(byte) IsCharAlphanumeric16
+434 pascal16 IsCharAlphaNumeric(byte) IsCharAlphaNumeric16
 435 pascal16 IsCharUpper(byte) IsCharUpper16
 436 pascal16 IsCharLower(byte) IsCharLower16
 437 pascal16 AnsiUpperBuff(ptr word) AnsiUpperBuff16
 438 pascal16 AnsiLowerBuff(ptr word) AnsiLowerBuff16
-441 stub InsertMenuItem
+441 pascal16 InsertMenuItem(word word word ptr) InsertMenuItem16
 443 stub GetMenuItemInfo
 445 pascal   DefFrameProc(word word word word long) DefFrameProc16
 446 stub SetMenuItemInfo
@@ -503,8 +503,8 @@
 804 stub CHOOSECOLOR_CALLBACK16
 819 stub PeekMessage32
 820 stub GetMessage32
-821 stub TranslateMessage32
-821 stub IsDialogMessage32
+821 stub TranslateMessage32	
+#821 stub IsDialogMessage32		# FIXME: two ordinal 821???
 822 stub DispatchMessage32
 825 stub PostMessage32
 826 stub PostThreadMessage32
diff --git a/if1632/user32.spec b/if1632/user32.spec
index 2144d97..78b5f23 100644
--- a/if1632/user32.spec
+++ b/if1632/user32.spec
@@ -165,7 +165,7 @@
 0158 stdcall DrawIcon(long long long long) DrawIcon32
 0159 stub DrawIconEx
 0160 stdcall DrawMenuBar(long) DrawMenuBar32
-0161 stub DrawStateA
+0161 stdcall DrawStateA(long long ptr long long long long long long long) DrawState32A
 0162 stub DrawStateW
 0163 stdcall DrawTextA(long ptr long ptr long) DrawText32A
 0164 stub DrawTextExA
@@ -253,7 +253,7 @@
 0246 stdcall GetKeyNameTextA(long ptr long) GetKeyNameText32A
 0247 stdcall GetKeyNameTextW(long ptr long) GetKeyNameText32W
 0248 stdcall GetKeyState(long) GetKeyState32
-0249 stub GetKeyboardLayout
+0249 stdcall GetKeyboardLayout(long) GetKeyboardLayout
 0250 stub GetKeyboardLayoutList
 0251 stub GetKeyboardLayoutNameA
 0252 stub GetKeyboardLayoutNameW
@@ -326,8 +326,8 @@
 0319 stdcall InSendMessage() InSendMessage32
 0320 stdcall InflateRect(ptr long long) InflateRect32
 0321 stdcall InsertMenuA(long long long long ptr) InsertMenu32A
-0322 stub InsertMenuItemA
-0323 stub InsertMenuItemW
+0322 stdcall InsertMenuItemA(long long long ptr) InsertMenuItem32A
+0323 stdcall InsertMenuItemW(long long long ptr) InsertMenuItem32W
 0324 stdcall InsertMenuW(long long long long ptr) InsertMenu32W
 0325 stub InternalGetWindowText
 0326 stdcall IntersectRect(ptr ptr ptr) IntersectRect32
@@ -492,10 +492,10 @@
 0485 stub SetLogonNotifyWindow
 0486 stdcall SetMenu(long long) SetMenu32
 0487 stub SetMenuContextHelpId
-0488 stub SetMenuDefaultItem
+0488 stdcall SetMenuDefaultItem(long long long) SetMenuDefaultItem32
 0489 stdcall SetMenuItemBitmaps(long long long long long) SetMenuItemBitmaps32
-0490 stub SetMenuItemInfoA
-0491 stub SetMenuItemInfoW
+0490 stdcall SetMenuItemInfoA(long long long ptr) SetMenuItemInfo32A
+0491 stdcall SetMenuItemInfoW(long long long ptr) SetMenuItemInfo32W
 0492 stub SetMessageExtraInfo
 0493 stdcall SetMessageQueue(long) SetMessageQueue32
 0494 stdcall SetParent(long long) SetParent32
diff --git a/if1632/winsock.spec b/if1632/winsock.spec
index 37ce932..2548e10 100644
--- a/if1632/winsock.spec
+++ b/if1632/winsock.spec
@@ -6,36 +6,36 @@
 name	winsock
 type	win16
 
-1   pascal16 accept(word ptr ptr) WINSOCK_accept
-2   pascal16 bind(word ptr word) WINSOCK_bind
-3   pascal16 closesocket(word) WINSOCK_closesocket
-4   pascal16 connect(word ptr word) WINSOCK_connect
-5   pascal16 getpeername(word ptr ptr) WINSOCK_getpeername
-6   pascal16 getsockname(word ptr ptr) WINSOCK_getsockname
-7   pascal16 getsockopt(word word word ptr ptr) WINSOCK_getsockopt
+1   pascal16 accept(word ptr ptr) WINSOCK_accept16
+2   pascal16 bind(word ptr word) WINSOCK_bind16
+3   pascal16 closesocket(word) WINSOCK_closesocket16
+4   pascal16 connect(word ptr word) WINSOCK_connect16
+5   pascal16 getpeername(word ptr ptr) WINSOCK_getpeername16
+6   pascal16 getsockname(word ptr ptr) WINSOCK_getsockname16
+7   pascal16 getsockopt(word word word ptr ptr) WINSOCK_getsockopt16
 8   pascal   htonl(long) WINSOCK_htonl
 9   pascal16 htons(word) WINSOCK_htons
 10  pascal   inet_addr(ptr) WINSOCK_inet_addr
 11  pascal   inet_ntoa(long) WINSOCK_inet_ntoa
-12  pascal16 ioctlsocket(word long ptr) WINSOCK_ioctlsocket
-13  pascal16 listen(word word) WINSOCK_listen
+12  pascal16 ioctlsocket(word long ptr) WINSOCK_ioctlsocket16
+13  pascal16 listen(word word) WINSOCK_listen16
 14  pascal   ntohl(long) WINSOCK_ntohl
 15  pascal16 ntohs(word) WINSOCK_ntohs
-16  pascal16 recv(word ptr word word) WINSOCK_recv
-17  pascal16 recvfrom(word ptr word word ptr ptr) WINSOCK_recvfrom
-18  pascal16 select(word ptr ptr ptr ptr) WINSOCK_select
-19  pascal16 send(word ptr word word) WINSOCK_send
-20  pascal16 sendto(word ptr word word ptr word) WINSOCK_sendto
-21  pascal16 setsockopt(word word word ptr word) WINSOCK_setsockopt
-22  pascal16 shutdown(word word) WINSOCK_shutdown
-23  pascal16 socket(word word word) WINSOCK_socket
-51  pascal   gethostbyaddr(ptr word word) WINSOCK_gethostbyaddr
-52  pascal   gethostbyname(ptr) WINSOCK_gethostbyname
-53  pascal   getprotobyname(ptr) WINSOCK_getprotobyname
-54  pascal   getprotobynumber(word) WINSOCK_getprotobynumber
-55  pascal   getservbyname(ptr ptr) WINSOCK_getservbyname
-56  pascal   getservbyport(word ptr) WINSOCK_getservbyport
-57  pascal   gethostname(ptr word) WINSOCK_gethostname
+16  pascal16 recv(word ptr word word) WINSOCK_recv16
+17  pascal16 recvfrom(word ptr word word ptr ptr) WINSOCK_recvfrom16
+18  pascal16 select(word ptr ptr ptr ptr) WINSOCK_select16
+19  pascal16 send(word ptr word word) WINSOCK_send16
+20  pascal16 sendto(word ptr word word ptr word) WINSOCK_sendto16
+21  pascal16 setsockopt(word word word ptr word) WINSOCK_setsockopt16
+22  pascal16 shutdown(word word) WINSOCK_shutdown16
+23  pascal16 socket(word word word) WINSOCK_socket16
+51  pascal   gethostbyaddr(ptr word word) WINSOCK_gethostbyaddr16
+52  pascal   gethostbyname(ptr) WINSOCK_gethostbyname16
+53  pascal   getprotobyname(ptr) WINSOCK_getprotobyname16
+54  pascal   getprotobynumber(word) WINSOCK_getprotobynumber16
+55  pascal   getservbyname(ptr ptr) WINSOCK_getservbyname16
+56  pascal   getservbyport(word ptr) WINSOCK_getservbyport16
+57  pascal   gethostname(ptr word) WINSOCK_gethostname16
 101 pascal16 WSAAsyncSelect(word word word long) WSAAsyncSelect
 102 pascal16 WSAAsyncGetHostByAddr(word word ptr word word segptr word)
              WSAAsyncGetHostByAddr
@@ -53,9 +53,9 @@
 109 pascal16 WSASetBlockingHook(segptr) WSASetBlockingHook16
 110 pascal16 WSAUnhookBlockingHook() WSAUnhookBlockingHook16
 111 pascal16 WSAGetLastError() WSAGetLastError
-112 pascal   WSASetLastError(word) WSASetLastError
+112 pascal   WSASetLastError(word) WSASetLastError16
 113 pascal16 WSACancelBlockingCall() WSACancelBlockingCall
 114 pascal16 WSAIsBlocking() WSAIsBlocking
-115 pascal   WSAStartup(word ptr) WSAStartup
+115 pascal   WSAStartup(word ptr) WSAStartup16
 116 pascal   WSACleanup() WSACleanup
-151 pascal16 __WSAFDIsSet(word ptr) __WSAFDIsSet
+151 pascal16 __WSAFDIsSet(word ptr) __WSAFDIsSet16
diff --git a/if1632/winspool.spec b/if1632/winspool.spec
index 12e16f6..ccc6dc7 100644
--- a/if1632/winspool.spec
+++ b/if1632/winspool.spec
@@ -52,11 +52,11 @@
 048 stub DeletePrinterIC
 049 stub DevQueryPrint
 050 stub DeviceCapabilities
-051 stub DeviceCapabilitiesA
+051 stdcall DeviceCapabilitiesA(ptr ptr long ptr ptr) DeviceCapabilities32A
 052 stub DeviceCapabilitiesW
 053 stub DeviceMode
 054 stub DocumentEvent
-055 stub DocumentPropertiesA
+055 stdcall DocumentPropertiesA(long long ptr ptr ptr long) DocumentProperties32A
 056 stub DocumentPropertiesW
 057 stub EXTDEVICEMODE
 058 stub EndDocPrinter
diff --git a/if1632/wprocs.spec b/if1632/wprocs.spec
index 2172fe7..48c1b4b 100644
--- a/if1632/wprocs.spec
+++ b/if1632/wprocs.spec
@@ -1,7 +1,6 @@
 name	wprocs
 type	win16
 
-1  pascal WINPROC_CallProc16To32A(word word word long long) WINPROC_CallProc16To32A
 10 pascal MDIClientWndProc(word word word long) MDIClientWndProc
 14 pascal FileOpenDlgProc(word word word long) FileOpenDlgProc
 15 pascal FileSaveDlgProc(word word word long) FileSaveDlgProc
@@ -11,7 +10,7 @@
 19 pascal PrintSetupDlgProc(word word word long) PrintSetupDlgProc
 20 pascal PrintDlgProc(word word word long) PrintDlgProc
 24 pascal16 TASK_Reschedule() TASK_Reschedule
-27 pascal EntryAddrProc(word word) MODULE_GetEntryPoint
+27 pascal EntryAddrProc(word word) EntryAddrProc
 28 pascal MyAlloc(word word word) MODULE_AllocateSegment
 30 pascal FormatCharDlgProc(word word word long) FormatCharDlgProc
  
@@ -279,6 +278,7 @@
 #
 #400+VXD_ID register <VxD handler>() <VxD handler>
 #
+405 register VXD_Timer() VXD_Timer
 414 register VXD_Comm() VXD_Comm
 #415 register VXD_Printer() VXD_Printer
 423 register VXD_Shell() VXD_Shell
diff --git a/if1632/wsock32.spec b/if1632/wsock32.spec
index 36893c2..1b36974 100644
--- a/if1632/wsock32.spec
+++ b/if1632/wsock32.spec
@@ -2,36 +2,36 @@
 type	win32
 base	0
 
-001 stdcall accept(long ptr ptr) WINSOCK_accept
-002 stdcall bind(long ptr long) WINSOCK_bind
-003 stdcall closesocket(long) WINSOCK_closesocket
-004 stdcall connect(long ptr long) WINSOCK_connect
-005 stub getpeername
-006 stdcall getsockname(long ptr ptr) WINSOCK_getsockname
-007 stub getsockopt
+001 stdcall accept(long ptr ptr) WINSOCK_accept32
+002 stdcall bind(long ptr long) WINSOCK_bind32
+003 stdcall closesocket(long) WINSOCK_closesocket32
+004 stdcall connect(long ptr long) WINSOCK_connect32
+005 stdcall getpeername(long ptr ptr) WINSOCK_getpeername32
+006 stdcall getsockname(long ptr ptr) WINSOCK_getsockname32
+007 stdcall getsockopt(long long long ptr ptr) WINSOCK_getsockopt32
 008 stdcall htonl(long) WINSOCK_htonl
 009 stdcall htons(long) WINSOCK_htons
 010 stdcall inet_addr(ptr) inet_addr
 011 stdcall inet_ntoa(ptr) inet_ntoa
-012 stub ioctlsocket
-013 stub listen
+012 stdcall ioctlsocket(long long ptr) WINSOCK_ioctlsocket32
+013 stdcall listen(long long) WINSOCK_listen32
 014 stdcall ntohl(long) WINSOCK_ntohl
 015 stdcall ntohs(long) WINSOCK_ntohs
-016 stub recv
-017 stub recvfrom
-018 stub select
-019 stub send
-020 stub sendto
-021 stub setsockopt
-022 stub shutdown
-023 stdcall socket(long long long) WINSOCK_socket
-051 stdcall gethostbyaddr(ptr long long) WINSOCK_gethostbyaddr
-052 stdcall gethostbyname(ptr) gethostbyname
-053 stub getprotobyname
-054 stub getprotobynumber
-055 stdcall getservbyname(ptr ptr) getservbyname
-056 stub getservbyport
-057 stdcall gethostname(ptr long) gethostname
+016 stdcall recv(long ptr long long) WINSOCK_recv32
+017 stdcall recvfrom(long ptr long long ptr ptr) WINSOCK_recvfrom32
+018 stdcall select(long ptr ptr ptr ptr) WINSOCK_select32
+019 stdcall send(long ptr long long) WINSOCK_send32
+020 stdcall sendto(long ptr long long ptr long) WINSOCK_sendto32
+021 stdcall setsockopt(long long long ptr long) WINSOCK_setsockopt32
+022 stdcall shutdown(long long) WINSOCK_shutdown32
+023 stdcall socket(long long long) WINSOCK_socket32
+051 stdcall gethostbyaddr(ptr long long) WINSOCK_gethostbyaddr32
+052 stdcall gethostbyname(ptr) WINSOCK_gethostbyname32
+053 stdcall getprotobyname(ptr) WINSOCK_getprotobyname32
+054 stdcall getprotobynumber(long) WINSOCK_getprotobynumber32
+055 stdcall getservbyname(ptr ptr) WINSOCK_getservbyname32
+056 stdcall getservbyport(long ptr) WINSOCK_getservbyport32
+057 stdcall gethostname(ptr long) WINSOCK_gethostname32
 101 stub WSAAsyncSelect
 102 stub WSAAsyncGetHostByAddr
 103 stub WSAAsyncGetHostByName
@@ -42,13 +42,13 @@
 108 stub WSACancelAsyncRequest
 109 stdcall WSASetBlockingHook(ptr) WSASetBlockingHook32
 110 stdcall WSAUnhookBlockingHook() WSAUnhookBlockingHook32
-111 stub WSAGetLastError
-112 stub WSASetLastError
-113 stub WSACancelBlockingCall
-114 stub WSAIsBlocking
-115 stdcall WSAStartup(long ptr) WSAStartup
+111 stdcall WSAGetLastError() WSAGetLastError
+112 stdcall WSASetLastError(long) WSASetLastError32
+113 stdcall WSACancelBlockingCall() WSACancelBlockingCall
+114 stdcall WSAIsBlocking() WSAIsBlocking
+115 stdcall WSAStartup(long ptr) WSAStartup32
 116 stdcall WSACleanup() WSACleanup
-151 stub __WSAFDIsSet
+151 stdcall __WSAFDIsSet(long ptr) __WSAFDIsSet32
 #500 stub WEP
 # applications *should* 'degrade gracefully if these are not present
 # ... as it is, they don't
diff --git a/include/bitmap.h b/include/bitmap.h
index b6c6545..6ec1ad0 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -53,6 +53,7 @@
 extern INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer );
 extern INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer );
 extern BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bitmap );
+extern XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp );
 
   /* objects/dib.c */
 extern int DIB_GetDIBWidthBytes( int width, int depth );
diff --git a/include/button.h b/include/button.h
index b0c7a1f..64c1c08 100644
--- a/include/button.h
+++ b/include/button.h
@@ -28,7 +28,7 @@
 
 #define BUTTON_STATE(hwnd)     ((WIN_FindWndPtr(hwnd))->wExtra[0])
 
-extern LRESULT ButtonWndProc( HWND32 hWnd, UINT32 uMsg,
-                              WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI ButtonWndProc( HWND32 hWnd, UINT32 uMsg,
+                                     WPARAM32 wParam, LPARAM lParam );
 
 #endif  /* __WINE_BUTTON_H */
diff --git a/include/callback.h b/include/callback.h
index c2d1020..4efb4e4 100644
--- a/include/callback.h
+++ b/include/callback.h
@@ -10,17 +10,22 @@
 #include "wintypes.h"
 #include "winnt.h"
 
-extern
-int CallTo32_LargeStack( int (*func)(), int nbargs, ... );
+extern int (*IF1632_CallLargeStack)( int (*func)(), void *arg );
+
+#define CALL_LARGE_STACK(func,arg) \
+    (IF1632_CallLargeStack ? \
+     IF1632_CallLargeStack( (int(*)())(func), (void *)(arg) ) : \
+     ((int(*)())(func))((void *)arg))
 
 /* List of the 16-bit callback functions. This list is used  */
 /* by the build program to generate the file if1632/callto16.S */
 
 #ifndef WINELIB
 
-extern void CallTo16_regs_     ( const CONTEXT *context );
+extern LONG CallTo16_regs_     ( const CONTEXT *context );
 extern WORD CallTo16_word_     ( FARPROC16 );
 extern WORD CallTo16_word_w    ( FARPROC16, WORD );
+extern LONG CallTo16_long_l    ( FARPROC16, LONG );
 extern WORD CallTo16_word_ww   ( FARPROC16, WORD, WORD );
 extern WORD CallTo16_word_wl   ( FARPROC16, WORD, LONG );
 extern WORD CallTo16_word_ll   ( FARPROC16, LONG, LONG );
@@ -67,6 +72,14 @@
 extern LONG CallTo32_3( FARPROC32, DWORD, DWORD, DWORD );
 extern LONG CallTo32_4( FARPROC32, DWORD, DWORD, DWORD, DWORD );
 extern LONG CallTo32_5( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_6( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_7( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_8( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_9( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_10( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_11( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_12( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
+extern LONG CallTo32_13( FARPROC32, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD );
 
 #define CallTaskStart32( func ) \
     CallTo32_0( func )
diff --git a/include/color.h b/include/color.h
index 985c877..735e629 100644
--- a/include/color.h
+++ b/include/color.h
@@ -17,7 +17,7 @@
 extern void	  COLOR_Cleanup(void);
 extern COLORREF	  COLOR_ToLogical(int pixel);
 extern int 	  COLOR_ToPhysical( DC *dc, COLORREF color );
-extern int 	  COLOR_SetMapping( PALETTEOBJ* pal, BOOL32 mapOnly );
+extern int 	  COLOR_SetMapping( PALETTEOBJ* pal, UINT32 uStart, UINT32 uNum, BOOL32 mapOnly );
 extern BOOL32 	  COLOR_IsSolid( COLORREF color );
 extern Colormap	  COLOR_GetColormap();
 extern UINT16	  COLOR_GetSystemPaletteSize();
diff --git a/include/combo.h b/include/combo.h
index 7060bdb..a4a861e 100644
--- a/include/combo.h
+++ b/include/combo.h
@@ -18,6 +18,7 @@
 #define CBF_CAPTURE             0x0020
 #define CBF_EDIT                0x0040
 #define CBF_NORESIZE		0x0080
+#define CBF_NOTIFY		0x0100
 #define CBF_EUI                 0x8000
 
 /* Combo state struct */
diff --git a/include/comm.h b/include/comm.h
index 5f2b0af..e65df31 100644
--- a/include/comm.h
+++ b/include/comm.h
@@ -1,7 +1,7 @@
 #ifndef __WINE_COMM_H
 #define __WINE_COMM_H
 
-#define MAX_PORTS   16
+#define MAX_PORTS   9
 
 struct DosDeviceStruct {
     char *devicename;   /* /dev/cua1 */
diff --git a/include/commctrl.h b/include/commctrl.h
index a16e7bf..7e6d09d 100644
--- a/include/commctrl.h
+++ b/include/commctrl.h
@@ -7,7 +7,7 @@
 
 #include "windows.h"
 
-void       InitCommonControls(void);
+void WINAPI InitCommonControls(void);
 
 /* StatusWindow */
 
@@ -41,11 +41,61 @@
 #define CCS_BOTTOM            0x0003
 #define SBARS_SIZEGRIP        0x0100
 
-HWND32     CreateStatusWindow32A(INT32,LPCSTR,HWND32,UINT32);
-HWND32     CreateStatusWindow32W(INT32,LPCWSTR,HWND32,UINT32);
+/* UpDown control */
+
+#define UPDOWN_CLASS32A  "msctls_updown32"
+#define UPDOWN_CLASS32W  "msctls_updown32"
+#define UPDOWN_CLASS16   "msctls_updown"
+#define UPDOWN_CLASS WINELIB_NAME_AW(UPDOWN_CLASS)
+
+typedef struct tagUDACCEL
+{
+  UINT32 nSec;
+  UINT32 nInc;
+} UDACCEL;
+ 
+typedef struct tagNM_UPDOWN
+{
+    NMHDR hdr;
+    int iPos;
+    int iDelta;
+} NM_UPDOWN;
+
+#define UD_MAXVAL          0x7fff
+#define UD_MINVAL          0x8001
+
+#define UDS_WRAP           0x0001
+#define UDS_SETBUDDYINT    0x0002
+#define UDS_ALIGNRIGHT     0x0004
+#define UDS_ALIGNLEFT      0x0008
+#define UDS_AUTOBUDDY      0x0010
+#define UDS_ARROWKEYS      0x0020
+#define UDS_HORZ           0x0040
+#define UDS_NOTHOUSANDS    0x0080
+
+#define UDN_FIRST          (0U-721)
+#define UDN_DELTAPOS       (UDN_FIRST - 1)
+
+#define UDM_SETRANGE       (WM_USER+101)
+#define UDM_GETRANGE       (WM_USER+102)
+#define UDM_SETPOS         (WM_USER+103)
+#define UDM_GETPOS         (WM_USER+104)
+#define UDM_SETBUDDY       (WM_USER+105)
+#define UDM_GETBUDDY       (WM_USER+106)
+#define UDM_SETACCEL       (WM_USER+107)
+#define UDM_GETACCEL       (WM_USER+108)
+#define UDM_SETBASE        (WM_USER+109)
+#define UDM_GETBASE        (WM_USER+110)
+
+/* Functions prototypes */
+
+HWND32     WINAPI CreateStatusWindow32A(INT32,LPCSTR,HWND32,UINT32);
+HWND32     WINAPI CreateStatusWindow32W(INT32,LPCWSTR,HWND32,UINT32);
 #define    CreateStatusWindow WINELIB_NAME_AW(CreateStatusWindow)
-VOID       DrawStatusText32A(HDC32,LPRECT32,LPCSTR,UINT32);
-VOID       DrawStatusText32W(HDC32,LPRECT32,LPCWSTR,UINT32);
+HWND32     WINAPI CreateUpDownControl(DWORD,INT32,INT32,INT32,INT32,HWND32,
+                                   INT32,HINSTANCE32,HWND32,INT32,INT32,INT32);
+VOID       WINAPI DrawStatusText32A(HDC32,LPRECT32,LPCSTR,UINT32);
+VOID       WINAPI DrawStatusText32W(HDC32,LPRECT32,LPCWSTR,UINT32);
 #define    DrawStatusText WINELIB_NAME_AW(DrawStatusText)
 
 #endif  /* __WINE_COMMCTRL_H */
diff --git a/include/commdlg.h b/include/commdlg.h
index 61ac06f..01d7bb7 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -325,33 +325,32 @@
 #define CDERR_NOHOOK           0x000B
 #define CDERR_REGISTERMSGFAIL  0x000C
 
-BOOL16  ChooseColor(LPCHOOSECOLOR lpChCol);
-DWORD CommDlgExtendedError(void);
-HWND16 FindText( SEGPTR find);
-INT16 GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf);
-INT16 GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf);
-INT16 GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf);
+BOOL16  WINAPI ChooseColor(LPCHOOSECOLOR lpChCol);
+DWORD   WINAPI CommDlgExtendedError(void);
+HWND16  WINAPI FindText( SEGPTR find);
+INT16   WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf);
+INT16   WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf);
+INT16   WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf);
 #define GetFileTitle WINELIB_NAME_AW(GetFileTitle)
-BOOL16  GetOpenFileName16(SEGPTR ofn);
-BOOL32  GetOpenFileName32A(LPOPENFILENAME32A ofn);
-BOOL32  GetOpenFileName32W(LPOPENFILENAME32W ofn);
+BOOL16  WINAPI GetOpenFileName16(SEGPTR ofn);
+BOOL32  WINAPI GetOpenFileName32A(LPOPENFILENAME32A ofn);
+BOOL32  WINAPI GetOpenFileName32W(LPOPENFILENAME32W ofn);
 #define GetOpenFileName WINELIB_NAME_AW(GetOpenFileName)
-BOOL16  GetSaveFileName16(SEGPTR ofn);
-BOOL32  GetSaveFileName32A(LPOPENFILENAME32A ofn);
-BOOL32  GetSaveFileName32W(LPOPENFILENAME32W ofn);
+BOOL16  WINAPI GetSaveFileName16(SEGPTR ofn);
+BOOL32  WINAPI GetSaveFileName32A(LPOPENFILENAME32A ofn);
+BOOL32  WINAPI GetSaveFileName32W(LPOPENFILENAME32W ofn);
 #define GetSaveFileName WINELIB_NAME_AW(GetSaveFileName)
-BOOL16  PrintDlg( SEGPTR print);
-HWND16 ReplaceText( SEGPTR find);
-BOOL16  ChooseFont(LPCHOOSEFONT lpChFont);
-
-LRESULT FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT ColorDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT FindTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT ReplaceTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
-LRESULT FormatCharDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+BOOL16  WINAPI PrintDlg( SEGPTR print);
+HWND16  WINAPI ReplaceText( SEGPTR find);
+BOOL16  WINAPI ChooseFont(LPCHOOSEFONT lpChFont);
+LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI ColorDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI FindTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI ReplaceTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
+LRESULT WINAPI FormatCharDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam);
 
 #ifdef __cplusplus
 }
diff --git a/include/compobj.h b/include/compobj.h
index baa348f..fb0d7ad 100644
--- a/include/compobj.h
+++ b/include/compobj.h
@@ -10,7 +10,7 @@
 
 typedef struct tagCLSID CLSID;
 
-OLESTATUS StringFromCLSID(const CLSID *id, LPSTR);
-OLESTATUS CLSIDFromString(const LPCSTR, CLSID *);
+OLESTATUS WINAPI StringFromCLSID(const CLSID *id, LPSTR);
+OLESTATUS WINAPI CLSIDFromString(const LPCSTR, CLSID *);
 
 #endif
diff --git a/include/debug.h b/include/debug.h
index 3308a57..9cc2e9a 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -80,6 +80,7 @@
 #undef DEBUG_TIMER
 #undef DEBUG_TOOLHELP
 #undef DEBUG_TWEAK
+#undef DEBUG_UPDOWN
 #undef DEBUG_VER
 #undef DEBUG_VIRTUAL
 #undef DEBUG_VXD
@@ -164,6 +165,7 @@
 #define DEBUG_TIMER
 #define DEBUG_TOOLHELP
 #define DEBUG_TWEAK
+#define DEBUG_UPDOWN
 #define DEBUG_VER
 #define DEBUG_VIRTUAL
 #define DEBUG_VXD
@@ -546,6 +548,11 @@
 #else
     0,
 #endif
+#ifdef DEBUG_UPDOWN
+    1,
+#else
+    0,
+#endif
 #ifdef DEBUG_VER
     1,
 #else
@@ -1551,8 +1558,21 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_ver if(!debug_msg_enabled[74]) ; else fprintf
-#define debugging_ver debug_msg_enabled[74]
+#define dprintf_updown if(!debug_msg_enabled[74]) ; else fprintf
+#define debugging_updown debug_msg_enabled[74]
+#else
+#ifdef DEBUG_UPDOWN
+#define dprintf_updown fprintf
+#define debugging_updown 1
+#else
+#define dprintf_updown while(0) fprintf
+#define debugging_updown 0
+#endif
+#endif
+
+#ifdef DEBUG_RUNTIME
+#define dprintf_ver if(!debug_msg_enabled[75]) ; else fprintf
+#define debugging_ver debug_msg_enabled[75]
 #else
 #ifdef DEBUG_VER
 #define dprintf_ver fprintf
@@ -1564,8 +1584,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_virtual if(!debug_msg_enabled[75]) ; else fprintf
-#define debugging_virtual debug_msg_enabled[75]
+#define dprintf_virtual if(!debug_msg_enabled[76]) ; else fprintf
+#define debugging_virtual debug_msg_enabled[76]
 #else
 #ifdef DEBUG_VIRTUAL
 #define dprintf_virtual fprintf
@@ -1577,8 +1597,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_vxd if(!debug_msg_enabled[76]) ; else fprintf
-#define debugging_vxd debug_msg_enabled[76]
+#define dprintf_vxd if(!debug_msg_enabled[77]) ; else fprintf
+#define debugging_vxd debug_msg_enabled[77]
 #else
 #ifdef DEBUG_VXD
 #define dprintf_vxd fprintf
@@ -1590,8 +1610,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win if(!debug_msg_enabled[77]) ; else fprintf
-#define debugging_win debug_msg_enabled[77]
+#define dprintf_win if(!debug_msg_enabled[78]) ; else fprintf
+#define debugging_win debug_msg_enabled[78]
 #else
 #ifdef DEBUG_WIN
 #define dprintf_win fprintf
@@ -1603,8 +1623,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win16drv if(!debug_msg_enabled[78]) ; else fprintf
-#define debugging_win16drv debug_msg_enabled[78]
+#define dprintf_win16drv if(!debug_msg_enabled[79]) ; else fprintf
+#define debugging_win16drv debug_msg_enabled[79]
 #else
 #ifdef DEBUG_WIN16DRV
 #define dprintf_win16drv fprintf
@@ -1616,8 +1636,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_win32 if(!debug_msg_enabled[79]) ; else fprintf
-#define debugging_win32 debug_msg_enabled[79]
+#define dprintf_win32 if(!debug_msg_enabled[80]) ; else fprintf
+#define debugging_win32 debug_msg_enabled[80]
 #else
 #ifdef DEBUG_WIN32
 #define dprintf_win32 fprintf
@@ -1629,8 +1649,8 @@
 #endif
 
 #ifdef DEBUG_RUNTIME
-#define dprintf_winsock if(!debug_msg_enabled[80]) ; else fprintf
-#define debugging_winsock debug_msg_enabled[80]
+#define dprintf_winsock if(!debug_msg_enabled[81]) ; else fprintf
+#define debugging_winsock debug_msg_enabled[81]
 #else
 #ifdef DEBUG_WINSOCK
 #define dprintf_winsock fprintf
@@ -1719,6 +1739,7 @@
     "timer",
     "toolhelp",
     "tweak",
+    "updown",
     "ver",
     "virtual",
     "vxd",
diff --git a/include/debugger.h b/include/debugger.h
index a6670ce..bf9ee7a 100644
--- a/include/debugger.h
+++ b/include/debugger.h
@@ -9,7 +9,7 @@
 
 #include "winnt.h"
 #include "selectors.h"
-#include "sigcontext.h"
+#include "sig_context.h"
 #include "pe_image.h"
 
 #define STEP_FLAG 0x100 /* single step flag */
diff --git a/include/desktop.h b/include/desktop.h
index 129f96e..7e8085f 100644
--- a/include/desktop.h
+++ b/include/desktop.h
@@ -18,7 +18,7 @@
 } DESKTOPINFO;
 
 extern BOOL32 DESKTOP_SetPattern( LPCSTR pattern );
-extern LRESULT DesktopWndProc( HWND32 hwnd, UINT32 message,
-                               WPARAM32 wParam, LPARAM lParam );
+extern LRESULT WINAPI DesktopWndProc( HWND32 hwnd, UINT32 message,
+                                      WPARAM32 wParam, LPARAM lParam );
 
 #endif  /* __WINE_DESKTOP_H */
diff --git a/include/driver.h b/include/driver.h
index 3eb7b7d..54fed12 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -57,14 +57,15 @@
     DRIVERPROC16          lpDrvProc;
 } DRIVERITEM, *LPDRIVERITEM;
 
-LRESULT DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
-                      LPARAM dwParam1, LPARAM dwParam2);
-HDRVR16 OpenDriver(LPSTR szDriverName, LPSTR szSectionName, LPARAM lParam2);
-LRESULT CloseDriver(HDRVR16 hDriver, LPARAM lParam1, LPARAM lParam2);
-LRESULT SendDriverMessage( HDRVR16 hDriver, UINT16 message, LPARAM lParam1,
-                           LPARAM lParam2 );
-HMODULE16 GetDriverModuleHandle(HDRVR16 hDriver);
-HDRVR16 GetNextDriver(HDRVR16, DWORD);
-BOOL16 GetDriverInfo(HDRVR16, DRIVERINFOSTRUCT16 *);
+LRESULT WINAPI DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
+                             LPARAM dwParam1, LPARAM dwParam2);
+HDRVR16 WINAPI OpenDriver(LPSTR szDriverName, LPSTR szSectionName,
+                          LPARAM lParam2);
+LRESULT WINAPI CloseDriver(HDRVR16 hDriver, LPARAM lParam1, LPARAM lParam2);
+LRESULT WINAPI SendDriverMessage( HDRVR16 hDriver, UINT16 message,
+                                  LPARAM lParam1, LPARAM lParam2 );
+HMODULE16 WINAPI GetDriverModuleHandle(HDRVR16 hDriver);
+HDRVR16 WINAPI GetNextDriver(HDRVR16, DWORD);
+BOOL16 WINAPI GetDriverInfo(HDRVR16, DRIVERINFOSTRUCT16 *);
 
 #endif  /* __WINE_DRIVER_H */
diff --git a/include/except.h b/include/except.h
index d55146b..8028060 100644
--- a/include/except.h
+++ b/include/except.h
@@ -15,7 +15,7 @@
 /* forward definition */
 struct __EXCEPTION_FRAME;
 
-typedef DWORD ( *PEXCEPTION_HANDLER)( PEXCEPTION_RECORD          pexcrec,
+typedef DWORD (CALLBACK *PEXCEPTION_HANDLER)( PEXCEPTION_RECORD pexcrec,
                                       struct __EXCEPTION_FRAME  *pestframe,
                                       PCONTEXT                   pcontext,
                                       LPVOID                     pdispatcher);
@@ -36,9 +36,9 @@
  * Function definitions  
  */
  
-void RaiseException(DWORD exccode, DWORD excflags, 
-                    DWORD nargs, const LPDWORD pargs,
-                    PCONTEXT pcontext /* Wine additional parameter */ ); 
+void WINAPI RaiseException(DWORD exccode, DWORD excflags, 
+                           DWORD nargs, const LPDWORD pargs,
+                           PCONTEXT pcontext /* Wine additional parameter */); 
                         
 /*
  *  this undocumented function is called when an exception
@@ -54,10 +54,10 @@
  *  context.   
  */
 
-void RtlUnwind( PEXCEPTION_FRAME pestframe,
-                LPVOID unusedEIP,
-                PEXCEPTION_RECORD pexcrec,
-                DWORD contextEAX,
-                PCONTEXT pcontext /* Wine additional parameter */ );
+void WINAPI RtlUnwind( PEXCEPTION_FRAME pestframe,
+                       LPVOID unusedEIP,
+                       PEXCEPTION_RECORD pexcrec,
+                       DWORD contextEAX,
+                       PCONTEXT pcontext /* Wine additional parameter */ );
 
 #endif  /* __WINE_EXCEPT_H */
diff --git a/include/gdi.h b/include/gdi.h
index 42d66cb..817fdf7 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -273,14 +273,21 @@
 
 #define GDI_HEAP_ALLOC(size) \
             LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
+#define GDI_HEAP_ALLOC_MOVEABLE(size) \
+            LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, (size) )
 #define GDI_HEAP_REALLOC(handle,size) \
             LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
 #define GDI_HEAP_FREE(handle) \
             LOCAL_Free( GDI_HeapSel, (handle) )
-#define GDI_HEAP_LIN_ADDR(handle)  \
-         ((handle) ? PTR_SEG_OFF_TO_LIN(GDI_HeapSel, (handle)) : NULL)
-#define GDI_HEAP_SEG_ADDR(handle)  \
-         ((handle) ? PTR_SEG_OFF_TO_SEGPTR(GDI_HeapSel, (handle)) : (SEGPTR)0)
+
+#define GDI_HEAP_LOCK(handle) \
+            LOCAL_Lock( GDI_HeapSel, (handle) )
+#define GDI_HEAP_LOCK_SEGPTR(handle) \
+            LOCAL_LockSegptr( GDI_HeapSel, (handle) )
+#define GDI_HEAP_UNLOCK(handle) \
+    ((((HGDIOBJ16)(handle) >= FIRST_STOCK_HANDLE) && \
+      ((HGDIOBJ16)(handle)<=LAST_STOCK_HANDLE)) ? \
+      0 : LOCAL_Unlock( GDI_HeapSel, (handle) ))
 
 extern BOOL32 GDI_Init(void);
 extern HGDIOBJ16 GDI_AllocObject( WORD, WORD );
diff --git a/include/listbox.h b/include/listbox.h
deleted file mode 100644
index 27cee05..0000000
--- a/include/listbox.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- *   Listbox definitions
- */
-
-typedef struct tagLISTSTRUCT {
-        MEASUREITEMSTRUCT16 mis;
-        UINT16            itemState;
-        RECT16          itemRect;
-	HLOCAL16	hData;
-	char            *itemText;
-	struct tagLISTSTRUCT *lpNext;
-} LISTSTRUCT, *LPLISTSTRUCT;
-
-typedef struct {
-	WORD    FirstVisible;
-	WORD    ItemsCount;
-	WORD    ItemsVisible;
-	WORD    ColumnsVisible;
-	WORD    ItemsPerColumn;
-	short   ItemFocused;
-	short   PrevFocused;
-	WORD    StdItemHeight;
-	WORD    ColumnsWidth;
-	WORD    DrawCtlType;
-        WORD    CtlID;
-	LPLISTSTRUCT lpFirst;
-	HWND16	hSelf;
-	DWORD   dwStyle;      /* added for COMBOLBOX style faking */
-	HWND16  hParent;
-	HFONT16 hFont;
-	BOOL32  bRedrawFlag;
-        BOOL32  HasStrings;
-        BOOL32  OwnerDrawn;
-	WORD    iNumStops;
-	LPINT16 TabStops;
-        BOOL32  needMeasure;
-	HGLOBAL16 HeapSel;
-/*	MDESC   *Heap; */
-} HEADLIST,*LPHEADLIST;
-
-/* shared code between listbox and combo controls */
-extern void CreateListBoxStruct(HWND16 hwnd, WORD CtlType, LONG styles, HWND16 parent);
-extern void DestroyListBoxStruct(LPHEADLIST lphl);
-
-extern void ListBoxSendNotification(LPHEADLIST lphl, WORD code);
-
-extern LPLISTSTRUCT ListBoxGetItem(LPHEADLIST lphl, UINT16 uIndex);
-extern int ListMaxFirstVisible(LPHEADLIST lphl);
-extern int ListBoxScrollToFocus(LPHEADLIST lphl);
-extern int ListBoxAddString(LPHEADLIST lphl, SEGPTR itemData);
-extern int ListBoxInsertString(LPHEADLIST lphl, UINT16 uIndex, LPCSTR newstr);
-extern int ListBoxGetText(LPHEADLIST lphl, UINT16 uIndex, LPSTR OutStr);
-extern DWORD ListBoxGetItemData(LPHEADLIST lphl, UINT16 uIndex);
-extern int ListBoxSetItemData(LPHEADLIST lphl, UINT16 uIndex, DWORD ItemData);
-extern int ListBoxDeleteString(LPHEADLIST lphl, UINT16 uIndex);
-extern int ListBoxFindString(LPHEADLIST lphl, UINT16 nFirst, SEGPTR MatchStr);
-extern int ListBoxFindStringExact(LPHEADLIST lphl, UINT16 nFirst, SEGPTR MatchStr);
-extern int ListBoxResetContent(LPHEADLIST lphl);
-extern int ListBoxSetCurSel(LPHEADLIST lphl, WORD wIndex);
-extern int ListBoxSetSel(LPHEADLIST lphl, WORD wIndex, WORD state);
-extern int ListBoxGetSel(LPHEADLIST lphl, WORD wIndex);
-extern LONG ListBoxDirectory(LPHEADLIST lphl, UINT16 attrib, LPCSTR filespec);
-extern int ListBoxGetItemRect(LPHEADLIST lphl, WORD wIndex, LPRECT16 rect);
-extern int ListBoxSetItemHeight(LPHEADLIST lphl, WORD wIndex, long height);
-extern int ListBoxFindNextMatch(LPHEADLIST lphl, WORD wChar);
-
-extern void ListBoxDrawItem (HWND16 hwnd, LPHEADLIST lphl, HDC16 hdc,
-			     LPLISTSTRUCT lpls, RECT16 *rect, WORD itemAction,
-			     WORD itemState);
-extern int ListBoxFindMouse(LPHEADLIST lphl, int X, int Y);
-extern void ListBoxAskMeasure(LPHEADLIST lphl, LPLISTSTRUCT lpls);
diff --git a/include/mdi.h b/include/mdi.h
index 812580c..38e5872 100644
--- a/include/mdi.h
+++ b/include/mdi.h
@@ -20,8 +20,8 @@
 
 #define WM_MDICALCCHILDSCROLL   0x10AC /* this is exactly what Windows uses */
 
-extern LRESULT MDIClientWndProc(HWND16 hwnd, UINT16 message, 
-				WPARAM16 wParam, LPARAM lParam); /* mdi.c */
+extern LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, 
+                                       WPARAM16 wParam, LPARAM lParam);
 
 typedef struct 
 {
diff --git a/include/menu.h b/include/menu.h
index 121c091..c270b84 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -7,7 +7,6 @@
 
 extern BOOL32 MENU_Init(void);
 extern HMENU32 MENU_GetSysMenu(HWND32 hWndOwner, HMENU32 hSysPopup);
-extern void MENU_InitSysMenuPopup(HMENU32 hmenu, DWORD style, DWORD clsStyle);
 extern UINT32 MENU_GetMenuBarHeight( HWND32 hwnd, UINT32 menubarWidth,
                                      INT32 orgX, INT32 orgY );
 extern void MENU_TrackMouseMenuBar( WND *wnd, INT32 ht, POINT32 pt );
diff --git a/include/message.h b/include/message.h
index 8a59d79..ecf33c4 100644
--- a/include/message.h
+++ b/include/message.h
@@ -26,8 +26,12 @@
 extern BOOL32 TIMER_GetTimerMsg( MSG16 *msg, HWND32 hwnd,
                                  HQUEUE16 hQueue, BOOL32 remove );
 
+#define EVENT_IO_READ		0
+#define EVENT_IO_WRITE		1
+#define EVENT_IO_EXCEPT		2
+
 /* event.c */
-extern BOOL32 EVENT_WaitXEvent( BOOL32 sleep, BOOL32 peek );
+extern BOOL32 EVENT_WaitNetEvent( BOOL32 sleep, BOOL32 peek );
 extern void EVENT_Synchronize(void);
 extern void EVENT_ProcessEvent( XEvent *event );
 extern void EVENT_RegisterWindow( WND *pWnd );
diff --git a/include/mmsystem.h b/include/mmsystem.h
index 2941b4a..4735202 100644
--- a/include/mmsystem.h
+++ b/include/mmsystem.h
@@ -108,7 +108,7 @@
 #define CALLBACK_TASK       0x00020000l    /* dwCallback is a HTASK */
 #define CALLBACK_FUNCTION   0x00030000l    /* dwCallback is a FARPROC */
 
-typedef void (*LPDRVCALLBACK) (HDRVR16 h, UINT16 uMessage, DWORD dwUser, DWORD dw1, DWORD dw2);
+typedef void (CALLBACK *LPDRVCALLBACK) (HDRVR16 h, UINT16 uMessage, DWORD dwUser, DWORD dw1, DWORD dw2);
 
 #define MM_MICROSOFT            1       /* Microsoft Corp. */
 
@@ -129,10 +129,8 @@
 #define MM_PC_JOYSTICK          12      /* Joystick adapter */
 
 
-WORD mmsystemGetVersion(void);
-void OutputDebugStr(LPCSTR);
-
-BOOL16 sndPlaySound(LPCSTR lpszSoundName, UINT16 uFlags);
+WORD WINAPI mmsystemGetVersion(void);
+BOOL16 WINAPI sndPlaySound(LPCSTR lpszSoundName, UINT16 uFlags);
 
 #define SND_SYNC            0x0000  /* play synchronously (default) */
 #define SND_ASYNC           0x0001  /* play asynchronously */
@@ -237,57 +235,60 @@
     WORD        wBitsPerSample;
 } PCMWAVEFORMAT, *LPPCMWAVEFORMAT;
 
-UINT16 waveOutGetNumDevs(void);
-UINT16 waveOutGetDevCaps(UINT16 uDeviceID, WAVEOUTCAPS * lpCaps,
-    UINT16 uSize);
-UINT16 waveOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
-UINT16 waveOutSetVolume(UINT16 uDeviceID, DWORD dwVolume);
-UINT16 waveOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 waveGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT16 uDeviceID,
+UINT16 WINAPI waveOutGetNumDevs(void);
+UINT16 WINAPI waveOutGetDevCaps(UINT16 uDeviceID, WAVEOUTCAPS * lpCaps,
+                                UINT16 uSize);
+UINT16 WINAPI waveOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
+UINT16 WINAPI waveOutSetVolume(UINT16 uDeviceID, DWORD dwVolume);
+UINT16 WINAPI waveOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI waveGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT16 uDeviceID,
     const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT16 waveOutClose(HWAVEOUT16 hWaveOut);
-UINT16 waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
-     WAVEHDR * lpWaveOutHdr, UINT16 uSize);
-UINT16 waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
-    WAVEHDR * lpWaveOutHdr, UINT16 uSize);
-UINT16 waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,
-    UINT16 uSize);
-UINT16 waveOutPause(HWAVEOUT16 hWaveOut);
-UINT16 waveOutRestart(HWAVEOUT16 hWaveOut);
-UINT16 waveOutReset(HWAVEOUT16 hWaveOut);
-UINT16 waveOutBreakLoop(HWAVEOUT16 hWaveOut);
-UINT16 waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpInfo,
-    UINT16 uSize);
-UINT16 waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch);
-UINT16 waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch);
-UINT16 waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate);
-UINT16 waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate);
-UINT16 waveOutGetID(HWAVEOUT16 hWaveOut, UINT16 * lpuDeviceID);
+UINT16 WINAPI waveOutClose(HWAVEOUT16 hWaveOut);
+UINT16 WINAPI waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
+                                   WAVEHDR *lpWaveOutHdr, UINT16 uSize);
+UINT16 WINAPI waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
+                                     WAVEHDR *lpWaveOutHdr, UINT16 uSize);
+UINT16 WINAPI waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,
+                           UINT16 uSize);
+UINT16 WINAPI waveOutPause(HWAVEOUT16 hWaveOut);
+UINT16 WINAPI waveOutRestart(HWAVEOUT16 hWaveOut);
+UINT16 WINAPI waveOutReset(HWAVEOUT16 hWaveOut);
+UINT16 WINAPI waveOutBreakLoop(HWAVEOUT16 hWaveOut);
+UINT16 WINAPI waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpInfo,
+                                 UINT16 uSize);
+UINT16 WINAPI waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch);
+UINT16 WINAPI waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch);
+UINT16 WINAPI waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate);
+UINT16 WINAPI waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate);
+UINT16 WINAPI waveOutGetID(HWAVEOUT16 hWaveOut, UINT16 * lpuDeviceID);
 
-DWORD waveOutMessage(HWAVEOUT16 hWaveOut, UINT16 uMessage, DWORD dw1, DWORD dw2);
+DWORD WINAPI waveOutMessage(HWAVEOUT16 hWaveOut, UINT16 uMessage, DWORD dw1,
+                            DWORD dw2);
 
-UINT16 waveInGetNumDevs(void);
-UINT16 waveInGetDevCaps(UINT16 uDeviceID, WAVEINCAPS * lpCaps,
-    UINT16 uSize);
-UINT16 waveInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 waveInOpen(HWAVEIN16 * lphWaveIn, UINT16 uDeviceID,
-    const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT16 waveInClose(HWAVEIN16 hWaveIn);
-UINT16 waveInPrepareHeader(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize);
-UINT16 waveInUnprepareHeader(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize);
-UINT16 waveInAddBuffer(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize);
-UINT16 waveInStart(HWAVEIN16 hWaveIn);
-UINT16 waveInStop(HWAVEIN16 hWaveIn);
-UINT16 waveInReset(HWAVEIN16 hWaveIn);
-UINT16 waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpInfo,
-    UINT16 uSize);
-UINT16 waveInGetID(HWAVEIN16 hWaveIn, UINT16 * lpuDeviceID);
+UINT16 WINAPI waveInGetNumDevs(void);
+UINT16 WINAPI waveInGetDevCaps(UINT16 uDeviceID, WAVEINCAPS * lpCaps,
+                               UINT16 uSize);
+UINT16 WINAPI waveInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI waveInOpen(HWAVEIN16 * lphWaveIn, UINT16 uDeviceID,
+                         const LPWAVEFORMAT lpFormat, DWORD dwCallback,
+                         DWORD dwInstance, DWORD dwFlags);
+UINT16 WINAPI waveInClose(HWAVEIN16 hWaveIn);
+UINT16 WINAPI waveInPrepareHeader(HWAVEIN16 hWaveIn, WAVEHDR * lpWaveInHdr,
+                                  UINT16 uSize);
+UINT16 WINAPI waveInUnprepareHeader(HWAVEIN16 hWaveIn, WAVEHDR * lpWaveInHdr,
+                                    UINT16 uSize);
+UINT16 WINAPI waveInAddBuffer(HWAVEIN16 hWaveIn, WAVEHDR * lpWaveInHdr,
+                              UINT16 uSize);
+UINT16 WINAPI waveInStart(HWAVEIN16 hWaveIn);
+UINT16 WINAPI waveInStop(HWAVEIN16 hWaveIn);
+UINT16 WINAPI waveInReset(HWAVEIN16 hWaveIn);
+UINT16 WINAPI waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpInfo,
+                                UINT16 uSize);
+UINT16 WINAPI waveInGetID(HWAVEIN16 hWaveIn, UINT16 * lpuDeviceID);
 
-DWORD waveInMessage(HWAVEIN16 hWaveIn, UINT16 uMessage, DWORD dw1, DWORD dw2);
+DWORD WINAPI waveInMessage(HWAVEIN16 hWaveIn, UINT16 uMessage, DWORD dw1,
+                           DWORD dw2);
 
 #define MIDIERR_UNPREPARED    (MIDIERR_BASE + 0)   /* header not prepared */
 #define MIDIERR_STILLPLAYING  (MIDIERR_BASE + 1)   /* still something playing */
@@ -370,51 +371,51 @@
 #define MHDR_PREPARED   0x00000002       /* set if header prepared */
 #define MHDR_INQUEUE    0x00000004       /* reserved for driver */
 
-UINT16 midiOutGetNumDevs(void);
-UINT16 midiOutGetDevCaps(UINT16 uDeviceID,
+UINT16 WINAPI midiOutGetNumDevs(void);
+UINT16 WINAPI midiOutGetDevCaps(UINT16 uDeviceID,
     MIDIOUTCAPS * lpCaps, UINT16 uSize);
-UINT16 midiOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
-UINT16 midiOutSetVolume(UINT16 uDeviceID, DWORD dwVolume);
-UINT16 midiOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT16 uDeviceID,
+UINT16 WINAPI midiOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
+UINT16 WINAPI midiOutSetVolume(UINT16 uDeviceID, DWORD dwVolume);
+UINT16 WINAPI midiOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT16 uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT16 midiOutClose(HMIDIOUT16 hMidiOut);
-UINT16 midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
+UINT16 WINAPI midiOutClose(HMIDIOUT16 hMidiOut);
+UINT16 WINAPI midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT16 uSize);
-UINT16 midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
+UINT16 WINAPI midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT16 uSize);
-UINT16 midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg);
-UINT16 midiOutLongMsg(HMIDIOUT16 hMidiOut,
+UINT16 WINAPI midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg);
+UINT16 WINAPI midiOutLongMsg(HMIDIOUT16 hMidiOut,
     MIDIHDR * lpMidiOutHdr, UINT16 uSize);
-UINT16 midiOutReset(HMIDIOUT16 hMidiOut);
-UINT16 midiOutCachePatches(HMIDIOUT16 hMidiOut,
+UINT16 WINAPI midiOutReset(HMIDIOUT16 hMidiOut);
+UINT16 WINAPI midiOutCachePatches(HMIDIOUT16 hMidiOut,
     UINT16 uBank, WORD * lpwPatchArray, UINT16 uFlags);
-UINT16 midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut,
+UINT16 WINAPI midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut,
     UINT16 uPatch, WORD * lpwKeyArray, UINT16 uFlags);
-UINT16 midiOutGetID(HMIDIOUT16 hMidiOut, UINT16 * lpuDeviceID);
+UINT16 WINAPI midiOutGetID(HMIDIOUT16 hMidiOut, UINT16 * lpuDeviceID);
 
-DWORD midiOutMessage(HMIDIOUT16 hMidiOut, UINT16 uMessage, DWORD dw1, DWORD dw2);
+DWORD WINAPI midiOutMessage(HMIDIOUT16 hMidiOut, UINT16 uMessage, DWORD dw1, DWORD dw2);
 
-UINT16 midiInGetNumDevs(void);
-UINT16 midiInGetDevCaps(UINT16 uDeviceID,
+UINT16 WINAPI midiInGetNumDevs(void);
+UINT16 WINAPI midiInGetDevCaps(UINT16 uDeviceID,
     LPMIDIINCAPS lpCaps, UINT16 uSize);
-UINT16 midiInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-UINT16 midiInOpen(HMIDIIN16 * lphMidiIn, UINT16 uDeviceID,
+UINT16 WINAPI midiInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
+UINT16 WINAPI midiInOpen(HMIDIIN16 * lphMidiIn, UINT16 uDeviceID,
     DWORD dwCallback, DWORD dwInstance, DWORD dwFlags);
-UINT16 midiInClose(HMIDIIN16 hMidiIn);
-UINT16 midiInPrepareHeader(HMIDIIN16 hMidiIn,
+UINT16 WINAPI midiInClose(HMIDIIN16 hMidiIn);
+UINT16 WINAPI midiInPrepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT16 uSize);
-UINT16 midiInUnprepareHeader(HMIDIIN16 hMidiIn,
+UINT16 WINAPI midiInUnprepareHeader(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT16 uSize);
-UINT16 midiInAddBuffer(HMIDIIN16 hMidiIn,
+UINT16 WINAPI midiInAddBuffer(HMIDIIN16 hMidiIn,
     MIDIHDR * lpMidiInHdr, UINT16 uSize);
-UINT16 midiInStart(HMIDIIN16 hMidiIn);
-UINT16 midiInStop(HMIDIIN16 hMidiIn);
-UINT16 midiInReset(HMIDIIN16 hMidiIn);
-UINT16 midiInGetID(HMIDIIN16 hMidiIn, UINT16 * lpuDeviceID);
+UINT16 WINAPI midiInStart(HMIDIIN16 hMidiIn);
+UINT16 WINAPI midiInStop(HMIDIIN16 hMidiIn);
+UINT16 WINAPI midiInReset(HMIDIIN16 hMidiIn);
+UINT16 WINAPI midiInGetID(HMIDIIN16 hMidiIn, UINT16 * lpuDeviceID);
 
-DWORD midiInMessage(HMIDIIN16 hMidiIn, UINT16 uMessage, DWORD dw1, DWORD dw2);
+DWORD WINAPI midiInMessage(HMIDIIN16 hMidiIn, UINT16 uMessage, DWORD dw1, DWORD dw2);
 
 #define AUX_MAPPER     (-1)
 
@@ -433,12 +434,12 @@
 #define AUXCAPS_VOLUME          0x0001  /* supports volume control */
 #define AUXCAPS_LRVOLUME        0x0002  /* separate left-right volume control */
 
-UINT16 auxGetNumDevs(void);
-UINT16 auxGetDevCaps(UINT16 uDeviceID, AUXCAPS * lpCaps, UINT16 uSize);
-UINT16 auxSetVolume(UINT16 uDeviceID, DWORD dwVolume);
-UINT16 auxGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
+UINT16 WINAPI auxGetNumDevs(void);
+UINT16 WINAPI auxGetDevCaps(UINT16 uDeviceID, AUXCAPS * lpCaps, UINT16 uSize);
+UINT16 WINAPI auxSetVolume(UINT16 uDeviceID, DWORD dwVolume);
+UINT16 WINAPI auxGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume);
 
-DWORD auxOutMessage(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2);
+DWORD WINAPI auxOutMessage(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2);
 
 #define TIMERR_NOERROR        (0)                  /* no error */
 #define TIMERR_NOCANDO        (TIMERR_BASE+1)      /* request not completed */
@@ -454,14 +455,14 @@
     UINT16    wPeriodMax;     /* maximum period supported  */
 } TIMECAPS, *LPTIMECAPS;
 
-UINT16 timeGetSystemTime(MMTIME * lpTime, UINT16 uSize);
-DWORD timeGetTime(void);
-UINT16 timeSetEvent(UINT16 uDelay, UINT16 uResolution,
+UINT16 WINAPI timeGetSystemTime(MMTIME * lpTime, UINT16 uSize);
+DWORD WINAPI timeGetTime(void);
+UINT16 WINAPI timeSetEvent(UINT16 uDelay, UINT16 uResolution,
     LPTIMECALLBACK lpFunction, DWORD dwUser, UINT16 uFlags);
-UINT16 timeKillEvent(UINT16 uTimerID);
-UINT16 timeGetDevCaps(TIMECAPS * lpTimeCaps, UINT16 uSize);
-UINT16 timeBeginPeriod(UINT16 uPeriod);
-UINT16 timeEndPeriod(UINT16 uPeriod);
+UINT16 WINAPI timeKillEvent(UINT16 uTimerID);
+UINT16 WINAPI timeGetDevCaps(TIMECAPS * lpTimeCaps, UINT16 uSize);
+UINT16 WINAPI timeBeginPeriod(UINT16 uPeriod);
+UINT16 WINAPI timeEndPeriod(UINT16 uPeriod);
 
 #define JOYERR_NOERROR        (0)                  /* no error */
 #define JOYERR_PARMS          (JOYERR_BASE+5)      /* bad parameters */
@@ -502,14 +503,14 @@
     UINT16 wButtons;              /* button states */
 } JOYINFO, *LPJOYINFO;
 
-UINT16 joyGetDevCaps(UINT16 uJoyID, JOYCAPS * lpCaps, UINT16 uSize);
-UINT16 joyGetNumDevs(void);
-UINT16 joyGetPos(UINT16 uJoyID, JOYINFO * lpInfo);
-UINT16 joyGetThreshold(UINT16 uJoyID, UINT16 * lpuThreshold);
-UINT16 joyReleaseCapture(UINT16 uJoyID);
-UINT16 joySetCapture(HWND16 hwnd, UINT16 uJoyID, UINT16 uPeriod,
+UINT16 WINAPI joyGetDevCaps(UINT16 uJoyID, JOYCAPS * lpCaps, UINT16 uSize);
+UINT16 WINAPI joyGetNumDevs(void);
+UINT16 WINAPI joyGetPos(UINT16 uJoyID, JOYINFO * lpInfo);
+UINT16 WINAPI joyGetThreshold(UINT16 uJoyID, UINT16 * lpuThreshold);
+UINT16 WINAPI joyReleaseCapture(UINT16 uJoyID);
+UINT16 WINAPI joySetCapture(HWND16 hwnd, UINT16 uJoyID, UINT16 uPeriod,
     BOOL16 bChanged);
-UINT16 joySetThreshold(UINT16 uJoyID, UINT16 uThreshold);
+UINT16 WINAPI joySetThreshold(UINT16 uJoyID, UINT16 uThreshold);
 
 #define MMIOERR_BASE            256
 #define MMIOERR_FILENOTFOUND    (MMIOERR_BASE + 1)  /* file not found */
@@ -526,8 +527,8 @@
 #define CFSEPCHAR       '+'             /* compound file name separator char. */
 
 typedef DWORD           FOURCC;         /* a four character code */
-typedef LONG (*LPMMIOPROC)(LPSTR lpmmioinfo, UINT16 uMessage,
-            LPARAM lParam1, LPARAM lParam2);
+typedef LONG (CALLBACK *LPMMIOPROC)(LPSTR lpmmioinfo, UINT16 uMessage,
+                                    LPARAM lParam1, LPARAM lParam2);
 
 typedef struct {
         DWORD           dwFlags;        /* general status flags */
@@ -622,48 +623,49 @@
                 ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \
                 ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
 
-FOURCC mmioStringToFOURCC(LPCSTR sz, UINT16 uFlags);
-LPMMIOPROC mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
+FOURCC WINAPI mmioStringToFOURCC(LPCSTR sz, UINT16 uFlags);
+LPMMIOPROC WINAPI mmioInstallIOProc(FOURCC fccIOProc, LPMMIOPROC pIOProc,
     DWORD dwFlags);
-HMMIO16 mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo,
+HMMIO16 WINAPI mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo,
     DWORD dwOpenFlags);
 
-UINT16 mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
+UINT16 WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
      MMIOINFO * lpmmioinfo, DWORD dwRenameFlags);
 
-UINT16 mmioClose(HMMIO16 hmmio, UINT16 uFlags);
-LONG mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch);
-LONG mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch);
-LONG mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin);
-UINT16 mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags);
-UINT16 mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT16 uFlags);
-UINT16 mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, LONG cchBuffer,
+UINT16 WINAPI mmioClose(HMMIO16 hmmio, UINT16 uFlags);
+LONG WINAPI mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch);
+LONG WINAPI mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch);
+LONG WINAPI mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin);
+UINT16 WINAPI mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags);
+UINT16 WINAPI mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT16 uFlags);
+UINT16 WINAPI mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, LONG cchBuffer,
     UINT16 uFlags);
-UINT16 mmioFlush(HMMIO16 hmmio, UINT16 uFlags);
-UINT16 mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags);
-LONG mmioSendMessage(HMMIO16 hmmio, UINT16 uMessage,
+UINT16 WINAPI mmioFlush(HMMIO16 hmmio, UINT16 uFlags);
+UINT16 WINAPI mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags);
+LONG WINAPI mmioSendMessage(HMMIO16 hmmio, UINT16 uMessage,
     LPARAM lParam1, LPARAM lParam2);
-UINT16 mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
+UINT16 WINAPI mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
     const MMCKINFO * lpckParent, UINT16 uFlags);
-UINT16 mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags);
-UINT16 mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags);
+UINT16 WINAPI mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags);
+UINT16 WINAPI mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags);
 
-typedef UINT16 (*YIELDPROC) (UINT16 uDeviceID, DWORD dwYieldData);
+typedef UINT16 (CALLBACK *YIELDPROC) (UINT16 uDeviceID, DWORD dwYieldData);
 
-DWORD mciSendCommand (UINT16 uDeviceID, UINT16 uMessage,
-    DWORD dwParam1, DWORD dwParam2);
-DWORD mciSendString (LPCSTR lpstrCommand,
-    LPSTR lpstrReturnString, UINT16 uReturnLength, HWND16 hwndCallback);
-UINT16 mciGetDeviceID (LPCSTR lpstrName);
-UINT16 mciGetDeviceIDFromElementID (DWORD dwElementID,
-    LPCSTR lpstrType);
-BOOL16 mciGetErrorString (DWORD wError, LPSTR lpstrBuffer,
-    UINT16 uLength);
-BOOL16 mciSetYieldProc (UINT16 uDeviceID, YIELDPROC fpYieldProc,
-    DWORD dwYieldData);
+DWORD WINAPI mciSendCommand (UINT16 uDeviceID, UINT16 uMessage,
+                             DWORD dwParam1, DWORD dwParam2);
+DWORD WINAPI mciSendString (LPCSTR lpstrCommand,
+                            LPSTR lpstrReturnString, UINT16 uReturnLength,
+                            HWND16 hwndCallback);
+UINT16 WINAPI mciGetDeviceID (LPCSTR lpstrName);
+UINT16 WINAPI mciGetDeviceIDFromElementID (DWORD dwElementID,
+                                           LPCSTR lpstrType);
+BOOL16 WINAPI mciGetErrorString (DWORD wError, LPSTR lpstrBuffer,
+                                 UINT16 uLength);
+BOOL16 WINAPI mciSetYieldProc (UINT16 uDeviceID, YIELDPROC fpYieldProc,
+                               DWORD dwYieldData);
 
-HTASK16 mciGetCreatorTask(UINT16 uDeviceID);
-YIELDPROC mciGetYieldProc (UINT16 uDeviceID, DWORD * lpdwYieldData);
+HTASK16 WINAPI mciGetCreatorTask(UINT16 uDeviceID);
+YIELDPROC WINAPI mciGetYieldProc (UINT16 uDeviceID, DWORD * lpdwYieldData);
 
 #define MCIERR_INVALID_DEVICE_ID        (MCIERR_BASE + 1)
 #define MCIERR_UNRECOGNIZED_KEYWORD     (MCIERR_BASE + 3)
@@ -1514,14 +1516,14 @@
 									/* filled in by the driver */
 } MCI_OPEN_DRIVER_PARMS, * LPMCI_OPEN_DRIVER_PARMS;
 
-DWORD mciGetDriverData(UINT16 uDeviceID);
-BOOL16  mciSetDriverData(UINT16 uDeviceID, DWORD dwData);
-UINT16  mciDriverYield(UINT16 uDeviceID);
-BOOL16  mciDriverNotify(HWND16 hwndCallback, UINT16 uDeviceID,
-                        UINT16 uStatus);
-UINT16  mciLoadCommandResource(HINSTANCE16 hInstance,
-                               LPCSTR lpResName, UINT16 uType);
-BOOL16  mciFreeCommandResource(UINT16 uTable);
+DWORD  WINAPI mciGetDriverData(UINT16 uDeviceID);
+BOOL16 WINAPI mciSetDriverData(UINT16 uDeviceID, DWORD dwData);
+UINT16 WINAPI mciDriverYield(UINT16 uDeviceID);
+BOOL16 WINAPI mciDriverNotify(HWND16 hwndCallback, UINT16 uDeviceID,
+                              UINT16 uStatus);
+UINT16 WINAPI mciLoadCommandResource(HINSTANCE16 hInstance,
+                                     LPCSTR lpResName, UINT16 uType);
+BOOL16 WINAPI mciFreeCommandResource(UINT16 uTable);
 
 #define DCB_NULL		0x0000
 #define DCB_WINDOW		0x0001			/* dwCallback is a HWND */
@@ -1530,17 +1532,17 @@
 #define DCB_TYPEMASK	0x0007
 #define DCB_NOSWITCH	0x0008			/* don't switch stacks for callback */
 
-BOOL16 DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, 
-                      WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
-DWORD auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
+BOOL16 WINAPI DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, 
+                             WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
+DWORD WINAPI auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2);
-DWORD midMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
+DWORD WINAPI midMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2);
-DWORD modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
+DWORD WINAPI modMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2);
-DWORD widMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
+DWORD WINAPI widMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2);
-DWORD wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
+DWORD WINAPI wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
 					DWORD dwParam1, DWORD dwParam2);
 
 #endif /* __WINE_MMSYSTEM_H */
diff --git a/include/msdos.h b/include/msdos.h
index 3eb18a6..1cc09b1 100644
--- a/include/msdos.h
+++ b/include/msdos.h
@@ -55,8 +55,6 @@
     DWORD  filesize;             /* 1c file size */
 } DOS_DIRENTRY_LAYOUT;
 
-#define DOSVERSION 0x1606      /* Major version in low byte: DOS 6.22 */
-#define WINDOSVER  0x0616      /* Windows reports the DOS version reversed */
 #define WINVERSION 0x0a03      /* Windows version 3.10 */
 
 #define MAX_DOS_DRIVES	26
diff --git a/include/neexe.h b/include/neexe.h
index 757b46f..ead7623 100644
--- a/include/neexe.h
+++ b/include/neexe.h
@@ -37,6 +37,7 @@
 #define	IMAGE_DOS_SIGNATURE	0x5A4D		/* MZ */
 #define	IMAGE_OS2_SIGNATURE	0x454E		/* NE */
 #define	IMAGE_OS2_SIGNATURE_LE	0x454C		/* LE */
+#define	IMAGE_OS2_SIGNATURE_LX  0x584C          /* LX */
 #define	IMAGE_VXD_SIGNATURE	0x454C		/* LE */
 #define	IMAGE_NT_SIGNATURE	0x00004550	/* PE00 */
 
diff --git a/include/ole.h b/include/ole.h
index 0692ee0..7e08b9d 100644
--- a/include/ole.h
+++ b/include/ole.h
@@ -151,8 +151,8 @@
 } OLETARGETDEVICE;
 typedef struct _OLESTREAM* LPOLESTREAM;
 typedef struct _OLESTREAMVTBL {
-	DWORD	(*Get)(LPOLESTREAM,LPSTR,DWORD);
-	DWORD	(*Put)(LPOLESTREAM,LPSTR,DWORD);
+	DWORD	(CALLBACK *Get)(LPOLESTREAM,LPSTR,DWORD);
+	DWORD	(CALLBACK *Put)(LPOLESTREAM,LPSTR,DWORD);
 } OLESTREAMVTBL;
 typedef OLESTREAMVTBL*	LPOLESTREAMVTBL;
 typedef struct _OLESTREAM {
@@ -162,15 +162,15 @@
 typedef struct _OLEOBJECT*	LPOLEOBJECT;
 typedef struct _OLECLIENT*	LPOLECLIENT;
 typedef struct _OLESERVERDOCVTBL {
-	OLESTATUS	(*Save)(LPOLESERVERDOC);
-	OLESTATUS	(*Close)(LPOLESERVERDOC);
-	OLESTATUS	(*SetHostNames)(LPOLESERVERDOC,OLE_LPCSTR,OLE_LPCSTR);
-	OLESTATUS	(*SetDocDimensions)(LPOLESERVERDOC,LPRECT16);
+	OLESTATUS	(CALLBACK *Save)(LPOLESERVERDOC);
+	OLESTATUS	(CALLBACK *Close)(LPOLESERVERDOC);
+	OLESTATUS	(CALLBACK *SetHostNames)(LPOLESERVERDOC,OLE_LPCSTR,OLE_LPCSTR);
+	OLESTATUS	(CALLBACK *SetDocDimensions)(LPOLESERVERDOC,LPRECT16);
 #undef GetObject  /* FIXME */
-	OLESTATUS	(*GetObject)(LPOLESERVERDOC,OLE_LPCSTR,LPOLEOBJECT*,LPOLECLIENT);
-	OLESTATUS	(*Release)(LPOLESERVERDOC);
-	OLESTATUS	(*SetColorScheme)(LPOLESERVERDOC,LPLOGPALETTE);
-	OLESTATUS	(*Execute)(LPOLESERVERDOC,HGLOBAL16);
+	OLESTATUS	(CALLBACK *GetObject)(LPOLESERVERDOC,OLE_LPCSTR,LPOLEOBJECT*,LPOLECLIENT);
+	OLESTATUS	(CALLBACK *Release)(LPOLESERVERDOC);
+	OLESTATUS	(CALLBACK *SetColorScheme)(LPOLESERVERDOC,LPLOGPALETTE);
+	OLESTATUS	(CALLBACK *Execute)(LPOLESERVERDOC,HGLOBAL16);
 } OLESERVERDOCVTBL;
 typedef OLESERVERDOCVTBL*	LPOLESERVERDOCVTBL;
 typedef struct _OLESERVERDOC {
@@ -180,13 +180,13 @@
 
 typedef struct _OLESERVER*	LPOLESERVER;
 typedef struct _OLESERVERVTBL {
-	OLESTATUS	(*Open)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,LPOLESERVERDOC *);
-	OLESTATUS	(*Create)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC*);
-	OLESTATUS	(*CreateFromTemplate)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC *);
-	OLESTATUS	(*Edit)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC *);
-	OLESTATUS	(*Exit)(LPOLESERVER);
-	OLESTATUS	(*Release)(LPOLESERVER); 
-	OLESTATUS	(*Execute)(LPOLESERVER); 
+	OLESTATUS	(CALLBACK *Open)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,LPOLESERVERDOC *);
+	OLESTATUS	(CALLBACK *Create)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC*);
+	OLESTATUS	(CALLBACK *CreateFromTemplate)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC *);
+	OLESTATUS	(CALLBACK *Edit)(LPOLESERVER,LHSERVERDOC,OLE_LPCSTR,OLE_LPCSTR,LPOLESERVERDOC *);
+	OLESTATUS	(CALLBACK *Exit)(LPOLESERVER);
+	OLESTATUS	(CALLBACK *Release)(LPOLESERVER); 
+	OLESTATUS	(CALLBACK *Execute)(LPOLESERVER); 
 } OLESERVERVTBL; 
 typedef OLESERVERVTBL	*LPOLESERVERVTBL;
 typedef struct _OLESERVER {
@@ -194,7 +194,7 @@
 	/* server specific data */
 } OLESERVER;
 typedef struct _OLECLIENTVTBL {
-	int (*CallBack)(LPOLECLIENT,OLE_NOTIFICATION,LPOLEOBJECT);
+	int (CALLBACK *CallBack)(LPOLECLIENT,OLE_NOTIFICATION,LPOLEOBJECT);
 } OLECLIENTVTBL;
 typedef OLECLIENTVTBL	*LPOLECLIENTVTBL;
 
@@ -204,44 +204,44 @@
 } OLECLIENT;
 
 typedef struct _OLEOBJECTVTBL {
-        void *  	(*QueryProtocol)(LPOLEOBJECT,OLE_LPCSTR);
-	OLESTATUS	(*Release)(LPOLEOBJECT);
-	OLESTATUS	(*Show)(LPOLEOBJECT,BOOL16);
-	OLESTATUS	(*DoVerb)(LPOLEOBJECT,UINT16,BOOL16,BOOL16);
-	OLESTATUS	(*GetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE16 *);
-	OLESTATUS	(*SetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE16);
-	OLESTATUS	(*SetTargetDevice)(LPOLEOBJECT,HGLOBAL16);
-	OLESTATUS	(*SetBounds)(LPOLEOBJECT,LPRECT16);
-	OLESTATUS	(*EnumFormats)(LPOLEOBJECT,OLECLIPFORMAT);
-	OLESTATUS	(*SetColorScheme)(LPOLEOBJECT,LPLOGPALETTE);
-	OLESTATUS	(*Delete)(LPOLEOBJECT);
-	OLESTATUS	(*SetHostNames)(LPOLEOBJECT,OLE_LPCSTR,OLE_LPCSTR);
-	OLESTATUS	(*SaveToStream)(LPOLEOBJECT,LPOLESTREAM);
-	OLESTATUS	(*Clone)(LPOLEOBJECT,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT *);
-	OLESTATUS	(*CopyFromLink)(LPOLEOBJECT,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT *);
-	OLESTATUS	(*Equal)(LPOLEOBJECT,LPOLEOBJECT);
-	OLESTATUS	(*CopyToClipBoard)(LPOLEOBJECT);
-	OLESTATUS	(*Draw)(LPOLEOBJECT,HDC16,LPRECT16,LPRECT16,HDC16);
-	OLESTATUS	(*Activate)(LPOLEOBJECT,UINT16,BOOL16,BOOL16,HWND16,LPRECT16);
-	OLESTATUS	(*Execute)(LPOLEOBJECT,HGLOBAL16,UINT16);
-	OLESTATUS	(*Close)(LPOLEOBJECT);
-	OLESTATUS	(*Update)(LPOLEOBJECT);
-	OLESTATUS	(*Reconnect)(LPOLEOBJECT);
-	OLESTATUS	(*ObjectConvert)(LPOLEOBJECT,OLE_LPCSTR,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT*);
-	OLESTATUS	(*GetLinkUpdateOptions)(LPOLEOBJECT,LPOLEOPT_UPDATE);
-	OLESTATUS	(*SetLinkUpdateOptions)(LPOLEOBJECT,OLEOPT_UPDATE);
-	OLESTATUS	(*Rename)(LPOLEOBJECT,OLE_LPCSTR);
-	OLESTATUS	(*QueryName)(LPOLEOBJECT,LPSTR,LPUINT16);
-	OLESTATUS	(*QueryType)(LPOLEOBJECT,LPLONG);
-	OLESTATUS	(*QueryBounds)(LPOLEOBJECT,LPRECT16);
-	OLESTATUS	(*QuerySize)(LPOLEOBJECT,LPDWORD);
-	OLESTATUS	(*QueryOpen)(LPOLEOBJECT);
-	OLESTATUS	(*QueryOutOfDate)(LPOLEOBJECT);
-	OLESTATUS	(*QueryReleaseStatus)(LPOLEOBJECT);
-	OLESTATUS	(*QueryReleaseError)(LPOLEOBJECT);
-	OLE_RELEASE_METHOD (*QueryReleaseMethod)(LPOLEOBJECT);
-	OLESTATUS	(*RequestData)(LPOLEOBJECT,OLECLIPFORMAT);
-	OLESTATUS	(*ObjectLong)(LPOLEOBJECT,UINT16,LPLONG);
+        void *  	(CALLBACK *QueryProtocol)(LPOLEOBJECT,OLE_LPCSTR);
+	OLESTATUS	(CALLBACK *Release)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *Show)(LPOLEOBJECT,BOOL16);
+	OLESTATUS	(CALLBACK *DoVerb)(LPOLEOBJECT,UINT16,BOOL16,BOOL16);
+	OLESTATUS	(CALLBACK *GetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE16 *);
+	OLESTATUS	(CALLBACK *SetData)(LPOLEOBJECT,OLECLIPFORMAT,HANDLE16);
+	OLESTATUS	(CALLBACK *SetTargetDevice)(LPOLEOBJECT,HGLOBAL16);
+	OLESTATUS	(CALLBACK *SetBounds)(LPOLEOBJECT,LPRECT16);
+	OLESTATUS	(CALLBACK *EnumFormats)(LPOLEOBJECT,OLECLIPFORMAT);
+	OLESTATUS	(CALLBACK *SetColorScheme)(LPOLEOBJECT,LPLOGPALETTE);
+	OLESTATUS	(CALLBACK *Delete)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *SetHostNames)(LPOLEOBJECT,OLE_LPCSTR,OLE_LPCSTR);
+	OLESTATUS	(CALLBACK *SaveToStream)(LPOLEOBJECT,LPOLESTREAM);
+	OLESTATUS	(CALLBACK *Clone)(LPOLEOBJECT,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT *);
+	OLESTATUS	(CALLBACK *CopyFromLink)(LPOLEOBJECT,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT *);
+	OLESTATUS	(CALLBACK *Equal)(LPOLEOBJECT,LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *CopyToClipBoard)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *Draw)(LPOLEOBJECT,HDC16,LPRECT16,LPRECT16,HDC16);
+	OLESTATUS	(CALLBACK *Activate)(LPOLEOBJECT,UINT16,BOOL16,BOOL16,HWND16,LPRECT16);
+	OLESTATUS	(CALLBACK *Execute)(LPOLEOBJECT,HGLOBAL16,UINT16);
+	OLESTATUS	(CALLBACK *Close)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *Update)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *Reconnect)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *ObjectConvert)(LPOLEOBJECT,OLE_LPCSTR,LPOLECLIENT,LHCLIENTDOC,OLE_LPCSTR,LPOLEOBJECT*);
+	OLESTATUS	(CALLBACK *GetLinkUpdateOptions)(LPOLEOBJECT,LPOLEOPT_UPDATE);
+	OLESTATUS	(CALLBACK *SetLinkUpdateOptions)(LPOLEOBJECT,OLEOPT_UPDATE);
+	OLESTATUS	(CALLBACK *Rename)(LPOLEOBJECT,OLE_LPCSTR);
+	OLESTATUS	(CALLBACK *QueryName)(LPOLEOBJECT,LPSTR,LPUINT16);
+	OLESTATUS	(CALLBACK *QueryType)(LPOLEOBJECT,LPLONG);
+	OLESTATUS	(CALLBACK *QueryBounds)(LPOLEOBJECT,LPRECT16);
+	OLESTATUS	(CALLBACK *QuerySize)(LPOLEOBJECT,LPDWORD);
+	OLESTATUS	(CALLBACK *QueryOpen)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *QueryOutOfDate)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *QueryReleaseStatus)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *QueryReleaseError)(LPOLEOBJECT);
+	OLE_RELEASE_METHOD (CALLBACK *QueryReleaseMethod)(LPOLEOBJECT);
+	OLESTATUS	(CALLBACK *RequestData)(LPOLEOBJECT,OLECLIPFORMAT);
+	OLESTATUS	(CALLBACK *ObjectLong)(LPOLEOBJECT,UINT16,LPLONG);
 } OLEOBJECTVTBL;
 typedef OLEOBJECTVTBL*	LPOLEOBJECTVTBL;
 
@@ -250,13 +250,13 @@
 } OLEOBJECT;
 
 
-OLESTATUS OleRegisterServer(LPCSTR,LPOLESERVER,LHSERVER *,HINSTANCE16,OLE_SERVER_USE);
-OLESTATUS OleUnblockServer(LHSERVER,BOOL16 *);
-OLESTATUS OleRegisterServerDoc(LHSERVER,LPCSTR,LPOLESERVERDOC,LHSERVERDOC *);
-OLESTATUS OleRegisterClientDoc(LPCSTR,LPCSTR,LONG,LHCLIENTDOC *);
-OLESTATUS OleRenameClientDoc(LHCLIENTDOC,LPCSTR);
-OLESTATUS OleRevokeServerDoc(LHSERVERDOC);
-OLESTATUS OleRevokeClientDoc(LHCLIENTDOC);
-OLESTATUS OleRevokeServer(LHSERVER);
+OLESTATUS WINAPI OleRegisterServer(LPCSTR,LPOLESERVER,LHSERVER *,HINSTANCE16,OLE_SERVER_USE);
+OLESTATUS WINAPI OleUnblockServer(LHSERVER,BOOL16 *);
+OLESTATUS WINAPI OleRegisterServerDoc(LHSERVER,LPCSTR,LPOLESERVERDOC,LHSERVERDOC *);
+OLESTATUS WINAPI OleRegisterClientDoc(LPCSTR,LPCSTR,LONG,LHCLIENTDOC *);
+OLESTATUS WINAPI OleRenameClientDoc(LHCLIENTDOC,LPCSTR);
+OLESTATUS WINAPI OleRevokeServerDoc(LHSERVERDOC);
+OLESTATUS WINAPI OleRevokeClientDoc(LHCLIENTDOC);
+OLESTATUS WINAPI OleRevokeServer(LHSERVER);
 
 #endif  /* __WINE_OLE_H */
diff --git a/include/peexe.h b/include/peexe.h
index c716f61..bc13148 100644
--- a/include/peexe.h
+++ b/include/peexe.h
@@ -97,6 +97,10 @@
 	IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
 } IMAGE_OPTIONAL_HEADER,*LPIMAGE_OPTIONAL_HEADER;
 
+/* Possible Magic values */
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
+#define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
+
 /* These are indexes into the DataDirectory array */
 #define IMAGE_FILE_EXPORT_DIRECTORY		0
 #define IMAGE_FILE_IMPORT_DIRECTORY		1
diff --git a/include/scroll.h b/include/scroll.h
index 7090245..0a70a6c 100644
--- a/include/scroll.h
+++ b/include/scroll.h
@@ -19,8 +19,8 @@
     UINT32  flags;    /* EnableScrollBar flags */
 } SCROLLBAR_INFO;
 
-extern LRESULT ScrollBarWndProc( HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam,
-                                 LPARAM lParam );
+extern LRESULT WINAPI ScrollBarWndProc( HWND32 hwnd, UINT32 uMsg,
+                                        WPARAM32 wParam, LPARAM lParam );
 extern void SCROLL_DrawScrollBar( HWND32 hwnd, HDC32 hdc, INT32 nBar,
                                   BOOL32 arrows );
 extern void SCROLL_HandleScrollEvent( HWND32 hwnd, INT32 nBar,
diff --git a/include/shell.h b/include/shell.h
index daebe80..947ec4d 100644
--- a/include/shell.h
+++ b/include/shell.h
@@ -65,10 +65,9 @@
 #define SHGFI_SHELLICONSIZE     0x000000004     /* get shell size icon */
 #define SHGFI_PIDL              0x000000008     /* pszPath is a pidl */
 #define SHGFI_USEFILEATTRIBUTES 0x000000010     /* use passed dwFileAttribute */
-
-DWORD SHGetFileInfo32A(LPCSTR,DWORD,SHFILEINFO32A*,UINT32,UINT32);
-DWORD SHGetFileInfo32W(LPCWSTR,DWORD,SHFILEINFO32W*,UINT32,UINT32);
-#define SHGetFileInfo WINELIB_NAME_AW(SHGetFileInfo)
+DWORD    WINAPI SHGetFileInfo32A(LPCSTR,DWORD,SHFILEINFO32A*,UINT32,UINT32);
+DWORD    WINAPI SHGetFileInfo32W(LPCWSTR,DWORD,SHFILEINFO32W*,UINT32,UINT32);
+#define  SHGetFileInfo WINELIB_NAME_AW(SHGetFileInfo)
 
 #define SE_ERR_SHARE            26
 #define SE_ERR_ASSOCINCOMPLETE  27
@@ -77,6 +76,4 @@
 #define SE_ERR_DDEBUSY          30
 #define SE_ERR_NOASSOC          31
 
-LRESULT AboutDlgProc(HWND32 hWnd,UINT32 msg,WPARAM16 wParam,LPARAM lParam);
-
 #endif  /* __WINE_SHELL_H */
diff --git a/include/sigcontext.h b/include/sig_context.h
similarity index 98%
rename from include/sigcontext.h
rename to include/sig_context.h
index d47b836..b971b97 100644
--- a/include/sigcontext.h
+++ b/include/sig_context.h
@@ -4,8 +4,8 @@
  * Copyright 1995 Alexandre Julliard
  */
 
-#ifndef __WINE_SIGCONTEXT_H
-#define __WINE_SIGCONTEXT_H
+#ifndef __WINE_SIG_CONTEXT_H
+#define __WINE_SIG_CONTEXT_H
 
 #ifdef WINELIB
 #error This file must not be used in Winelib
@@ -202,4 +202,4 @@
                             
 #define FL_sig(context)      (*(WORD*)&EFL_sig(context))
 
-#endif /* __WINE_SIGCONTEXT_H */
+#endif /* __WINE_SIG_CONTEXT_H */
diff --git a/include/static.h b/include/static.h
index 355359a..f29dd7b 100644
--- a/include/static.h
+++ b/include/static.h
@@ -17,7 +17,7 @@
     HICON16  hIcon;   /* Icon handle for SS_ICON controls */ 
 } STATICINFO;
 
-extern LRESULT StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
-                              LPARAM lParam );
+extern LRESULT WINAPI StaticWndProc( HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
+                                     LPARAM lParam );
 
 #endif  /* __WINE_STATIC_H */
diff --git a/include/status.h b/include/status.h
index 424394f..24a2290 100644
--- a/include/status.h
+++ b/include/status.h
@@ -7,8 +7,8 @@
 #ifndef __WINE_STATUS_H
 #define __WINE_STATUS_H
 
-LRESULT StatusWindowProc( HWND32 hwnd, UINT32 msg,
-                          WPARAM32 wParam, LPARAM lParam );
+LRESULT WINAPI StatusWindowProc( HWND32 hwnd, UINT32 msg,
+                                 WPARAM32 wParam, LPARAM lParam );
 
 typedef struct
 {
diff --git a/include/stddebug.h b/include/stddebug.h
index 71b0151..819ae53 100644
--- a/include/stddebug.h
+++ b/include/stddebug.h
@@ -150,6 +150,7 @@
 #undef DEBUG_TIMER
 #undef DEBUG_TOOLHELP
 #undef DEBUG_TWEAK
+#undef DEBUG_UPDOWN
 #undef DEBUG_VER
 #undef DEBUG_VIRTUAL
 #undef DEBUG_VXD
@@ -234,6 +235,7 @@
 #define DEBUG_TIMER
 #define DEBUG_TOOLHELP
 #define DEBUG_TWEAK
+#define DEBUG_UPDOWN
 #define DEBUG_VER
 #define DEBUG_VIRTUAL
 #define DEBUG_VXD
diff --git a/include/stress.h b/include/stress.h
index 86f718c..f38857e 100644
--- a/include/stress.h
+++ b/include/stress.h
@@ -11,17 +11,17 @@
 #define EDS_CUR		2
 #define EDS_TEMP	3
 
-BOOL16	AllocGDIMem(UINT16);
-BOOL16	AllocMem(DWORD);
-BOOL16	AllocUserMem(UINT16);
-int	AllocDiskSpace(long, UINT16);
-int	AllocFileHandles(int);
-int	GetFreeFileHandles(void);
-void	FreeAllGDIMem(void);
-void	FreeAllMem(void);
-void	FreeAllUserMem(void);
-void	UnAllocDiskSpace(UINT16);
-void	UnAllocFileHandles(void);
+BOOL16	WINAPI AllocGDIMem(UINT16);
+BOOL16	WINAPI AllocMem(DWORD);
+BOOL16	WINAPI AllocUserMem(UINT16);
+int	WINAPI AllocDiskSpace(long, UINT16);
+int	WINAPI AllocFileHandles(int);
+int	WINAPI GetFreeFileHandles(void);
+void	WINAPI FreeAllGDIMem(void);
+void	WINAPI FreeAllMem(void);
+void	WINAPI FreeAllUserMem(void);
+void	WINAPI UnAllocDiskSpace(UINT16);
+void	WINAPI UnAllocFileHandles(void);
 
 #ifdef __cplusplus
 }
diff --git a/include/task.h b/include/task.h
index 62fc59e..5712979 100644
--- a/include/task.h
+++ b/include/task.h
@@ -49,8 +49,12 @@
 #define THUNK_MAGIC  ('P' | ('T' << 8))
 
 struct _THDB;
+struct _WSINFO;
 
-  /* Task database. See 'Windows Internals' p. 226 */
+  /* Task database. See 'Windows Internals' p. 226.
+   * Note that 16-bit OLE 2 libs like to read it directly 
+   * so we have to keep entry offsets as they are. 
+   */
 typedef struct
 {
     HTASK16   hNext;                      /* 00 Selector of next TDB */
@@ -82,8 +86,9 @@
     DWORD     int75 WINE_PACKED;          /* 4a int 75 (80x87 error) handler */
     DWORD     compat_flags WINE_PACKED;   /* 4e Compatibility flags */
     BYTE      unused4[2];                 /* 52 */
-    struct _THDB *thdb;                   /* 54 Pointer to thread database */
-    BYTE      unused5[8];                 /* 58 */
+    struct _THDB   *thdb;                 /* 54 Pointer to thread database */
+    struct _WSINFO *pwsi;		  /* 58 Socket control struct */
+    BYTE      unused5[4];                 /* 5B */
     HANDLE16  hPDB;                       /* 60 Selector of PDB (i.e. PSP) */
     SEGPTR    dta WINE_PACKED;            /* 62 Current DTA */
     BYTE      curdrive;                   /* 66 Current drive */
diff --git a/include/toolhelp.h b/include/toolhelp.h
index eaf30ec..8d1cd81 100644
--- a/include/toolhelp.h
+++ b/include/toolhelp.h
@@ -76,11 +76,13 @@
 /* wFlags values */
 #define GF_PDB_OWNER        0x0100      /* Low byte is KERNEL flags */
 
-BOOL16 GlobalInfo( GLOBALINFO *pInfo );
-BOOL16 GlobalFirst( GLOBALENTRY *pGlobal, WORD wFlags );
-BOOL16 GlobalNext( GLOBALENTRY *pGlobal, WORD wFlags) ;
-BOOL16 GlobalEntryHandle( GLOBALENTRY *pGlobal, HGLOBAL16 hItem );
-BOOL16 GlobalEntryModule( GLOBALENTRY *pGlobal, HMODULE16 hModule, WORD wSeg );
+WORD   WINAPI GlobalHandleToSel( HGLOBAL16 handle );
+BOOL16 WINAPI GlobalInfo( GLOBALINFO *pInfo );
+BOOL16 WINAPI GlobalFirst( GLOBALENTRY *pGlobal, WORD wFlags );
+BOOL16 WINAPI GlobalNext( GLOBALENTRY *pGlobal, WORD wFlags) ;
+BOOL16 WINAPI GlobalEntryHandle( GLOBALENTRY *pGlobal, HGLOBAL16 hItem );
+BOOL16 WINAPI GlobalEntryModule( GLOBALENTRY *pGlobal, HMODULE16 hModule,
+                                 WORD wSeg );
 
 /* Local heap */
 
@@ -154,9 +156,9 @@
 #define LT_USER_HANDLETABLE         32
 #define LT_USER_MAX                 LT_USER_HANDLETABLE
 
-BOOL16 LocalInfo( LOCALINFO *pLocalInfo, HGLOBAL16 handle );
-BOOL16 LocalFirst( LOCALENTRY *pLocalEntry, HGLOBAL16 handle );
-BOOL16 LocalNext( LOCALENTRY *pLocalEntry );
+BOOL16 WINAPI LocalInfo( LOCALINFO *pLocalInfo, HGLOBAL16 handle );
+BOOL16 WINAPI LocalFirst( LOCALENTRY *pLocalEntry, HGLOBAL16 handle );
+BOOL16 WINAPI LocalNext( LOCALENTRY *pLocalEntry );
 
 
 /* modules */
@@ -171,10 +173,10 @@
     HANDLE16   wNext;
 } MODULEENTRY, *LPMODULEENTRY;
 
-BOOL16 ModuleFirst(MODULEENTRY *lpModule);
-BOOL16 ModuleNext(MODULEENTRY *lpModule);
-BOOL16 ModuleFindName(MODULEENTRY *lpModule, LPCSTR lpstrName);
-BOOL16 ModuleFindHandle(MODULEENTRY *lpModule, HMODULE16 hModule);
+BOOL16 WINAPI ModuleFirst(MODULEENTRY *lpModule);
+BOOL16 WINAPI ModuleNext(MODULEENTRY *lpModule);
+BOOL16 WINAPI ModuleFindName(MODULEENTRY *lpModule, LPCSTR lpstrName);
+BOOL16 WINAPI ModuleFindHandle(MODULEENTRY *lpModule, HMODULE16 hModule);
 
 /* tasks */
 
@@ -197,12 +199,12 @@
     HANDLE16     hNext;
 } TASKENTRY, *LPTASKENTRY;
 
-BOOL16 TaskFirst(LPTASKENTRY lpTask);
-BOOL16 TaskNext(LPTASKENTRY lpTask);
-BOOL16 TaskFindHandle(LPTASKENTRY lpTask, HTASK16 hTask);
-DWORD TaskSetCSIP(HTASK16 hTask, WORD wCS, WORD wIP);
-DWORD TaskGetCSIP(HTASK16 hTask);
-BOOL16 TaskSwitch(HTASK16 hTask, DWORD dwNewCSIP);
+BOOL16 WINAPI TaskFirst(LPTASKENTRY lpTask);
+BOOL16 WINAPI TaskNext(LPTASKENTRY lpTask);
+BOOL16 WINAPI TaskFindHandle(LPTASKENTRY lpTask, HTASK16 hTask);
+DWORD  WINAPI TaskSetCSIP(HTASK16 hTask, WORD wCS, WORD wIP);
+DWORD  WINAPI TaskGetCSIP(HTASK16 hTask);
+BOOL16 WINAPI TaskSwitch(HTASK16 hTask, DWORD dwNewCSIP);
 
 /* mem info */
 
@@ -230,8 +232,8 @@
     HGLOBAL16 hGDISegment;
 } SYSHEAPINFO;
 
-BOOL16 MemManInfo(LPMEMMANINFO lpEnhMode);
-BOOL16 SystemHeapInfo( SYSHEAPINFO *pHeapInfo );
+BOOL16 WINAPI MemManInfo(LPMEMMANINFO lpEnhMode);
+BOOL16 WINAPI SystemHeapInfo( SYSHEAPINFO *pHeapInfo );
 
 /* timer info */
 
@@ -241,7 +243,7 @@
 	DWORD dwmsThisVM;
 } TIMERINFO;
 
-BOOL16 TimerCount( TIMERINFO *pTimerInfo );
+BOOL16 WINAPI TimerCount( TIMERINFO *pTimerInfo );
 
 /* Window classes */
 
@@ -253,14 +255,14 @@
     HANDLE16  wNext;
 } CLASSENTRY;
 
-BOOL16 ClassFirst( CLASSENTRY *pClassEntry );
-BOOL16 ClassNext( CLASSENTRY *pClassEntry );
+BOOL16 WINAPI ClassFirst( CLASSENTRY *pClassEntry );
+BOOL16 WINAPI ClassNext( CLASSENTRY *pClassEntry );
 
 
 /* Memory read/write */
 
-DWORD MemoryRead( WORD sel, DWORD offset, void *buffer, DWORD count );
-DWORD MemoryWrite( WORD sel, DWORD offset, void *buffer, DWORD count );
+DWORD WINAPI MemoryRead( WORD sel, DWORD offset, void *buffer, DWORD count );
+DWORD WINAPI MemoryWrite( WORD sel, DWORD offset, void *buffer, DWORD count );
 
 /* flags to NotifyRegister() */
 #define NF_NORMAL	0	/* everything except taskswitches, debugerrors,
@@ -269,7 +271,7 @@
 #define NF_TASKSWITCH	1	/* get taskswitch information */
 #define NF_RIP		2	/* get debugerrors of system */
 
-BOOL16 NotifyRegister(HTASK16 htask,FARPROC16 lpfnCallback,WORD wFlags);
+BOOL16 WINAPI NotifyRegister(HTASK16 htask,FARPROC16 lpfnCallback,WORD wFlags);
 
 #define NFY_UNKNOWN	0
 #define NFY_LOADSEG	1
diff --git a/include/updown.h b/include/updown.h
new file mode 100644
index 0000000..07b132e
--- /dev/null
+++ b/include/updown.h
@@ -0,0 +1,28 @@
+/*
+ * Up-down class extra info
+ *
+ * Copyright 1997 Dimitrie O. Paun
+ */
+
+#ifndef __WINE_UPDOWN_H
+#define __WINE_UPDOWN_H
+
+#include "windows.h"
+#include "commctrl.h"
+
+typedef struct
+{
+  UINT32      AccelCount;   /* Number of elements in AccelVect */
+  UDACCEL*    AccelVect;    /* Vector containing AccelCount elements */
+  INT32       Base;         /* Base to display nr in the buddy window */
+  INT32       CurVal;       /* Current up-down value */
+  INT32       MinVal;       /* Minimum up-down value */
+  INT32       MaxVal;       /* Maximum up-down value */
+  HWND32      Buddy;        /* Handle to the buddy window */
+  INT32       Flags;        /* Internal Flags FLAG_* */
+} UPDOWN_INFO;
+
+LRESULT WINAPI UpDownWindowProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                                 LPARAM lParam);
+
+#endif  /* __WINE_UPDOWN_H */
diff --git a/include/ver.h b/include/ver.h
index 05342f2..60d0dee 100644
--- a/include/ver.h
+++ b/include/ver.h
@@ -127,15 +127,6 @@
 	DWORD   dwFileDateLS;
 } VS_FIXEDFILEINFO;
 
-/* following two aren't in version.dll */
-DWORD
-GetFileResourceSize(LPCSTR filename,SEGPTR restype,SEGPTR resid,LPDWORD off);
-
-DWORD
-GetFileResource(LPCSTR filename,SEGPTR restype,SEGPTR resid,
-		DWORD off,DWORD reslen,LPVOID data
-);
-
 
 /* 20 GETFILEVERSIONINFORAW */
 
diff --git a/include/win.h b/include/win.h
index 139e919..c952000 100644
--- a/include/win.h
+++ b/include/win.h
@@ -74,7 +74,7 @@
     HWND32         hwndLastActive;/* Last active popup hwnd */
     DWORD          dwStyle;       /* Window style (from CreateWindow) */
     DWORD          dwExStyle;     /* Extended style (from CreateWindowEx) */
-    UINT16         wIDmenu;       /* ID or hmenu (from CreateWindow) */
+    UINT32         wIDmenu;       /* ID or hmenu (from CreateWindow) */
     WORD           flags;         /* Misc. flags (see below) */
     Window         window;        /* X window (only for top-level windows) */
     HMENU16        hSysMenu;      /* window's copy of System Menu */
@@ -124,6 +124,7 @@
 extern void   WIN_ResetQueueWindows( WND* wnd, HQUEUE16 hQueue, HQUEUE16 hNew );
 extern BOOL32 WIN_CreateDesktopWindow(void);
 extern HWND32 WIN_GetTopParent( HWND32 hwnd );
+extern WND*   WIN_GetTopParentPtr( WND* pWnd );
 extern BOOL32 WIN_IsWindowDrawable(WND*, BOOL32 );
 extern HINSTANCE16 WIN_GetWindowInstance( HWND32 hwnd );
 extern WND**  WIN_BuildWinArray( WND *wndPtr, UINT32 bwa, UINT32* pnum );
diff --git a/include/winbase.h b/include/winbase.h
index e860418..46aaa97 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -57,7 +57,6 @@
 #define FS_CASE_IS_PRESERVED            FILE_CASE_PRESERVED_NAMES
 #define FS_UNICODE_STORED_ON_DISK       FILE_UNICODE_ON_DISK
 
-/*WINAPI int  SetErrorMode(int);*/
 
 #define STATUS_SUCCESS                   0x00000000
 #define STATUS_WAIT_0                    0x00000000    
@@ -156,19 +155,17 @@
 #define VER_PLATFORM_WIN32_NT           2
 
 /*DWORD WINAPI GetVersion( void );*/
-BOOL32 GetVersionEx32A(OSVERSIONINFO32A*);
-BOOL32 GetVersionEx32W(OSVERSIONINFO32W*);
+BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A*);
+BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W*);
 #define GetVersionEx WINELIB_NAME_AW(GetVersionEx)
 
 /*int WinMain(HINSTANCE, HINSTANCE prev, char *cmd, int show);*/
 
-HACCEL32 LoadAcceleratorsA(   HINSTANCE32, const char *);
-
-void     DeleteCriticalSection(CRITICAL_SECTION *lpCrit);
-void     EnterCriticalSection(CRITICAL_SECTION *lpCrit);
-void     InitializeCriticalSection(CRITICAL_SECTION *lpCrit);
-void     LeaveCriticalSection(CRITICAL_SECTION *lpCrit);
-HANDLE32 OpenProcess(DWORD access, BOOL32 inherit, DWORD id);
-int      TerminateProcess(HANDLE32 h, int ret);
+void      WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI InitializeCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCrit);
+HANDLE32  WINAPI OpenProcess(DWORD access, BOOL32 inherit, DWORD id);
+int       WINAPI TerminateProcess(HANDLE32 h, int ret);
 
 #endif  /* __WINE_WINBASE_H */
diff --git a/include/windows.h b/include/windows.h
index 06814ac..139c33b 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -1100,6 +1100,14 @@
 
 typedef struct 
 {
+  UINT32	ciCharset;
+  UINT32	ciACP;
+  FONTSIGNATURE	fs;
+} CHARSETINFO,*LPCHARSETINFO;
+
+
+typedef struct 
+{
     INT16  txfHeight;
     INT16  txfWidth;
     INT16  txfEscapement;
@@ -2787,6 +2795,7 @@
 #define SWP_NOSENDCHANGING  0x0400
 #define SWP_DEFERERASE      0x2000
 
+#define HWND_DESKTOP        ((HWND32)0)
 #define HWND_BROADCAST      ((HWND32)0xffff)
 
 /* SetWindowPos() hwndInsertAfter field values */
@@ -2840,8 +2849,10 @@
 #define MF_BYCOMMAND       0x0000
 #define MF_BYPOSITION      0x0400
 #define MF_SEPARATOR       0x0800
+#define MF_DEFAULT         0x1000
 #define MF_SYSMENU         0x2000
 #define MF_HELP            0x4000
+#define MF_RIGHTJUSTIFY    0x4000
 #define MF_MOUSESELECT     0x8000
 
 /* Flags for extended menu item types.  */
@@ -2865,6 +2876,21 @@
 #define MFS_UNHILITE        MF_UNHILITE
 #define MFS_DEFAULT         MF_DEFAULT
 
+/* FIXME: not sure this one is correct */
+typedef struct {
+  UINT16    cbSize;
+  UINT16    fMask;
+  UINT16    fType;
+  UINT16    fState;
+  UINT16    wID;
+  HMENU16   hSubMenu;
+  HBITMAP16 hbmpChecked;
+  HBITMAP16 hbmpUnchecked;
+  DWORD     dwItemData;
+  LPSTR     dwTypeData;
+  UINT16    cch;
+} MENUITEMINFO16, *LPMENUITEMINFO16;
+
 typedef struct {
   UINT32    cbSize;
   UINT32    fMask;
@@ -3035,6 +3061,23 @@
 #define DFCS_FLAT               0x4000
 #define DFCS_MONO               0x8000
 
+/* DrawState defines ... */
+typedef BOOL32 (CALLBACK *DRAWSTATEPROC)(HDC32,LPARAM,WPARAM32,INT32,INT32);
+
+/* Image type */
+#define	DST_COMPLEX	0x0000
+#define	DST_TEXT	0x0001
+#define	DST_PREFIXTEXT	0x0002
+#define	DST_ICON	0x0003
+#define	DST_BITMAP	0x0004
+
+/* State type */
+#define	DSS_NORMAL	0x0000
+#define	DSS_UNION	0x0010  /* Gray string appearance */
+#define	DSS_DISABLED	0x0020
+#define	DSS_MONO	0x0080
+#define	DSS_RIGHT	0x8000
+
 /* Window Styles */
 #define WS_OVERLAPPED    0x00000000L
 #define WS_POPUP         0x80000000L
@@ -5118,2521 +5161,2591 @@
 DECL_WINELIB_TYPE_AW(NONCLIENTMETRICS);
 DECL_WINELIB_TYPE_AW(LPNONCLIENTMETRICS);
 
+typedef struct tagNMHDR
+{
+    HWND32  hwndFrom;
+    UINT32  idFrom;
+    UINT32  code;
+} NMHDR, *LPNMHDR;
+
 #pragma pack(4)
 
 /* Declarations for functions that exist only in Win16 */
 
-WORD       AllocCStoDSAlias(WORD);
-WORD       AllocDStoCSAlias(WORD);
-WORD       AllocSelector(WORD);
-WORD       AllocSelectorArray(WORD);
-VOID       CalcChildScroll(HWND16,WORD);
-INT16      Catch(LPCATCHBUF);
-WORD       ChangeSelector(WORD,WORD);
-INT16      CloseComm(INT16);
-HGLOBAL16  CreateCursorIconIndirect(HINSTANCE16,CURSORICONINFO*,LPCVOID,LPCVOID);
-WORD       CreateSystemTimer(WORD,FARPROC16);
-BOOL16     DCHook(HDC16,WORD,DWORD,LPARAM);
-VOID       DirectedYield(HTASK16);
-HGLOBAL16  DirectResAlloc(HINSTANCE16,WORD,UINT16);
-VOID       DisableSystemTimers(void);
-BOOL16     DlgDirSelect(HWND16,LPSTR,INT16);
-BOOL16     DlgDirSelectComboBox(HWND16,LPSTR,INT16);
-DWORD      DumpIcon(SEGPTR,WORD*,SEGPTR*,SEGPTR*);
-BOOL16     EnableCommNotification(INT16,HWND16,INT16,INT16);
-BOOL16     EnableHardwareInput(BOOL16);
-VOID       EnableSystemTimers(void);
-INT16      ExcludeVisRect(HDC16,INT16,INT16,INT16,INT16);
-HANDLE16   FarGetOwner(HGLOBAL16);
-VOID       FarSetOwner(HGLOBAL16,HANDLE16);
-BOOL16     FastWindowFrame(HDC16,const RECT16*,INT16,INT16,DWORD);
-VOID       FillWindow(HWND16,HWND16,HDC16,HBRUSH16);
-INT16      FlushComm(INT16,INT16);
-WORD       FreeSelector(WORD);
-UINT16     GDIRealizePalette(HDC16);
-HPALETTE16 GDISelectPalette(HDC16,HPALETTE16,WORD);
-HANDLE16   GetAtomHandle(ATOM);
-DWORD      GetBitmapDimension(HBITMAP16);
-DWORD      GetBrushOrg(HDC16);
-HANDLE16   GetCodeHandle(FARPROC16);
-INT16      GetCommError(INT16,LPCOMSTAT);
-UINT16     GetCommEventMask(INT16,UINT16);
-HBRUSH16   GetControlBrush(HWND16,HDC16,UINT16);
-VOID       GetCodeInfo(FARPROC16,LPVOID);
-HANDLE16   GetCurrentPDB(void);
-DWORD      GetCurrentPosition(HDC16);
-HTASK16    GetCurrentTask(void);
-DWORD      GetDCHook(HDC16,FARPROC16*);
-DWORD      GetDCOrg(HDC16);
-HDC16      GetDCState(HDC16);
-HWND16     GetDesktopHwnd(void);
-SEGPTR     GetDOSEnvironment(void);
-INT16      GetEnvironment(LPCSTR,LPSTR,UINT16);
-HMODULE16  GetExePtr(HANDLE16);
-WORD       GetExeVersion(void);
-DWORD      GetHeapSpaces(HMODULE16);
-INT16      GetKbCodePage(VOID);
-INT16      GetInstanceData(HINSTANCE16,WORD,INT16);
-HGLOBAL16  GetMetaFileBits(HMETAFILE16);
-BOOL16     GetModuleName(HINSTANCE16,LPSTR,INT16);
-INT16      GetModuleUsage(HINSTANCE16);
-FARPROC16  GetMouseEventProc(void);
-UINT16     GetNumTasks(void);
-DWORD      GetSelectorBase(WORD);
-DWORD      GetSelectorLimit(WORD);
-HINSTANCE16 GetTaskDS(void);
-HQUEUE16   GetTaskQueue(HTASK16);
-BYTE       GetTempDrive(BYTE);
-DWORD      GetTextExtent(HDC16,LPCSTR,INT16);
-DWORD      GetViewportExt(HDC16);
-DWORD      GetViewportOrg(HDC16);
-BOOL16     GetWinDebugInfo(LPWINDEBUGINFO,UINT16);
-DWORD      GetWindowExt(HDC16);
-DWORD      GetWindowOrg(HDC16);
-DWORD      GetWinFlags(void);
-DWORD      GlobalDOSAlloc(DWORD);
-WORD       GlobalDOSFree(WORD);
-void       GlobalFreeAll(HGLOBAL16);
-HGLOBAL16  GlobalLRUNewest(HGLOBAL16);
-HGLOBAL16  GlobalLRUOldest(HGLOBAL16);
-VOID       GlobalNotify(FARPROC16);
-WORD       GlobalPageLock(HGLOBAL16);
-WORD       GlobalPageUnlock(HGLOBAL16);
-INT16      InitApp(HINSTANCE16);
-HRGN16     InquireVisRgn(HDC16);
-INT16      IntersectVisRect(HDC16,INT16,INT16,INT16,INT16);
-BOOL16     IsDCCurrentPalette(HDC16);
-BOOL16     IsGDIObject(HGDIOBJ16);
-BOOL16     IsSharedSelector(HANDLE16);
-BOOL16     IsTask(HTASK16);
-HTASK16    IsTaskLocked(void);
-BOOL16     IsValidMetaFile(HMETAFILE16);
-VOID       LogError(UINT16, LPVOID);
-VOID       LogParamError(UINT16,FARPROC16,LPVOID);
-BOOL16     LocalInit(HANDLE16,WORD,WORD);
-FARPROC16  LocalNotify(FARPROC16);
-HTASK16    LockCurrentTask(BOOL16);
-HMENU16    LookupMenuHandle(HMENU16,INT16);
-DWORD      MoveTo(HDC16,INT16,INT16);
-DWORD      OffsetViewportOrg(HDC16,INT16,INT16);
-INT16      OffsetVisRgn(HDC16,INT16,INT16);
-DWORD      OffsetWindowOrg(HDC16,INT16,INT16);
-VOID       OldYield(void);
-INT16      OpenComm(LPCSTR,UINT16,UINT16);
-VOID       PaintRect(HWND16,HWND16,HDC16,HBRUSH16,const RECT16*);
-VOID       PostEvent(HTASK16);
-WORD       PrestoChangoSelector(WORD,WORD);
-INT16      ReadComm(INT16,LPSTR,INT16);
-UINT16     RealizeDefaultPalette(HDC16);
-BOOL32     RegisterShellHook(HWND16,UINT16);
-INT16      RestoreVisRgn(HDC16);
-HRGN16     SaveVisRgn(HDC16);
-DWORD      ScaleViewportExt(HDC16,INT16,INT16,INT16,INT16);
-DWORD      ScaleWindowExt(HDC16,INT16,INT16,INT16,INT16);
-WORD       SelectorAccessRights(WORD,WORD,WORD);
-INT16      SelectVisRgn(HDC16,HRGN16);
-DWORD      SetBitmapDimension(HBITMAP16,INT16,INT16);
-DWORD      SetBrushOrg(HDC16,INT16,INT16);
-UINT16*    SetCommEventMask(INT16,UINT16);
-BOOL16     SetDCHook(HDC16,FARPROC16,DWORD);
-DWORD      SetDCOrg(HDC16,INT16,INT16);
-VOID       SetDCState(HDC16,HDC16);
-BOOL16     SetDeskPattern(void);
-INT16      SetEnvironment(LPCSTR,LPCSTR,UINT16);
-WORD       SetHookFlags(HDC16,WORD);
-HMETAFILE16 SetMetaFileBits(HGLOBAL16);
-VOID       SetPriority(HTASK16,INT16);
-FARPROC16  SetResourceHandler(HINSTANCE16,SEGPTR,FARPROC16);
-WORD       SetSelectorBase(WORD,DWORD);
-WORD       SetSelectorLimit(WORD,DWORD);
-LONG       SetSwapAreaSize(WORD);
-HQUEUE16   SetTaskQueue(HTASK16,HQUEUE16);
-FARPROC16  SetTaskSignalProc(HTASK16,FARPROC16);
-DWORD      SetViewportExt(HDC16,INT16,INT16);
-DWORD      SetViewportOrg(HDC16,INT16,INT16);
-BOOL16     SetWinDebugInfo(LPWINDEBUGINFO);
-DWORD      SetWindowExt(HDC16,INT16,INT16);
-DWORD      SetWindowOrg(HDC16,INT16,INT16);
-VOID       SwitchStackBack(void);
-VOID       SwitchStackTo(WORD,WORD,WORD);
-INT16      Throw(LPCATCHBUF,INT16);
-INT16      UngetCommChar(INT16,CHAR);
-VOID       UserYield(void);
-BOOL16     WaitEvent(HTASK16);
-INT16      WriteComm(INT16,LPSTR,INT16);
-VOID       WriteOutProfiles(VOID);
-VOID       hmemcpy(LPVOID,LPCVOID,LONG);
-VOID       Yield(void);
+WORD        WINAPI AllocCStoDSAlias(WORD);
+WORD        WINAPI AllocDStoCSAlias(WORD);
+WORD        WINAPI AllocSelector(WORD);
+WORD        WINAPI AllocSelectorArray(WORD);
+VOID        WINAPI CalcChildScroll(HWND16,WORD);
+INT16       WINAPI Catch(LPCATCHBUF);
+VOID        WINAPI CascadeChildWindows(HWND16,WORD);
+INT16       WINAPI CloseComm(INT16);
+HGLOBAL16   WINAPI CreateCursorIconIndirect(HINSTANCE16,CURSORICONINFO*,
+                                            LPCVOID,LPCVOID);
+WORD        WINAPI CreateSystemTimer(WORD,FARPROC16);
+BOOL16      WINAPI DCHook(HDC16,WORD,DWORD,LPARAM);
+VOID        WINAPI DirectedYield(HTASK16);
+HGLOBAL16   WINAPI DirectResAlloc(HINSTANCE16,WORD,UINT16);
+VOID        WINAPI DisableSystemTimers(void);
+BOOL16      WINAPI DlgDirSelect(HWND16,LPSTR,INT16);
+BOOL16      WINAPI DlgDirSelectComboBox(HWND16,LPSTR,INT16);
+DWORD       WINAPI DumpIcon(SEGPTR,WORD*,SEGPTR*,SEGPTR*);
+BOOL16      WINAPI EnableCommNotification(INT16,HWND16,INT16,INT16);
+BOOL16      WINAPI EnableHardwareInput(BOOL16);
+VOID        WINAPI EnableSystemTimers(void);
+INT16       WINAPI ExcludeVisRect(HDC16,INT16,INT16,INT16,INT16);
+HANDLE16    WINAPI FarGetOwner(HGLOBAL16);
+VOID        WINAPI FarSetOwner(HGLOBAL16,HANDLE16);
+BOOL16      WINAPI FastWindowFrame(HDC16,const RECT16*,INT16,INT16,DWORD);
+VOID        WINAPI FileCDR(FARPROC16);
+VOID        WINAPI FillWindow(HWND16,HWND16,HDC16,HBRUSH16);
+INT16       WINAPI FlushComm(INT16,INT16);
+WORD        WINAPI FreeSelector(WORD);
+UINT16      WINAPI GDIRealizePalette(HDC16);
+HPALETTE16  WINAPI GDISelectPalette(HDC16,HPALETTE16,WORD);
+HANDLE16    WINAPI GetAtomHandle(ATOM);
+DWORD       WINAPI GetBitmapDimension(HBITMAP16);
+DWORD       WINAPI GetBrushOrg(HDC16);
+HANDLE16    WINAPI GetCodeHandle(FARPROC16);
+INT16       WINAPI GetCommError(INT16,LPCOMSTAT);
+UINT16      WINAPI GetCommEventMask(INT16,UINT16);
+HBRUSH16    WINAPI GetControlBrush(HWND16,HDC16,UINT16);
+VOID        WINAPI GetCodeInfo(FARPROC16,LPVOID);
+HANDLE16    WINAPI GetCurrentPDB(void);
+DWORD       WINAPI GetCurrentPosition(HDC16);
+HTASK16     WINAPI GetCurrentTask(void);
+DWORD       WINAPI GetDCHook(HDC16,FARPROC16*);
+DWORD       WINAPI GetDCOrg(HDC16);
+HDC16       WINAPI GetDCState(HDC16);
+HWND16      WINAPI GetDesktopHwnd(void);
+SEGPTR      WINAPI GetDOSEnvironment(void);
+INT16       WINAPI GetEnvironment(LPCSTR,LPSTR,UINT16);
+HMODULE16   WINAPI GetExePtr(HANDLE16);
+WORD        WINAPI GetExeVersion(void);
+WORD        WINAPI GetExpWinVer(HMODULE16);
+DWORD       WINAPI GetFileResourceSize(LPCSTR,SEGPTR,SEGPTR,LPDWORD);
+DWORD       WINAPI GetFileResource(LPCSTR,SEGPTR,SEGPTR,DWORD,DWORD,LPVOID);
+DWORD       WINAPI GetHeapSpaces(HMODULE16);
+INT16       WINAPI GetInstanceData(HINSTANCE16,WORD,INT16);
+HGLOBAL16   WINAPI GetMetaFileBits(HMETAFILE16);
+BOOL16      WINAPI GetModuleName(HINSTANCE16,LPSTR,INT16);
+INT16       WINAPI GetModuleUsage(HINSTANCE16);
+FARPROC16   WINAPI GetMouseEventProc(void);
+UINT16      WINAPI GetNumTasks(void);
+DWORD       WINAPI GetSelectorBase(WORD);
+DWORD       WINAPI GetSelectorLimit(WORD);
+HINSTANCE16 WINAPI GetTaskDS(void);
+HQUEUE16    WINAPI GetTaskQueue(HTASK16);
+BYTE        WINAPI GetTempDrive(BYTE);
+DWORD       WINAPI GetTextExtent(HDC16,LPCSTR,INT16);
+DWORD       WINAPI GetViewportExt(HDC16);
+DWORD       WINAPI GetViewportOrg(HDC16);
+BOOL16      WINAPI GetWinDebugInfo(LPWINDEBUGINFO,UINT16);
+DWORD       WINAPI GetWindowExt(HDC16);
+DWORD       WINAPI GetWindowOrg(HDC16);
+DWORD       WINAPI GetWinFlags(void);
+DWORD       WINAPI GlobalDOSAlloc(DWORD);
+WORD        WINAPI GlobalDOSFree(WORD);
+void        WINAPI GlobalFreeAll(HGLOBAL16);
+HGLOBAL16   WINAPI GlobalLRUNewest(HGLOBAL16);
+HGLOBAL16   WINAPI GlobalLRUOldest(HGLOBAL16);
+VOID        WINAPI GlobalNotify(FARPROC16);
+WORD        WINAPI GlobalPageLock(HGLOBAL16);
+WORD        WINAPI GlobalPageUnlock(HGLOBAL16);
+INT16       WINAPI InitApp(HINSTANCE16);
+HRGN16      WINAPI InquireVisRgn(HDC16);
+INT16       WINAPI IntersectVisRect(HDC16,INT16,INT16,INT16,INT16);
+BOOL16      WINAPI IsDCCurrentPalette(HDC16);
+BOOL16      WINAPI IsGDIObject(HGDIOBJ16);
+BOOL16      WINAPI IsSharedSelector(HANDLE16);
+BOOL16      WINAPI IsTask(HTASK16);
+HTASK16     WINAPI IsTaskLocked(void);
+BOOL16      WINAPI IsValidMetaFile(HMETAFILE16);
+VOID        WINAPI LogError(UINT16, LPVOID);
+VOID        WINAPI LogParamError(UINT16,FARPROC16,LPVOID);
+WORD        WINAPI LocalCountFree(void);
+WORD        WINAPI LocalHandleDelta(WORD);
+WORD        WINAPI LocalHeapSize(void);
+BOOL16      WINAPI LocalInit(HANDLE16,WORD,WORD);
+FARPROC16   WINAPI LocalNotify(FARPROC16);
+HTASK16     WINAPI LockCurrentTask(BOOL16);
+HMENU16     WINAPI LookupMenuHandle(HMENU16,INT16);
+DWORD       WINAPI MoveTo(HDC16,INT16,INT16);
+DWORD       WINAPI OffsetViewportOrg(HDC16,INT16,INT16);
+INT16       WINAPI OffsetVisRgn(HDC16,INT16,INT16);
+DWORD       WINAPI OffsetWindowOrg(HDC16,INT16,INT16);
+VOID        WINAPI OldYield(void);
+INT16       WINAPI OpenComm(LPCSTR,UINT16,UINT16);
+VOID        WINAPI PaintRect(HWND16,HWND16,HDC16,HBRUSH16,const RECT16*);
+VOID        WINAPI PostEvent(HTASK16);
+WORD        WINAPI PrestoChangoSelector(WORD,WORD);
+INT16       WINAPI ReadComm(INT16,LPSTR,INT16);
+UINT16      WINAPI RealizeDefaultPalette(HDC16);
+BOOL32      WINAPI RegisterShellHook(HWND16,UINT16);
+INT16       WINAPI RestoreVisRgn(HDC16);
+HRGN16      WINAPI SaveVisRgn(HDC16);
+DWORD       WINAPI ScaleViewportExt(HDC16,INT16,INT16,INT16,INT16);
+DWORD       WINAPI ScaleWindowExt(HDC16,INT16,INT16,INT16,INT16);
+WORD        WINAPI SelectorAccessRights(WORD,WORD,WORD);
+INT16       WINAPI SelectVisRgn(HDC16,HRGN16);
+DWORD       WINAPI SetBitmapDimension(HBITMAP16,INT16,INT16);
+DWORD       WINAPI SetBrushOrg(HDC16,INT16,INT16);
+UINT16*     WINAPI SetCommEventMask(INT16,UINT16);
+BOOL16      WINAPI SetDCHook(HDC16,FARPROC16,DWORD);
+DWORD       WINAPI SetDCOrg(HDC16,INT16,INT16);
+VOID        WINAPI SetDCState(HDC16,HDC16);
+BOOL16      WINAPI SetDeskPattern(void);
+INT16       WINAPI SetEnvironment(LPCSTR,LPCSTR,UINT16);
+WORD        WINAPI SetHookFlags(HDC16,WORD);
+HMETAFILE16 WINAPI SetMetaFileBits(HGLOBAL16);
+VOID        WINAPI SetPriority(HTASK16,INT16);
+FARPROC16   WINAPI SetResourceHandler(HINSTANCE16,SEGPTR,FARPROC16);
+WORD        WINAPI SetSelectorBase(WORD,DWORD);
+WORD        WINAPI SetSelectorLimit(WORD,DWORD);
+LONG        WINAPI SetSwapAreaSize(WORD);
+HQUEUE16    WINAPI SetTaskQueue(HTASK16,HQUEUE16);
+FARPROC16   WINAPI SetTaskSignalProc(HTASK16,FARPROC16);
+DWORD       WINAPI SetViewportExt(HDC16,INT16,INT16);
+DWORD       WINAPI SetViewportOrg(HDC16,INT16,INT16);
+BOOL16      WINAPI SetWinDebugInfo(LPWINDEBUGINFO);
+DWORD       WINAPI SetWindowExt(HDC16,INT16,INT16);
+DWORD       WINAPI SetWindowOrg(HDC16,INT16,INT16);
+VOID        WINAPI SwitchStackBack(void);
+VOID        WINAPI SwitchStackTo(WORD,WORD,WORD);
+VOID        WINAPI TileChildWindows(HWND16,WORD);
+INT16       WINAPI Throw(LPCATCHBUF,INT16);
+INT16       WINAPI UngetCommChar(INT16,CHAR);
+VOID        WINAPI UserYield(void);
+BOOL16      WINAPI WaitEvent(HTASK16);
+INT16       WINAPI WriteComm(INT16,LPSTR,INT16);
+VOID        WINAPI WriteOutProfiles(VOID);
+VOID        WINAPI hmemcpy(LPVOID,LPCVOID,LONG);
+VOID        WINAPI Yield(void);
+
 
 /* Declarations for functions that exist only in Win32 */
-BOOL32     Beep(DWORD,DWORD);
-BOOL32     ClearCommError(INT32,LPDWORD,LPCOMSTAT);
-BOOL32     CloseHandle(HANDLE32);
-BOOL32     CopyFile32A(LPCSTR,LPCSTR,BOOL32);
-BOOL32     CopyFile32W(LPCWSTR,LPCWSTR,BOOL32);
-#define    CopyFile WINELIB_NAME_AW(CopyFile)
-INT32      CompareFileTime(LPFILETIME,LPFILETIME);
-HANDLE32   CreateEvent32A(LPSECURITY_ATTRIBUTES,BOOL32,BOOL32,LPCSTR);
-HANDLE32   CreateEvent32W(LPSECURITY_ATTRIBUTES,BOOL32,BOOL32,LPCWSTR);
-#define    CreateEvent WINELIB_NAME_AW(CreateEvent)
-HFILE32    CreateFile32A(LPCSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE32);
-HFILE32    CreateFile32W(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE32);
-#define    CreateFile WINELIB_NAME_AW(CreateFile)
-HANDLE32   CreateFileMapping32A(HANDLE32,LPSECURITY_ATTRIBUTES,DWORD,DWORD,DWORD,LPCSTR);
-HANDLE32   CreateFileMapping32W(HANDLE32,LPSECURITY_ATTRIBUTES,DWORD,DWORD,DWORD,LPCWSTR);
-#define    CreateFileMapping WINELIB_NAME_AW(CreateFileMapping)
-HANDLE32   CreateMutex32A(LPSECURITY_ATTRIBUTES,BOOL32,LPCSTR);
-HANDLE32   CreateMutex32W(LPSECURITY_ATTRIBUTES,BOOL32,LPCWSTR);
-#define    CreateMutex WINELIB_NAME_AW(CreateMutex)
-HANDLE32   CreateSemaphore32A(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCSTR);
-HANDLE32   CreateSemaphore32W(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCWSTR);
-#define    CreateSemaphore WINELIB_NAME_AW(CreateSemaphore)
-BOOL32     DosDateTimeToFileTime(WORD,WORD,LPFILETIME);
-INT32      EnumPropsEx32A(HWND32,PROPENUMPROCEX32A,LPARAM);
-INT32      EnumPropsEx32W(HWND32,PROPENUMPROCEX32W,LPARAM);
-#define    EnumPropsEx WINELIB_NAME_AW(EnumPropsEx)
-BOOL32     EnumResourceLanguages32A(HMODULE32,LPCSTR,LPCSTR,ENUMRESLANGPROC32A,LONG);
-BOOL32     EnumResourceLanguages32W(HMODULE32,LPCWSTR,LPCWSTR,ENUMRESLANGPROC32W,LONG);
-#define    EnumResourceLanguages WINELIB_NAME_AW(EnumResourceLanguages)
-BOOL32     EnumResourceNames32A(HMODULE32,LPCSTR,ENUMRESNAMEPROC32A,LONG);
-BOOL32     EnumResourceNames32W(HMODULE32,LPCWSTR,ENUMRESNAMEPROC32W,LONG);
-#define    EnumResourceNames WINELIB_NAME_AW(EnumResourceNames)
-BOOL32     EnumResourceTypes32A(HMODULE32,ENUMRESTYPEPROC32A,LONG);
-BOOL32     EnumResourceTypes32W(HMODULE32,ENUMRESTYPEPROC32W,LONG);
-#define    EnumResourceTypes WINELIB_NAME_AW(EnumResourceTypes)
-BOOL32     EnumSystemCodePages32A(CODEPAGE_ENUMPROC32A,DWORD);
-BOOL32     EnumSystemCodePages32W(CODEPAGE_ENUMPROC32W,DWORD);
-#define    EnumSystemCodePages WINELIB_NAME_AW(EnumSystemCodePages)
-BOOL32     EnumSystemLocales32A(LOCALE_ENUMPROC32A,DWORD);
-BOOL32     EnumSystemLocales32W(LOCALE_ENUMPROC32W,DWORD);
-#define    EnumSystemLocales WINELIB_NAME_AW(EnumSystemLocales)
-BOOL32     EnumThreadWindows(DWORD,WNDENUMPROC32,LPARAM);
-void       ExitProcess(DWORD);
-BOOL32     ExitWindowsEx(UINT32,DWORD);
-DWORD      ExpandEnvironmentStrings32A(LPCSTR,LPSTR,DWORD);
-DWORD      ExpandEnvironmentStrings32W(LPCWSTR,LPWSTR,DWORD);
-#define    ExpandEnvironmentStrings WINELIB_NAME_AW(ExpandEnvironmentStrings)
-BOOL32     FileTimeToDosDateTime(const FILETIME*,LPWORD,LPWORD);
-BOOL32     FileTimeToLocalFileTime(const FILETIME*,LPFILETIME);
-BOOL32     FileTimeToSystemTime(const FILETIME*,LPSYSTEMTIME);
-HRSRC32    FindResourceEx32A(HINSTANCE32,LPCSTR,LPCSTR,WORD);
-HRSRC32    FindResourceEx32W(HINSTANCE32,LPCWSTR,LPCWSTR,WORD);
-#define    FindResourceEx WINELIB_NAME_AW(FindResourceEx)
-BOOL32     FlushFileBuffers(HFILE32);
-BOOL32     FreeEnvironmentStrings32A(LPSTR);
-BOOL32     FreeEnvironmentStrings32W(LPWSTR);
-#define    FreeEnvironmentStrings WINELIB_NAME_AW(FreeEnvironmentStrings)
-UINT32     GetACP(void);
-LPCSTR     GetCommandLine32A();
-LPCWSTR    GetCommandLine32W();
-#define    GetCommandLine WINELIB_NAME_AW(GetCommandLine)
-BOOL32     GetCommTimeouts(INT32,LPCOMMTIMEOUTS);
-BOOL32     GetCPInfo(UINT32,LPCPINFO);
-HANDLE32   GetCurrentProcess(void);
-DWORD      GetCurrentProcessId(void);
-HANDLE32   GetCurrentThread(void);
-DWORD      GetCurrentThreadId(void);
-BOOL32     GetDCOrgEx(HDC32,LPPOINT32);
-LPSTR      GetEnvironmentStrings32A(void);
-LPWSTR     GetEnvironmentStrings32W(void);
-#define    GetEnvironmentStrings WINELIB_NAME_AW(GetEnvironmentStrings)
-DWORD      GetEnvironmentVariable32A(LPCSTR,LPSTR,DWORD);
-DWORD      GetEnvironmentVariable32W(LPCWSTR,LPWSTR,DWORD);
-#define    GetEnvironmentVariable WINELIB_NAME_AW(GetEnvironmentVariable)
-DWORD      GetFileInformationByHandle(HFILE32,BY_HANDLE_FILE_INFORMATION*);
-DWORD      GetFileSize(HFILE32,LPDWORD);
-BOOL32     GetFileTime(HFILE32,LPFILETIME,LPFILETIME,LPFILETIME);
-DWORD      GetFileType(HFILE32);
-DWORD      GetFullPathName32A(LPCSTR,DWORD,LPSTR,LPSTR*);
-DWORD      GetFullPathName32W(LPCWSTR,DWORD,LPWSTR,LPWSTR*);
-#define    GetFullPathName WINELIB_NAME_AW(GetFullPathName)
-VOID       GetLocalTime(LPSYSTEMTIME);
-DWORD      GetLogicalDrives(void);
-BOOL32     GetMenuItemInfo32A(HMENU32,UINT32,BOOL32,MENUITEMINFO32A*);
-BOOL32     GetMenuItemInfo32W(HMENU32,UINT32,BOOL32,MENUITEMINFO32W*);
-#define    GetMenuItemInfo WINELIB_NAME_AW(GetMenuItemInfo)
-UINT32     GetOEMCP(void);
-DWORD      GetPriorityClass(HANDLE32);
-HANDLE32   GetProcessHeap(void);
-DWORD      GetShortPathName32A(LPCSTR,LPSTR,DWORD);
-DWORD      GetShortPathName32W(LPCWSTR,LPWSTR,DWORD);
-#define    GetShortPathName WINELIB_NAME_AW(GetShortPathName)
-HFILE32    GetStdHandle(DWORD);
-BOOL32     GetStringTypeEx32A(LCID,DWORD,LPCSTR,INT32,LPWORD);
-BOOL32     GetStringTypeEx32W(LCID,DWORD,LPCWSTR,INT32,LPWORD);
-#define    GetStringTypeEx WINELIB_NAME_AW(GetStringTypeEx)
-VOID       GetSystemInfo(LPSYSTEM_INFO);
-BOOL32     GetSystemPowerStatus(LPSYSTEM_POWER_STATUS);
-VOID       GetSystemTime(LPSYSTEMTIME);
-LCID       GetThreadLocale();
-INT32      GetThreadPriority(HANDLE32);
-DWORD      GetWindowThreadProcessId(HWND32,LPDWORD);
-VOID       GlobalMemoryStatus(LPMEMORYSTATUS);
-LPVOID     HeapAlloc(HANDLE32,DWORD,DWORD);
-DWORD      HeapCompact(HANDLE32,DWORD);
-HANDLE32   HeapCreate(DWORD,DWORD,DWORD);
-BOOL32     HeapDestroy(HANDLE32);
-BOOL32     HeapFree(HANDLE32,DWORD,LPVOID);
-BOOL32     HeapLock(HANDLE32);
-LPVOID     HeapReAlloc(HANDLE32,DWORD,LPVOID,DWORD);
-DWORD      HeapSize(HANDLE32,DWORD,LPVOID);
-BOOL32     HeapUnlock(HANDLE32);
-BOOL32     HeapValidate(HANDLE32,DWORD,LPVOID);
-BOOL32     IsDBCSLeadByteEx(UINT32,BYTE);
-BOOL32     IsWindowUnicode(HWND32);
-BOOL32     IsValidLocale(DWORD,DWORD);
-BOOL32     LocalFileTimeToFileTime(const FILETIME*,LPFILETIME);
-BOOL32     LockFile(HFILE32,DWORD,DWORD,DWORD,DWORD);
-SEGPTR     MapLS(LPVOID);
-LPVOID     MapSL(SEGPTR);
-LPVOID     MapViewOfFile(HANDLE32,DWORD,DWORD,DWORD,DWORD);
-LPVOID     MapViewOfFileEx(HANDLE32,DWORD,DWORD,DWORD,DWORD,LPVOID);
-INT32      MessageBoxEx32A(HWND32,LPCSTR,LPCSTR,UINT32,WORD);
-INT32      MessageBoxEx32W(HWND32,LPCWSTR,LPCWSTR,UINT32,WORD);
-#define    MessageBoxEx WINELIB_NAME_AW(MessageBoxEx)
-BOOL32     MoveFile32A(LPCSTR,LPCSTR);
-BOOL32     MoveFile32W(LPCWSTR,LPCWSTR);
-#define    MoveFile WINELIB_NAME_AW(MoveFile)
-HANDLE32   OpenEvent32A(DWORD,BOOL32,LPCSTR);
-HANDLE32   OpenEvent32W(DWORD,BOOL32,LPCWSTR);
-#define    OpenEvent WINELIB_NAME_AW(OpenEvent)
-HANDLE32   OpenFileMapping32A(DWORD,BOOL32,LPCSTR);
-HANDLE32   OpenFileMapping32W(DWORD,BOOL32,LPCWSTR);
-#define    OpenFileMapping WINELIB_NAME_AW(OpenFileMapping)
-HANDLE32   OpenMutex32A(DWORD,BOOL32,LPCSTR);
-HANDLE32   OpenMutex32W(DWORD,BOOL32,LPCWSTR);
-#define    OpenMutex WINELIB_NAME_AW(OpenMutex)
-HANDLE32   OpenSemaphore32A(DWORD,BOOL32,LPCSTR);
-HANDLE32   OpenSemaphore32W(DWORD,BOOL32,LPCWSTR);
-#define    OpenSemaphore WINELIB_NAME_AW(OpenSemaphore)
-DWORD      QueryDosDevice32A(LPCSTR,LPSTR,DWORD);
-DWORD      QueryDosDevice32W(LPCWSTR,LPWSTR,DWORD);
-#define    QueryDosDevice WINELIB_NAME_AW(QueryDosDevice)
-BOOL32     QueryPerformanceCounter(LPLARGE_INTEGER);
-BOOL32     ReadConsole32A(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
-BOOL32     ReadConsole32W(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
-#define    ReadConsole WINELIB_NAME_AW(ReadConsole)
-BOOL32     ReadFile(HFILE32,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
-DWORD      RegCreateKeyEx32A(HKEY,LPCSTR,DWORD,LPSTR,DWORD,REGSAM,
-                             LPSECURITY_ATTRIBUTES,LPHKEY,LPDWORD);
-DWORD      RegCreateKeyEx32W(HKEY,LPCWSTR,DWORD,LPWSTR,DWORD,REGSAM,
-                             LPSECURITY_ATTRIBUTES,LPHKEY,LPDWORD);
-#define    RegCreateKeyEx WINELIB_NAME_AW(RegCreateKeyEx)
-DWORD      RegEnumKeyEx32A(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPSTR,LPDWORD,LPFILETIME);
-DWORD      RegEnumKeyEx32W(HKEY,DWORD,LPWSTR,LPDWORD,LPDWORD,LPWSTR,LPDWORD,LPFILETIME);
-#define    RegEnumKeyEx WINELIB_NAME_AW(RegEnumKeyEx)
-DWORD      RegOpenKeyEx32W(HKEY,LPCWSTR,DWORD,REGSAM,LPHKEY);
-DWORD      RegOpenKeyEx32A(HKEY,LPCSTR,DWORD,REGSAM,LPHKEY);
-#define    RegOpenKeyEx WINELIB_NAME_AW(RegOpenKeyEx)
-DWORD      RegQueryInfoKey32W(HKEY,LPWSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD,
-                            LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPFILETIME);
-DWORD      RegQueryInfoKey32A(HKEY,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD,
-                            LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPFILETIME);
-#define    RegQueryInfoKey WINELIB_NAME_AW(RegQueryInfoKey)
-BOOL32     ReleaseSemaphore(HANDLE32,LONG,LPLONG);
-VOID       RtlFillMemory(LPVOID,UINT32,UINT32);
-VOID       RtlMoveMemory(LPVOID,LPCVOID,UINT32);
-VOID       RtlZeroMemory(LPVOID,UINT32);
-DWORD      SearchPath32A(LPCSTR,LPCSTR,LPCSTR,DWORD,LPSTR,LPSTR*);
-DWORD      SearchPath32W(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,LPWSTR,LPWSTR*);
-#define    SearchPath WINELIB_NAME(SearchPath)
-BOOL32     SetBrushOrgEx(HDC32,INT32,INT32,LPPOINT32);
-BOOL32     SetCommMask(INT32,DWORD);
-BOOL32     SetCommTimeouts(INT32,LPCOMMTIMEOUTS);
-BOOL32     SetConsoleTitle32A(LPCSTR);
-BOOL32     SetConsoleTitle32W(LPCWSTR);
-#define    SetConsoleTitle WINELIB_NAME_AW(SetConsoleTitle)
-BOOL32     SetEndOfFile(HFILE32);
-BOOL32     SetEnvironmentVariable32A(LPCSTR,LPCSTR);
-BOOL32     SetEnvironmentVariable32W(LPCWSTR,LPCWSTR);
-#define    SetEnvironmentVariable WINELIB_NAME_AW(SetEnvironmentVariable)
-DWORD      SetFilePointer(HFILE32,LONG,LPLONG,DWORD);
-BOOL32     SetFileTime(HFILE32,const FILETIME*,const FILETIME*,const FILETIME*);
-VOID       SetLastErrorEx(DWORD,DWORD);
-BOOL32     SetPriorityClass(HANDLE32,DWORD);
-BOOL32     SetStdHandle(DWORD,HANDLE32);
-BOOL32     SetSystemPowerState(BOOL32,BOOL32);
-BOOL32     SetSystemTime(const SYSTEMTIME*);
-BOOL32     SetThreadPriority(HANDLE32,INT32);
-BOOL32     SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION);
-VOID       Sleep(DWORD);
-BOOL32     SystemTimeToFileTime(const SYSTEMTIME*,LPFILETIME);
-BOOL32     TrackPopupMenuEx(HMENU32,UINT32,INT32,INT32,HWND32,LPTPMPARAMS);
-DWORD      TlsAlloc(void);
-BOOL32     TlsFree(DWORD);
-LPVOID     TlsGetValue(DWORD);
-BOOL32     TlsSetValue(DWORD,LPVOID);
-VOID       UnMapLS(SEGPTR);
-BOOL32     UnlockFile(HFILE32,DWORD,DWORD,DWORD,DWORD);
-BOOL32     UnmapViewOfFile(LPVOID);
-LPVOID     VirtualAlloc(LPVOID,DWORD,DWORD,DWORD);
-BOOL32     VirtualFree(LPVOID,DWORD,DWORD);
-BOOL32     VirtualLock(LPVOID,DWORD);
-BOOL32     VirtualProtect(LPVOID,DWORD,DWORD,LPDWORD);
-BOOL32     VirtualProtectEx(HANDLE32,LPVOID,DWORD,DWORD,LPDWORD);
-BOOL32     VirtualQuery(LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
-BOOL32     VirtualQueryEx(HANDLE32,LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
-BOOL32     VirtualUnlock(LPVOID,DWORD);
-BOOL32     WriteConsole32A(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
-BOOL32     WriteConsole32W(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
-#define    WriteConsole WINELIB_NAME_AW(WriteConsole)
-BOOL32     WriteFile(HFILE32,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
+
+BOOL32      WINAPI AreFileApisANSI(void);
+BOOL32      WINAPI Beep(DWORD,DWORD);
+BOOL32      WINAPI ClearCommError(INT32,LPDWORD,LPCOMSTAT);
+BOOL32      WINAPI CloseHandle(HANDLE32);
+BOOL32      WINAPI CopyFile32A(LPCSTR,LPCSTR,BOOL32);
+BOOL32      WINAPI CopyFile32W(LPCWSTR,LPCWSTR,BOOL32);
+#define     CopyFile WINELIB_NAME_AW(CopyFile)
+INT32       WINAPI CompareFileTime(LPFILETIME,LPFILETIME);
+HANDLE32    WINAPI CreateEvent32A(LPSECURITY_ATTRIBUTES,BOOL32,BOOL32,LPCSTR);
+HANDLE32    WINAPI CreateEvent32W(LPSECURITY_ATTRIBUTES,BOOL32,BOOL32,LPCWSTR);
+#define     CreateEvent WINELIB_NAME_AW(CreateEvent)
+HFILE32     WINAPI CreateFile32A(LPCSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,
+                                 DWORD,DWORD,HANDLE32);
+HFILE32     WINAPI CreateFile32W(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,
+                                 DWORD,DWORD,HANDLE32);
+#define     CreateFile WINELIB_NAME_AW(CreateFile)
+HANDLE32    WINAPI CreateFileMapping32A(HANDLE32,LPSECURITY_ATTRIBUTES,DWORD,
+                                        DWORD,DWORD,LPCSTR);
+HANDLE32    WINAPI CreateFileMapping32W(HANDLE32,LPSECURITY_ATTRIBUTES,DWORD,
+                                        DWORD,DWORD,LPCWSTR);
+#define     CreateFileMapping WINELIB_NAME_AW(CreateFileMapping)
+HANDLE32    WINAPI CreateMutex32A(LPSECURITY_ATTRIBUTES,BOOL32,LPCSTR);
+HANDLE32    WINAPI CreateMutex32W(LPSECURITY_ATTRIBUTES,BOOL32,LPCWSTR);
+#define     CreateMutex WINELIB_NAME_AW(CreateMutex)
+HANDLE32    WINAPI CreateSemaphore32A(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCSTR);
+HANDLE32    WINAPI CreateSemaphore32W(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCWSTR);
+#define     CreateSemaphore WINELIB_NAME_AW(CreateSemaphore)
+BOOL32      WINAPI DisableThreadLibraryCalls(HMODULE32);
+BOOL32      WINAPI DosDateTimeToFileTime(WORD,WORD,LPFILETIME);
+INT32       WINAPI EnumPropsEx32A(HWND32,PROPENUMPROCEX32A,LPARAM);
+INT32       WINAPI EnumPropsEx32W(HWND32,PROPENUMPROCEX32W,LPARAM);
+#define     EnumPropsEx WINELIB_NAME_AW(EnumPropsEx)
+BOOL32      WINAPI EnumResourceLanguages32A(HMODULE32,LPCSTR,LPCSTR,
+                                            ENUMRESLANGPROC32A,LONG);
+BOOL32      WINAPI EnumResourceLanguages32W(HMODULE32,LPCWSTR,LPCWSTR,
+                                            ENUMRESLANGPROC32W,LONG);
+#define     EnumResourceLanguages WINELIB_NAME_AW(EnumResourceLanguages)
+BOOL32      WINAPI EnumResourceNames32A(HMODULE32,LPCSTR,ENUMRESNAMEPROC32A,
+                                        LONG);
+BOOL32      WINAPI EnumResourceNames32W(HMODULE32,LPCWSTR,ENUMRESNAMEPROC32W,
+                                        LONG);
+#define     EnumResourceNames WINELIB_NAME_AW(EnumResourceNames)
+BOOL32      WINAPI EnumResourceTypes32A(HMODULE32,ENUMRESTYPEPROC32A,LONG);
+BOOL32      WINAPI EnumResourceTypes32W(HMODULE32,ENUMRESTYPEPROC32W,LONG);
+#define     EnumResourceTypes WINELIB_NAME_AW(EnumResourceTypes)
+BOOL32      WINAPI EnumSystemCodePages32A(CODEPAGE_ENUMPROC32A,DWORD);
+BOOL32      WINAPI EnumSystemCodePages32W(CODEPAGE_ENUMPROC32W,DWORD);
+#define     EnumSystemCodePages WINELIB_NAME_AW(EnumSystemCodePages)
+BOOL32      WINAPI EnumSystemLocales32A(LOCALE_ENUMPROC32A,DWORD);
+BOOL32      WINAPI EnumSystemLocales32W(LOCALE_ENUMPROC32W,DWORD);
+#define     EnumSystemLocales WINELIB_NAME_AW(EnumSystemLocales)
+BOOL32      WINAPI EnumThreadWindows(DWORD,WNDENUMPROC32,LPARAM);
+void        WINAPI ExitProcess(DWORD);
+BOOL32      WINAPI ExitWindowsEx(UINT32,DWORD);
+DWORD       WINAPI ExpandEnvironmentStrings32A(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI ExpandEnvironmentStrings32W(LPCWSTR,LPWSTR,DWORD);
+#define     ExpandEnvironmentStrings WINELIB_NAME_AW(ExpandEnvironmentStrings)
+BOOL32      WINAPI FileTimeToDosDateTime(const FILETIME*,LPWORD,LPWORD);
+BOOL32      WINAPI FileTimeToLocalFileTime(const FILETIME*,LPFILETIME);
+BOOL32      WINAPI FileTimeToSystemTime(const FILETIME*,LPSYSTEMTIME);
+HRSRC32     WINAPI FindResourceEx32A(HINSTANCE32,LPCSTR,LPCSTR,WORD);
+HRSRC32     WINAPI FindResourceEx32W(HINSTANCE32,LPCWSTR,LPCWSTR,WORD);
+#define     FindResourceEx WINELIB_NAME_AW(FindResourceEx)
+BOOL32      WINAPI FlushFileBuffers(HFILE32);
+BOOL32      WINAPI FreeEnvironmentStrings32A(LPSTR);
+BOOL32      WINAPI FreeEnvironmentStrings32W(LPWSTR);
+#define     FreeEnvironmentStrings WINELIB_NAME_AW(FreeEnvironmentStrings)
+UINT32      WINAPI GetACP(void);
+LPCSTR      WINAPI GetCommandLine32A();
+LPCWSTR     WINAPI GetCommandLine32W();
+#define     GetCommandLine WINELIB_NAME_AW(GetCommandLine)
+BOOL32      WINAPI GetCommTimeouts(INT32,LPCOMMTIMEOUTS);
+BOOL32      WINAPI GetComputerName32A(LPSTR,LPDWORD);
+BOOL32      WINAPI GetComputerName32W(LPWSTR,LPDWORD);
+#define     GetComputerName WINELIB_NAME_AW(GetComputerName)
+BOOL32      WINAPI GetCPInfo(UINT32,LPCPINFO);
+HANDLE32    WINAPI GetCurrentProcess(void);
+DWORD       WINAPI GetCurrentProcessId(void);
+HANDLE32    WINAPI GetCurrentThread(void);
+DWORD       WINAPI GetCurrentThreadId(void);
+BOOL32      WINAPI GetDCOrgEx(HDC32,LPPOINT32);
+LPSTR       WINAPI GetEnvironmentStrings32A(void);
+LPWSTR      WINAPI GetEnvironmentStrings32W(void);
+#define     GetEnvironmentStrings WINELIB_NAME_AW(GetEnvironmentStrings)
+DWORD       WINAPI GetEnvironmentVariable32A(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI GetEnvironmentVariable32W(LPCWSTR,LPWSTR,DWORD);
+#define     GetEnvironmentVariable WINELIB_NAME_AW(GetEnvironmentVariable)
+DWORD       WINAPI GetFileInformationByHandle(HFILE32,BY_HANDLE_FILE_INFORMATION*);
+DWORD       WINAPI GetFileSize(HFILE32,LPDWORD);
+BOOL32      WINAPI GetFileTime(HFILE32,LPFILETIME,LPFILETIME,LPFILETIME);
+DWORD       WINAPI GetFileType(HFILE32);
+DWORD       WINAPI GetFullPathName32A(LPCSTR,DWORD,LPSTR,LPSTR*);
+DWORD       WINAPI GetFullPathName32W(LPCWSTR,DWORD,LPWSTR,LPWSTR*);
+#define     GetFullPathName WINELIB_NAME_AW(GetFullPathName)
+VOID        WINAPI GetLocalTime(LPSYSTEMTIME);
+DWORD       WINAPI GetLogicalDrives(void);
+BOOL32      WINAPI GetMenuItemInfo32A(HMENU32,UINT32,BOOL32,MENUITEMINFO32A*);
+BOOL32      WINAPI GetMenuItemInfo32W(HMENU32,UINT32,BOOL32,MENUITEMINFO32W*);
+#define     GetMenuItemInfo WINELIB_NAME_AW(GetMenuItemInfo)
+UINT32      WINAPI GetOEMCP(void);
+DWORD       WINAPI GetPriorityClass(HANDLE32);
+HANDLE32    WINAPI GetProcessHeap(void);
+DWORD       WINAPI GetShortPathName32A(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI GetShortPathName32W(LPCWSTR,LPWSTR,DWORD);
+#define     GetShortPathName WINELIB_NAME_AW(GetShortPathName)
+HFILE32     WINAPI GetStdHandle(DWORD);
+BOOL32      WINAPI GetStringTypeEx32A(LCID,DWORD,LPCSTR,INT32,LPWORD);
+BOOL32      WINAPI GetStringTypeEx32W(LCID,DWORD,LPCWSTR,INT32,LPWORD);
+#define     GetStringTypeEx WINELIB_NAME_AW(GetStringTypeEx)
+VOID        WINAPI GetSystemInfo(LPSYSTEM_INFO);
+BOOL32      WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS);
+VOID        WINAPI GetSystemTime(LPSYSTEMTIME);
+BOOL32      WINAPI GetTextExtentExPoint32A(HDC32,LPCSTR,INT32,INT32,
+                                           LPINT32,LPINT32,LPSIZE32);
+BOOL32      WINAPI GetTextExtentExPoint32W(HDC32,LPCWSTR,INT32,INT32,
+                                           LPINT32,LPINT32,LPSIZE32);
+#define     GetTextExtentExPoint WINELIB_NAME_AW(GetTextExtentExPoint)
+LCID        WINAPI GetThreadLocale();
+INT32       WINAPI GetThreadPriority(HANDLE32);
+BOOL32      WINAPI GetUserName32A(LPSTR,LPDWORD);
+BOOL32      WINAPI GetUserName32W(LPWSTR,LPDWORD);
+#define     GetUserName WINELIB_NAME_AW(GetUserName)
+DWORD       WINAPI GetWindowThreadProcessId(HWND32,LPDWORD);
+VOID        WINAPI GlobalMemoryStatus(LPMEMORYSTATUS);
+LPVOID      WINAPI HeapAlloc(HANDLE32,DWORD,DWORD);
+DWORD       WINAPI HeapCompact(HANDLE32,DWORD);
+HANDLE32    WINAPI HeapCreate(DWORD,DWORD,DWORD);
+BOOL32      WINAPI HeapDestroy(HANDLE32);
+BOOL32      WINAPI HeapFree(HANDLE32,DWORD,LPVOID);
+BOOL32      WINAPI HeapLock(HANDLE32);
+LPVOID      WINAPI HeapReAlloc(HANDLE32,DWORD,LPVOID,DWORD);
+DWORD       WINAPI HeapSize(HANDLE32,DWORD,LPVOID);
+BOOL32      WINAPI HeapUnlock(HANDLE32);
+BOOL32      WINAPI HeapValidate(HANDLE32,DWORD,LPVOID);
+BOOL32      WINAPI IsDBCSLeadByteEx(UINT32,BYTE);
+BOOL32      WINAPI IsWindowUnicode(HWND32);
+BOOL32      WINAPI IsValidLocale(DWORD,DWORD);
+BOOL32      WINAPI LocalFileTimeToFileTime(const FILETIME*,LPFILETIME);
+BOOL32      WINAPI LockFile(HFILE32,DWORD,DWORD,DWORD,DWORD);
+SEGPTR      WINAPI MapLS(LPVOID);
+LPVOID      WINAPI MapSL(SEGPTR);
+LPVOID      WINAPI MapViewOfFile(HANDLE32,DWORD,DWORD,DWORD,DWORD);
+LPVOID      WINAPI MapViewOfFileEx(HANDLE32,DWORD,DWORD,DWORD,DWORD,LPVOID);
+INT32       WINAPI MessageBoxEx32A(HWND32,LPCSTR,LPCSTR,UINT32,WORD);
+INT32       WINAPI MessageBoxEx32W(HWND32,LPCWSTR,LPCWSTR,UINT32,WORD);
+#define     MessageBoxEx WINELIB_NAME_AW(MessageBoxEx)
+BOOL32      WINAPI MoveFile32A(LPCSTR,LPCSTR);
+BOOL32      WINAPI MoveFile32W(LPCWSTR,LPCWSTR);
+#define     MoveFile WINELIB_NAME_AW(MoveFile)
+HANDLE32    WINAPI OpenEvent32A(DWORD,BOOL32,LPCSTR);
+HANDLE32    WINAPI OpenEvent32W(DWORD,BOOL32,LPCWSTR);
+#define     OpenEvent WINELIB_NAME_AW(OpenEvent)
+HANDLE32    WINAPI OpenFileMapping32A(DWORD,BOOL32,LPCSTR);
+HANDLE32    WINAPI OpenFileMapping32W(DWORD,BOOL32,LPCWSTR);
+#define     OpenFileMapping WINELIB_NAME_AW(OpenFileMapping)
+HANDLE32    WINAPI OpenMutex32A(DWORD,BOOL32,LPCSTR);
+HANDLE32    WINAPI OpenMutex32W(DWORD,BOOL32,LPCWSTR);
+#define     OpenMutex WINELIB_NAME_AW(OpenMutex)
+HANDLE32    WINAPI OpenSemaphore32A(DWORD,BOOL32,LPCSTR);
+HANDLE32    WINAPI OpenSemaphore32W(DWORD,BOOL32,LPCWSTR);
+#define     OpenSemaphore WINELIB_NAME_AW(OpenSemaphore)
+DWORD       WINAPI QueryDosDevice32A(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI QueryDosDevice32W(LPCWSTR,LPWSTR,DWORD);
+#define     QueryDosDevice WINELIB_NAME_AW(QueryDosDevice)
+BOOL32      WINAPI QueryPerformanceCounter(LPLARGE_INTEGER);
+BOOL32      WINAPI ReadConsole32A(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
+BOOL32      WINAPI ReadConsole32W(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
+#define     ReadConsole WINELIB_NAME_AW(ReadConsole)
+BOOL32      WINAPI ReadFile(HFILE32,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
+DWORD       WINAPI RegCreateKeyEx32A(HKEY,LPCSTR,DWORD,LPSTR,DWORD,REGSAM,
+                                     LPSECURITY_ATTRIBUTES,LPHKEY,LPDWORD);
+DWORD       WINAPI RegCreateKeyEx32W(HKEY,LPCWSTR,DWORD,LPWSTR,DWORD,REGSAM,
+                                     LPSECURITY_ATTRIBUTES,LPHKEY,LPDWORD);
+#define     RegCreateKeyEx WINELIB_NAME_AW(RegCreateKeyEx)
+DWORD       WINAPI RegEnumKeyEx32A(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPSTR,
+                                   LPDWORD,LPFILETIME);
+DWORD       WINAPI RegEnumKeyEx32W(HKEY,DWORD,LPWSTR,LPDWORD,LPDWORD,LPWSTR,
+                                   LPDWORD,LPFILETIME);
+#define     RegEnumKeyEx WINELIB_NAME_AW(RegEnumKeyEx)
+DWORD       WINAPI RegOpenKeyEx32W(HKEY,LPCWSTR,DWORD,REGSAM,LPHKEY);
+DWORD       WINAPI RegOpenKeyEx32A(HKEY,LPCSTR,DWORD,REGSAM,LPHKEY);
+#define     RegOpenKeyEx WINELIB_NAME_AW(RegOpenKeyEx)
+DWORD       WINAPI RegQueryInfoKey32W(HKEY,LPWSTR,LPDWORD,LPDWORD,LPDWORD,
+                                      LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPDWORD,
+                                      LPDWORD,LPFILETIME);
+DWORD       WINAPI RegQueryInfoKey32A(HKEY,LPSTR,LPDWORD,LPDWORD,LPDWORD,
+                                      LPDWORD,LPDWORD,LPDWORD,LPDWORD,LPDWORD,
+                                      LPDWORD,LPFILETIME);
+#define     RegQueryInfoKey WINELIB_NAME_AW(RegQueryInfoKey)
+BOOL32      WINAPI ReleaseSemaphore(HANDLE32,LONG,LPLONG);
+VOID        WINAPI RtlFillMemory(LPVOID,UINT32,UINT32);
+VOID        WINAPI RtlMoveMemory(LPVOID,LPCVOID,UINT32);
+VOID        WINAPI RtlZeroMemory(LPVOID,UINT32);
+DWORD       WINAPI SearchPath32A(LPCSTR,LPCSTR,LPCSTR,DWORD,LPSTR,LPSTR*);
+DWORD       WINAPI SearchPath32W(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,LPWSTR,LPWSTR*);
+#define     SearchPath WINELIB_NAME(SearchPath)
+BOOL32      WINAPI SetBrushOrgEx(HDC32,INT32,INT32,LPPOINT32);
+BOOL32      WINAPI SetCommMask(INT32,DWORD);
+BOOL32      WINAPI SetCommTimeouts(INT32,LPCOMMTIMEOUTS);
+BOOL32      WINAPI SetConsoleTitle32A(LPCSTR);
+BOOL32      WINAPI SetConsoleTitle32W(LPCWSTR);
+#define     SetConsoleTitle WINELIB_NAME_AW(SetConsoleTitle)
+BOOL32      WINAPI SetEndOfFile(HFILE32);
+BOOL32      WINAPI SetEnvironmentVariable32A(LPCSTR,LPCSTR);
+BOOL32      WINAPI SetEnvironmentVariable32W(LPCWSTR,LPCWSTR);
+#define     SetEnvironmentVariable WINELIB_NAME_AW(SetEnvironmentVariable)
+VOID        WINAPI SetFileApisToANSI(void);
+VOID        WINAPI SetFileApisToOEM(void);
+DWORD       WINAPI SetFilePointer(HFILE32,LONG,LPLONG,DWORD);
+BOOL32      WINAPI SetFileTime(HFILE32,const FILETIME*,const FILETIME*,
+                               const FILETIME*);
+VOID        WINAPI SetLastErrorEx(DWORD,DWORD);
+BOOL32      WINAPI SetMenuItemInfo32A(HMENU32,UINT32,BOOL32,const MENUITEMINFO32A*);
+BOOL32      WINAPI SetMenuItemInfo32W(HMENU32,UINT32,BOOL32,const MENUITEMINFO32W*);
+#define     SetMenuItemInfo WINELIB_NAME_AW(SetMenuItemInfo)
+BOOL32      WINAPI SetPriorityClass(HANDLE32,DWORD);
+BOOL32      WINAPI SetStdHandle(DWORD,HANDLE32);
+BOOL32      WINAPI SetSystemPowerState(BOOL32,BOOL32);
+BOOL32      WINAPI SetSystemTime(const SYSTEMTIME*);
+BOOL32      WINAPI SetThreadPriority(HANDLE32,INT32);
+BOOL32      WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION);
+VOID        WINAPI Sleep(DWORD);
+BOOL32      WINAPI SystemTimeToFileTime(const SYSTEMTIME*,LPFILETIME);
+BOOL32      WINAPI TrackPopupMenuEx(HMENU32,UINT32,INT32,INT32,HWND32,
+                                    LPTPMPARAMS);
+DWORD       WINAPI TlsAlloc(void);
+BOOL32      WINAPI TlsFree(DWORD);
+LPVOID      WINAPI TlsGetValue(DWORD);
+BOOL32      WINAPI TlsSetValue(DWORD,LPVOID);
+VOID        WINAPI UnMapLS(SEGPTR);
+BOOL32      WINAPI UnlockFile(HFILE32,DWORD,DWORD,DWORD,DWORD);
+BOOL32      WINAPI UnmapViewOfFile(LPVOID);
+LPVOID      WINAPI VirtualAlloc(LPVOID,DWORD,DWORD,DWORD);
+BOOL32      WINAPI VirtualFree(LPVOID,DWORD,DWORD);
+BOOL32      WINAPI VirtualLock(LPVOID,DWORD);
+BOOL32      WINAPI VirtualProtect(LPVOID,DWORD,DWORD,LPDWORD);
+BOOL32      WINAPI VirtualProtectEx(HANDLE32,LPVOID,DWORD,DWORD,LPDWORD);
+BOOL32      WINAPI VirtualQuery(LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
+BOOL32      WINAPI VirtualQueryEx(HANDLE32,LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
+BOOL32      WINAPI VirtualUnlock(LPVOID,DWORD);
+BOOL32      WINAPI WriteConsole32A(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
+BOOL32      WINAPI WriteConsole32W(HANDLE32,LPVOID,DWORD,LPDWORD,LPVOID);
+#define     WriteConsole WINELIB_NAME_AW(WriteConsole)
+BOOL32      WINAPI WriteFile(HFILE32,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
 
 
 /* Declarations for functions that are the same in Win16 and Win32 */
 
-VOID       CloseSound(VOID);
-DWORD      GetDialogBaseUnits(void);
-VOID       GetKeyboardState(LPBYTE);
-DWORD      GetLastError(void);
-DWORD      GetMenuCheckMarkDimensions(void);
-LONG       GetMessageExtraInfo(void);
-DWORD      GetMessagePos(void);
-LONG       GetMessageTime(void);
-DWORD      GetTickCount(void);
-ATOM       GlobalDeleteAtom(ATOM);
-VOID       LZDone(void);
-DWORD      OemKeyScan(WORD);
-DWORD      RegCloseKey(HKEY);
-DWORD      RegFlushKey(HKEY);
-VOID       ReleaseCapture(void);
-VOID       SetKeyboardState(LPBYTE);
-VOID       SetLastError(DWORD);
-VOID       WaitMessage(VOID);
+VOID        WINAPI CloseSound(VOID);
+VOID        WINAPI EndMenu(void);
+DWORD       WINAPI GetDialogBaseUnits(void);
+VOID        WINAPI GetKeyboardState(LPBYTE);
+DWORD       WINAPI GetLastError(void);
+DWORD       WINAPI GetMenuCheckMarkDimensions(void);
+LONG        WINAPI GetMessageExtraInfo(void);
+DWORD       WINAPI GetMessagePos(void);
+LONG        WINAPI GetMessageTime(void);
+DWORD       WINAPI GetTickCount(void);
+ATOM        WINAPI GlobalDeleteAtom(ATOM);
+VOID        WINAPI LZDone(void);
+DWORD       WINAPI OemKeyScan(WORD);
+DWORD       WINAPI RegCloseKey(HKEY);
+DWORD       WINAPI RegFlushKey(HKEY);
+VOID        WINAPI ReleaseCapture(void);
+VOID        WINAPI SetKeyboardState(LPBYTE);
+VOID        WINAPI SetLastError(DWORD);
+VOID        WINAPI WaitMessage(VOID);
 
 
 /* Declarations for functions that change between Win16 and Win32 */
 
-INT16      AccessResource16(HINSTANCE16,HRSRC16);
-INT32      AccessResource32(HINSTANCE32,HRSRC32);
-#define    AccessResource WINELIB_NAME(AccessResource)
-ATOM       AddAtom16(SEGPTR);
-ATOM       AddAtom32A(LPCSTR);
-ATOM       AddAtom32W(LPCWSTR);
-#define    AddAtom WINELIB_NAME_AW(AddAtom)
-INT16      AddFontResource16(LPCSTR);
-INT32      AddFontResource32A(LPCSTR);
-INT32      AddFontResource32W(LPCWSTR);
-#define    AddFontResource WINELIB_NAME_AW(AddFontResource)
-BOOL16     AdjustWindowRect16(LPRECT16,DWORD,BOOL16);
-BOOL32     AdjustWindowRect32(LPRECT32,DWORD,BOOL32);
-#define    AdjustWindowRect WINELIB_NAME(AdjustWindowRect)
-BOOL16     AdjustWindowRectEx16(LPRECT16,DWORD,BOOL16,DWORD);
-BOOL32     AdjustWindowRectEx32(LPRECT32,DWORD,BOOL32,DWORD);
-#define    AdjustWindowRectEx WINELIB_NAME(AdjustWindowRectEx)
-HGLOBAL16  AllocResource16(HINSTANCE16,HRSRC16,DWORD);
-HGLOBAL32  AllocResource32(HINSTANCE32,HRSRC32,DWORD);
-#define    AllocResource WINELIB_NAME(AllocResource)
-BOOL16     AnimatePalette16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
-BOOL32     AnimatePalette32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
-#define    AnimatePalette WINELIB_NAME(AnimatePalette)
-SEGPTR     AnsiLower16(SEGPTR);
-#define    AnsiLower32A CharLower32A
-#define    AnsiLower32W CharLower32W
-#define    AnsiLower WINELIB_NAME_AW(AnsiLower)
-UINT16     AnsiLowerBuff16(LPSTR,UINT16);
-#define    AnsiLowerBuff32A CharLowerBuff32A
-#define    AnsiLowerBuff32W CharLowerBuff32W
-#define    AnsiLowerBuff WINELIB_NAME_AW(AnsiLowerBuff)
-SEGPTR     AnsiNext16(SEGPTR);
-#define    AnsiNext32A CharNext32A
-#define    AnsiNext32W CharNext32W
-#define    AnsiNext WINELIB_NAME_AW(AnsiNext)
-SEGPTR     AnsiPrev16(SEGPTR,SEGPTR);
-#define    AnsiPrev32A CharPrev32A
-#define    AnsiPrev32W CharPrev32W
-#define    AnsiPrev WINELIB_NAME_AW(AnsiPrev)
-INT16      AnsiToOem16(LPCSTR,LPSTR);
-#define    AnsiToOem32A CharToOem32A
-#define    AnsiToOem32W CharToOem32W
-#define    AnsiToOem WINELIB_NAME_AW(AnsiToOem)
-VOID       AnsiToOemBuff16(LPCSTR,LPSTR,UINT16);
-#define    AnsiToOemBuff32A CharToOemBuff32A
-#define    AnsiToOemBuff32W CharToOemBuff32W
-#define    AnsiToOemBuff WINELIB_NAME_AW(AnsiToOemBuff)
-SEGPTR     AnsiUpper16(SEGPTR);
-#define    AnsiUpper32A CharUpper32A
-#define    AnsiUpper32W CharUpper32W
-#define    AnsiUpper WINELIB_NAME_AW(AnsiUpper)
-UINT16     AnsiUpperBuff16(LPSTR,UINT16);
-#define    AnsiUpperBuff32A CharUpperBuff32A
-#define    AnsiUpperBuff32W CharUpperBuff32W
-#define    AnsiUpperBuff WINELIB_NAME_AW(AnsiUpperBuff)
-BOOL16     AnyPopup16(void);
-BOOL32     AnyPopup32(void);
-#define    AnyPopup WINELIB_NAME(AnyPopup)
-BOOL16     AppendMenu16(HMENU16,UINT16,UINT16,SEGPTR);
-BOOL32     AppendMenu32A(HMENU32,UINT32,UINT32,LPCSTR);
-BOOL32     AppendMenu32W(HMENU32,UINT32,UINT32,LPCWSTR);
-#define    AppendMenu WINELIB_NAME_AW(AppendMenu)
-BOOL16     Arc16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
-BOOL32     Arc32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
-#define    Arc WINELIB_NAME(Arc)
-UINT16     ArrangeIconicWindows16(HWND16);
-UINT32     ArrangeIconicWindows32(HWND32);
-#define    ArrangeIconicWindows WINELIB_NAME(ArrangeIconicWindows)
-HDWP16     BeginDeferWindowPos16(INT16);
-HDWP32     BeginDeferWindowPos32(INT32);
-#define    BeginDeferWindowPos WINELIB_NAME(BeginDeferWindowPos)
-HDC16      BeginPaint16(HWND16,LPPAINTSTRUCT16);
-HDC32      BeginPaint32(HWND32,LPPAINTSTRUCT32);
-#define    BeginPaint WINELIB_NAME(BeginPaint)
-BOOL16     BitBlt16(HDC16,INT16,INT16,INT16,INT16,HDC16,INT16,INT16,DWORD);
-BOOL32     BitBlt32(HDC32,INT32,INT32,INT32,INT32,HDC32,INT32,INT32,DWORD);
-#define    BitBlt WINELIB_NAME(BitBlt)
-BOOL16     BringWindowToTop16(HWND16);
-BOOL32     BringWindowToTop32(HWND32);
-#define    BringWindowToTop WINELIB_NAME(BringWindowToTop)
-BOOL16     BuildCommDCB16(LPCSTR,LPDCB16);
-BOOL32     BuildCommDCB32A(LPCSTR,LPDCB32);
-BOOL32     BuildCommDCB32W(LPCWSTR,LPDCB32);
-#define    BuildCommDCB WINELIB_NAME_AW(BuildCommDCB)
-BOOL32     BuildCommDCBAndTimeouts32A(LPCSTR,LPDCB32,LPCOMMTIMEOUTS);
-BOOL32     BuildCommDCBAndTimeouts32W(LPCWSTR,LPDCB32,LPCOMMTIMEOUTS);
-#define    BuildCommDCBAndTimeouts WINELIB_NAME_AW(BuildCommDCBAndTimeouts)
-BOOL16     CallMsgFilter16(SEGPTR,INT16);
-BOOL32     CallMsgFilter32A(LPMSG32,INT32);
-BOOL32     CallMsgFilter32W(LPMSG32,INT32);
-#define    CallMsgFilter WINELIB_NAME_AW(CallMsgFilter)
-LRESULT    CallNextHookEx16(HHOOK,INT16,WPARAM16,LPARAM);
-LRESULT    CallNextHookEx32(HHOOK,INT32,WPARAM32,LPARAM);
-#define    CallNextHookEx WINELIB_NAME(CallNextHookEx)
-LRESULT    CallWindowProc16(WNDPROC16,HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    CallWindowProc32A(WNDPROC32,HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    CallWindowProc32W(WNDPROC32,HWND32,UINT32,WPARAM32,LPARAM);
-#define    CallWindowProc WINELIB_NAME_AW(CallWindowProc)
-BOOL16     ChangeClipboardChain16(HWND16,HWND16);
-BOOL32     ChangeClipboardChain32(HWND32,HWND32);
-#define    ChangeClipboardChain WINELIB_NAME(ChangeClipboardChain)
-BOOL16     ChangeMenu16(HMENU16,UINT16,SEGPTR,UINT16,UINT16);
-BOOL32     ChangeMenu32A(HMENU32,UINT32,LPCSTR,UINT32,UINT32);
-BOOL32     ChangeMenu32W(HMENU32,UINT32,LPCWSTR,UINT32,UINT32);
-#define    ChangeMenu WINELIB_NAME_AW(ChangeMenu)
-LPSTR      CharLower32A(LPSTR);
-LPWSTR     CharLower32W(LPWSTR);
-#define    CharLower WINELIB_NAME_AW(CharLower)
-DWORD      CharLowerBuff32A(LPSTR,DWORD);
-DWORD      CharLowerBuff32W(LPWSTR,DWORD);
-#define    CharLowerBuff WINELIB_NAME_AW(CharLowerBuff)
-LPSTR      CharNext32A(LPCSTR);
-LPWSTR     CharNext32W(LPCWSTR);
-#define    CharNext WINELIB_NAME_AW(CharNext)
-LPSTR      CharNextEx32A(WORD,LPCSTR,DWORD);
-LPWSTR     CharNextEx32W(WORD,LPCWSTR,DWORD);
-#define    CharNextEx WINELIB_NAME_AW(CharNextEx)
-LPSTR      CharPrev32A(LPCSTR,LPCSTR);
-LPWSTR     CharPrev32W(LPCWSTR,LPCWSTR);
-#define    CharPrev WINELIB_NAME_AW(CharPrev)
-LPSTR      CharPrevEx32A(WORD,LPCSTR,LPCSTR,DWORD);
-LPWSTR     CharPrevEx32W(WORD,LPCWSTR,LPCWSTR,DWORD);
-#define    CharPrevEx WINELIB_NAME_AW(CharPrevEx)
-LPSTR      CharUpper32A(LPSTR);
-LPWSTR     CharUpper32W(LPWSTR);
-#define    CharUpper WINELIB_NAME_AW(CharUpper)
-DWORD      CharUpperBuff32A(LPSTR,DWORD);
-DWORD      CharUpperBuff32W(LPWSTR,DWORD);
-#define    CharUpperBuff WINELIB_NAME_AW(CharUpperBuff)
-BOOL32     CharToOem32A(LPCSTR,LPSTR);
-BOOL32     CharToOem32W(LPCWSTR,LPSTR);
-#define    CharToOem WINELIB_NAME_AW(CharToOem)
-BOOL32     CharToOemBuff32A(LPCSTR,LPSTR,DWORD);
-BOOL32     CharToOemBuff32W(LPCWSTR,LPSTR,DWORD);
-#define    CharToOemBuff WINELIB_NAME_AW(CharToOemBuff)
-BOOL16     CheckDlgButton16(HWND16,INT16,UINT16);
-BOOL32     CheckDlgButton32(HWND32,INT32,UINT32);
-#define    CheckDlgButton WINELIB_NAME(CheckDlgButton)
-BOOL16     CheckMenuItem16(HMENU16,UINT16,UINT16);
-DWORD      CheckMenuItem32(HMENU32,UINT32,UINT32);
-#define    CheckMenuItem WINELIB_NAME(CheckMenuItem)
-BOOL16     CheckRadioButton16(HWND16,UINT16,UINT16,UINT16);
-BOOL32     CheckRadioButton32(HWND32,UINT32,UINT32,UINT32);
-#define    CheckRadioButton WINELIB_NAME(CheckRadioButton)
-HWND16     ChildWindowFromPoint16(HWND16,POINT16);
-HWND32     ChildWindowFromPoint32(HWND32,POINT32);
-#define    ChildWindowFromPoint WINELIB_NAME(ChildWindowFromPoint)
-BOOL16     Chord16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
-BOOL32     Chord32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
-#define    Chord WINELIB_NAME(Chord)
-INT16      ClearCommBreak16(INT16);
-BOOL32     ClearCommBreak32(INT32);
-#define    ClearCommBreak WINELIB_NAME(ClearCommBreak)
-BOOL16     ClientToScreen16(HWND16,LPPOINT16);
-BOOL32     ClientToScreen32(HWND32,LPPOINT32);
-#define    ClientToScreen WINELIB_NAME(ClientToScreen)
-BOOL16     ClipCursor16(const RECT16*);
-BOOL32     ClipCursor32(const RECT32*);
-#define    ClipCursor WINELIB_NAME(ClipCursor)
-BOOL16     CloseClipboard16(void);
-BOOL32     CloseClipboard32(void);
-#define    CloseClipboard WINELIB_NAME(CloseClipboard)
-HMETAFILE16 CloseMetaFile16(HDC16);
-HMETAFILE32 CloseMetaFile32(HDC32);
-#define    CloseMetaFile WINELIB_NAME(CloseMetaFile)
-BOOL16     CloseWindow16(HWND16);
-BOOL32     CloseWindow32(HWND32);
-#define    CloseWindow WINELIB_NAME(CloseWindow)
-INT16      CombineRgn16(HRGN16,HRGN16,HRGN16,INT16);
-INT32      CombineRgn32(HRGN32,HRGN32,HRGN32,INT32);
-#define    CombineRgn WINELIB_NAME(CombineRgn)
-UINT16     CompareString16(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
-UINT32     CompareString32A(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
-UINT32     CompareString32W(DWORD,DWORD,LPCWSTR,DWORD,LPCWSTR,DWORD);
-#define    CompareString WINELIB_NAME_AW(CompareString)
-HCURSOR16  CopyCursor16(HINSTANCE16,HCURSOR16);
-#define    CopyCursor32(cur) ((HCURSOR32)CopyIcon32((HICON32)(cur)))
-#define    CopyCursor WINELIB_NAME(CopyCursor)
-HICON16    CopyIcon16(HINSTANCE16,HICON16);
-HICON32    CopyIcon32(HICON32);
-#define    CopyIcon WINELIB_NAME(CopyIcon)
-LONG       CopyLZFile16(HFILE16,HFILE16);
-LONG       CopyLZFile32(HFILE32,HFILE32);
-#define    CopyLZFile WINELIB_NAME(CopyLZFile)
-HMETAFILE16 CopyMetaFile16(HMETAFILE16,LPCSTR);
-HMETAFILE32 CopyMetaFile32A(HMETAFILE32,LPCSTR);
-HMETAFILE32 CopyMetaFile32W(HMETAFILE32,LPCWSTR);
-#define    CopyMetaFile WINELIB_NAME_AW(CopyMetaFile)
-BOOL16     CopyRect16(RECT16*,const RECT16*);
-BOOL32     CopyRect32(RECT32*,const RECT32*);
-#define    CopyRect WINELIB_NAME(CopyRect)
-INT16      CountClipboardFormats16(void);
-INT32      CountClipboardFormats32(void);
-#define    CountClipboardFormats WINELIB_NAME(CountClipboardFormats)
-INT16      CountVoiceNotes16(INT16);
-DWORD      CountVoiceNotes32(DWORD);
-#define    CountVoiceNotes WINELIB_NAME(CountVoiceNotes)
-HBITMAP16  CreateBitmap16(INT16,INT16,UINT16,UINT16,LPCVOID);
-HBITMAP32  CreateBitmap32(INT32,INT32,UINT32,UINT32,LPCVOID);
-#define    CreateBitmap WINELIB_NAME(CreateBitmap)
-HBITMAP16  CreateBitmapIndirect16(const BITMAP16*);
-HBITMAP32  CreateBitmapIndirect32(const BITMAP32*);
-#define    CreateBitmapIndirect WINELIB_NAME(CreateBitmapIndirect)
-HBRUSH16   CreateBrushIndirect16(const LOGBRUSH16*);
-HBRUSH32   CreateBrushIndirect32(const LOGBRUSH32*);
-#define    CreateBrushIndirect WINELIB_NAME(CreateBrushIndirect)
-VOID       CreateCaret16(HWND16,HBITMAP16,INT16,INT16);
-BOOL32     CreateCaret32(HWND32,HBITMAP32,INT32,INT32);
-#define    CreateCaret WINELIB_NAME(CreateCaret)
-HBITMAP16  CreateCompatibleBitmap16(HDC16,INT16,INT16);
-HBITMAP32  CreateCompatibleBitmap32(HDC32,INT32,INT32);
-#define    CreateCompatibleBitmap WINELIB_NAME(CreateCompatibleBitmap)
-HDC16      CreateCompatibleDC16(HDC16);
-HDC32      CreateCompatibleDC32(HDC32);
-#define    CreateCompatibleDC WINELIB_NAME(CreateCompatibleDC)
-HCURSOR16  CreateCursor16(HINSTANCE16,INT16,INT16,INT16,INT16,LPCVOID,LPCVOID);
-HCURSOR32  CreateCursor32(HINSTANCE32,INT32,INT32,INT32,INT32,LPCVOID,LPCVOID);
-#define    CreateCursor WINELIB_NAME(CreateCursor)
-HDC16      CreateDC16(LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
-HDC32      CreateDC32A(LPCSTR,LPCSTR,LPCSTR,const DEVMODE32A*);
-HDC32      CreateDC32W(LPCWSTR,LPCWSTR,LPCWSTR,const DEVMODE32W*);
-#define    CreateDC WINELIB_NAME_AW(CreateDC)
-HWND16     CreateDialog16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16);
-#define    CreateDialog32A(inst,ptr,hwnd,dlg) \
+LRESULT     WINAPI AboutDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI AboutDlgProc32(HWND32,UINT32,WPARAM32,LPARAM);
+#define     AboutDlgProc WINELIB_NAME(AboutDlgProc)
+INT16       WINAPI AccessResource16(HINSTANCE16,HRSRC16);
+INT32       WINAPI AccessResource32(HINSTANCE32,HRSRC32);
+#define     AccessResource WINELIB_NAME(AccessResource)
+ATOM        WINAPI AddAtom16(SEGPTR);
+ATOM        WINAPI AddAtom32A(LPCSTR);
+ATOM        WINAPI AddAtom32W(LPCWSTR);
+#define     AddAtom WINELIB_NAME_AW(AddAtom)
+INT16       WINAPI AddFontResource16(LPCSTR);
+INT32       WINAPI AddFontResource32A(LPCSTR);
+INT32       WINAPI AddFontResource32W(LPCWSTR);
+#define     AddFontResource WINELIB_NAME_AW(AddFontResource)
+BOOL16      WINAPI AdjustWindowRect16(LPRECT16,DWORD,BOOL16);
+BOOL32      WINAPI AdjustWindowRect32(LPRECT32,DWORD,BOOL32);
+#define     AdjustWindowRect WINELIB_NAME(AdjustWindowRect)
+BOOL16      WINAPI AdjustWindowRectEx16(LPRECT16,DWORD,BOOL16,DWORD);
+BOOL32      WINAPI AdjustWindowRectEx32(LPRECT32,DWORD,BOOL32,DWORD);
+#define     AdjustWindowRectEx WINELIB_NAME(AdjustWindowRectEx)
+HGLOBAL16   WINAPI AllocResource16(HINSTANCE16,HRSRC16,DWORD);
+HGLOBAL32   WINAPI AllocResource32(HINSTANCE32,HRSRC32,DWORD);
+#define     AllocResource WINELIB_NAME(AllocResource)
+void        WINAPI AnimatePalette16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
+BOOL32      WINAPI AnimatePalette32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
+#define     AnimatePalette WINELIB_NAME(AnimatePalette)
+SEGPTR      WINAPI AnsiLower16(SEGPTR);
+#define     AnsiLower32A CharLower32A
+#define     AnsiLower32W CharLower32W
+#define     AnsiLower WINELIB_NAME_AW(AnsiLower)
+UINT16      WINAPI AnsiLowerBuff16(LPSTR,UINT16);
+#define     AnsiLowerBuff32A CharLowerBuff32A
+#define     AnsiLowerBuff32W CharLowerBuff32W
+#define     AnsiLowerBuff WINELIB_NAME_AW(AnsiLowerBuff)
+SEGPTR      WINAPI AnsiNext16(SEGPTR);
+#define     AnsiNext32A CharNext32A
+#define     AnsiNext32W CharNext32W
+#define     AnsiNext WINELIB_NAME_AW(AnsiNext)
+SEGPTR      WINAPI AnsiPrev16(SEGPTR,SEGPTR);
+#define     AnsiPrev32A CharPrev32A
+#define     AnsiPrev32W CharPrev32W
+#define     AnsiPrev WINELIB_NAME_AW(AnsiPrev)
+INT16       WINAPI AnsiToOem16(LPCSTR,LPSTR);
+#define     AnsiToOem32A CharToOem32A
+#define     AnsiToOem32W CharToOem32W
+#define     AnsiToOem WINELIB_NAME_AW(AnsiToOem)
+VOID        WINAPI AnsiToOemBuff16(LPCSTR,LPSTR,UINT16);
+#define     AnsiToOemBuff32A CharToOemBuff32A
+#define     AnsiToOemBuff32W CharToOemBuff32W
+#define     AnsiToOemBuff WINELIB_NAME_AW(AnsiToOemBuff)
+SEGPTR      WINAPI AnsiUpper16(SEGPTR);
+#define     AnsiUpper32A CharUpper32A
+#define     AnsiUpper32W CharUpper32W
+#define     AnsiUpper WINELIB_NAME_AW(AnsiUpper)
+UINT16      WINAPI AnsiUpperBuff16(LPSTR,UINT16);
+#define     AnsiUpperBuff32A CharUpperBuff32A
+#define     AnsiUpperBuff32W CharUpperBuff32W
+#define     AnsiUpperBuff WINELIB_NAME_AW(AnsiUpperBuff)
+BOOL16      WINAPI AnyPopup16(void);
+BOOL32      WINAPI AnyPopup32(void);
+#define     AnyPopup WINELIB_NAME(AnyPopup)
+BOOL16      WINAPI AppendMenu16(HMENU16,UINT16,UINT16,SEGPTR);
+BOOL32      WINAPI AppendMenu32A(HMENU32,UINT32,UINT32,LPCSTR);
+BOOL32      WINAPI AppendMenu32W(HMENU32,UINT32,UINT32,LPCWSTR);
+#define     AppendMenu WINELIB_NAME_AW(AppendMenu)
+BOOL16      WINAPI Arc16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI Arc32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
+#define     Arc WINELIB_NAME(Arc)
+UINT16      WINAPI ArrangeIconicWindows16(HWND16);
+UINT32      WINAPI ArrangeIconicWindows32(HWND32);
+#define     ArrangeIconicWindows WINELIB_NAME(ArrangeIconicWindows)
+HDWP16      WINAPI BeginDeferWindowPos16(INT16);
+HDWP32      WINAPI BeginDeferWindowPos32(INT32);
+#define     BeginDeferWindowPos WINELIB_NAME(BeginDeferWindowPos)
+HDC16       WINAPI BeginPaint16(HWND16,LPPAINTSTRUCT16);
+HDC32       WINAPI BeginPaint32(HWND32,LPPAINTSTRUCT32);
+#define     BeginPaint WINELIB_NAME(BeginPaint)
+BOOL16      WINAPI BitBlt16(HDC16,INT16,INT16,INT16,INT16,HDC16,INT16,INT16,DWORD);
+BOOL32      WINAPI BitBlt32(HDC32,INT32,INT32,INT32,INT32,HDC32,INT32,INT32,DWORD);
+#define     BitBlt WINELIB_NAME(BitBlt)
+BOOL16      WINAPI BringWindowToTop16(HWND16);
+BOOL32      WINAPI BringWindowToTop32(HWND32);
+#define     BringWindowToTop WINELIB_NAME(BringWindowToTop)
+BOOL16      WINAPI BuildCommDCB16(LPCSTR,LPDCB16);
+BOOL32      WINAPI BuildCommDCB32A(LPCSTR,LPDCB32);
+BOOL32      WINAPI BuildCommDCB32W(LPCWSTR,LPDCB32);
+#define     BuildCommDCB WINELIB_NAME_AW(BuildCommDCB)
+BOOL32      WINAPI BuildCommDCBAndTimeouts32A(LPCSTR,LPDCB32,LPCOMMTIMEOUTS);
+BOOL32      WINAPI BuildCommDCBAndTimeouts32W(LPCWSTR,LPDCB32,LPCOMMTIMEOUTS);
+#define     BuildCommDCBAndTimeouts WINELIB_NAME_AW(BuildCommDCBAndTimeouts)
+BOOL16      WINAPI CallMsgFilter16(SEGPTR,INT16);
+BOOL32      WINAPI CallMsgFilter32A(LPMSG32,INT32);
+BOOL32      WINAPI CallMsgFilter32W(LPMSG32,INT32);
+#define     CallMsgFilter WINELIB_NAME_AW(CallMsgFilter)
+LRESULT     WINAPI CallNextHookEx16(HHOOK,INT16,WPARAM16,LPARAM);
+LRESULT     WINAPI CallNextHookEx32(HHOOK,INT32,WPARAM32,LPARAM);
+#define     CallNextHookEx WINELIB_NAME(CallNextHookEx)
+LRESULT     WINAPI CallWindowProc16(WNDPROC16,HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI CallWindowProc32A(WNDPROC32,HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI CallWindowProc32W(WNDPROC32,HWND32,UINT32,WPARAM32,LPARAM);
+#define     CallWindowProc WINELIB_NAME_AW(CallWindowProc)
+BOOL16      WINAPI ChangeClipboardChain16(HWND16,HWND16);
+BOOL32      WINAPI ChangeClipboardChain32(HWND32,HWND32);
+#define     ChangeClipboardChain WINELIB_NAME(ChangeClipboardChain)
+BOOL16      WINAPI ChangeMenu16(HMENU16,UINT16,SEGPTR,UINT16,UINT16);
+BOOL32      WINAPI ChangeMenu32A(HMENU32,UINT32,LPCSTR,UINT32,UINT32);
+BOOL32      WINAPI ChangeMenu32W(HMENU32,UINT32,LPCWSTR,UINT32,UINT32);
+#define     ChangeMenu WINELIB_NAME_AW(ChangeMenu)
+LPSTR       WINAPI CharLower32A(LPSTR);
+LPWSTR      WINAPI CharLower32W(LPWSTR);
+#define     CharLower WINELIB_NAME_AW(CharLower)
+DWORD       WINAPI CharLowerBuff32A(LPSTR,DWORD);
+DWORD       WINAPI CharLowerBuff32W(LPWSTR,DWORD);
+#define     CharLowerBuff WINELIB_NAME_AW(CharLowerBuff)
+LPSTR       WINAPI CharNext32A(LPCSTR);
+LPWSTR      WINAPI CharNext32W(LPCWSTR);
+#define     CharNext WINELIB_NAME_AW(CharNext)
+LPSTR       WINAPI CharNextEx32A(WORD,LPCSTR,DWORD);
+LPWSTR      WINAPI CharNextEx32W(WORD,LPCWSTR,DWORD);
+#define     CharNextEx WINELIB_NAME_AW(CharNextEx)
+LPSTR       WINAPI CharPrev32A(LPCSTR,LPCSTR);
+LPWSTR      WINAPI CharPrev32W(LPCWSTR,LPCWSTR);
+#define     CharPrev WINELIB_NAME_AW(CharPrev)
+LPSTR       WINAPI CharPrevEx32A(WORD,LPCSTR,LPCSTR,DWORD);
+LPWSTR      WINAPI CharPrevEx32W(WORD,LPCWSTR,LPCWSTR,DWORD);
+#define     CharPrevEx WINELIB_NAME_AW(CharPrevEx)
+LPSTR       WINAPI CharUpper32A(LPSTR);
+LPWSTR      WINAPI CharUpper32W(LPWSTR);
+#define     CharUpper WINELIB_NAME_AW(CharUpper)
+DWORD       WINAPI CharUpperBuff32A(LPSTR,DWORD);
+DWORD       WINAPI CharUpperBuff32W(LPWSTR,DWORD);
+#define     CharUpperBuff WINELIB_NAME_AW(CharUpperBuff)
+BOOL32      WINAPI CharToOem32A(LPCSTR,LPSTR);
+BOOL32      WINAPI CharToOem32W(LPCWSTR,LPSTR);
+#define     CharToOem WINELIB_NAME_AW(CharToOem)
+BOOL32      WINAPI CharToOemBuff32A(LPCSTR,LPSTR,DWORD);
+BOOL32      WINAPI CharToOemBuff32W(LPCWSTR,LPSTR,DWORD);
+#define     CharToOemBuff WINELIB_NAME_AW(CharToOemBuff)
+BOOL16      WINAPI CheckDlgButton16(HWND16,INT16,UINT16);
+BOOL32      WINAPI CheckDlgButton32(HWND32,INT32,UINT32);
+#define     CheckDlgButton WINELIB_NAME(CheckDlgButton)
+BOOL16      WINAPI CheckMenuItem16(HMENU16,UINT16,UINT16);
+DWORD       WINAPI CheckMenuItem32(HMENU32,UINT32,UINT32);
+#define     CheckMenuItem WINELIB_NAME(CheckMenuItem)
+BOOL16      WINAPI CheckRadioButton16(HWND16,UINT16,UINT16,UINT16);
+BOOL32      WINAPI CheckRadioButton32(HWND32,UINT32,UINT32,UINT32);
+#define     CheckRadioButton WINELIB_NAME(CheckRadioButton)
+HWND16      WINAPI ChildWindowFromPoint16(HWND16,POINT16);
+HWND32      WINAPI ChildWindowFromPoint32(HWND32,POINT32);
+#define     ChildWindowFromPoint WINELIB_NAME(ChildWindowFromPoint)
+BOOL16      WINAPI Chord16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI Chord32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
+#define     Chord WINELIB_NAME(Chord)
+INT16       WINAPI ClearCommBreak16(INT16);
+BOOL32      WINAPI ClearCommBreak32(INT32);
+#define     ClearCommBreak WINELIB_NAME(ClearCommBreak)
+BOOL16      WINAPI ClientToScreen16(HWND16,LPPOINT16);
+BOOL32      WINAPI ClientToScreen32(HWND32,LPPOINT32);
+#define     ClientToScreen WINELIB_NAME(ClientToScreen)
+BOOL16      WINAPI ClipCursor16(const RECT16*);
+BOOL32      WINAPI ClipCursor32(const RECT32*);
+#define     ClipCursor WINELIB_NAME(ClipCursor)
+BOOL16      WINAPI CloseClipboard16(void);
+BOOL32      WINAPI CloseClipboard32(void);
+#define     CloseClipboard WINELIB_NAME(CloseClipboard)
+HMETAFILE16 WINAPI CloseMetaFile16(HDC16);
+HMETAFILE32 WINAPI CloseMetaFile32(HDC32);
+#define     CloseMetaFile WINELIB_NAME(CloseMetaFile)
+BOOL16      WINAPI CloseWindow16(HWND16);
+BOOL32      WINAPI CloseWindow32(HWND32);
+#define     CloseWindow WINELIB_NAME(CloseWindow)
+INT16       WINAPI CombineRgn16(HRGN16,HRGN16,HRGN16,INT16);
+INT32       WINAPI CombineRgn32(HRGN32,HRGN32,HRGN32,INT32);
+#define     CombineRgn WINELIB_NAME(CombineRgn)
+UINT16      WINAPI CompareString16(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
+UINT32      WINAPI CompareString32A(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
+UINT32      WINAPI CompareString32W(DWORD,DWORD,LPCWSTR,DWORD,LPCWSTR,DWORD);
+#define     CompareString WINELIB_NAME_AW(CompareString)
+HCURSOR16   WINAPI CopyCursor16(HINSTANCE16,HCURSOR16);
+#define     CopyCursor32(cur) ((HCURSOR32)CopyIcon32((HICON32)(cur)))
+#define     CopyCursor WINELIB_NAME(CopyCursor)
+HICON16     WINAPI CopyIcon16(HINSTANCE16,HICON16);
+HICON32     WINAPI CopyIcon32(HICON32);
+#define     CopyIcon WINELIB_NAME(CopyIcon)
+LONG        WINAPI CopyLZFile16(HFILE16,HFILE16);
+LONG        WINAPI CopyLZFile32(HFILE32,HFILE32);
+#define     CopyLZFile WINELIB_NAME(CopyLZFile)
+HMETAFILE16 WINAPI CopyMetaFile16(HMETAFILE16,LPCSTR);
+HMETAFILE32 WINAPI CopyMetaFile32A(HMETAFILE32,LPCSTR);
+HMETAFILE32 WINAPI CopyMetaFile32W(HMETAFILE32,LPCWSTR);
+#define     CopyMetaFile WINELIB_NAME_AW(CopyMetaFile)
+BOOL16      WINAPI CopyRect16(RECT16*,const RECT16*);
+BOOL32      WINAPI CopyRect32(RECT32*,const RECT32*);
+#define     CopyRect WINELIB_NAME(CopyRect)
+INT16       WINAPI CountClipboardFormats16(void);
+INT32       WINAPI CountClipboardFormats32(void);
+#define     CountClipboardFormats WINELIB_NAME(CountClipboardFormats)
+INT16       WINAPI CountVoiceNotes16(INT16);
+DWORD       WINAPI CountVoiceNotes32(DWORD);
+#define     CountVoiceNotes WINELIB_NAME(CountVoiceNotes)
+HBITMAP16   WINAPI CreateBitmap16(INT16,INT16,UINT16,UINT16,LPCVOID);
+HBITMAP32   WINAPI CreateBitmap32(INT32,INT32,UINT32,UINT32,LPCVOID);
+#define     CreateBitmap WINELIB_NAME(CreateBitmap)
+HBITMAP16   WINAPI CreateBitmapIndirect16(const BITMAP16*);
+HBITMAP32   WINAPI CreateBitmapIndirect32(const BITMAP32*);
+#define     CreateBitmapIndirect WINELIB_NAME(CreateBitmapIndirect)
+HBRUSH16    WINAPI CreateBrushIndirect16(const LOGBRUSH16*);
+HBRUSH32    WINAPI CreateBrushIndirect32(const LOGBRUSH32*);
+#define     CreateBrushIndirect WINELIB_NAME(CreateBrushIndirect)
+VOID        WINAPI CreateCaret16(HWND16,HBITMAP16,INT16,INT16);
+BOOL32      WINAPI CreateCaret32(HWND32,HBITMAP32,INT32,INT32);
+#define     CreateCaret WINELIB_NAME(CreateCaret)
+HBITMAP16   WINAPI CreateCompatibleBitmap16(HDC16,INT16,INT16);
+HBITMAP32   WINAPI CreateCompatibleBitmap32(HDC32,INT32,INT32);
+#define     CreateCompatibleBitmap WINELIB_NAME(CreateCompatibleBitmap)
+HDC16       WINAPI CreateCompatibleDC16(HDC16);
+HDC32       WINAPI CreateCompatibleDC32(HDC32);
+#define     CreateCompatibleDC WINELIB_NAME(CreateCompatibleDC)
+HCURSOR16   WINAPI CreateCursor16(HINSTANCE16,INT16,INT16,INT16,INT16,LPCVOID,LPCVOID);
+HCURSOR32   WINAPI CreateCursor32(HINSTANCE32,INT32,INT32,INT32,INT32,LPCVOID,LPCVOID);
+#define     CreateCursor WINELIB_NAME(CreateCursor)
+HDC16       WINAPI CreateDC16(LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
+HDC32       WINAPI CreateDC32A(LPCSTR,LPCSTR,LPCSTR,const DEVMODE32A*);
+HDC32       WINAPI CreateDC32W(LPCWSTR,LPCWSTR,LPCWSTR,const DEVMODE32W*);
+#define     CreateDC WINELIB_NAME_AW(CreateDC)
+HWND16      WINAPI CreateDialog16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16);
+#define     CreateDialog32A(inst,ptr,hwnd,dlg) \
            CreateDialogParam32A(inst,ptr,hwnd,dlg,0)
-#define    CreateDialog32W(inst,ptr,hwnd,dlg) \
+#define     CreateDialog32W(inst,ptr,hwnd,dlg) \
            CreateDialogParam32W(inst,ptr,hwnd,dlg,0)
-#define    CreateDialog WINELIB_NAME_AW(CreateDialog)
-HWND16     CreateDialogIndirect16(HINSTANCE16,LPCVOID,HWND16,DLGPROC16);
-#define    CreateDialogIndirect32A(inst,ptr,hwnd,dlg) \
+#define     CreateDialog WINELIB_NAME_AW(CreateDialog)
+HWND16      WINAPI CreateDialogIndirect16(HINSTANCE16,LPCVOID,HWND16,DLGPROC16);
+#define     CreateDialogIndirect32A(inst,ptr,hwnd,dlg) \
            CreateDialogIndirectParam32A(inst,ptr,hwnd,dlg,0)
-#define    CreateDialogIndirect32W(inst,ptr,hwnd,dlg) \
+#define     CreateDialogIndirect32W(inst,ptr,hwnd,dlg) \
            CreateDialogIndirectParam32W(inst,ptr,hwnd,dlg,0)
-#define    CreateDialogIndirect WINELIB_NAME_AW(CreateDialogIndirect)
-HWND16     CreateDialogIndirectParam16(HINSTANCE16,LPCVOID,HWND16,DLGPROC16,LPARAM);
-HWND32     CreateDialogIndirectParam32A(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
-HWND32     CreateDialogIndirectParam32W(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
-#define    CreateDialogIndirectParam WINELIB_NAME_AW(CreateDialogIndirectParam)
-HWND16     CreateDialogParam16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16,LPARAM);
-HWND32     CreateDialogParam32A(HINSTANCE32,LPCSTR,HWND32,DLGPROC32,LPARAM);
-HWND32     CreateDialogParam32W(HINSTANCE32,LPCWSTR,HWND32,DLGPROC32,LPARAM);
-#define    CreateDialogParam WINELIB_NAME_AW(CreateDialogParam)
-HBITMAP16  CreateDIBitmap16(HDC16,const BITMAPINFOHEADER*,DWORD,LPCVOID,
-                            const BITMAPINFO*,UINT16);
-HBITMAP32  CreateDIBitmap32(HDC32,const BITMAPINFOHEADER*,DWORD,LPCVOID,
-                            const BITMAPINFO*,UINT32);
-#define    CreateDIBitmap WINELIB_NAME(CreateDIBitmap)
-HBRUSH16   CreateDIBPatternBrush16(HGLOBAL16,UINT16);
-HBRUSH32   CreateDIBPatternBrush32(HGLOBAL32,UINT32);
-#define    CreateDIBPatternBrush WINELIB_NAME(CreateDIBPatternBrush)
-BOOL16     CreateDirectory16(LPCSTR,LPVOID);
-BOOL32     CreateDirectory32A(LPCSTR,LPSECURITY_ATTRIBUTES);
-BOOL32     CreateDirectory32W(LPCWSTR,LPSECURITY_ATTRIBUTES);
-#define    CreateDirectory WINELIB_NAME_AW(CreateDirectory)
-BOOL32     CreateDirectoryEx32A(LPCSTR,LPCSTR,LPSECURITY_ATTRIBUTES);
-BOOL32     CreateDirectoryEx32W(LPCWSTR,LPCWSTR,LPSECURITY_ATTRIBUTES);
-#define    CreateDirectoryEx WINELIB_NAME_AW(CreateDirectoryEx)
-HBITMAP16  CreateDiscardableBitmap16(HDC16,INT16,INT16);
-HBITMAP32  CreateDiscardableBitmap32(HDC32,INT32,INT32);
-#define    CreateDiscardableBitmap WINELIB_NAME(CreateDiscardableBitmap)
-HRGN16     CreateEllipticRgn16(INT16,INT16,INT16,INT16);
-HRGN32     CreateEllipticRgn32(INT32,INT32,INT32,INT32);
-#define    CreateEllipticRgn WINELIB_NAME(CreateEllipticRgn)
-HRGN16     CreateEllipticRgnIndirect16(const RECT16 *);
-HRGN32     CreateEllipticRgnIndirect32(const RECT32 *);
-#define    CreateEllipticRgnIndirect WINELIB_NAME(CreateEllipticRgnIndirect)
-HFONT16    CreateFont16(INT16,INT16,INT16,INT16,INT16,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,BYTE,LPCSTR);
-HFONT32    CreateFont32A(INT32,INT32,INT32,INT32,INT32,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCSTR);
-HFONT32    CreateFont32W(INT32,INT32,INT32,INT32,INT32,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR);
-#define    CreateFont WINELIB_NAME_AW(CreateFont)
-HFONT16    CreateFontIndirect16(const LOGFONT16*);
-HFONT32    CreateFontIndirect32A(const LOGFONT32A*);
-HFONT32    CreateFontIndirect32W(const LOGFONT32W*);
-#define    CreateFontIndirect WINELIB_NAME_AW(CreateFontIndirect)
-HBRUSH16   CreateHatchBrush16(INT16,COLORREF);
-HBRUSH32   CreateHatchBrush32(INT32,COLORREF);
-#define    CreateHatchBrush WINELIB_NAME(CreateHatchBrush)
-HDC16      CreateIC16(LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
-HDC32      CreateIC32A(LPCSTR,LPCSTR,LPCSTR,const DEVMODE32A*);
-HDC32      CreateIC32W(LPCWSTR,LPCWSTR,LPCWSTR,const DEVMODE32W*);
-#define    CreateIC WINELIB_NAME_AW(CreateIC)
-HICON16    CreateIcon16(HINSTANCE16,INT16,INT16,BYTE,BYTE,LPCVOID,LPCVOID);
-HICON32    CreateIcon32(HINSTANCE32,INT32,INT32,BYTE,BYTE,LPCVOID,LPCVOID);
-#define    CreateIcon WINELIB_NAME(CreateIcon)
-HMENU16    CreateMenu16(void);
-HMENU32    CreateMenu32(void);
-#define    CreateMenu WINELIB_NAME(CreateMenu)
-HDC16      CreateMetaFile16(LPCSTR);
-HDC32      CreateMetaFile32A(LPCSTR);
-HDC32      CreateMetaFile32W(LPCWSTR);
-#define    CreateMetaFile WINELIB_NAME_AW(CreateMetaFile)
-HPALETTE16 CreatePalette16(const LOGPALETTE*);
-HPALETTE32 CreatePalette32(const LOGPALETTE*);
-#define    CreatePalette WINELIB_NAME(CreatePalette)
-HBRUSH16   CreatePatternBrush16(HBITMAP16);
-HBRUSH32   CreatePatternBrush32(HBITMAP32);
-#define    CreatePatternBrush WINELIB_NAME(CreatePatternBrush)
-HPEN16     CreatePen16(INT16,INT16,COLORREF);
-HPEN32     CreatePen32(INT32,INT32,COLORREF);
-#define    CreatePen WINELIB_NAME(CreatePen)
-HPEN16     CreatePenIndirect16(const LOGPEN16*);
-HPEN32     CreatePenIndirect32(const LOGPEN32*);
-#define    CreatePenIndirect WINELIB_NAME(CreatePenIndirect)
-HRGN16     CreatePolyPolygonRgn16(const POINT16*,const INT16*,INT16,INT16);
-HRGN32     CreatePolyPolygonRgn32(const POINT32*,const INT32*,INT32,INT32);
-#define    CreatePolyPolygonRgn WINELIB_NAME(CreatePolyPolygonRgn)
-HRGN16     CreatePolygonRgn16(const POINT16*,INT16,INT16);
-HRGN32     CreatePolygonRgn32(const POINT32*,INT32,INT32);
-#define    CreatePolygonRgn WINELIB_NAME(CreatePolygonRgn)
-HMENU16    CreatePopupMenu16(void);
-HMENU32    CreatePopupMenu32(void);
-#define    CreatePopupMenu WINELIB_NAME(CreatePopupMenu)
-HRGN16     CreateRectRgn16(INT16,INT16,INT16,INT16);
-HRGN32     CreateRectRgn32(INT32,INT32,INT32,INT32);
-#define    CreateRectRgn WINELIB_NAME(CreateRectRgn)
-HRGN16     CreateRectRgnIndirect16(const RECT16*);
-HRGN32     CreateRectRgnIndirect32(const RECT32*);
-#define    CreateRectRgnIndirect WINELIB_NAME(CreateRectRgnIndirect)
-HRGN16     CreateRoundRectRgn16(INT16,INT16,INT16,INT16,INT16,INT16);
-HRGN32     CreateRoundRectRgn32(INT32,INT32,INT32,INT32,INT32,INT32);
-#define    CreateRoundRectRgn WINELIB_NAME(CreateRoundRectRgn)
-BOOL16     CreateScalableFontResource16(UINT16,LPCSTR,LPCSTR,LPCSTR);
-BOOL32     CreateScalableFontResource32A(DWORD,LPCSTR,LPCSTR,LPCSTR);
-BOOL32     CreateScalableFontResource32W(DWORD,LPCWSTR,LPCWSTR,LPCWSTR);
-#define    CreateScalableFontResource WINELIB_NAME_AW(CreateScalableFontResource)
-HBRUSH16   CreateSolidBrush16(COLORREF);
-HBRUSH32   CreateSolidBrush32(COLORREF);
-#define    CreateSolidBrush WINELIB_NAME(CreateSolidBrush)
-HWND16     CreateWindow16(LPCSTR,LPCSTR,DWORD,INT16,INT16,INT16,INT16,HWND16,HMENU16,HINSTANCE16,LPVOID);
-#define    CreateWindow32A(className,titleName,style,x,y,width,height,\
-                           parent,menu,instance,param) \
-           CreateWindowEx32A(0,className,titleName,style,x,y,width,height,\
-                           parent,menu,instance,param)
-#define    CreateWindow32W(className,titleName,style,x,y,width,height,\
-                           parent,menu,instance,param) \
-           CreateWindowEx32W(0,className,titleName,style,x,y,width,height,\
-                           parent,menu,instance,param)
-#define    CreateWindow WINELIB_NAME_AW(CreateWindow)
-HWND16     CreateWindowEx16(DWORD,LPCSTR,LPCSTR,DWORD,INT16,INT16,INT16,INT16,HWND16,HMENU16,HINSTANCE16,LPVOID);
-HWND32     CreateWindowEx32A(DWORD,LPCSTR,LPCSTR,DWORD,INT32,INT32,INT32,INT32,HWND32,HMENU32,HINSTANCE32,LPVOID);
-HWND32     CreateWindowEx32W(DWORD,LPCWSTR,LPCWSTR,DWORD,INT32,INT32,INT32,INT32,HWND32,HMENU32,HINSTANCE32,LPVOID);
-#define    CreateWindowEx WINELIB_NAME_AW(CreateWindowEx)
-LRESULT    DefDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    DefDlgProc32A(HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    DefDlgProc32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define    DefDlgProc WINELIB_NAME_AW(DefDlgProc)
-HDWP16     DeferWindowPos16(HDWP16,HWND16,HWND16,INT16,INT16,INT16,INT16,UINT16);
-HDWP32     DeferWindowPos32(HDWP32,HWND32,HWND32,INT32,INT32,INT32,INT32,UINT32);
-#define    DeferWindowPos WINELIB_NAME(DeferWindowPos)
-LRESULT    DefFrameProc16(HWND16,HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    DefFrameProc32A(HWND32,HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    DefFrameProc32W(HWND32,HWND32,UINT32,WPARAM32,LPARAM);
-#define    DefFrameProc WINELIB_NAME_AW(DefFrameProc)
-LRESULT    DefHookProc16(INT16,WPARAM16,LPARAM,HHOOK*);
-#define    DefHookProc32(code,wparam,lparam,phhook) \
-           CallNextHookEx32(*(phhook),code,wparam,lparam)
-#define    DefHookProc WINELIB_NAME(DefHookProc)
-LRESULT    DefMDIChildProc16(HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    DefMDIChildProc32A(HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    DefMDIChildProc32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define    DefMDIChildProc WINELIB_NAME_AW(DefMDIChildProc)
-LRESULT    DefWindowProc16(HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    DefWindowProc32A(HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    DefWindowProc32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define    DefWindowProc WINELIB_NAME_AW(DefWindowProc)
-ATOM       DeleteAtom16(ATOM);
-ATOM       DeleteAtom32(ATOM);
-#define    DeleteAtom WINELIB_NAME(DeleteAtom)
-BOOL16     DeleteDC16(HDC16);
-BOOL32     DeleteDC32(HDC32);
-#define    DeleteDC WINELIB_NAME(DeleteDC)
-BOOL16     DeleteFile16(LPCSTR);
-BOOL32     DeleteFile32A(LPCSTR);
-BOOL32     DeleteFile32W(LPCWSTR);
-#define    DeleteFile WINELIB_NAME_AW(DeleteFile)
-BOOL16     DeleteMenu16(HMENU16,UINT16,UINT16);
-BOOL32     DeleteMenu32(HMENU32,UINT32,UINT32);
-#define    DeleteMenu WINELIB_NAME(DeleteMenu)
-BOOL16     DeleteMetaFile16(HMETAFILE16);
-BOOL32     DeleteMetaFile32(HMETAFILE32);
-#define    DeleteMetaFile WINELIB_NAME(DeleteMetaFile)
-BOOL16     DeleteObject16(HGDIOBJ16);
-BOOL32     DeleteObject32(HGDIOBJ32);
-#define    DeleteObject WINELIB_NAME(DeleteObject)
-VOID       DestroyCaret16(void);
-BOOL32     DestroyCaret32(void);
-#define    DestroyCaret WINELIB_NAME(DestroyCaret)
-BOOL16     DestroyCursor16(HCURSOR16);
-BOOL32     DestroyCursor32(HCURSOR32);
-#define    DestroyCursor WINELIB_NAME(DestroyCursor)
-BOOL16     DestroyIcon16(HICON16);
-BOOL32     DestroyIcon32(HICON32);
-#define    DestroyIcon WINELIB_NAME(DestroyIcon)
-BOOL16     DestroyMenu16(HMENU16);
-BOOL32     DestroyMenu32(HMENU32);
-#define    DestroyMenu WINELIB_NAME(DestroyMenu)
-BOOL16     DestroyWindow16(HWND16);
-BOOL32     DestroyWindow32(HWND32);
-#define    DestroyWindow WINELIB_NAME(DestroyWindow)
-INT16      DialogBox16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16);
-#define    DialogBox32A(inst,template,owner,func) \
-           DialogBoxParam32A(inst,template,owner,func,0)
-#define    DialogBox32W(inst,template,owner,func) \
-           DialogBoxParam32W(inst,template,owner,func,0)
-#define    DialogBox WINELIB_NAME_AW(DialogBox)
-INT16      DialogBoxIndirect16(HINSTANCE16,HANDLE16,HWND16,DLGPROC16);
-#define    DialogBoxIndirect32A(inst,template,owner,func) \
-           DialogBoxIndirectParam32A(inst,template,owner,func,0)
-#define    DialogBoxIndirect32W(inst,template,owner,func) \
-           DialogBoxIndirectParam32W(inst,template,owner,func,0)
-#define    DialogBoxIndirect WINELIB_NAME_AW(DialogBoxIndirect)
-INT16      DialogBoxIndirectParam16(HINSTANCE16,HANDLE16,HWND16,DLGPROC16,LPARAM);
-INT32      DialogBoxIndirectParam32A(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
-INT32      DialogBoxIndirectParam32W(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
-#define    DialogBoxIndirectParam WINELIB_NAME_AW(DialogBoxIndirectParam)
-INT16      DialogBoxParam16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16,LPARAM);
-INT32      DialogBoxParam32A(HINSTANCE32,LPCSTR,HWND32,DLGPROC32,LPARAM);
-INT32      DialogBoxParam32W(HINSTANCE32,LPCWSTR,HWND32,DLGPROC32,LPARAM);
-#define    DialogBoxParam WINELIB_NAME_AW(DialogBoxParam)
-LONG       DispatchMessage16(const MSG16*);
-LONG       DispatchMessage32A(const MSG32*);
-LONG       DispatchMessage32W(const MSG32*);
-#define    DispatchMessage WINELIB_NAME_AW(DispatchMessage)
-INT16      DlgDirList16(HWND16,LPSTR,INT16,INT16,UINT16);
-INT32      DlgDirList32A(HWND32,LPSTR,INT32,INT32,UINT32);
-INT32      DlgDirList32W(HWND32,LPWSTR,INT32,INT32,UINT32);
-#define    DlgDirList WINELIB_NAME_AW(DlgDirList)
-INT16      DlgDirListComboBox16(HWND16,LPSTR,INT16,INT16,UINT16);
-INT32      DlgDirListComboBox32A(HWND32,LPSTR,INT32,INT32,UINT32);
-INT32      DlgDirListComboBox32W(HWND32,LPWSTR,INT32,INT32,UINT32);
-#define    DlgDirListComboBox WINELIB_NAME_AW(DlgDirListComboBox)
-BOOL16     DlgDirSelectComboBoxEx16(HWND16,LPSTR,INT16,INT16);
-BOOL32     DlgDirSelectComboBoxEx32A(HWND32,LPSTR,INT32,INT32);
-BOOL32     DlgDirSelectComboBoxEx32W(HWND32,LPWSTR,INT32,INT32);
-#define    DlgDirSelectComboBoxEx WINELIB_NAME_AW(DlgDirSelectComboBoxEx)
-BOOL16     DlgDirSelectEx16(HWND16,LPSTR,INT16,INT16);
-BOOL32     DlgDirSelectEx32A(HWND32,LPSTR,INT32,INT32);
-BOOL32     DlgDirSelectEx32W(HWND32,LPWSTR,INT32,INT32);
-#define    DlgDirSelectEx WINELIB_NAME_AW(DlgDirSelectEx)
-BOOL16     DPtoLP16(HDC16,LPPOINT16,INT16);
-BOOL32     DPtoLP32(HDC32,LPPOINT32,INT32);
-#define    DPtoLP WINELIB_NAME(DPtoLP)
-BOOL16     DragDetect16(HWND16,POINT16);
-BOOL32     DragDetect32(HWND32,POINT32);
-#define    DragDetect WINELIB_NAME(DragDetect)
-DWORD      DragObject16(HWND16,HWND16,UINT16,HANDLE16,WORD,HCURSOR16);
-DWORD      DragObject32(HWND32,HWND32,UINT32,DWORD,HCURSOR32);
-#define    DragObject WINELIB_NAME(DragObject)
-BOOL16     DrawEdge16(HDC16,LPRECT16,UINT16,UINT16);
-BOOL32     DrawEdge32(HDC32,LPRECT32,UINT32,UINT32);
-#define    DrawEdge WINELIB_NAME(DrawEdge)
-void       DrawFocusRect16(HDC16,const RECT16*);
-void       DrawFocusRect32(HDC32,const RECT32*);
-#define    DrawFocusRect WINELIB_NAME(DrawFocusRect)
-BOOL16     DrawFrameControl16(HDC16,LPRECT16,UINT16,UINT16);
-BOOL32     DrawFrameControl32(HDC32,LPRECT32,UINT32,UINT32);
-#define    DrawFrameControl WINELIB_NAME(DrawFrameControl)
-BOOL16     DrawIcon16(HDC16,INT16,INT16,HICON16);
-BOOL32     DrawIcon32(HDC32,INT32,INT32,HICON32);
-#define    DrawIcon WINELIB_NAME(DrawIcon)
-VOID       DrawMenuBar16(HWND16);
-BOOL32     DrawMenuBar32(HWND32);
-#define    DrawMenuBar WINELIB_NAME(DrawMenuBar)
-INT16      DrawText16(HDC16,LPCSTR,INT16,LPRECT16,UINT16);
-INT32      DrawText32A(HDC32,LPCSTR,INT32,LPRECT32,UINT32);
-INT32      DrawText32W(HDC32,LPCWSTR,INT32,LPRECT32,UINT32);
-#define    DrawText WINELIB_NAME_AW(DrawText)
-BOOL16     Ellipse16(HDC16,INT16,INT16,INT16,INT16);
-BOOL32     Ellipse32(HDC32,INT32,INT32,INT32,INT32);
-#define    Ellipse WINELIB_NAME(Ellipse)
-BOOL16     EmptyClipboard16(void);
-BOOL32     EmptyClipboard32(void);
-#define    EmptyClipboard WINELIB_NAME(EmptyClipboard)
-BOOL16     EnableMenuItem16(HMENU16,UINT16,UINT16);
-BOOL32     EnableMenuItem32(HMENU32,UINT32,UINT32);
-#define    EnableMenuItem WINELIB_NAME(EnableMenuItem)
-BOOL16     EnableScrollBar16(HWND16,INT16,UINT16);
-BOOL32     EnableScrollBar32(HWND32,INT32,UINT32);
-#define    EnableScrollBar WINELIB_NAME(EnableScrollBar)
-BOOL16     EnableWindow16(HWND16,BOOL16);
-BOOL32     EnableWindow32(HWND32,BOOL32);
-#define    EnableWindow WINELIB_NAME(EnableWindow)
-BOOL16     EndDeferWindowPos16(HDWP16);
-BOOL32     EndDeferWindowPos32(HDWP32);
-#define    EndDeferWindowPos WINELIB_NAME(EndDeferWindowPos)
-BOOL16     EndDialog16(HWND16,INT16);
-BOOL32     EndDialog32(HWND32,INT32);
-#define    EndDialog WINELIB_NAME(EndDialog)
-INT16      EndDoc16(HDC16);
-INT32      EndDoc32(HDC32);
-#define    EndDoc WINELIB_NAME(EndDoc)
-BOOL16     EndPaint16(HWND16,const PAINTSTRUCT16*);
-BOOL32     EndPaint32(HWND32,const PAINTSTRUCT32*);
-#define    EndPaint WINELIB_NAME(EndPaint)
-BOOL16     EnumChildWindows16(HWND16,WNDENUMPROC16,LPARAM);
-BOOL32     EnumChildWindows32(HWND32,WNDENUMPROC32,LPARAM);
-#define    EnumChildWindows WINELIB_NAME(EnumChildWindows)
-UINT16     EnumClipboardFormats16(UINT16);
-UINT32     EnumClipboardFormats32(UINT32);
-#define    EnumClipboardFormats WINELIB_NAME(EnumClipboardFormats)
-INT16      EnumFontFamilies16(HDC16,LPCSTR,FONTENUMPROC16,LPARAM);
-INT32      EnumFontFamilies32A(HDC32,LPCSTR,FONTENUMPROC32A,LPARAM);
-INT32      EnumFontFamilies32W(HDC32,LPCWSTR,FONTENUMPROC32W,LPARAM);
-#define    EnumFontFamilies WINELIB_NAME_AW(EnumFontFamilies)
-INT16      EnumFontFamiliesEx16(HDC16,LPLOGFONT16,FONTENUMPROCEX16,LPARAM,DWORD);
-INT32      EnumFontFamiliesEx32A(HDC32,LPLOGFONT32A,FONTENUMPROCEX32A,LPARAM,DWORD);
-INT32      EnumFontFamiliesEx32W(HDC32,LPLOGFONT32W,FONTENUMPROCEX32W,LPARAM,DWORD);
-#define    EnumFontFamiliesEx WINELIB_NAME_AW(EnumFontFamiliesEx)
-INT16      EnumFonts16(HDC16,LPCSTR,FONTENUMPROC16,LPARAM);
-INT32      EnumFonts32A(HDC32,LPCSTR,FONTENUMPROC32A,LPARAM);
-INT32      EnumFonts32W(HDC32,LPCWSTR,FONTENUMPROC32W,LPARAM);
-#define    EnumFonts WINELIB_NAME_AW(EnumFonts)
-BOOL16     EnumMetaFile16(HDC16,HMETAFILE16,MFENUMPROC16,LPARAM);
-BOOL32     EnumMetaFile32(HDC32,HMETAFILE32,MFENUMPROC32,LPARAM);
-#define    EnumMetaFile WINELIB_NAME(EnumMetaFile)
-INT16      EnumObjects16(HDC16,INT16,GOBJENUMPROC16,LPARAM);
-INT32      EnumObjects32(HDC32,INT32,GOBJENUMPROC32,LPARAM);
-#define    EnumObjects WINELIB_NAME(EnumObjects)
-INT16      EnumProps16(HWND16,PROPENUMPROC16);
-INT32      EnumProps32A(HWND32,PROPENUMPROC32A);
-INT32      EnumProps32W(HWND32,PROPENUMPROC32W);
-#define    EnumProps WINELIB_NAME_AW(EnumProps)
-BOOL16     EnumTaskWindows16(HTASK16,WNDENUMPROC16,LPARAM);
-#define    EnumTaskWindows32(handle,proc,lparam) \
-           EnumThreadWindows(handle,proc,lparam)
-#define    EnumTaskWindows WINELIB_NAME(EnumTaskWindows)
-BOOL16     EnumWindows16(WNDENUMPROC16,LPARAM);
-BOOL32     EnumWindows32(WNDENUMPROC32,LPARAM);
-#define    EnumWindows WINELIB_NAME(EnumWindows)
-BOOL16     EqualRect16(const RECT16*,const RECT16*);
-BOOL32     EqualRect32(const RECT32*,const RECT32*);
-#define    EqualRect WINELIB_NAME(EqualRect)
-BOOL16     EqualRgn16(HRGN16,HRGN16);
-BOOL32     EqualRgn32(HRGN32,HRGN32);
-#define    EqualRgn WINELIB_NAME(EqualRgn)
-INT16      Escape16(HDC16,INT16,INT16,SEGPTR,SEGPTR);
-INT32      Escape32(HDC32,INT32,INT32,LPVOID,LPVOID);
-#define    Escape WINELIB_NAME(Escape)
-LONG       EscapeCommFunction16(UINT16,UINT16);
-BOOL32     EscapeCommFunction32(INT32,UINT32);
-#define    EscapeCommFunction WINELIB_NAME(EscapeCommFunction)
-INT16      ExcludeClipRect16(HDC16,INT16,INT16,INT16,INT16);
-INT32      ExcludeClipRect32(HDC32,INT32,INT32,INT32,INT32);
-#define    ExcludeClipRect WINELIB_NAME(ExcludeClipRect)
-INT16      ExcludeUpdateRgn16(HDC16,HWND16);
-INT32      ExcludeUpdateRgn32(HDC32,HWND32);
-#define    ExcludeUpdateRgn WINELIB_NAME(ExcludeUpdateRgn)
-BOOL16     ExitWindows16(DWORD,UINT16);
-#define    ExitWindows32(a,b) ExitWindowsEx(EWX_LOGOFF,0xffffffff)
-#define    ExitWindows WINELIB_NAME(ExitWindows)
-BOOL16     ExtFloodFill16(HDC16,INT16,INT16,COLORREF,UINT16);
-BOOL32     ExtFloodFill32(HDC32,INT32,INT32,COLORREF,UINT32);
-#define    ExtFloodFill WINELIB_NAME(ExtFloodFill)
-HICON16    ExtractIcon16(HINSTANCE16,LPCSTR,UINT16);
-HICON32    ExtractIcon32A(HINSTANCE32,LPCSTR,UINT32);
-HICON32    ExtractIcon32W(HINSTANCE32,LPCWSTR,UINT32);
-#define    ExtractIcon WINELIB_NAME_AW(ExtractIcon)
-BOOL16     ExtTextOut16(HDC16,INT16,INT16,UINT16,const RECT16*,LPCSTR,UINT16,const INT16*);
-BOOL32     ExtTextOut32A(HDC32,INT32,INT32,UINT32,const RECT32*,LPCSTR,UINT32,const INT32*);
-BOOL32     ExtTextOut32W(HDC32,INT32,INT32,UINT32,const RECT32*,LPCWSTR,UINT32,const INT32*);
-#define    ExtTextOut WINELIB_NAME_AW(ExtTextOut)
-void       FatalAppExit16(UINT16,LPCSTR);
-void       FatalAppExit32A(UINT32,LPCSTR);
-void       FatalAppExit32W(UINT32,LPCWSTR);
-#define    FatalAppExit WINELIB_NAME_AW(FatalAppExit)
-INT16      FillRect16(HDC16,const RECT16*,HBRUSH16);
-INT32      FillRect32(HDC32,const RECT32*,HBRUSH32);
-#define    FillRect WINELIB_NAME(FillRect)
-BOOL16     FillRgn16(HDC16,HRGN16,HBRUSH16);
-BOOL32     FillRgn32(HDC32,HRGN32,HBRUSH32);
-#define    FillRgn WINELIB_NAME(FillRgn)
-ATOM       FindAtom16(SEGPTR);
-ATOM       FindAtom32A(LPCSTR);
-ATOM       FindAtom32W(LPCWSTR);
-#define    FindAtom WINELIB_NAME_AW(FindAtom)
-BOOL16     FindClose16(HANDLE16);
-BOOL32     FindClose32(HANDLE32);
-#define    FindClose WINELIB_NAME(FindClose)
-HINSTANCE16 FindExecutable16(LPCSTR,LPCSTR,LPSTR);
-HINSTANCE32 FindExecutable32A(LPCSTR,LPCSTR,LPSTR);
-HINSTANCE32 FindExecutable32W(LPCWSTR,LPCWSTR,LPWSTR);
-#define    FindExecutable WINELIB_NAME_AW(FindExecutable)
-HANDLE16   FindFirstFile16(LPCSTR,LPWIN32_FIND_DATA32A);
-HANDLE32   FindFirstFile32A(LPCSTR,LPWIN32_FIND_DATA32A);
-HANDLE32   FindFirstFile32W(LPCWSTR,LPWIN32_FIND_DATA32W);
-#define    FindFirst WINELIB_NAME_AW(FindFirst)
-BOOL16     FindNextFile16(HANDLE16,LPWIN32_FIND_DATA32A);
-BOOL32     FindNextFile32A(HANDLE32,LPWIN32_FIND_DATA32A);
-BOOL32     FindNextFile32W(HANDLE32,LPWIN32_FIND_DATA32W);
-#define    FindNext WINELIB_NAME_AW(FindNext)
-HRSRC16    FindResource16(HINSTANCE16,SEGPTR,SEGPTR);
-HRSRC32    FindResource32A(HINSTANCE32,LPCSTR,LPCSTR);
-HRSRC32    FindResource32W(HINSTANCE32,LPCWSTR,LPCWSTR);
-#define    FindResource WINELIB_NAME_AW(FindResource)
-HWND16     FindWindow16(SEGPTR,LPCSTR);
-HWND32     FindWindow32A(LPCSTR,LPCSTR);
-HWND32     FindWindow32W(LPCWSTR,LPCWSTR);
-#define    FindWindow WINELIB_NAME_AW(FindWindow)
-HWND16     FindWindowEx16(HWND16,HWND16,SEGPTR,LPCSTR);
-HWND32     FindWindowEx32A(HWND32,HWND32,LPCSTR,LPCSTR);
-HWND32     FindWindowEx32W(HWND32,HWND32,LPCWSTR,LPCWSTR);
-#define    FindWindowEx WINELIB_NAME_AW(FindWindowEx)
-BOOL16     FlashWindow16(HWND16,BOOL16);
-BOOL32     FlashWindow32(HWND32,BOOL32);
-#define    FlashWindow WINELIB_NAME(FlashWindow)
-BOOL16     FloodFill16(HDC16,INT16,INT16,COLORREF);
-BOOL32     FloodFill32(HDC32,INT32,INT32,COLORREF);
-#define    FloodFill WINELIB_NAME(FloodFill)
-INT16      FrameRect16(HDC16,const RECT16*,HBRUSH16);
-INT32      FrameRect32(HDC32,const RECT32*,HBRUSH32);
-#define    FrameRect WINELIB_NAME(FrameRect)
-BOOL16     FrameRgn16(HDC16,HRGN16,HBRUSH16,INT16,INT16);
-BOOL32     FrameRgn32(HDC32,HRGN32,HBRUSH32,INT32,INT32);
-#define    FrameRgn WINELIB_NAME(FrameRgn)
-VOID       FreeLibrary16(HINSTANCE16);
-BOOL32     FreeLibrary32(HMODULE32);
-#define    FreeLibrary WINELIB_NAME(FreeLibrary)
-BOOL16     FreeModule16(HMODULE16);
-#define    FreeModule32(handle) FreeLibrary32(handle)
-#define    FreeModule WINELIB_NAME(FreeModule)
-void       FreeProcInstance16(FARPROC16);
-#define    FreeProcInstance32(proc) /*nothing*/
-#define    FreeProcInstance WINELIB_NAME(FreeProcInstance)
-BOOL16     FreeResource16(HGLOBAL16);
-BOOL32     FreeResource32(HGLOBAL32);
-#define    FreeResource WINELIB_NAME(FreeResource)
-HWND16     GetActiveWindow16(void);
-HWND32     GetActiveWindow32(void);
-#define    GetActiveWindow WINELIB_NAME(GetActiveWindow)
-DWORD      GetAppCompatFlags16(HTASK16);
-DWORD      GetAppCompatFlags32(HTASK32);
-#define    GetAppCompatFlags WINELIB_NAME(GetAppCompatFlags)
-WORD       GetAsyncKeyState16(INT16);
-WORD       GetAsyncKeyState32(INT32);
-#define    GetAsyncKeyState WINELIB_NAME(GetAsyncKeyState)
-UINT16     GetAtomName16(ATOM,LPSTR,INT16);
-UINT32     GetAtomName32A(ATOM,LPSTR,INT32);
-UINT32     GetAtomName32W(ATOM,LPWSTR,INT32);
-#define    GetAtomName WINELIB_NAME_AW(GetAtomName)
-LONG       GetBitmapBits16(HBITMAP16,LONG,LPVOID);
-LONG       GetBitmapBits32(HBITMAP32,LONG,LPVOID);
-#define    GetBitmapBits WINELIB_NAME(GetBitmapBits)
-BOOL16     GetBitmapDimensionEx16(HBITMAP16,LPSIZE16);
-BOOL32     GetBitmapDimensionEx32(HBITMAP32,LPSIZE32);
-#define    GetBitmapDimensionEx WINELIB_NAME(GetBitmapDimensionEx)
-BOOL16     GetBrushOrgEx16(HDC16,LPPOINT16);
-BOOL32     GetBrushOrgEx32(HDC32,LPPOINT32);
-#define    GetBrushOrgEx WINELIB_NAME(GetBrushOrgEx)
-COLORREF   GetBkColor16(HDC16);
-COLORREF   GetBkColor32(HDC32);
-#define    GetBkColor WINELIB_NAME(GetBkColor)
-INT16      GetBkMode16(HDC16);
-INT32      GetBkMode32(HDC32);
-#define    GetBkMode WINELIB_NAME(GetBkMode)
-HWND16     GetCapture16(void);
-HWND32     GetCapture32(void);
-#define    GetCapture WINELIB_NAME(GetCapture)
-UINT16     GetCaretBlinkTime16(void);
-UINT32     GetCaretBlinkTime32(void);
-#define    GetCaretBlinkTime WINELIB_NAME(GetCaretBlinkTime)
-VOID       GetCaretPos16(LPPOINT16);
-BOOL32     GetCaretPos32(LPPOINT32);
-#define    GetCaretPos WINELIB_NAME(GetCaretPos)
-BOOL16     GetCharABCWidths16(HDC16,UINT16,UINT16,LPABC16);
-BOOL32     GetCharABCWidths32A(HDC32,UINT32,UINT32,LPABC32);
-BOOL32     GetCharABCWidths32W(HDC32,UINT32,UINT32,LPABC32);
-#define    GetCharABCWidths WINELIB_NAME_AW(GetCharABCWidths)
-BOOL16     GetCharWidth16(HDC16,UINT16,UINT16,LPINT16);
-BOOL32     GetCharWidth32A(HDC32,UINT32,UINT32,LPINT32);
-BOOL32     GetCharWidth32W(HDC32,UINT32,UINT32,LPINT32);
-#define    GetCharWidth WINELIB_NAME_AW(GetCharWidth)
-BOOL16     GetClassInfo16(HINSTANCE16,SEGPTR,WNDCLASS16 *);
-BOOL32     GetClassInfo32A(HINSTANCE32,LPCSTR,WNDCLASS32A *);
-BOOL32     GetClassInfo32W(HINSTANCE32,LPCWSTR,WNDCLASS32W *);
-#define    GetClassInfo WINELIB_NAME_AW(GetClassInfo)
-BOOL16     GetClassInfoEx16(HINSTANCE16,SEGPTR,WNDCLASSEX16 *);
-BOOL32     GetClassInfoEx32A(HINSTANCE32,LPCSTR,WNDCLASSEX32A *);
-BOOL32     GetClassInfoEx32W(HINSTANCE32,LPCWSTR,WNDCLASSEX32W *);
-#define    GetClassInfoEx WINELIB_NAME_AW(GetClassInfoEx)
-LONG       GetClassLong16(HWND16,INT16);
-LONG       GetClassLong32A(HWND32,INT32);
-LONG       GetClassLong32W(HWND32,INT32);
-#define    GetClassLong WINELIB_NAME_AW(GetClassLong)
-INT16      GetClassName16(HWND16,LPSTR,INT16);
-INT32      GetClassName32A(HWND32,LPSTR,INT32);
-INT32      GetClassName32W(HWND32,LPWSTR,INT32);
-#define    GetClassName WINELIB_NAME_AW(GetClassName)
-WORD       GetClassWord16(HWND16,INT16);
-WORD       GetClassWord32(HWND32,INT32);
-#define    GetClassWord WINELIB_NAME(GetClassWord)
-void       GetClientRect16(HWND16,LPRECT16);
-void       GetClientRect32(HWND32,LPRECT32);
-#define    GetClientRect WINELIB_NAME(GetClientRect)
-HANDLE16   GetClipboardData16(UINT16);
-HANDLE32   GetClipboardData32(UINT32);
-#define    GetClipboardData WINELIB_NAME(GetClipboardData)
-INT16      GetClipboardFormatName16(UINT16,LPSTR,INT16);
-INT32      GetClipboardFormatName32A(UINT32,LPSTR,INT32);
-INT32      GetClipboardFormatName32W(UINT32,LPWSTR,INT32);
-#define    GetClipboardFormatName WINELIB_NAME_AW(GetClipboardFormatName)
-HWND16     GetClipboardOwner16(void);
-HWND32     GetClipboardOwner32(void);
-#define    GetClipboardOwner WINELIB_NAME(GetClipboardOwner)
-HWND16     GetClipboardViewer16(void);
-HWND32     GetClipboardViewer32(void);
-#define    GetClipboardViewer WINELIB_NAME(GetClipboardViewer)
-INT16      GetClipBox16(HDC16,LPRECT16);
-INT32      GetClipBox32(HDC32,LPRECT32);
-#define    GetClipBox WINELIB_NAME(GetClipBox)
-void       GetClipCursor16(LPRECT16);
-void       GetClipCursor32(LPRECT32);
-#define    GetClipCursor WINELIB_NAME(GetClipCursor)
-HRGN16     GetClipRgn16(HDC16);
-INT32      GetClipRgn32(HDC32,HRGN32);
-#define    GetClipRgn WINELIB_NAME(GetClipRgn)
-INT16      GetCommState16(INT16,LPDCB16);
-BOOL32     GetCommState32(INT32,LPDCB32);
-#define    GetCommState WINELIB_NAME(GetCommState)
-UINT16     GetCurrentDirectory16(UINT16,LPSTR);
-UINT32     GetCurrentDirectory32A(UINT32,LPSTR);
-UINT32     GetCurrentDirectory32W(UINT32,LPWSTR);
-#define    GetCurrentDirectory WINELIB_NAME_AW(GetCurrentDirectory)
-BOOL16     GetCurrentPositionEx16(HDC16,LPPOINT16);
-BOOL32     GetCurrentPositionEx32(HDC32,LPPOINT32);
-#define    GetCurrentPositionEx WINELIB_NAME(GetCurrentPositionEx)
-DWORD      GetCurrentTime16(void);
-#define    GetCurrentTime32() GetTickCount()
-#define    GetCurrentTime WINELIB_NAME(GetCurrentTime)
-HCURSOR16  GetCursor16(void);
-HCURSOR32  GetCursor32(void);
-#define    GetCursor WINELIB_NAME(GetCursor)
-void       GetCursorPos16(LPPOINT16);
-void       GetCursorPos32(LPPOINT32);
-#define    GetCursorPos WINELIB_NAME(GetCursorPos)
-HDC16      GetDC16(HWND16);
-HDC32      GetDC32(HWND32);
-#define    GetDC WINELIB_NAME(GetDC)
-HDC16      GetDCEx16(HWND16,HRGN16,DWORD);
-HDC32      GetDCEx32(HWND32,HRGN32,DWORD);
-#define    GetDCEx WINELIB_NAME(GetDCEx)
-HWND16     GetDesktopWindow16(void);
-HWND32     GetDesktopWindow32(void);
-#define    GetDesktopWindow WINELIB_NAME(GetDesktopWindow)
-INT16      GetDeviceCaps16(HDC16,INT16);
-INT32      GetDeviceCaps32(HDC32,INT32);
-#define    GetDeviceCaps WINELIB_NAME(GetDeviceCaps)
-INT16      GetDIBits16(HDC16,HBITMAP16,UINT16,UINT16,LPSTR,LPBITMAPINFO,UINT16);
-INT32      GetDIBits32(HDC32,HBITMAP32,UINT32,UINT32,LPSTR,LPBITMAPINFO,UINT32);
-#define    GetDIBits WINELIB_NAME(GetDIBits)
-BOOL16     GetDiskFreeSpace16(LPCSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
-BOOL32     GetDiskFreeSpace32A(LPCSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
-BOOL32     GetDiskFreeSpace32W(LPCWSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
-#define    GetDiskFreeSpace WINELIB_NAME_AW(GetDiskFreeSpace)
-INT16      GetDlgCtrlID16(HWND16);
-INT32      GetDlgCtrlID32(HWND32);
-#define    GetDlgCtrlID WINELIB_NAME(GetDlgCtrlID)
-HWND16     GetDlgItem16(HWND16,INT16);
-HWND32     GetDlgItem32(HWND32,INT32);
-#define    GetDlgItem WINELIB_NAME(GetDlgItem)
-UINT16     GetDlgItemInt16(HWND16,INT16,BOOL16*,BOOL16);
-UINT32     GetDlgItemInt32(HWND32,INT32,BOOL32*,BOOL32);
-#define    GetDlgItemInt WINELIB_NAME(GetDlgItemInt)
-INT16      GetDlgItemText16(HWND16,INT16,SEGPTR,UINT16);
-INT32      GetDlgItemText32A(HWND32,INT32,LPSTR,UINT32);
-INT32      GetDlgItemText32W(HWND32,INT32,LPWSTR,UINT32);
-#define    GetDlgItemText WINELIB_NAME_AW(GetDlgItemText)
-UINT16     GetDoubleClickTime16(void);
-UINT32     GetDoubleClickTime32(void);
-#define    GetDoubleClickTime WINELIB_NAME(GetDoubleClickTime)
-UINT16     GetDriveType16(UINT16); /* yes, the arguments differ */
-UINT32     GetDriveType32A(LPCSTR);
-UINT32     GetDriveType32W(LPCWSTR);
-#define    GetDriveType WINELIB_NAME_AW(GetDriveType)
-INT16      GetExpandedName16(LPCSTR,LPSTR);
-INT32      GetExpandedName32A(LPCSTR,LPSTR);
-INT32      GetExpandedName32W(LPCWSTR,LPWSTR);
-#define    GetExpandedName WINELIB_NAME_AW(GetExpandedName)
-DWORD      GetFileAttributes16(LPCSTR);
-DWORD      GetFileAttributes32A(LPCSTR);
-DWORD      GetFileAttributes32W(LPCWSTR);
-#define    GetFileAttributes WINELIB_NAME_AW(GetFileAttributes)
-DWORD      GetFileVersionInfoSize16(LPCSTR,LPDWORD);
-DWORD      GetFileVersionInfoSize32A(LPCSTR,LPDWORD);
-DWORD      GetFileVersionInfoSize32W(LPCWSTR,LPDWORD);
-#define    GetFileVersionInfoSize WINELIB_NAME_AW(GetFileVersionInfoSize)
-DWORD      GetFileVersionInfo16(LPCSTR,DWORD,DWORD,LPVOID);
-DWORD      GetFileVersionInfo32A(LPCSTR,DWORD,DWORD,LPVOID);
-DWORD      GetFileVersionInfo32W(LPCWSTR,DWORD,DWORD,LPVOID);
-#define    GetFileVersionInfo WINELIB_NAME_AW(GetFileVersionInfo)
-HWND16     GetFocus16(void);
-HWND32     GetFocus32(void);
-#define    GetFocus WINELIB_NAME(GetFocus)
-DWORD      GetFreeSpace16(UINT16);
-#define    GetFreeSpace32(w) (0x100000L)
-#define    GetFreeSpace WINELIB_NAME(GetFreeSpace)
-DWORD      GetGlyphOutLine16(HDC16,UINT16,UINT16,LPGLYPHMETRICS16,DWORD,LPVOID,const MAT2*);
-DWORD      GetGlyphOutLine32A(HDC32,UINT32,UINT32,LPGLYPHMETRICS32,DWORD,LPVOID,const MAT2*);
-DWORD      GetGlyphOutLine32W(HDC32,UINT32,UINT32,LPGLYPHMETRICS32,DWORD,LPVOID,const MAT2*);
-#define    GetGlyphOutLine WINELIB_NAME_AW(GetGlyphOutLine)
-BOOL16     GetInputState16(void);
-BOOL32     GetInputState32(void);
-#define    GetInputState WINELIB_NAME(GetInputState)
-UINT16     GetInternalWindowPos16(HWND16,LPRECT16,LPPOINT16);
-UINT32     GetInternalWindowPos32(HWND32,LPRECT32,LPPOINT32);
-#define    GetInternalWindowPos WINELIB_NAME(GetInternalWindowPos)
-INT16      GetKBCodePage16(void);
-UINT32     GetKBCodePage32(void);
-#define    GetKBCodePage WINELIB_NAME(GetKBCodePage)
-INT16      GetKerningPairs16(HDC16,INT16,LPKERNINGPAIR16);
-DWORD      GetKerningPairs32A(HDC32,DWORD,LPKERNINGPAIR32);
-DWORD      GetKerningPairs32W(HDC32,DWORD,LPKERNINGPAIR32);
-#define    GetKerningPairs WINELIB_NAME_AW(GetKerningPairs)
-INT16      GetKeyboardType16(INT16);
-INT32      GetKeyboardType32(INT32);
-#define    GetKeyboardType WINELIB_NAME(GetKeyboardType)
-INT16      GetKeyNameText16(LONG,LPSTR,INT16);
-INT32      GetKeyNameText32A(LONG,LPSTR,INT32);
-INT32      GetKeyNameText32W(LONG,LPWSTR,INT32);
-#define    GetKeyNameText WINELIB_NAME_AW(GetKeyNameText)
-WORD       GetKeyState16(INT16);
-WORD       GetKeyState32(INT32);
-#define    GetKeyState WINELIB_NAME(GetKeyState)
-HWND16     GetLastActivePopup16(HWND16);
-HWND32     GetLastActivePopup32(HWND32);
-#define    GetLastActivePopup WINELIB_NAME(GetLastActivePopup)
-UINT32     GetLogicalDriveStrings32A(UINT32,LPSTR);
-UINT32     GetLogicalDriveStrings32W(UINT32,LPWSTR);
-#define    GetLogicalDriveStrings WINELIB_NAME_AW(GetLogicalDriveStrings)
-INT16      GetLocaleInfo16(LCID,LCTYPE,LPSTR,INT16);
-INT32      GetLocaleInfo32A(LCID,LCTYPE,LPSTR,INT32);
-INT32      GetLocaleInfo32W(LCID,LCTYPE,LPWSTR,INT32);
-#define    GetLocaleInfo WINELIB_NAME_AW(GetLocaleInfo)
-INT16      GetMapMode16(HDC16);
-INT32      GetMapMode32(HDC32);
-#define    GetMapMode WINELIB_NAME(GetMapMode)
-HMENU16    GetMenu16(HWND16);
-HMENU32    GetMenu32(HWND32);
-#define    GetMenu WINELIB_NAME(GetMenu)
-INT16      GetMenuItemCount16(HMENU16);
-INT32      GetMenuItemCount32(HMENU32);
-#define    GetMenuItemCount WINELIB_NAME(GetMenuItemCount)
-UINT16     GetMenuItemID16(HMENU16,INT16);
-UINT32     GetMenuItemID32(HMENU32,INT32);
-#define    GetMenuItemID WINELIB_NAME(GetMenuItemID)
-UINT16     GetMenuState16(HMENU16,UINT16,UINT16);
-UINT32     GetMenuState32(HMENU32,UINT32,UINT32);
-#define    GetMenuState WINELIB_NAME(GetMenuState)
-INT16      GetMenuString16(HMENU16,UINT16,LPSTR,INT16,UINT16);
-INT32      GetMenuString32A(HMENU32,UINT32,LPSTR,INT32,UINT32);
-INT32      GetMenuString32W(HMENU32,UINT32,LPWSTR,INT32,UINT32);
-#define    GetMenuString WINELIB_NAME_AW(GetMenuString)
-BOOL16     GetMessage16(SEGPTR,HWND16,UINT16,UINT16);
-BOOL32     GetMessage32A(LPMSG32,HWND32,UINT32,UINT32);
-BOOL32     GetMessage32W(LPMSG32,HWND32,UINT32,UINT32);
-#define    GetMessage WINELIB_NAME_AW(GetMessage)
-HMETAFILE16 GetMetaFile16(LPCSTR);
-HMETAFILE32 GetMetaFile32A(LPCSTR);
-HMETAFILE32 GetMetaFile32W(LPCWSTR);
-#define    GetMetaFile WINELIB_NAME_AW(GetMetaFile)
-INT16      GetModuleFileName16(HINSTANCE16,LPSTR,INT16);
-DWORD      GetModuleFileName32A(HMODULE32,LPSTR,DWORD);
-DWORD      GetModuleFileName32W(HMODULE32,LPWSTR,DWORD);
-#define    GetModuleFileName WINELIB_NAME_AW(GetModuleFileName)
-HMODULE16  GetModuleHandle16(LPCSTR);
-HMODULE32  GetModuleHandle32A(LPCSTR);
-HMODULE32  GetModuleHandle32W(LPCSTR);
-#define    GetModuleHandle WINELIB_NAME_AW(GetModuleHandle)
-DWORD      GetNearestColor16(HDC16,DWORD);
-DWORD      GetNearestColor32(HDC32,DWORD);
-#define    GetNearestColor WINELIB_NAME(GetNearestColor)
-UINT16     GetNearestPaletteIndex16(HPALETTE16,COLORREF);
-UINT32     GetNearestPaletteIndex32(HPALETTE32,COLORREF);
-#define    GetNearestPaletteIndex WINELIB_NAME(GetNearestPaletteIndex)
-HWND16     GetNextDlgGroupItem16(HWND16,HWND16,BOOL16);
-HWND32     GetNextDlgGroupItem32(HWND32,HWND32,BOOL32);
-#define    GetNextDlgGroupItem WINELIB_NAME(GetNextDlgGroupItem)
-HWND16     GetNextDlgTabItem16(HWND16,HWND16,BOOL16);
-HWND32     GetNextDlgTabItem32(HWND32,HWND32,BOOL32);
-#define    GetNextDlgTabItem WINELIB_NAME(GetNextDlgTabItem)
-HWND16     GetNextWindow16(HWND16,WORD);
-#define    GetNextWindow32 GetWindow32
-#define    GetNextWindow WINELIB_NAME(GetNextWindow)
-INT16      GetObject16(HANDLE16,INT16,LPVOID);
-INT32      GetObject32A(HANDLE32,INT32,LPVOID);
-INT32      GetObject32W(HANDLE32,INT32,LPVOID);
-#define    GetObject WINELIB_NAME_AW(GetObject)
-HWND16     GetOpenClipboardWindow16(void);
-HWND32     GetOpenClipboardWindow32(void);
-#define    GetOpenClipboardWindow WINELIB_NAME(GetOpenClipboardWindow)
-UINT16     GetPaletteEntries16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
-UINT32     GetPaletteEntries32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
-#define    GetPaletteEntries WINELIB_NAME(GetPaletteEntries)
-HWND16     GetParent16(HWND16);
-HWND32     GetParent32(HWND32);
-#define    GetParent WINELIB_NAME(GetParent)
-COLORREF   GetPixel16(HDC16,INT16,INT16);
-COLORREF   GetPixel32(HDC32,INT32,INT32);
-#define    GetPixel WINELIB_NAME(GetPixel)
-INT16      GetPolyFillMode16(HDC16);
-INT32      GetPolyFillMode32(HDC32);
-#define    GetPolyFillMode WINELIB_NAME(GetPolyFillMode)
-INT16      GetPriorityClipboardFormat16(UINT16*,INT16);
-INT32      GetPriorityClipboardFormat32(UINT32*,INT32);
-#define    GetPriorityClipboardFormat WINELIB_NAME(GetPriorityClipboardFormat)
-UINT16     GetPrivateProfileInt16(LPCSTR,LPCSTR,INT16,LPCSTR);
-UINT32     GetPrivateProfileInt32A(LPCSTR,LPCSTR,INT32,LPCSTR);
-UINT32     GetPrivateProfileInt32W(LPCWSTR,LPCWSTR,INT32,LPCWSTR);
-#define    GetPrivateProfileInt WINELIB_NAME_AW(GetPrivateProfileInt)
-INT16      GetPrivateProfileString16(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT16,LPCSTR);
-INT32      GetPrivateProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT32,LPCSTR);
-INT32      GetPrivateProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,INT32,LPCWSTR);
-#define    GetPrivateProfileString WINELIB_NAME_AW(GetPrivateProfileString)
-FARPROC16  GetProcAddress16(HMODULE16,SEGPTR);
-FARPROC32  GetProcAddress32(HMODULE32,LPCSTR);
-#define    GetProcAddress WINELIB_NAME(GetProcAddress)
-UINT16     GetProfileInt16(LPCSTR,LPCSTR,INT16);
-UINT32     GetProfileInt32A(LPCSTR,LPCSTR,INT32);
-UINT32     GetProfileInt32W(LPCWSTR,LPCWSTR,INT32);
-#define    GetProfileInt WINELIB_NAME_AW(GetProfileInt)
-INT16      GetProfileString16(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT16);
-INT32      GetProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT32);
-INT32      GetProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,INT32);
-#define    GetProfileString WINELIB_NAME_AW(GetProfileString)
-HANDLE16   GetProp16(HWND16,LPCSTR);
-HANDLE32   GetProp32A(HWND32,LPCSTR);
-HANDLE32   GetProp32W(HWND32,LPCWSTR);
-#define    GetProp WINELIB_NAME_AW(GetProp)
-DWORD      GetQueueStatus16(UINT16);
-DWORD      GetQueueStatus32(UINT32);
-#define    GetQueueStatus WINELIB_NAME(GetQueueStatus)
-BOOL16     GetRasterizerCaps16(LPRASTERIZER_STATUS,UINT16);
-BOOL32     GetRasterizerCaps32(LPRASTERIZER_STATUS,UINT32);
-#define    GetRasterizerCaps WINELIB_NAME(GetRasterizerCaps)
-INT16      GetRelAbs16(HDC16);
-INT32      GetRelAbs32(HDC32);
-#define    GetRelAbs WINELIB_NAME(GetRelAbs)
-INT16      GetRgnBox16(HRGN16,LPRECT16);
-INT32      GetRgnBox32(HRGN32,LPRECT32);
-#define    GetRgnBox WINELIB_NAME(GetRgnBox)
-INT16      GetROP216(HDC16);
-INT32      GetROP232(HDC32);
-#define    GetROP2 WINELIB_NAME(GetROP2)
-BOOL16     GetScrollInfo16(HWND16,INT16,LPSCROLLINFO);
-BOOL32     GetScrollInfo32(HWND32,INT32,LPSCROLLINFO);
-#define    GetScrollInfo WINELIB_NAME(GetScrollInfo)
-INT16      GetScrollPos16(HWND16,INT16);
-INT32      GetScrollPos32(HWND32,INT32);
-#define    GetScrollPos WINELIB_NAME(GetScrollPos)
-BOOL16     GetScrollRange16(HWND16,INT16,LPINT16,LPINT16);
-BOOL32     GetScrollRange32(HWND32,INT32,LPINT32,LPINT32);
-#define    GetScrollRange WINELIB_NAME(GetScrollRange)
-HGDIOBJ16  GetStockObject16(INT16);
-HGDIOBJ32  GetStockObject32(INT32);
-#define    GetStockObject WINELIB_NAME(GetStockObject)
-INT16      GetStretchBltMode16(HDC16);
-INT32      GetStretchBltMode32(HDC32);
-#define    GetStretchBltMode WINELIB_NAME(GetStretchBltMode)
-BOOL16     GetStringType16(LCID,DWORD,LPCSTR,INT16,LPWORD);
-BOOL32     GetStringType32A(LCID,DWORD,LPCSTR,INT32,LPWORD);
-BOOL32     GetStringType32W(DWORD,LPCWSTR,INT32,LPWORD);
-#define    GetStringType WINELIB_NAME_AW(GetStringType)
-HMENU16    GetSubMenu16(HMENU16,INT16);
-HMENU32    GetSubMenu32(HMENU32,INT32);
-#define    GetSubMenu WINELIB_NAME(GetSubMenu)
-COLORREF   GetSysColor16(INT16);
-COLORREF   GetSysColor32(INT32);
-#define    GetSysColor WINELIB_NAME(GetSysColor)
-HBRUSH16   GetSysColorBrush16(INT16);
-HBRUSH32   GetSysColorBrush32(INT32);
-#define    GetSysColorBrush WINELIB_NAME(GetSysColorBrush)
-HWND16     GetSysModalWindow16(void);
-#define    GetSysModalWindow32() ((HWND32)0)
-#define    GetSysModalWindow WINELIB_NAME(GetSysModalWindow)
-UINT16     GetSystemDirectory16(LPSTR,UINT16);
-UINT32     GetSystemDirectory32A(LPSTR,UINT32);
-UINT32     GetSystemDirectory32W(LPWSTR,UINT32);
-#define    GetSystemDirectory WINELIB_NAME_AW(GetSystemDirectory)
-HMENU16    GetSystemMenu16(HWND16,BOOL16);
-HMENU32    GetSystemMenu32(HWND32,BOOL32);
-#define    GetSystemMenu WINELIB_NAME(GetSystemMenu)
-INT16      GetSystemMetrics16(INT16);
-INT32      GetSystemMetrics32(INT32);
-#define    GetSystemMetrics WINELIB_NAME(GetSystemMetrics)
-UINT16     GetSystemPaletteEntries16(HDC16,UINT16,UINT16,LPPALETTEENTRY);
-UINT32     GetSystemPaletteEntries32(HDC32,UINT32,UINT32,LPPALETTEENTRY);
-#define    GetSystemPaletteEntries WINELIB_NAME(GetSystemPaletteEntries)
-UINT16     GetSystemPaletteUse16(HDC16);
-UINT32     GetSystemPaletteUse32(HDC32);
-#define    GetSystemPaletteUse WINELIB_NAME(GetSystemPaletteUse)
-DWORD      GetTabbedTextExtent16(HDC16,LPCSTR,INT16,INT16,const INT16*);
-DWORD      GetTabbedTextExtent32A(HDC32,LPCSTR,INT32,INT32,const INT32*);
-DWORD      GetTabbedTextExtent32W(HDC32,LPCWSTR,INT32,INT32,const INT32*);
-#define    GetTabbedTextExtent WINELIB_NAME_AW(GetTabbedTextExtent)
-UINT16     GetTempFileName16(BYTE,LPCSTR,UINT16,LPSTR);
-UINT32     GetTempFileName32A(LPCSTR,LPCSTR,UINT32,LPSTR);
-UINT32     GetTempFileName32W(LPCWSTR,LPCWSTR,UINT32,LPWSTR);
-#define    GetTempFileName WINELIB_NAME_AW(GetTempFileName)
-UINT32     GetTempPath32A(UINT32,LPSTR);
-UINT32     GetTempPath32W(UINT32,LPWSTR);
-#define    GetTempPath WINELIB_NAME_AW(GetTempPath)
-UINT16     GetTextAlign16(HDC16);
-UINT32     GetTextAlign32(HDC32);
-#define    GetTextAlign WINELIB_NAME(GetTextAlign)
-INT16      GetTextCharacterExtra16(HDC16);
-INT32      GetTextCharacterExtra32(HDC32);
-#define    GetTextCharacterExtra WINELIB_NAME(GetTextCharacterExtra)
-COLORREF   GetTextColor16(HDC16);
-COLORREF   GetTextColor32(HDC32);
-#define    GetTextColor WINELIB_NAME(GetTextColor)
-BOOL16     GetTextExtentPoint16(HDC16,LPCSTR,INT16,LPSIZE16);
-BOOL32     GetTextExtentPoint32A(HDC32,LPCSTR,INT32,LPSIZE32);
-BOOL32     GetTextExtentPoint32W(HDC32,LPCWSTR,INT32,LPSIZE32);
-#define    GetTextExtentPoint WINELIB_NAME_AW(GetTextExtentPoint)
-INT16      GetTextFace16(HDC16,INT16,LPSTR);
-INT32      GetTextFace32A(HDC32,INT32,LPSTR);
-INT32      GetTextFace32W(HDC32,INT32,LPWSTR);
-#define    GetTextFace WINELIB_NAME_AW(GetTextFace)
-BOOL16     GetTextMetrics16(HDC16,LPTEXTMETRIC16);
-BOOL32     GetTextMetrics32A(HDC32,LPTEXTMETRIC32A);
-BOOL32     GetTextMetrics32W(HDC32,LPTEXTMETRIC32W);
-#define    GetTextMetrics WINELIB_NAME_AW(GetTextMetrics)
-LPINT16    GetThresholdEvent16(void);
-LPDWORD    GetThresholdEvent32(void);
-#define    GetThresholdEvent WINELIB_NAME(GetThresholdEvent)
-INT16      GetThresholdStatus16(void);
-DWORD      GetThresholdStatus32(void);
-#define    GetThresholdStatus WINELIB_NAME(GetThresholdStatus)
-HWND16     GetTopWindow16(HWND16);
-HWND32     GetTopWindow32(HWND32);
-#define    GetTopWindow WINELIB_NAME(GetTopWindow)
-BOOL16     GetUpdateRect16(HWND16,LPRECT16,BOOL16);
-BOOL32     GetUpdateRect32(HWND32,LPRECT32,BOOL32);
-#define    GetUpdateRect WINELIB_NAME(GetUpdateRect)
-INT16      GetUpdateRgn16(HWND16,HRGN16,BOOL16);
-INT32      GetUpdateRgn32(HWND32,HRGN32,BOOL32);
-#define    GetUpdateRgn WINELIB_NAME(GetUpdateRgn)
-LONG       GetVersion16(void);
-LONG       GetVersion32(void);
-#define    GetVersion WINELIB_NAME(GetVersion)
-BOOL16     GetViewportExtEx16(HDC16,LPPOINT16);
-BOOL32     GetViewportExtEx32(HDC32,LPPOINT32);
-#define    GetViewportExtEx WINELIB_NAME(GetViewportExtEx)
-BOOL16     GetViewportOrgEx16(HDC16,LPPOINT16);
-BOOL32     GetViewportOrgEx32(HDC32,LPPOINT32);
-#define    GetViewportOrgEx WINELIB_NAME(GetViewportOrgEx)
-BOOL32     GetVolumeInformation32A(LPCSTR,LPSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPSTR,DWORD);
-BOOL32     GetVolumeInformation32W(LPCWSTR,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR,DWORD);
-#define    GetVolumeInformation WINELIB_NAME_AW(GetVolumeInformation)
-HWND16     GetWindow16(HWND16,WORD);
-HWND32     GetWindow32(HWND32,WORD);
-#define    GetWindow WINELIB_NAME(GetWindow)
-HDC16      GetWindowDC16(HWND16);
-HDC32      GetWindowDC32(HWND32);
-#define    GetWindowDC WINELIB_NAME(GetWindowDC)
-BOOL16     GetWindowExtEx16(HDC16,LPPOINT16);
-BOOL32     GetWindowExtEx32(HDC32,LPPOINT32);
-#define    GetWindowExtEx WINELIB_NAME(GetWindowExtEx)
-LONG       GetWindowLong16(HWND16,INT16);
-LONG       GetWindowLong32A(HWND32,INT32);
-LONG       GetWindowLong32W(HWND32,INT32);
-#define    GetWindowLong WINELIB_NAME_AW(GetWindowLong)
-BOOL16     GetWindowOrgEx16(HDC16,LPPOINT16);
-BOOL32     GetWindowOrgEx32(HDC32,LPPOINT32);
-#define    GetWindowOrgEx WINELIB_NAME(GetWindowOrgEx)
-BOOL16     GetWindowPlacement16(HWND16,LPWINDOWPLACEMENT16);
-BOOL32     GetWindowPlacement32(HWND32,LPWINDOWPLACEMENT32);
-#define    GetWindowPlacement WINELIB_NAME(GetWindowPlacement)
-void       GetWindowRect16(HWND16,LPRECT16);
-void       GetWindowRect32(HWND32,LPRECT32);
-#define    GetWindowRect WINELIB_NAME(GetWindowRect)
-UINT16     GetWindowsDirectory16(LPSTR,UINT16);
-UINT32     GetWindowsDirectory32A(LPSTR,UINT32);
-UINT32     GetWindowsDirectory32W(LPWSTR,UINT32);
-#define    GetWindowsDirectory WINELIB_NAME_AW(GetWindowsDirectory)
-HTASK16    GetWindowTask16(HWND16);
-#define    GetWindowTask32(hwnd) ((HTASK32)GetWindowThreadProcessId(hwnd,NULL))
-#define    GetWindowTask WINELIB_NAME(GetWindowTask)
-INT16      GetWindowText16(HWND16,SEGPTR,INT16);
-INT32      GetWindowText32A(HWND32,LPSTR,INT32);
-INT32      GetWindowText32W(HWND32,LPWSTR,INT32);
-#define    GetWindowText WINELIB_NAME_AW(GetWindowText)
-INT16      GetWindowTextLength16(HWND16);
-INT32      GetWindowTextLength32A(HWND32);
-INT32      GetWindowTextLength32W(HWND32);
-#define    GetWindowTextLength WINELIB_NAME_AW(GetWindowTextLength)
-WORD       GetWindowWord16(HWND16,INT16);
-WORD       GetWindowWord32(HWND32,INT32);
-#define    GetWindowWord WINELIB_NAME(GetWindowWord)
-ATOM       GlobalAddAtom16(SEGPTR);
-ATOM       GlobalAddAtom32A(LPCSTR);
-ATOM       GlobalAddAtom32W(LPCWSTR);
-#define    GlobalAddAtom WINELIB_NAME_AW(GlobalAddAtom)
-HGLOBAL16  GlobalAlloc16(UINT16,DWORD);
-HGLOBAL32  GlobalAlloc32(UINT32,DWORD);
-#define    GlobalAlloc WINELIB_NAME(GlobalAlloc)
-DWORD      GlobalCompact16(DWORD);
-DWORD      GlobalCompact32(DWORD);
-#define    GlobalCompact WINELIB_NAME(GlobalCompact)
-UINT16     GlobalFlags16(HGLOBAL16);
-UINT32     GlobalFlags32(HGLOBAL32);
-#define    GlobalFlags WINELIB_NAME(GlobalFlags)
-ATOM       GlobalFindAtom16(SEGPTR);
-ATOM       GlobalFindAtom32A(LPCSTR);
-ATOM       GlobalFindAtom32W(LPCWSTR);
-#define    GlobalFindAtom WINELIB_NAME_AW(GlobalFindAtom)
-HGLOBAL16  GlobalFree16(HGLOBAL16);
-HGLOBAL32  GlobalFree32(HGLOBAL32);
-#define    GlobalFree WINELIB_NAME(GlobalFree)
-UINT16     GlobalGetAtomName16(ATOM,LPSTR,INT16);
-UINT32     GlobalGetAtomName32A(ATOM,LPSTR,INT32);
-UINT32     GlobalGetAtomName32W(ATOM,LPWSTR,INT32);
-#define    GlobalGetAtomName WINELIB_NAME_AW(GlobalGetAtomName)
-DWORD      GlobalHandle16(WORD);
-HGLOBAL32  GlobalHandle32(LPCVOID);
-#define    GlobalHandle WINELIB_NAME(GlobalHandle)
-VOID       GlobalFix16(HGLOBAL16);
-VOID       GlobalFix32(HGLOBAL32);
-#define    GlobalFix WINELIB_NAME(GlobalFix)
-LPVOID     GlobalLock16(HGLOBAL16);
-LPVOID     GlobalLock32(HGLOBAL32);
-#define    GlobalLock WINELIB_NAME(GlobalLock)
-HGLOBAL16  GlobalReAlloc16(HGLOBAL16,DWORD,UINT16);
-HGLOBAL32  GlobalReAlloc32(HGLOBAL32,DWORD,UINT32);
-#define    GlobalReAlloc WINELIB_NAME(GlobalReAlloc)
-DWORD      GlobalSize16(HGLOBAL16);
-DWORD      GlobalSize32(HGLOBAL32);
-#define    GlobalSize WINELIB_NAME(GlobalSize)
-VOID       GlobalUnfix16(HGLOBAL16);
-VOID       GlobalUnfix32(HGLOBAL32);
-#define    GlobalUnfix WINELIB_NAME(GlobalUnfix)
-BOOL16     GlobalUnlock16(HGLOBAL16);
-BOOL32     GlobalUnlock32(HGLOBAL32);
-#define    GlobalUnlock WINELIB_NAME(GlobalUnlock)
-BOOL16     GlobalUnWire16(HGLOBAL16);
-BOOL32     GlobalUnWire32(HGLOBAL32);
-#define    GlobalUnWire WINELIB_NAME(GlobalUnWire)
-SEGPTR     GlobalWire16(HGLOBAL16);
-LPVOID     GlobalWire32(HGLOBAL32);
-#define    GlobalWire WINELIB_NAME(GlobalWire)
-BOOL16     GrayString16(HDC16,HBRUSH16,GRAYSTRINGPROC16,LPARAM,
-                        INT16,INT16,INT16,INT16,INT16);
-BOOL32     GrayString32A(HDC32,HBRUSH32,GRAYSTRINGPROC32,LPARAM,
-                         INT32,INT32,INT32,INT32,INT32);
-BOOL32     GrayString32W(HDC32,HBRUSH32,GRAYSTRINGPROC32,LPARAM,
-                         INT32,INT32,INT32,INT32,INT32);
-#define    GrayString WINELIB_NAME_AW(GrayString)
-VOID       HideCaret16(HWND16);
-BOOL32     HideCaret32(HWND32);
-#define    HideCaret WINELIB_NAME(HideCaret)
-BOOL16     HiliteMenuItem16(HWND16,HMENU16,UINT16,UINT16);
-BOOL32     HiliteMenuItem32(HWND32,HMENU32,UINT32,UINT32);
-#define    HiliteMenuItem WINELIB_NAME(HiliteMenuItem)
-void       InflateRect16(LPRECT16,INT16,INT16);
-void       InflateRect32(LPRECT32,INT32,INT32);
-#define    InflateRect WINELIB_NAME(InflateRect)
-WORD       InitAtomTable16(WORD);
-BOOL32     InitAtomTable32(DWORD);
-#define    InitAtomTable WINELIB_NAME(InitAtomTable)
-BOOL16     InSendMessage16(void);
-BOOL32     InSendMessage32(void);
-#define    InSendMessage WINELIB_NAME(InSendMessage)
-BOOL16     InsertMenu16(HMENU16,UINT16,UINT16,UINT16,SEGPTR);
-BOOL32     InsertMenu32A(HMENU32,UINT32,UINT32,UINT32,LPCSTR);
-BOOL32     InsertMenu32W(HMENU32,UINT32,UINT32,UINT32,LPCWSTR);
-#define    InsertMenu WINELIB_NAME_AW(InsertMenu)
-INT16      IntersectClipRect16(HDC16,INT16,INT16,INT16,INT16);
-INT32      IntersectClipRect32(HDC32,INT32,INT32,INT32,INT32);
-#define    IntersectClipRect WINELIB_NAME(IntersectClipRect)
-BOOL16     IntersectRect16(LPRECT16,const RECT16*,const RECT16*);
-BOOL32     IntersectRect32(LPRECT32,const RECT32*,const RECT32*);
-#define    IntersectRect WINELIB_NAME(IntersectRect)
-void       InvalidateRect16(HWND16,const RECT16*,BOOL16);
-void       InvalidateRect32(HWND32,const RECT32*,BOOL32);
-#define    InvalidateRect WINELIB_NAME(InvalidateRect)
-void       InvalidateRgn16(HWND16,HRGN16,BOOL16);
-void       InvalidateRgn32(HWND32,HRGN32,BOOL32);
-#define    InvalidateRgn WINELIB_NAME(InvalidateRgn)
-void       InvertRect16(HDC16,const RECT16*);
-void       InvertRect32(HDC32,const RECT32*);
-#define    InvertRect WINELIB_NAME(InvertRect)
-BOOL16     InvertRgn16(HDC16,HRGN16);
-BOOL32     InvertRgn32(HDC32,HRGN32);
-#define    InvertRgn WINELIB_NAME(InvertRgn)
-BOOL16     IsBadCodePtr16(SEGPTR);
-BOOL32     IsBadCodePtr32(FARPROC32);
-#define    IsBadCodePtr WINELIB_NAME(IsBadCodePtr)
-BOOL16     IsBadHugeReadPtr16(SEGPTR,DWORD);
-BOOL32     IsBadHugeReadPtr32(LPCVOID,UINT32);
-#define    IsBadHugeReadPtr WINELIB_NAME(IsBadHugeReadPtr)
-BOOL16     IsBadHugeWritePtr16(SEGPTR,DWORD);
-BOOL32     IsBadHugeWritePtr32(LPVOID,UINT32);
-#define    IsBadHugeWritePtr WINELIB_NAME(IsBadHugeWritePtr)
-BOOL16     IsBadReadPtr16(SEGPTR,UINT16);
-BOOL32     IsBadReadPtr32(LPCVOID,UINT32);
-#define    IsBadReadPtr WINELIB_NAME(IsBadReadPtr)
-BOOL16     IsBadStringPtr16(SEGPTR,UINT16);
-BOOL32     IsBadStringPtr32A(LPCSTR,UINT32);
-BOOL32     IsBadStringPtr32W(LPCWSTR,UINT32);
-#define    IsBadStringPtr WINELIB_NAME_AW(IsBadStringPtr)
-BOOL16     IsBadWritePtr16(SEGPTR,UINT16);
-BOOL32     IsBadWritePtr32(LPVOID,UINT32);
-#define    IsBadWritePtr WINELIB_NAME(IsBadWritePtr)
-BOOL16     IsCharAlpha16(CHAR);
-BOOL32     IsCharAlpha32A(CHAR);
-BOOL32     IsCharAlpha32W(WCHAR);
-#define    IsCharAlpha WINELIB_NAME_AW(IsCharAlpha)
-BOOL16     IsCharAlphaNumeric16(CHAR);
-BOOL32     IsCharAlphaNumeric32A(CHAR);
-BOOL32     IsCharAlphaNumeric32W(WCHAR);
-#define    IsCharAlphaNumeric WINELIB_NAME_AW(IsCharAlphaNumeric)
-BOOL16     IsCharLower16(CHAR);
-BOOL32     IsCharLower32A(CHAR);
-BOOL32     IsCharLower32W(WCHAR);
-#define    IsCharLower WINELIB_NAME_AW(IsCharLower)
-BOOL16     IsCharUpper16(CHAR);
-BOOL32     IsCharUpper32A(CHAR);
-BOOL32     IsCharUpper32W(WCHAR);
-#define    IsCharUpper WINELIB_NAME_AW(IsCharUpper)
-BOOL16     IsChild16(HWND16,HWND16);
-BOOL32     IsChild32(HWND32,HWND32);
-#define    IsChild WINELIB_NAME(IsChild)
-BOOL16     IsClipboardFormatAvailable16(UINT16);
-BOOL32     IsClipboardFormatAvailable32(UINT32);
-#define    IsClipboardFormatAvailable WINELIB_NAME(IsClipboardFormatAvailable)
-BOOL16     IsDBCSLeadByte16(BYTE);
-BOOL32     IsDBCSLeadByte32(BYTE);
-#define    IsDBCSLeadByte WINELIB_NAME(IsDBCSLeadByte)
-BOOL16     IsDialogMessage16(HWND16,LPMSG16);
-BOOL32     IsDialogMessage32A(HWND32,LPMSG32);
-BOOL32     IsDialogMessage32W(HWND32,LPMSG32);
-#define    IsDialogMessage WINELIB_NAME(IsDialogMessage)
-UINT16     IsDlgButtonChecked16(HWND16,UINT16);
-UINT32     IsDlgButtonChecked32(HWND32,UINT32);
-#define    IsDlgButtonChecked WINELIB_NAME(IsDlgButtonChecked)
-BOOL16     IsIconic16(HWND16);
-BOOL32     IsIconic32(HWND32);
-#define    IsIconic WINELIB_NAME(IsIconic)
-BOOL16     IsMenu16(HMENU16);
-BOOL32     IsMenu32(HMENU32);
-#define    IsMenu WINELIB_NAME(IsMenu)
-BOOL16     IsRectEmpty16(const RECT16*);
-BOOL32     IsRectEmpty32(const RECT32*);
-#define    IsRectEmpty WINELIB_NAME(IsRectEmpty)
-BOOL16     IsWindow16(HWND16);
-BOOL32     IsWindow32(HWND32);
-#define    IsWindow WINELIB_NAME(IsWindow)
-BOOL16     IsWindowEnabled16(HWND16);
-BOOL32     IsWindowEnabled32(HWND32);
-#define    IsWindowEnabled WINELIB_NAME(IsWindowEnabled)
-BOOL16     IsWindowVisible16(HWND16);
-BOOL32     IsWindowVisible32(HWND32);
-#define    IsWindowVisible WINELIB_NAME(IsWindowVisible)
-BOOL16     IsZoomed16(HWND16);
-BOOL32     IsZoomed32(HWND32);
-#define    IsZoomed WINELIB_NAME(IsZoomed)
-BOOL16     KillSystemTimer16(HWND16,UINT16);
-BOOL32     KillSystemTimer32(HWND32,UINT32);
-#define    KillSystemTimer WINELIB_NAME(KillSystemTimer)
-BOOL16     KillTimer16(HWND16,UINT16);
-BOOL32     KillTimer32(HWND32,UINT32);
-#define    KillTimer WINELIB_NAME(KillTimer)
-HFILE16    LZOpenFile16(LPCSTR,LPOFSTRUCT,UINT16);
-HFILE32    LZOpenFile32A(LPCSTR,LPOFSTRUCT,UINT32);
-HFILE32    LZOpenFile32W(LPCWSTR,LPOFSTRUCT,UINT32);
-#define    LZOpenFile WINELIB_NAME_AW(LZOpenFile)
-INT16      LZRead16(HFILE16,LPVOID,UINT16); 
-INT32      LZRead32(HFILE32,LPVOID,UINT32); 
-#define    LZRead WINELIB_NAME(LZRead)
-INT16      LZStart16(void);
-INT32      LZStart32(void);
-#define    LZStart WINELIB_NAME(LZStart)
-VOID       LineDDA16(INT16,INT16,INT16,INT16,LINEDDAPROC16,LPARAM);
-BOOL32     LineDDA32(INT32,INT32,INT32,INT32,LINEDDAPROC32,LPARAM);
-#define    LineDDA WINELIB_NAME(LineDDA)
-BOOL16     LineTo16(HDC16,INT16,INT16);
-BOOL32     LineTo32(HDC32,INT32,INT32);
-#define    LineTo WINELIB_NAME(LineTo)
-HACCEL16   LoadAccelerators16(HINSTANCE16,SEGPTR);
-HACCEL32   LoadAccelerators32A(HINSTANCE32,LPCSTR);
-HACCEL32   LoadAccelerators32W(HINSTANCE32,LPCWSTR);
-#define    LoadAccelerators WINELIB_NAME_AW(LoadAccelerators)
-HBITMAP16  LoadBitmap16(HANDLE16,SEGPTR);
-HBITMAP32  LoadBitmap32A(HANDLE32,LPCSTR);
-HBITMAP32  LoadBitmap32W(HANDLE32,LPCWSTR);
-#define    LoadBitmap WINELIB_NAME(LoadBitmap)
-HCURSOR16  LoadCursor16(HINSTANCE16,SEGPTR);
-HCURSOR32  LoadCursor32A(HINSTANCE32,LPCSTR);
-HCURSOR32  LoadCursor32W(HINSTANCE32,LPCWSTR);
-#define    LoadCursor WINELIB_NAME_AW(LoadCursor)
-HICON16    LoadIcon16(HINSTANCE16,SEGPTR);
-HICON32    LoadIcon32A(HINSTANCE32,LPCSTR);
-HICON32    LoadIcon32W(HINSTANCE32,LPCWSTR);
-#define    LoadIcon WINELIB_NAME_AW(LoadIcon)
-HINSTANCE16 LoadLibrary16(LPCSTR);
-HINSTANCE32 LoadLibrary32A(LPCSTR);
-HINSTANCE32 LoadLibrary32W(LPCWSTR);
-#define    LoadLibrary WINELIB_NAME_AW(LoadLibrary)
-HMENU16    LoadMenu16(HINSTANCE16,SEGPTR);
-HMENU32    LoadMenu32A(HINSTANCE32,LPCSTR);
-HMENU32    LoadMenu32W(HINSTANCE32,LPCWSTR);
-#define    LoadMenu WINELIB_NAME_AW(LoadMenu)
-HMENU16    LoadMenuIndirect16(LPCVOID);
-HMENU32    LoadMenuIndirect32A(LPCVOID);
-HMENU32    LoadMenuIndirect32W(LPCVOID);
-#define    LoadMenuIndirect WINELIB_NAME_AW(LoadMenuIndirect)
-HINSTANCE16 LoadModule16(LPCSTR,LPVOID);
-DWORD      LoadModule32(LPCSTR,LPVOID);
-#define    LoadModule WINELIB_NAME(LoadModule)
-HGLOBAL16  LoadResource16(HINSTANCE16,HRSRC16);
-HGLOBAL32  LoadResource32(HINSTANCE32,HRSRC32);
-#define    LoadResource WINELIB_NAME(LoadResource)
-INT16      LoadString16(HINSTANCE16,UINT16,LPSTR,INT16);
-INT32      LoadString32A(HINSTANCE32,UINT32,LPSTR,INT32);
-INT32      LoadString32W(HINSTANCE32,UINT32,LPWSTR,INT32);
-#define    LoadString WINELIB_NAME_AW(LoadString)
-HLOCAL16   LocalAlloc16(UINT16,WORD);
-HLOCAL32   LocalAlloc32(UINT32,DWORD);
-#define    LocalAlloc WINELIB_NAME(LocalAlloc)
-UINT16     LocalCompact16(UINT16);
-UINT32     LocalCompact32(UINT32);
-#define    LocalCompact WINELIB_NAME(LocalCompact)
-UINT16     LocalFlags16(HLOCAL16);
-UINT32     LocalFlags32(HLOCAL32);
-#define    LocalFlags WINELIB_NAME(LocalFlags)
-HLOCAL16   LocalFree16(HLOCAL16);
-HLOCAL32   LocalFree32(HLOCAL32);
-#define    LocalFree WINELIB_NAME(LocalFree)
-HLOCAL16   LocalHandle16(WORD);
-HLOCAL32   LocalHandle32(LPCVOID);
-#define    LocalHandle WINELIB_NAME(LocalHandle)
-SEGPTR     LocalLock16(HLOCAL16);
-LPVOID     LocalLock32(HLOCAL32);
-#define    LocalLock WINELIB_NAME(LocalLock)
-HLOCAL16   LocalReAlloc16(HLOCAL16,WORD,UINT16);
-HLOCAL32   LocalReAlloc32(HLOCAL32,DWORD,UINT32);
-#define    LocalReAlloc WINELIB_NAME(LocalReAlloc)
-UINT16     LocalShrink16(HGLOBAL16,UINT16);
-UINT32     LocalShrink32(HGLOBAL32,UINT32);
-#define    LocalShrink WINELIB_NAME(LocalShrink)
-UINT16     LocalSize16(HLOCAL16);
-UINT32     LocalSize32(HLOCAL32);
-#define    LocalSize WINELIB_NAME(LocalSize)
-BOOL16     LocalUnlock16(HLOCAL16);
-BOOL32     LocalUnlock32(HLOCAL32);
-#define    LocalUnlock WINELIB_NAME(LocalUnlock)
-LPVOID     LockResource16(HGLOBAL16);
-LPVOID     LockResource32(HGLOBAL32);
-#define    LockResource WINELIB_NAME(LockResource)
-HGLOBAL16  LockSegment16(HGLOBAL16);
-#define    LockSegment32(handle) GlobalFix32((HANDLE32)(handle))
-#define    LockSegment WINELIB_NAME(LockSegment)
-BOOL16     LockWindowUpdate16(HWND16);
-BOOL32     LockWindowUpdate32(HWND32);
-#define    LockWindowUpdate WINELIB_NAME(LockWindowUpdate)
-BOOL16     LPtoDP16(HDC16,LPPOINT16,INT16);
-BOOL32     LPtoDP32(HDC32,LPPOINT32,INT32);
-#define    LPtoDP WINELIB_NAME(LPtoDP)
-void       LZClose16(HFILE16);
-void       LZClose32(HFILE32);
-#define    LZClose WINELIB_NAME(LZClose)
-LONG       LZCopy16(HFILE16,HFILE16);
-LONG       LZCopy32(HFILE32,HFILE32);
-#define    LZCopy WINELIB_NAME(LZCopy)
-HFILE16    LZInit16(HFILE16);
-HFILE32    LZInit32(HFILE32);
-#define    LZInit WINELIB_NAME(LZInit)
-LONG       LZSeek16(HFILE16,LONG,INT16);
-LONG       LZSeek32(HFILE32,LONG,INT32);
-#define    LZSeek WINELIB_NAME(LZSeek)
-UINT16     MapVirtualKey16(UINT16,UINT16);
-UINT32     MapVirtualKey32A(UINT32,UINT32);
-UINT32     MapVirtualKey32W(UINT32,UINT32);
-#define    MapVirtualKey WINELIB_NAME_AW(MapVirtualKey)
-FARPROC16  MakeProcInstance16(FARPROC16,HANDLE16);
-#define    MakeProcInstance32(proc,inst) (proc)
-#define    MakeProcInstance WINELIB_NAME(MakeProcInstance)
-void       MapDialogRect16(HWND16,LPRECT16);
-void       MapDialogRect32(HWND32,LPRECT32);
-#define    MapDialogRect WINELIB_NAME(MapDialogRect)
-void       MapWindowPoints16(HWND16,HWND16,LPPOINT16,UINT16);
-void       MapWindowPoints32(HWND32,HWND32,LPPOINT32,UINT32);
-#define    MapWindowPoints WINELIB_NAME(MapWindowPoints)
-VOID       MessageBeep16(UINT16);
-BOOL32     MessageBeep32(UINT32);
-#define    MessageBeep WINELIB_NAME(MessageBeep)
-INT16      MessageBox16(HWND16,LPCSTR,LPCSTR,UINT16);
-INT32      MessageBox32A(HWND32,LPCSTR,LPCSTR,UINT32);
-INT32      MessageBox32W(HWND32,LPCWSTR,LPCWSTR,UINT32);
-#define    MessageBox WINELIB_NAME_AW(MessageBox)
-BOOL16     ModifyMenu16(HMENU16,UINT16,UINT16,UINT16,SEGPTR);
-BOOL32     ModifyMenu32A(HMENU32,UINT32,UINT32,UINT32,LPCSTR);
-BOOL32     ModifyMenu32W(HMENU32,UINT32,UINT32,UINT32,LPCWSTR);
-#define    ModifyMenu WINELIB_NAME_AW(ModifyMenu)
-BOOL16     MoveToEx16(HDC16,INT16,INT16,LPPOINT16);
-BOOL32     MoveToEx32(HDC32,INT32,INT32,LPPOINT32);
-#define    MoveToEx WINELIB_NAME(MoveToEx)
-BOOL16     MoveWindow16(HWND16,INT16,INT16,INT16,INT16,BOOL16);
-BOOL32     MoveWindow32(HWND32,INT32,INT32,INT32,INT32,BOOL32);
-#define    MoveWindow WINELIB_NAME(MoveWindow)
-INT16      MulDiv16(INT16,INT16,INT16);
-INT32      MulDiv32(INT32,INT32,INT32);
-#define    MulDiv WINELIB_NAME(MulDiv)
-INT16      OemToAnsi16(LPCSTR,LPSTR);
-#define    OemToAnsi32A OemToChar32A
-#define    OemToAnsi32W OemToChar32W
-#define    OemToAnsi WINELIB_NAME_AW(OemToAnsi)
-VOID       OemToAnsiBuff16(LPCSTR,LPSTR,UINT16);
-#define    OemToAnsiBuff32A OemToCharBuff32A
-#define    OemToAnsiBuff32W OemToCharBuff32W
-#define    OemToAnsiBuff WINELIB_NAME_AW(OemToAnsiBuff)
-BOOL32     OemToChar32A(LPCSTR,LPSTR);
-BOOL32     OemToChar32W(LPCSTR,LPWSTR);
-#define    OemToChar WINELIB_NAME_AW(OemToChar)
-BOOL32     OemToCharBuff32A(LPCSTR,LPSTR,DWORD);
-BOOL32     OemToCharBuff32W(LPCSTR,LPWSTR,DWORD);
-#define    OemToCharBuff WINELIB_NAME_AW(OemToCharBuff)
-INT16      OffsetClipRgn16(HDC16,INT16,INT16);
-INT32      OffsetClipRgn32(HDC32,INT32,INT32);
-#define    OffsetClipRgn WINELIB_NAME(OffsetClipRgn)
-void       OffsetRect16(LPRECT16,INT16,INT16);
-void       OffsetRect32(LPRECT32,INT32,INT32);
-#define    OffsetRect WINELIB_NAME(OffsetRect)
-INT16      OffsetRgn16(HRGN16,INT16,INT16);
-INT32      OffsetRgn32(HRGN32,INT32,INT32);
-#define    OffsetRgn WINELIB_NAME(OffsetRgn)
-BOOL16     OffsetViewportOrgEx16(HDC16,INT16,INT16,LPPOINT16);
-BOOL32     OffsetViewportOrgEx32(HDC32,INT32,INT32,LPPOINT32);
-#define    OffsetViewportOrgEx WINELIB_NAME(OffsetViewportOrgEx)
-BOOL16     OffsetWindowOrgEx16(HDC16,INT16,INT16,LPPOINT16);
-BOOL32     OffsetWindowOrgEx32(HDC32,INT32,INT32,LPPOINT32);
-#define    OffsetWindowOrgEx WINELIB_NAME(OffsetWindowOrgEx)
-BOOL16     OpenClipboard16(HWND16);
-BOOL32     OpenClipboard32(HWND32);
-#define    OpenClipboard WINELIB_NAME(OpenClipboard)
-HFILE16    OpenFile16(LPCSTR,OFSTRUCT*,UINT16);
-HFILE32    OpenFile32(LPCSTR,OFSTRUCT*,UINT32);
-#define    OpenFile WINELIB_NAME(OpenFile)
-BOOL16     OpenIcon16(HWND16);
-BOOL32     OpenIcon32(HWND32);
-#define    OpenIcon WINELIB_NAME(OpenIcon)
-INT16      OpenSound16(void);
-VOID       OpenSound32(void);
-#define    OpenSound WINELIB_NAME(OpenSound)
-VOID       OutputDebugString16(LPCSTR);
-VOID       OutputDebugString32A(LPCSTR);
-VOID       OutputDebugString32W(LPCWSTR);
-#define    OutputDebugString WINELIB_NAME_AW(OutputDebugString)
-BOOL16     PaintRgn16(HDC16,HRGN16);
-BOOL32     PaintRgn32(HDC32,HRGN32);
-#define    PaintRgn WINELIB_NAME(PaintRgn)
-BOOL16     PatBlt16(HDC16,INT16,INT16,INT16,INT16,DWORD);
-BOOL32     PatBlt32(HDC32,INT32,INT32,INT32,INT32,DWORD);
-#define    PatBlt WINELIB_NAME(PatBlt)
-BOOL16     PeekMessage16(LPMSG16,HWND16,UINT16,UINT16,UINT16);
-BOOL32     PeekMessage32A(LPMSG32,HWND32,UINT32,UINT32,UINT32);
-BOOL32     PeekMessage32W(LPMSG32,HWND32,UINT32,UINT32,UINT32);
-#define    PeekMessage WINELIB_NAME_AW(PeekMessage)
-BOOL16     Pie16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
-BOOL32     Pie32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
-#define    Pie WINELIB_NAME(Pie)
-BOOL16     PlayMetaFile16(HDC16,HMETAFILE16);
-BOOL32     PlayMetaFile32(HDC32,HMETAFILE32);
-#define    PlayMetaFile WINELIB_NAME(PlayMetaFile)
-VOID       PlayMetaFileRecord16(HDC16,LPHANDLETABLE16,LPMETARECORD,UINT16);
-BOOL32     PlayMetaFileRecord32(HDC32,LPHANDLETABLE32,LPMETARECORD,UINT32);
-#define    PlayMetaFileRecord WINELIB_NAME(PlayMetaFileRecord)
-BOOL16     PolyPolygon16(HDC16,LPPOINT16,LPINT16,UINT16);
-BOOL32     PolyPolygon32(HDC32,LPPOINT32,LPINT32,UINT32);
-#define    PolyPolygon WINELIB_NAME(PolyPolygon)
-BOOL16     Polygon16(HDC16,LPPOINT16,INT16);
-BOOL32     Polygon32(HDC32,LPPOINT32,INT32);
-#define    Polygon WINELIB_NAME(Polygon)
-BOOL16     Polyline16(HDC16,LPPOINT16,INT16);
-BOOL32     Polyline32(HDC32,LPPOINT32,INT32);
-#define    Polyline WINELIB_NAME(Polyline)
-BOOL16     PostAppMessage16(HTASK16,UINT16,WPARAM16,LPARAM);
-#define    PostAppMessage32A(thread,msg,wparam,lparam) \
-           PostThreadMessage32A((DWORD)(thread),msg,wparam,lparam)
-#define    PostAppMessage32W(thread,msg,wparam,lparam) \
-           PostThreadMessage32W((DWORD)(thread),msg,wparam,lparam)
-#define    PostAppMessage WINELIB_NAME_AW(PostAppMessage)
-BOOL16     PostMessage16(HWND16,UINT16,WPARAM16,LPARAM);
-BOOL32     PostMessage32A(HWND32,UINT32,WPARAM32,LPARAM);
-BOOL32     PostMessage32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define    PostMessage WINELIB_NAME_AW(PostMessage)
-void       PostQuitMessage16(INT16);
-void       PostQuitMessage32(INT32);
-#define    PostQuitMessage WINELIB_NAME(PostQuitMessage)
-BOOL16     PtInRect16(const RECT16*,POINT16);
-BOOL32     PtInRect32(const RECT32*,POINT32);
-#define    PtInRect WINELIB_NAME(PtInRect)
-BOOL16     PtInRegion16(HRGN16,INT16,INT16);
-BOOL32     PtInRegion32(HRGN32,INT32,INT32);
-#define    PtInRegion WINELIB_NAME(PtInRegion)
-BOOL16     PtVisible16(HDC16,INT16,INT16);
-BOOL32     PtVisible32(HDC32,INT32,INT32);
-#define    PtVisible WINELIB_NAME(PtVisible)
-UINT16     RealizePalette16(HDC16);
-UINT32     RealizePalette32(HDC32);
-#define    RealizePalette WINELIB_NAME(RealizePalette)
-BOOL16     Rectangle16(HDC16,INT16,INT16,INT16,INT16);
-BOOL32     Rectangle32(HDC32,INT32,INT32,INT32,INT32);
-#define    Rectangle WINELIB_NAME(Rectangle)
-BOOL16     RectInRegion16(HRGN16,const RECT16 *);
-BOOL32     RectInRegion32(HRGN32,const RECT32 *);
-#define    RectInRegion WINELIB_NAME(RectInRegion)
-BOOL16     RectVisible16(HDC16,LPRECT16);
-BOOL32     RectVisible32(HDC32,LPRECT32);
-#define    RectVisible WINELIB_NAME(RectVisible)
-BOOL16     RedrawWindow16(HWND16,const RECT16*,HRGN16,UINT16);
-BOOL32     RedrawWindow32(HWND32,const RECT32*,HRGN32,UINT32);
-#define    RedrawWindow WINELIB_NAME(RedrawWindow)
-DWORD      RegCreateKey16(HKEY,LPCSTR,LPHKEY);
-DWORD      RegCreateKey32A(HKEY,LPCSTR,LPHKEY);
-DWORD      RegCreateKey32W(HKEY,LPCWSTR,LPHKEY);
-#define    RegCreateKey WINELIB_NAME_AW(RegCreateKey)
-DWORD      RegDeleteKey16(HKEY,LPCSTR);
-DWORD      RegDeleteKey32A(HKEY,LPCSTR);
-DWORD      RegDeleteKey32W(HKEY,LPWSTR);
-#define    RegDeleteKey WINELIB_NAME_AW(RegDeleteKey)
-DWORD      RegDeleteValue16(HKEY,LPSTR);
-DWORD      RegDeleteValue32A(HKEY,LPSTR);
-DWORD      RegDeleteValue32W(HKEY,LPWSTR);
-#define    RegDeleteValue WINELIB_NAME_AW(RegDeleteValue)
-DWORD      RegEnumKey16(HKEY,DWORD,LPSTR,DWORD);
-DWORD      RegEnumKey32A(HKEY,DWORD,LPSTR,DWORD);
-DWORD      RegEnumKey32W(HKEY,DWORD,LPWSTR,DWORD);
-#define    RegEnumKey WINELIB_NAME_AW(RegEnumKey)
-DWORD      RegEnumValue16(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-DWORD      RegEnumValue32A(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-DWORD      RegEnumValue32W(HKEY,DWORD,LPWSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-#define    RegEnumValue WINELIB_NAME_AW(RegEnumValue)
-ATOM       RegisterClass16(const WNDCLASS16*);
-ATOM       RegisterClass32A(const WNDCLASS32A *);
-ATOM       RegisterClass32W(const WNDCLASS32W *);
-#define    RegisterClass WINELIB_NAME_AW(RegisterClass)
-ATOM       RegisterClassEx16(const WNDCLASSEX16*);
-ATOM       RegisterClassEx32A(const WNDCLASSEX32A *);
-ATOM       RegisterClassEx32W(const WNDCLASSEX32W *);
-#define    RegisterClassEx WINELIB_NAME_AW(RegisterClassEx)
-UINT16     RegisterClipboardFormat16(LPCSTR);
-UINT32     RegisterClipboardFormat32A(LPCSTR);
-UINT32     RegisterClipboardFormat32W(LPCWSTR);
-#define    RegisterClipboardFormat WINELIB_NAME_AW(RegisterClipboardFormat)
-WORD       RegisterWindowMessage16(SEGPTR);
-WORD       RegisterWindowMessage32A(LPCSTR);
-WORD       RegisterWindowMessage32W(LPCWSTR);
-#define    RegisterWindowMessage WINELIB_NAME_AW(RegisterWindowMessage)
-DWORD      RegOpenKey16(HKEY,LPCSTR,LPHKEY);
-DWORD      RegOpenKey32A(HKEY,LPCSTR,LPHKEY);
-DWORD      RegOpenKey32W(HKEY,LPCWSTR,LPHKEY);
-#define    RegOpenKey WINELIB_NAME_AW(RegOpenKey)
-DWORD      RegQueryValue16(HKEY,LPSTR,LPSTR,LPDWORD);
-DWORD      RegQueryValue32A(HKEY,LPSTR,LPSTR,LPDWORD);
-DWORD      RegQueryValue32W(HKEY,LPWSTR,LPWSTR,LPDWORD);
-#define    RegQueryValue WINELIB_NAME_AW(RegQueryValue)
-DWORD      RegQueryValueEx16(HKEY,LPSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-DWORD      RegQueryValueEx32A(HKEY,LPSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-DWORD      RegQueryValueEx32W(HKEY,LPWSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
-#define    RegQueryValueEx WINELIB_NAME_AW(RegQueryValueEx)
-DWORD      RegSetValue16(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
-DWORD      RegSetValue32A(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
-DWORD      RegSetValue32W(HKEY,LPCWSTR,DWORD,LPCWSTR,DWORD);
-#define    RegSetValue WINELIB_NAME_AW(RegSetValue)
-DWORD      RegSetValueEx16(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD);
-DWORD      RegSetValueEx32A(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD);
-DWORD      RegSetValueEx32W(HKEY,LPWSTR,DWORD,DWORD,LPBYTE,DWORD);
-#define    RegSetValueEx WINELIB_NAME_AW(RegSetValueEx)
-INT16      ReleaseDC16(HWND16,HDC16);
-INT32      ReleaseDC32(HWND32,HDC32);
-#define    ReleaseDC WINELIB_NAME(ReleaseDC)
-BOOL16     RemoveDirectory16(LPCSTR);
-BOOL32     RemoveDirectory32A(LPCSTR);
-BOOL32     RemoveDirectory32W(LPCWSTR);
-#define    RemoveDirectory WINELIB_NAME_AW(RemoveDirectory)
-BOOL16     RemoveFontResource16(SEGPTR);
-BOOL32     RemoveFontResource32A(LPCSTR);
-BOOL32     RemoveFontResource32W(LPCWSTR);
-#define    RemoveFontResource WINELIB_NAME_AW(RemoveFontResource)
-BOOL16     RemoveMenu16(HMENU16,UINT16,UINT16);
-BOOL32     RemoveMenu32(HMENU32,UINT32,UINT32);
-#define    RemoveMenu WINELIB_NAME(RemoveMenu)
-HANDLE16   RemoveProp16(HWND16,LPCSTR);
-HANDLE32   RemoveProp32A(HWND32,LPCSTR);
-HANDLE32   RemoveProp32W(HWND32,LPCWSTR);
-#define    RemoveProp WINELIB_NAME_AW(RemoveProp)
-VOID       ReplyMessage16(LRESULT);
-BOOL32     ReplyMessage32(LRESULT);
-#define    ReplyMessage WINELIB_NAME(ReplyMessage)
-HDC16      ResetDC16(HDC16,const DEVMODE16 *);
-HDC32      ResetDC32A(HDC32,const DEVMODE32A *);
-HDC32      ResetDC32W(HDC32,const DEVMODE32W *);
-#define    ResetDC WINELIB_NAME_AW(ResetDC)
-BOOL16     ResizePalette16(HPALETTE16,UINT16);
-BOOL32     ResizePalette32(HPALETTE32,UINT32);
-#define    ResizePalette WINELIB_NAME(ResizePalette)
-BOOL16     RestoreDC16(HDC16,INT16);
-BOOL32     RestoreDC32(HDC32,INT32);
-#define    RestoreDC WINELIB_NAME(RestoreDC)
-BOOL16     RoundRect16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16);
-BOOL32     RoundRect32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32);
-#define    RoundRect WINELIB_NAME(RoundRect)
-INT16      SaveDC16(HDC16);
-INT32      SaveDC32(HDC32);
-#define    SaveDC WINELIB_NAME(SaveDC)
-BOOL16     ScaleViewportExtEx16(HDC16,INT16,INT16,INT16,INT16,LPSIZE16);
-BOOL32     ScaleViewportExtEx32(HDC32,INT32,INT32,INT32,INT32,LPSIZE32);
-#define    ScaleViewportExtEx WINELIB_NAME(ScaleViewportExtEx)
-BOOL16     ScaleWindowExtEx16(HDC16,INT16,INT16,INT16,INT16,LPSIZE16);
-BOOL32     ScaleWindowExtEx32(HDC32,INT32,INT32,INT32,INT32,LPSIZE32);
-#define    ScaleWindowExtEx WINELIB_NAME(ScaleWindowExtEx)
-void       ScreenToClient16(HWND16,LPPOINT16);
-void       ScreenToClient32(HWND32,LPPOINT32);
-#define    ScreenToClient WINELIB_NAME(ScreenToClient)
-VOID       ScrollChildren16(HWND16,UINT16,WPARAM16,LPARAM);
-VOID       ScrollChildren32(HWND32,UINT32,WPARAM32,LPARAM);
-#define    ScrollChildren WINELIB_NAME(ScrollChildren)
-BOOL16     ScrollDC16(HDC16,INT16,INT16,const RECT16*,const RECT16*,
+#define     CreateDialogIndirect WINELIB_NAME_AW(CreateDialogIndirect)
+HWND16      WINAPI CreateDialogIndirectParam16(HINSTANCE16,LPCVOID,HWND16,
+                                               DLGPROC16,LPARAM);
+HWND32      WINAPI CreateDialogIndirectParam32A(HINSTANCE32,LPCVOID,HWND32,
+                                                DLGPROC32,LPARAM);
+HWND32      WINAPI CreateDialogIndirectParam32W(HINSTANCE32,LPCVOID,HWND32,
+                                                DLGPROC32,LPARAM);
+#define     CreateDialogIndirectParam WINELIB_NAME_AW(CreateDialogIndirectParam)
+HWND16      WINAPI CreateDialogParam16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16,LPARAM);
+HWND32      WINAPI CreateDialogParam32A(HINSTANCE32,LPCSTR,HWND32,DLGPROC32,LPARAM);
+HWND32      WINAPI CreateDialogParam32W(HINSTANCE32,LPCWSTR,HWND32,DLGPROC32,LPARAM);
+#define     CreateDialogParam WINELIB_NAME_AW(CreateDialogParam)
+HBITMAP16   WINAPI CreateDIBitmap16(HDC16,const BITMAPINFOHEADER*,DWORD,
+                                    LPCVOID,const BITMAPINFO*,UINT16);
+HBITMAP32   WINAPI CreateDIBitmap32(HDC32,const BITMAPINFOHEADER*,DWORD,
+                                    LPCVOID,const BITMAPINFO*,UINT32);
+#define     CreateDIBitmap WINELIB_NAME(CreateDIBitmap)
+HBRUSH16    WINAPI CreateDIBPatternBrush16(HGLOBAL16,UINT16);
+HBRUSH32    WINAPI CreateDIBPatternBrush32(HGLOBAL32,UINT32);
+#define     CreateDIBPatternBrush WINELIB_NAME(CreateDIBPatternBrush)
+BOOL16      WINAPI CreateDirectory16(LPCSTR,LPVOID);
+BOOL32      WINAPI CreateDirectory32A(LPCSTR,LPSECURITY_ATTRIBUTES);
+BOOL32      WINAPI CreateDirectory32W(LPCWSTR,LPSECURITY_ATTRIBUTES);
+#define     CreateDirectory WINELIB_NAME_AW(CreateDirectory)
+BOOL32      WINAPI CreateDirectoryEx32A(LPCSTR,LPCSTR,LPSECURITY_ATTRIBUTES);
+BOOL32      WINAPI CreateDirectoryEx32W(LPCWSTR,LPCWSTR,LPSECURITY_ATTRIBUTES);
+#define     CreateDirectoryEx WINELIB_NAME_AW(CreateDirectoryEx)
+HBITMAP16   WINAPI CreateDiscardableBitmap16(HDC16,INT16,INT16);
+HBITMAP32   WINAPI CreateDiscardableBitmap32(HDC32,INT32,INT32);
+#define     CreateDiscardableBitmap WINELIB_NAME(CreateDiscardableBitmap)
+HRGN16      WINAPI CreateEllipticRgn16(INT16,INT16,INT16,INT16);
+HRGN32      WINAPI CreateEllipticRgn32(INT32,INT32,INT32,INT32);
+#define     CreateEllipticRgn WINELIB_NAME(CreateEllipticRgn)
+HRGN16      WINAPI CreateEllipticRgnIndirect16(const RECT16 *);
+HRGN32      WINAPI CreateEllipticRgnIndirect32(const RECT32 *);
+#define     CreateEllipticRgnIndirect WINELIB_NAME(CreateEllipticRgnIndirect)
+HFONT16     WINAPI CreateFont16(INT16,INT16,INT16,INT16,INT16,BYTE,BYTE,BYTE,
+                                BYTE,BYTE,BYTE,BYTE,BYTE,LPCSTR);
+HFONT32     WINAPI CreateFont32A(INT32,INT32,INT32,INT32,INT32,DWORD,DWORD,
+                                 DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCSTR);
+HFONT32     WINAPI CreateFont32W(INT32,INT32,INT32,INT32,INT32,DWORD,DWORD,
+                                 DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR);
+#define     CreateFont WINELIB_NAME_AW(CreateFont)
+HFONT16     WINAPI CreateFontIndirect16(const LOGFONT16*);
+HFONT32     WINAPI CreateFontIndirect32A(const LOGFONT32A*);
+HFONT32     WINAPI CreateFontIndirect32W(const LOGFONT32W*);
+#define     CreateFontIndirect WINELIB_NAME_AW(CreateFontIndirect)
+HBRUSH16    WINAPI CreateHatchBrush16(INT16,COLORREF);
+HBRUSH32    WINAPI CreateHatchBrush32(INT32,COLORREF);
+#define     CreateHatchBrush WINELIB_NAME(CreateHatchBrush)
+HDC16       WINAPI CreateIC16(LPCSTR,LPCSTR,LPCSTR,const DEVMODE16*);
+HDC32       WINAPI CreateIC32A(LPCSTR,LPCSTR,LPCSTR,const DEVMODE32A*);
+HDC32       WINAPI CreateIC32W(LPCWSTR,LPCWSTR,LPCWSTR,const DEVMODE32W*);
+#define     CreateIC WINELIB_NAME_AW(CreateIC)
+HICON16     WINAPI CreateIcon16(HINSTANCE16,INT16,INT16,BYTE,BYTE,LPCVOID,LPCVOID);
+HICON32     WINAPI CreateIcon32(HINSTANCE32,INT32,INT32,BYTE,BYTE,LPCVOID,LPCVOID);
+#define     CreateIcon WINELIB_NAME(CreateIcon)
+HMENU16     WINAPI CreateMenu16(void);
+HMENU32     WINAPI CreateMenu32(void);
+#define     CreateMenu WINELIB_NAME(CreateMenu)
+HDC16       WINAPI CreateMetaFile16(LPCSTR);
+HDC32       WINAPI CreateMetaFile32A(LPCSTR);
+HDC32       WINAPI CreateMetaFile32W(LPCWSTR);
+#define     CreateMetaFile WINELIB_NAME_AW(CreateMetaFile)
+HPALETTE16  WINAPI CreatePalette16(const LOGPALETTE*);
+HPALETTE32  WINAPI CreatePalette32(const LOGPALETTE*);
+#define     CreatePalette WINELIB_NAME(CreatePalette)
+HBRUSH16    WINAPI CreatePatternBrush16(HBITMAP16);
+HBRUSH32    WINAPI CreatePatternBrush32(HBITMAP32);
+#define     CreatePatternBrush WINELIB_NAME(CreatePatternBrush)
+HPEN16      WINAPI CreatePen16(INT16,INT16,COLORREF);
+HPEN32      WINAPI CreatePen32(INT32,INT32,COLORREF);
+#define     CreatePen WINELIB_NAME(CreatePen)
+HPEN16      WINAPI CreatePenIndirect16(const LOGPEN16*);
+HPEN32      WINAPI CreatePenIndirect32(const LOGPEN32*);
+#define     CreatePenIndirect WINELIB_NAME(CreatePenIndirect)
+HRGN16      WINAPI CreatePolyPolygonRgn16(const POINT16*,const INT16*,INT16,INT16);
+HRGN32      WINAPI CreatePolyPolygonRgn32(const POINT32*,const INT32*,INT32,INT32);
+#define     CreatePolyPolygonRgn WINELIB_NAME(CreatePolyPolygonRgn)
+HRGN16      WINAPI CreatePolygonRgn16(const POINT16*,INT16,INT16);
+HRGN32      WINAPI CreatePolygonRgn32(const POINT32*,INT32,INT32);
+#define     CreatePolygonRgn WINELIB_NAME(CreatePolygonRgn)
+HMENU16     WINAPI CreatePopupMenu16(void);
+HMENU32     WINAPI CreatePopupMenu32(void);
+#define     CreatePopupMenu WINELIB_NAME(CreatePopupMenu)
+HRGN16      WINAPI CreateRectRgn16(INT16,INT16,INT16,INT16);
+HRGN32      WINAPI CreateRectRgn32(INT32,INT32,INT32,INT32);
+#define     CreateRectRgn WINELIB_NAME(CreateRectRgn)
+HRGN16      WINAPI CreateRectRgnIndirect16(const RECT16*);
+HRGN32      WINAPI CreateRectRgnIndirect32(const RECT32*);
+#define     CreateRectRgnIndirect WINELIB_NAME(CreateRectRgnIndirect)
+HRGN16      WINAPI CreateRoundRectRgn16(INT16,INT16,INT16,INT16,INT16,INT16);
+HRGN32      WINAPI CreateRoundRectRgn32(INT32,INT32,INT32,INT32,INT32,INT32);
+#define     CreateRoundRectRgn WINELIB_NAME(CreateRoundRectRgn)
+BOOL16      WINAPI CreateScalableFontResource16(UINT16,LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI CreateScalableFontResource32A(DWORD,LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI CreateScalableFontResource32W(DWORD,LPCWSTR,LPCWSTR,LPCWSTR);
+#define     CreateScalableFontResource WINELIB_NAME_AW(CreateScalableFontResource)
+HBRUSH16    WINAPI CreateSolidBrush16(COLORREF);
+HBRUSH32    WINAPI CreateSolidBrush32(COLORREF);
+#define     CreateSolidBrush WINELIB_NAME(CreateSolidBrush)
+HWND16      WINAPI CreateWindow16(LPCSTR,LPCSTR,DWORD,INT16,INT16,INT16,INT16,
+                                  HWND16,HMENU16,HINSTANCE16,LPVOID);
+#define     CreateWindow32A(className,titleName,style,x,y,width,height,\
+                            parent,menu,instance,param) \
+            CreateWindowEx32A(0,className,titleName,style,x,y,width,height,\
+                              parent,menu,instance,param)
+#define     CreateWindow32W(className,titleName,style,x,y,width,height,\
+                            parent,menu,instance,param) \
+            CreateWindowEx32W(0,className,titleName,style,x,y,width,height,\
+                              parent,menu,instance,param)
+#define     CreateWindow WINELIB_NAME_AW(CreateWindow)
+HWND16      WINAPI CreateWindowEx16(DWORD,LPCSTR,LPCSTR,DWORD,INT16,INT16,
+                                INT16,INT16,HWND16,HMENU16,HINSTANCE16,LPVOID);
+HWND32      WINAPI CreateWindowEx32A(DWORD,LPCSTR,LPCSTR,DWORD,INT32,INT32,
+                                INT32,INT32,HWND32,HMENU32,HINSTANCE32,LPVOID);
+HWND32      WINAPI CreateWindowEx32W(DWORD,LPCWSTR,LPCWSTR,DWORD,INT32,INT32,
+                                INT32,INT32,HWND32,HMENU32,HINSTANCE32,LPVOID);
+#define     CreateWindowEx WINELIB_NAME_AW(CreateWindowEx)
+LRESULT     WINAPI DefDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI DefDlgProc32A(HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI DefDlgProc32W(HWND32,UINT32,WPARAM32,LPARAM);
+#define     DefDlgProc WINELIB_NAME_AW(DefDlgProc)
+HDWP16      WINAPI DeferWindowPos16(HDWP16,HWND16,HWND16,INT16,INT16,INT16,INT16,UINT16);
+HDWP32      WINAPI DeferWindowPos32(HDWP32,HWND32,HWND32,INT32,INT32,INT32,INT32,UINT32);
+#define     DeferWindowPos WINELIB_NAME(DeferWindowPos)
+LRESULT     WINAPI DefFrameProc16(HWND16,HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI DefFrameProc32A(HWND32,HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI DefFrameProc32W(HWND32,HWND32,UINT32,WPARAM32,LPARAM);
+#define     DefFrameProc WINELIB_NAME_AW(DefFrameProc)
+LRESULT     WINAPI DefHookProc16(INT16,WPARAM16,LPARAM,HHOOK*);
+#define     DefHookProc32(code,wparam,lparam,phhook) \
+            CallNextHookEx32(*(phhook),code,wparam,lparam)
+#define     DefHookProc WINELIB_NAME(DefHookProc)
+LRESULT     WINAPI DefMDIChildProc16(HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI DefMDIChildProc32A(HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI DefMDIChildProc32W(HWND32,UINT32,WPARAM32,LPARAM);
+#define     DefMDIChildProc WINELIB_NAME_AW(DefMDIChildProc)
+LRESULT     WINAPI DefWindowProc16(HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI DefWindowProc32A(HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI DefWindowProc32W(HWND32,UINT32,WPARAM32,LPARAM);
+#define     DefWindowProc WINELIB_NAME_AW(DefWindowProc)
+ATOM        WINAPI DeleteAtom16(ATOM);
+ATOM        WINAPI DeleteAtom32(ATOM);
+#define     DeleteAtom WINELIB_NAME(DeleteAtom)
+BOOL16      WINAPI DeleteDC16(HDC16);
+BOOL32      WINAPI DeleteDC32(HDC32);
+#define     DeleteDC WINELIB_NAME(DeleteDC)
+BOOL16      WINAPI DeleteFile16(LPCSTR);
+BOOL32      WINAPI DeleteFile32A(LPCSTR);
+BOOL32      WINAPI DeleteFile32W(LPCWSTR);
+#define     DeleteFile WINELIB_NAME_AW(DeleteFile)
+BOOL16      WINAPI DeleteMenu16(HMENU16,UINT16,UINT16);
+BOOL32      WINAPI DeleteMenu32(HMENU32,UINT32,UINT32);
+#define     DeleteMenu WINELIB_NAME(DeleteMenu)
+BOOL16      WINAPI DeleteMetaFile16(HMETAFILE16);
+BOOL32      WINAPI DeleteMetaFile32(HMETAFILE32);
+#define     DeleteMetaFile WINELIB_NAME(DeleteMetaFile)
+BOOL16      WINAPI DeleteObject16(HGDIOBJ16);
+BOOL32      WINAPI DeleteObject32(HGDIOBJ32);
+#define     DeleteObject WINELIB_NAME(DeleteObject)
+VOID        WINAPI DestroyCaret16(void);
+BOOL32      WINAPI DestroyCaret32(void);
+#define     DestroyCaret WINELIB_NAME(DestroyCaret)
+BOOL16      WINAPI DestroyCursor16(HCURSOR16);
+BOOL32      WINAPI DestroyCursor32(HCURSOR32);
+#define     DestroyCursor WINELIB_NAME(DestroyCursor)
+BOOL16      WINAPI DestroyIcon16(HICON16);
+BOOL32      WINAPI DestroyIcon32(HICON32);
+#define     DestroyIcon WINELIB_NAME(DestroyIcon)
+BOOL16      WINAPI DestroyMenu16(HMENU16);
+BOOL32      WINAPI DestroyMenu32(HMENU32);
+#define     DestroyMenu WINELIB_NAME(DestroyMenu)
+BOOL16      WINAPI DestroyWindow16(HWND16);
+BOOL32      WINAPI DestroyWindow32(HWND32);
+#define     DestroyWindow WINELIB_NAME(DestroyWindow)
+INT16       WINAPI DialogBox16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16);
+#define     DialogBox32A(inst,template,owner,func) \
+            DialogBoxParam32A(inst,template,owner,func,0)
+#define     DialogBox32W(inst,template,owner,func) \
+            DialogBoxParam32W(inst,template,owner,func,0)
+#define     DialogBox WINELIB_NAME_AW(DialogBox)
+INT16       WINAPI DialogBoxIndirect16(HINSTANCE16,HANDLE16,HWND16,DLGPROC16);
+#define     DialogBoxIndirect32A(inst,template,owner,func) \
+            DialogBoxIndirectParam32A(inst,template,owner,func,0)
+#define     DialogBoxIndirect32W(inst,template,owner,func) \
+            DialogBoxIndirectParam32W(inst,template,owner,func,0)
+#define     DialogBoxIndirect WINELIB_NAME_AW(DialogBoxIndirect)
+INT16       WINAPI DialogBoxIndirectParam16(HINSTANCE16,HANDLE16,HWND16,DLGPROC16,LPARAM);
+INT32       WINAPI DialogBoxIndirectParam32A(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
+INT32       WINAPI DialogBoxIndirectParam32W(HINSTANCE32,LPCVOID,HWND32,DLGPROC32,LPARAM);
+#define     DialogBoxIndirectParam WINELIB_NAME_AW(DialogBoxIndirectParam)
+INT16       WINAPI DialogBoxParam16(HINSTANCE16,SEGPTR,HWND16,DLGPROC16,LPARAM);
+INT32       WINAPI DialogBoxParam32A(HINSTANCE32,LPCSTR,HWND32,DLGPROC32,LPARAM);
+INT32       WINAPI DialogBoxParam32W(HINSTANCE32,LPCWSTR,HWND32,DLGPROC32,LPARAM);
+#define     DialogBoxParam WINELIB_NAME_AW(DialogBoxParam)
+LONG        WINAPI DispatchMessage16(const MSG16*);
+LONG        WINAPI DispatchMessage32A(const MSG32*);
+LONG        WINAPI DispatchMessage32W(const MSG32*);
+#define     DispatchMessage WINELIB_NAME_AW(DispatchMessage)
+INT16       WINAPI DlgDirList16(HWND16,LPSTR,INT16,INT16,UINT16);
+INT32       WINAPI DlgDirList32A(HWND32,LPSTR,INT32,INT32,UINT32);
+INT32       WINAPI DlgDirList32W(HWND32,LPWSTR,INT32,INT32,UINT32);
+#define     DlgDirList WINELIB_NAME_AW(DlgDirList)
+INT16       WINAPI DlgDirListComboBox16(HWND16,LPSTR,INT16,INT16,UINT16);
+INT32       WINAPI DlgDirListComboBox32A(HWND32,LPSTR,INT32,INT32,UINT32);
+INT32       WINAPI DlgDirListComboBox32W(HWND32,LPWSTR,INT32,INT32,UINT32);
+#define     DlgDirListComboBox WINELIB_NAME_AW(DlgDirListComboBox)
+BOOL16      WINAPI DlgDirSelectComboBoxEx16(HWND16,LPSTR,INT16,INT16);
+BOOL32      WINAPI DlgDirSelectComboBoxEx32A(HWND32,LPSTR,INT32,INT32);
+BOOL32      WINAPI DlgDirSelectComboBoxEx32W(HWND32,LPWSTR,INT32,INT32);
+#define     DlgDirSelectComboBoxEx WINELIB_NAME_AW(DlgDirSelectComboBoxEx)
+BOOL16      WINAPI DlgDirSelectEx16(HWND16,LPSTR,INT16,INT16);
+BOOL32      WINAPI DlgDirSelectEx32A(HWND32,LPSTR,INT32,INT32);
+BOOL32      WINAPI DlgDirSelectEx32W(HWND32,LPWSTR,INT32,INT32);
+#define     DlgDirSelectEx WINELIB_NAME_AW(DlgDirSelectEx)
+BOOL16      WINAPI DPtoLP16(HDC16,LPPOINT16,INT16);
+BOOL32      WINAPI DPtoLP32(HDC32,LPPOINT32,INT32);
+#define     DPtoLP WINELIB_NAME(DPtoLP)
+BOOL16      WINAPI DragDetect16(HWND16,POINT16);
+BOOL32      WINAPI DragDetect32(HWND32,POINT32);
+#define     DragDetect WINELIB_NAME(DragDetect)
+DWORD       WINAPI DragObject16(HWND16,HWND16,UINT16,HANDLE16,WORD,HCURSOR16);
+DWORD       WINAPI DragObject32(HWND32,HWND32,UINT32,DWORD,HCURSOR32);
+#define     DragObject WINELIB_NAME(DragObject)
+BOOL16      WINAPI DrawEdge16(HDC16,LPRECT16,UINT16,UINT16);
+BOOL32      WINAPI DrawEdge32(HDC32,LPRECT32,UINT32,UINT32);
+#define     DrawEdge WINELIB_NAME(DrawEdge)
+void        WINAPI DrawFocusRect16(HDC16,const RECT16*);
+void        WINAPI DrawFocusRect32(HDC32,const RECT32*);
+#define     DrawFocusRect WINELIB_NAME(DrawFocusRect)
+BOOL16      WINAPI DrawFrameControl16(HDC16,LPRECT16,UINT16,UINT16);
+BOOL32      WINAPI DrawFrameControl32(HDC32,LPRECT32,UINT32,UINT32);
+#define     DrawFrameControl WINELIB_NAME(DrawFrameControl)
+BOOL16      WINAPI DrawIcon16(HDC16,INT16,INT16,HICON16);
+BOOL32      WINAPI DrawIcon32(HDC32,INT32,INT32,HICON32);
+#define     DrawIcon WINELIB_NAME(DrawIcon)
+VOID        WINAPI DrawMenuBar16(HWND16);
+BOOL32      WINAPI DrawMenuBar32(HWND32);
+#define     DrawMenuBar WINELIB_NAME(DrawMenuBar)
+INT16       WINAPI DrawText16(HDC16,LPCSTR,INT16,LPRECT16,UINT16);
+INT32       WINAPI DrawText32A(HDC32,LPCSTR,INT32,LPRECT32,UINT32);
+INT32       WINAPI DrawText32W(HDC32,LPCWSTR,INT32,LPRECT32,UINT32);
+#define     DrawText WINELIB_NAME_AW(DrawText)
+BOOL16      WINAPI Ellipse16(HDC16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI Ellipse32(HDC32,INT32,INT32,INT32,INT32);
+#define     Ellipse WINELIB_NAME(Ellipse)
+BOOL16      WINAPI EmptyClipboard16(void);
+BOOL32      WINAPI EmptyClipboard32(void);
+#define     EmptyClipboard WINELIB_NAME(EmptyClipboard)
+BOOL16      WINAPI EnableMenuItem16(HMENU16,UINT16,UINT16);
+BOOL32      WINAPI EnableMenuItem32(HMENU32,UINT32,UINT32);
+#define     EnableMenuItem WINELIB_NAME(EnableMenuItem)
+BOOL16      WINAPI EnableScrollBar16(HWND16,INT16,UINT16);
+BOOL32      WINAPI EnableScrollBar32(HWND32,INT32,UINT32);
+#define     EnableScrollBar WINELIB_NAME(EnableScrollBar)
+BOOL16      WINAPI EnableWindow16(HWND16,BOOL16);
+BOOL32      WINAPI EnableWindow32(HWND32,BOOL32);
+#define     EnableWindow WINELIB_NAME(EnableWindow)
+BOOL16      WINAPI EndDeferWindowPos16(HDWP16);
+BOOL32      WINAPI EndDeferWindowPos32(HDWP32);
+#define     EndDeferWindowPos WINELIB_NAME(EndDeferWindowPos)
+BOOL16      WINAPI EndDialog16(HWND16,INT16);
+BOOL32      WINAPI EndDialog32(HWND32,INT32);
+#define     EndDialog WINELIB_NAME(EndDialog)
+INT16       WINAPI EndDoc16(HDC16);
+INT32       WINAPI EndDoc32(HDC32);
+#define     EndDoc WINELIB_NAME(EndDoc)
+BOOL16      WINAPI EndPaint16(HWND16,const PAINTSTRUCT16*);
+BOOL32      WINAPI EndPaint32(HWND32,const PAINTSTRUCT32*);
+#define     EndPaint WINELIB_NAME(EndPaint)
+BOOL16      WINAPI EnumChildWindows16(HWND16,WNDENUMPROC16,LPARAM);
+BOOL32      WINAPI EnumChildWindows32(HWND32,WNDENUMPROC32,LPARAM);
+#define     EnumChildWindows WINELIB_NAME(EnumChildWindows)
+UINT16      WINAPI EnumClipboardFormats16(UINT16);
+UINT32      WINAPI EnumClipboardFormats32(UINT32);
+#define     EnumClipboardFormats WINELIB_NAME(EnumClipboardFormats)
+INT16       WINAPI EnumFontFamilies16(HDC16,LPCSTR,FONTENUMPROC16,LPARAM);
+INT32       WINAPI EnumFontFamilies32A(HDC32,LPCSTR,FONTENUMPROC32A,LPARAM);
+INT32       WINAPI EnumFontFamilies32W(HDC32,LPCWSTR,FONTENUMPROC32W,LPARAM);
+#define     EnumFontFamilies WINELIB_NAME_AW(EnumFontFamilies)
+INT16       WINAPI EnumFontFamiliesEx16(HDC16,LPLOGFONT16,FONTENUMPROCEX16,LPARAM,DWORD);
+INT32       WINAPI EnumFontFamiliesEx32A(HDC32,LPLOGFONT32A,FONTENUMPROCEX32A,LPARAM,DWORD);
+INT32       WINAPI EnumFontFamiliesEx32W(HDC32,LPLOGFONT32W,FONTENUMPROCEX32W,LPARAM,DWORD);
+#define     EnumFontFamiliesEx WINELIB_NAME_AW(EnumFontFamiliesEx)
+INT16       WINAPI EnumFonts16(HDC16,LPCSTR,FONTENUMPROC16,LPARAM);
+INT32       WINAPI EnumFonts32A(HDC32,LPCSTR,FONTENUMPROC32A,LPARAM);
+INT32       WINAPI EnumFonts32W(HDC32,LPCWSTR,FONTENUMPROC32W,LPARAM);
+#define     EnumFonts WINELIB_NAME_AW(EnumFonts)
+BOOL16      WINAPI EnumMetaFile16(HDC16,HMETAFILE16,MFENUMPROC16,LPARAM);
+BOOL32      WINAPI EnumMetaFile32(HDC32,HMETAFILE32,MFENUMPROC32,LPARAM);
+#define     EnumMetaFile WINELIB_NAME(EnumMetaFile)
+INT16       WINAPI EnumObjects16(HDC16,INT16,GOBJENUMPROC16,LPARAM);
+INT32       WINAPI EnumObjects32(HDC32,INT32,GOBJENUMPROC32,LPARAM);
+#define     EnumObjects WINELIB_NAME(EnumObjects)
+INT16       WINAPI EnumProps16(HWND16,PROPENUMPROC16);
+INT32       WINAPI EnumProps32A(HWND32,PROPENUMPROC32A);
+INT32       WINAPI EnumProps32W(HWND32,PROPENUMPROC32W);
+#define     EnumProps WINELIB_NAME_AW(EnumProps)
+BOOL16      WINAPI EnumTaskWindows16(HTASK16,WNDENUMPROC16,LPARAM);
+#define     EnumTaskWindows32(handle,proc,lparam) \
+            EnumThreadWindows(handle,proc,lparam)
+#define     EnumTaskWindows WINELIB_NAME(EnumTaskWindows)
+BOOL16      WINAPI EnumWindows16(WNDENUMPROC16,LPARAM);
+BOOL32      WINAPI EnumWindows32(WNDENUMPROC32,LPARAM);
+#define     EnumWindows WINELIB_NAME(EnumWindows)
+BOOL16      WINAPI EqualRect16(const RECT16*,const RECT16*);
+BOOL32      WINAPI EqualRect32(const RECT32*,const RECT32*);
+#define     EqualRect WINELIB_NAME(EqualRect)
+BOOL16      WINAPI EqualRgn16(HRGN16,HRGN16);
+BOOL32      WINAPI EqualRgn32(HRGN32,HRGN32);
+#define     EqualRgn WINELIB_NAME(EqualRgn)
+INT16       WINAPI Escape16(HDC16,INT16,INT16,SEGPTR,SEGPTR);
+INT32       WINAPI Escape32(HDC32,INT32,INT32,LPVOID,LPVOID);
+#define     Escape WINELIB_NAME(Escape)
+LONG        WINAPI EscapeCommFunction16(UINT16,UINT16);
+BOOL32      WINAPI EscapeCommFunction32(INT32,UINT32);
+#define     EscapeCommFunction WINELIB_NAME(EscapeCommFunction)
+INT16       WINAPI ExcludeClipRect16(HDC16,INT16,INT16,INT16,INT16);
+INT32       WINAPI ExcludeClipRect32(HDC32,INT32,INT32,INT32,INT32);
+#define     ExcludeClipRect WINELIB_NAME(ExcludeClipRect)
+INT16       WINAPI ExcludeUpdateRgn16(HDC16,HWND16);
+INT32       WINAPI ExcludeUpdateRgn32(HDC32,HWND32);
+#define     ExcludeUpdateRgn WINELIB_NAME(ExcludeUpdateRgn)
+BOOL16      WINAPI ExitWindows16(DWORD,UINT16);
+#define     ExitWindows32(a,b) ExitWindowsEx(EWX_LOGOFF,0xffffffff)
+#define     ExitWindows WINELIB_NAME(ExitWindows)
+BOOL16      WINAPI ExtFloodFill16(HDC16,INT16,INT16,COLORREF,UINT16);
+BOOL32      WINAPI ExtFloodFill32(HDC32,INT32,INT32,COLORREF,UINT32);
+#define     ExtFloodFill WINELIB_NAME(ExtFloodFill)
+HICON16     WINAPI ExtractIcon16(HINSTANCE16,LPCSTR,UINT16);
+HICON32     WINAPI ExtractIcon32A(HINSTANCE32,LPCSTR,UINT32);
+HICON32     WINAPI ExtractIcon32W(HINSTANCE32,LPCWSTR,UINT32);
+#define     ExtractIcon WINELIB_NAME_AW(ExtractIcon)
+BOOL16      WINAPI ExtTextOut16(HDC16,INT16,INT16,UINT16,const RECT16*,
+                                LPCSTR,UINT16,const INT16*);
+BOOL32      WINAPI ExtTextOut32A(HDC32,INT32,INT32,UINT32,const RECT32*,
+                                 LPCSTR,UINT32,const INT32*);
+BOOL32      WINAPI ExtTextOut32W(HDC32,INT32,INT32,UINT32,const RECT32*,
+                                 LPCWSTR,UINT32,const INT32*);
+#define     ExtTextOut WINELIB_NAME_AW(ExtTextOut)
+void        WINAPI FatalAppExit16(UINT16,LPCSTR);
+void        WINAPI FatalAppExit32A(UINT32,LPCSTR);
+void        WINAPI FatalAppExit32W(UINT32,LPCWSTR);
+#define     FatalAppExit WINELIB_NAME_AW(FatalAppExit)
+INT16       WINAPI FillRect16(HDC16,const RECT16*,HBRUSH16);
+INT32       WINAPI FillRect32(HDC32,const RECT32*,HBRUSH32);
+#define     FillRect WINELIB_NAME(FillRect)
+BOOL16      WINAPI FillRgn16(HDC16,HRGN16,HBRUSH16);
+BOOL32      WINAPI FillRgn32(HDC32,HRGN32,HBRUSH32);
+#define     FillRgn WINELIB_NAME(FillRgn)
+ATOM        WINAPI FindAtom16(SEGPTR);
+ATOM        WINAPI FindAtom32A(LPCSTR);
+ATOM        WINAPI FindAtom32W(LPCWSTR);
+#define     FindAtom WINELIB_NAME_AW(FindAtom)
+BOOL16      WINAPI FindClose16(HANDLE16);
+BOOL32      WINAPI FindClose32(HANDLE32);
+#define     FindClose WINELIB_NAME(FindClose)
+HINSTANCE16 WINAPI FindExecutable16(LPCSTR,LPCSTR,LPSTR);
+HINSTANCE32 WINAPI FindExecutable32A(LPCSTR,LPCSTR,LPSTR);
+HINSTANCE32 WINAPI FindExecutable32W(LPCWSTR,LPCWSTR,LPWSTR);
+#define     FindExecutable WINELIB_NAME_AW(FindExecutable)
+HANDLE16    WINAPI FindFirstFile16(LPCSTR,LPWIN32_FIND_DATA32A);
+HANDLE32    WINAPI FindFirstFile32A(LPCSTR,LPWIN32_FIND_DATA32A);
+HANDLE32    WINAPI FindFirstFile32W(LPCWSTR,LPWIN32_FIND_DATA32W);
+#define     FindFirst WINELIB_NAME_AW(FindFirst)
+BOOL16      WINAPI FindNextFile16(HANDLE16,LPWIN32_FIND_DATA32A);
+BOOL32      WINAPI FindNextFile32A(HANDLE32,LPWIN32_FIND_DATA32A);
+BOOL32      WINAPI FindNextFile32W(HANDLE32,LPWIN32_FIND_DATA32W);
+#define     FindNext WINELIB_NAME_AW(FindNext)
+HRSRC16     WINAPI FindResource16(HINSTANCE16,SEGPTR,SEGPTR);
+HRSRC32     WINAPI FindResource32A(HINSTANCE32,LPCSTR,LPCSTR);
+HRSRC32     WINAPI FindResource32W(HINSTANCE32,LPCWSTR,LPCWSTR);
+#define     FindResource WINELIB_NAME_AW(FindResource)
+HWND16      WINAPI FindWindow16(SEGPTR,LPCSTR);
+HWND32      WINAPI FindWindow32A(LPCSTR,LPCSTR);
+HWND32      WINAPI FindWindow32W(LPCWSTR,LPCWSTR);
+#define     FindWindow WINELIB_NAME_AW(FindWindow)
+HWND16      WINAPI FindWindowEx16(HWND16,HWND16,SEGPTR,LPCSTR);
+HWND32      WINAPI FindWindowEx32A(HWND32,HWND32,LPCSTR,LPCSTR);
+HWND32      WINAPI FindWindowEx32W(HWND32,HWND32,LPCWSTR,LPCWSTR);
+#define     FindWindowEx WINELIB_NAME_AW(FindWindowEx)
+BOOL16      WINAPI FlashWindow16(HWND16,BOOL16);
+BOOL32      WINAPI FlashWindow32(HWND32,BOOL32);
+#define     FlashWindow WINELIB_NAME(FlashWindow)
+BOOL16      WINAPI FloodFill16(HDC16,INT16,INT16,COLORREF);
+BOOL32      WINAPI FloodFill32(HDC32,INT32,INT32,COLORREF);
+#define     FloodFill WINELIB_NAME(FloodFill)
+INT16       WINAPI FrameRect16(HDC16,const RECT16*,HBRUSH16);
+INT32       WINAPI FrameRect32(HDC32,const RECT32*,HBRUSH32);
+#define     FrameRect WINELIB_NAME(FrameRect)
+BOOL16      WINAPI FrameRgn16(HDC16,HRGN16,HBRUSH16,INT16,INT16);
+BOOL32      WINAPI FrameRgn32(HDC32,HRGN32,HBRUSH32,INT32,INT32);
+#define     FrameRgn WINELIB_NAME(FrameRgn)
+VOID        WINAPI FreeLibrary16(HINSTANCE16);
+BOOL32      WINAPI FreeLibrary32(HMODULE32);
+#define     FreeLibrary WINELIB_NAME(FreeLibrary)
+BOOL16      WINAPI FreeModule16(HMODULE16);
+#define     FreeModule32(handle) FreeLibrary32(handle)
+#define     FreeModule WINELIB_NAME(FreeModule)
+void        WINAPI FreeProcInstance16(FARPROC16);
+#define     FreeProcInstance32(proc) /*nothing*/
+#define     FreeProcInstance WINELIB_NAME(FreeProcInstance)
+BOOL16      WINAPI FreeResource16(HGLOBAL16);
+BOOL32      WINAPI FreeResource32(HGLOBAL32);
+#define     FreeResource WINELIB_NAME(FreeResource)
+HWND16      WINAPI GetActiveWindow16(void);
+HWND32      WINAPI GetActiveWindow32(void);
+#define     GetActiveWindow WINELIB_NAME(GetActiveWindow)
+DWORD       WINAPI GetAppCompatFlags16(HTASK16);
+DWORD       WINAPI GetAppCompatFlags32(HTASK32);
+#define     GetAppCompatFlags WINELIB_NAME(GetAppCompatFlags)
+WORD        WINAPI GetAsyncKeyState16(INT16);
+WORD        WINAPI GetAsyncKeyState32(INT32);
+#define     GetAsyncKeyState WINELIB_NAME(GetAsyncKeyState)
+UINT16      WINAPI GetAtomName16(ATOM,LPSTR,INT16);
+UINT32      WINAPI GetAtomName32A(ATOM,LPSTR,INT32);
+UINT32      WINAPI GetAtomName32W(ATOM,LPWSTR,INT32);
+#define     GetAtomName WINELIB_NAME_AW(GetAtomName)
+LONG        WINAPI GetBitmapBits16(HBITMAP16,LONG,LPVOID);
+LONG        WINAPI GetBitmapBits32(HBITMAP32,LONG,LPVOID);
+#define     GetBitmapBits WINELIB_NAME(GetBitmapBits)
+BOOL16      WINAPI GetBitmapDimensionEx16(HBITMAP16,LPSIZE16);
+BOOL32      WINAPI GetBitmapDimensionEx32(HBITMAP32,LPSIZE32);
+#define     GetBitmapDimensionEx WINELIB_NAME(GetBitmapDimensionEx)
+BOOL16      WINAPI GetBrushOrgEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetBrushOrgEx32(HDC32,LPPOINT32);
+#define     GetBrushOrgEx WINELIB_NAME(GetBrushOrgEx)
+COLORREF    WINAPI GetBkColor16(HDC16);
+COLORREF    WINAPI GetBkColor32(HDC32);
+#define     GetBkColor WINELIB_NAME(GetBkColor)
+INT16       WINAPI GetBkMode16(HDC16);
+INT32       WINAPI GetBkMode32(HDC32);
+#define     GetBkMode WINELIB_NAME(GetBkMode)
+HWND16      WINAPI GetCapture16(void);
+HWND32      WINAPI GetCapture32(void);
+#define     GetCapture WINELIB_NAME(GetCapture)
+UINT16      WINAPI GetCaretBlinkTime16(void);
+UINT32      WINAPI GetCaretBlinkTime32(void);
+#define     GetCaretBlinkTime WINELIB_NAME(GetCaretBlinkTime)
+VOID        WINAPI GetCaretPos16(LPPOINT16);
+BOOL32      WINAPI GetCaretPos32(LPPOINT32);
+#define     GetCaretPos WINELIB_NAME(GetCaretPos)
+BOOL16      WINAPI GetCharABCWidths16(HDC16,UINT16,UINT16,LPABC16);
+BOOL32      WINAPI GetCharABCWidths32A(HDC32,UINT32,UINT32,LPABC32);
+BOOL32      WINAPI GetCharABCWidths32W(HDC32,UINT32,UINT32,LPABC32);
+#define     GetCharABCWidths WINELIB_NAME_AW(GetCharABCWidths)
+BOOL16      WINAPI GetCharWidth16(HDC16,UINT16,UINT16,LPINT16);
+BOOL32      WINAPI GetCharWidth32A(HDC32,UINT32,UINT32,LPINT32);
+BOOL32      WINAPI GetCharWidth32W(HDC32,UINT32,UINT32,LPINT32);
+#define     GetCharWidth WINELIB_NAME_AW(GetCharWidth)
+BOOL16      WINAPI GetClassInfo16(HINSTANCE16,SEGPTR,WNDCLASS16 *);
+BOOL32      WINAPI GetClassInfo32A(HINSTANCE32,LPCSTR,WNDCLASS32A *);
+BOOL32      WINAPI GetClassInfo32W(HINSTANCE32,LPCWSTR,WNDCLASS32W *);
+#define     GetClassInfo WINELIB_NAME_AW(GetClassInfo)
+BOOL16      WINAPI GetClassInfoEx16(HINSTANCE16,SEGPTR,WNDCLASSEX16 *);
+BOOL32      WINAPI GetClassInfoEx32A(HINSTANCE32,LPCSTR,WNDCLASSEX32A *);
+BOOL32      WINAPI GetClassInfoEx32W(HINSTANCE32,LPCWSTR,WNDCLASSEX32W *);
+#define     GetClassInfoEx WINELIB_NAME_AW(GetClassInfoEx)
+LONG        WINAPI GetClassLong16(HWND16,INT16);
+LONG        WINAPI GetClassLong32A(HWND32,INT32);
+LONG        WINAPI GetClassLong32W(HWND32,INT32);
+#define     GetClassLong WINELIB_NAME_AW(GetClassLong)
+INT16       WINAPI GetClassName16(HWND16,LPSTR,INT16);
+INT32       WINAPI GetClassName32A(HWND32,LPSTR,INT32);
+INT32       WINAPI GetClassName32W(HWND32,LPWSTR,INT32);
+#define     GetClassName WINELIB_NAME_AW(GetClassName)
+WORD        WINAPI GetClassWord16(HWND16,INT16);
+WORD        WINAPI GetClassWord32(HWND32,INT32);
+#define     GetClassWord WINELIB_NAME(GetClassWord)
+void        WINAPI GetClientRect16(HWND16,LPRECT16);
+void        WINAPI GetClientRect32(HWND32,LPRECT32);
+#define     GetClientRect WINELIB_NAME(GetClientRect)
+HANDLE16    WINAPI GetClipboardData16(UINT16);
+HANDLE32    WINAPI GetClipboardData32(UINT32);
+#define     GetClipboardData WINELIB_NAME(GetClipboardData)
+INT16       WINAPI GetClipboardFormatName16(UINT16,LPSTR,INT16);
+INT32       WINAPI GetClipboardFormatName32A(UINT32,LPSTR,INT32);
+INT32       WINAPI GetClipboardFormatName32W(UINT32,LPWSTR,INT32);
+#define     GetClipboardFormatName WINELIB_NAME_AW(GetClipboardFormatName)
+HWND16      WINAPI GetClipboardOwner16(void);
+HWND32      WINAPI GetClipboardOwner32(void);
+#define     GetClipboardOwner WINELIB_NAME(GetClipboardOwner)
+HWND16      WINAPI GetClipboardViewer16(void);
+HWND32      WINAPI GetClipboardViewer32(void);
+#define     GetClipboardViewer WINELIB_NAME(GetClipboardViewer)
+INT16       WINAPI GetClipBox16(HDC16,LPRECT16);
+INT32       WINAPI GetClipBox32(HDC32,LPRECT32);
+#define     GetClipBox WINELIB_NAME(GetClipBox)
+void        WINAPI GetClipCursor16(LPRECT16);
+void        WINAPI GetClipCursor32(LPRECT32);
+#define     GetClipCursor WINELIB_NAME(GetClipCursor)
+HRGN16      WINAPI GetClipRgn16(HDC16);
+INT32       WINAPI GetClipRgn32(HDC32,HRGN32);
+#define     GetClipRgn WINELIB_NAME(GetClipRgn)
+INT16       WINAPI GetCommState16(INT16,LPDCB16);
+BOOL32      WINAPI GetCommState32(INT32,LPDCB32);
+#define     GetCommState WINELIB_NAME(GetCommState)
+UINT16      WINAPI GetCurrentDirectory16(UINT16,LPSTR);
+UINT32      WINAPI GetCurrentDirectory32A(UINT32,LPSTR);
+UINT32      WINAPI GetCurrentDirectory32W(UINT32,LPWSTR);
+#define     GetCurrentDirectory WINELIB_NAME_AW(GetCurrentDirectory)
+BOOL16      WINAPI GetCurrentPositionEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetCurrentPositionEx32(HDC32,LPPOINT32);
+#define     GetCurrentPositionEx WINELIB_NAME(GetCurrentPositionEx)
+DWORD       WINAPI GetCurrentTime16(void);
+#define     GetCurrentTime32() GetTickCount()
+#define     GetCurrentTime WINELIB_NAME(GetCurrentTime)
+HCURSOR16   WINAPI GetCursor16(void);
+HCURSOR32   WINAPI GetCursor32(void);
+#define     GetCursor WINELIB_NAME(GetCursor)
+void        WINAPI GetCursorPos16(LPPOINT16);
+void        WINAPI GetCursorPos32(LPPOINT32);
+#define     GetCursorPos WINELIB_NAME(GetCursorPos)
+HDC16       WINAPI GetDC16(HWND16);
+HDC32       WINAPI GetDC32(HWND32);
+#define     GetDC WINELIB_NAME(GetDC)
+HDC16       WINAPI GetDCEx16(HWND16,HRGN16,DWORD);
+HDC32       WINAPI GetDCEx32(HWND32,HRGN32,DWORD);
+#define     GetDCEx WINELIB_NAME(GetDCEx)
+HWND16      WINAPI GetDesktopWindow16(void);
+HWND32      WINAPI GetDesktopWindow32(void);
+#define     GetDesktopWindow WINELIB_NAME(GetDesktopWindow)
+INT16       WINAPI GetDeviceCaps16(HDC16,INT16);
+INT32       WINAPI GetDeviceCaps32(HDC32,INT32);
+#define     GetDeviceCaps WINELIB_NAME(GetDeviceCaps)
+INT16       WINAPI GetDIBits16(HDC16,HBITMAP16,UINT16,UINT16,LPSTR,LPBITMAPINFO,UINT16);
+INT32       WINAPI GetDIBits32(HDC32,HBITMAP32,UINT32,UINT32,LPSTR,LPBITMAPINFO,UINT32);
+#define     GetDIBits WINELIB_NAME(GetDIBits)
+BOOL16      WINAPI GetDiskFreeSpace16(LPCSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
+BOOL32      WINAPI GetDiskFreeSpace32A(LPCSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
+BOOL32      WINAPI GetDiskFreeSpace32W(LPCWSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
+#define     GetDiskFreeSpace WINELIB_NAME_AW(GetDiskFreeSpace)
+INT16       WINAPI GetDlgCtrlID16(HWND16);
+INT32       WINAPI GetDlgCtrlID32(HWND32);
+#define     GetDlgCtrlID WINELIB_NAME(GetDlgCtrlID)
+HWND16      WINAPI GetDlgItem16(HWND16,INT16);
+HWND32      WINAPI GetDlgItem32(HWND32,INT32);
+#define     GetDlgItem WINELIB_NAME(GetDlgItem)
+UINT16      WINAPI GetDlgItemInt16(HWND16,INT16,BOOL16*,BOOL16);
+UINT32      WINAPI GetDlgItemInt32(HWND32,INT32,BOOL32*,BOOL32);
+#define     GetDlgItemInt WINELIB_NAME(GetDlgItemInt)
+INT16       WINAPI GetDlgItemText16(HWND16,INT16,SEGPTR,UINT16);
+INT32       WINAPI GetDlgItemText32A(HWND32,INT32,LPSTR,UINT32);
+INT32       WINAPI GetDlgItemText32W(HWND32,INT32,LPWSTR,UINT32);
+#define     GetDlgItemText WINELIB_NAME_AW(GetDlgItemText)
+UINT16      WINAPI GetDoubleClickTime16(void);
+UINT32      WINAPI GetDoubleClickTime32(void);
+#define     GetDoubleClickTime WINELIB_NAME(GetDoubleClickTime)
+UINT16      WINAPI GetDriveType16(UINT16); /* yes, the arguments differ */
+UINT32      WINAPI GetDriveType32A(LPCSTR);
+UINT32      WINAPI GetDriveType32W(LPCWSTR);
+#define     GetDriveType WINELIB_NAME_AW(GetDriveType)
+INT16       WINAPI GetExpandedName16(LPCSTR,LPSTR);
+INT32       WINAPI GetExpandedName32A(LPCSTR,LPSTR);
+INT32       WINAPI GetExpandedName32W(LPCWSTR,LPWSTR);
+#define     GetExpandedName WINELIB_NAME_AW(GetExpandedName)
+DWORD       WINAPI GetFileAttributes16(LPCSTR);
+DWORD       WINAPI GetFileAttributes32A(LPCSTR);
+DWORD       WINAPI GetFileAttributes32W(LPCWSTR);
+#define     GetFileAttributes WINELIB_NAME_AW(GetFileAttributes)
+DWORD       WINAPI GetFileVersionInfoSize16(LPCSTR,LPDWORD);
+DWORD       WINAPI GetFileVersionInfoSize32A(LPCSTR,LPDWORD);
+DWORD       WINAPI GetFileVersionInfoSize32W(LPCWSTR,LPDWORD);
+#define     GetFileVersionInfoSize WINELIB_NAME_AW(GetFileVersionInfoSize)
+DWORD       WINAPI GetFileVersionInfo16(LPCSTR,DWORD,DWORD,LPVOID);
+DWORD       WINAPI GetFileVersionInfo32A(LPCSTR,DWORD,DWORD,LPVOID);
+DWORD       WINAPI GetFileVersionInfo32W(LPCWSTR,DWORD,DWORD,LPVOID);
+#define     GetFileVersionInfo WINELIB_NAME_AW(GetFileVersionInfo)
+HWND16      WINAPI GetFocus16(void);
+HWND32      WINAPI GetFocus32(void);
+#define     GetFocus WINELIB_NAME(GetFocus)
+DWORD       WINAPI GetFreeSpace16(UINT16);
+#define     GetFreeSpace32(w) (0x100000L)
+#define     GetFreeSpace WINELIB_NAME(GetFreeSpace)
+DWORD       WINAPI GetGlyphOutline16(HDC16,UINT16,UINT16,LPGLYPHMETRICS16,DWORD,LPVOID,const MAT2*);
+DWORD       WINAPI GetGlyphOutline32A(HDC32,UINT32,UINT32,LPGLYPHMETRICS32,DWORD,LPVOID,const MAT2*);
+DWORD       WINAPI GetGlyphOutline32W(HDC32,UINT32,UINT32,LPGLYPHMETRICS32,DWORD,LPVOID,const MAT2*);
+#define     GetGlyphOutline WINELIB_NAME_AW(GetGlyphOutline)
+BOOL16      WINAPI GetInputState16(void);
+BOOL32      WINAPI GetInputState32(void);
+#define     GetInputState WINELIB_NAME(GetInputState)
+UINT16      WINAPI GetInternalWindowPos16(HWND16,LPRECT16,LPPOINT16);
+UINT32      WINAPI GetInternalWindowPos32(HWND32,LPRECT32,LPPOINT32);
+#define     GetInternalWindowPos WINELIB_NAME(GetInternalWindowPos)
+INT16       WINAPI GetKBCodePage16(void);
+UINT32      WINAPI GetKBCodePage32(void);
+#define     GetKBCodePage WINELIB_NAME(GetKBCodePage)
+INT16       WINAPI GetKerningPairs16(HDC16,INT16,LPKERNINGPAIR16);
+DWORD       WINAPI GetKerningPairs32A(HDC32,DWORD,LPKERNINGPAIR32);
+DWORD       WINAPI GetKerningPairs32W(HDC32,DWORD,LPKERNINGPAIR32);
+#define     GetKerningPairs WINELIB_NAME_AW(GetKerningPairs)
+INT16       WINAPI GetKeyboardType16(INT16);
+INT32       WINAPI GetKeyboardType32(INT32);
+#define     GetKeyboardType WINELIB_NAME(GetKeyboardType)
+INT16       WINAPI GetKeyNameText16(LONG,LPSTR,INT16);
+INT32       WINAPI GetKeyNameText32A(LONG,LPSTR,INT32);
+INT32       WINAPI GetKeyNameText32W(LONG,LPWSTR,INT32);
+#define     GetKeyNameText WINELIB_NAME_AW(GetKeyNameText)
+WORD        WINAPI GetKeyState16(INT16);
+WORD        WINAPI GetKeyState32(INT32);
+#define     GetKeyState WINELIB_NAME(GetKeyState)
+HWND16      WINAPI GetLastActivePopup16(HWND16);
+HWND32      WINAPI GetLastActivePopup32(HWND32);
+#define     GetLastActivePopup WINELIB_NAME(GetLastActivePopup)
+UINT32      WINAPI GetLogicalDriveStrings32A(UINT32,LPSTR);
+UINT32      WINAPI GetLogicalDriveStrings32W(UINT32,LPWSTR);
+#define     GetLogicalDriveStrings WINELIB_NAME_AW(GetLogicalDriveStrings)
+INT16       WINAPI GetLocaleInfo16(LCID,LCTYPE,LPSTR,INT16);
+INT32       WINAPI GetLocaleInfo32A(LCID,LCTYPE,LPSTR,INT32);
+INT32       WINAPI GetLocaleInfo32W(LCID,LCTYPE,LPWSTR,INT32);
+#define     GetLocaleInfo WINELIB_NAME_AW(GetLocaleInfo)
+INT16       WINAPI GetMapMode16(HDC16);
+INT32       WINAPI GetMapMode32(HDC32);
+#define     GetMapMode WINELIB_NAME(GetMapMode)
+HMENU16     WINAPI GetMenu16(HWND16);
+HMENU32     WINAPI GetMenu32(HWND32);
+#define     GetMenu WINELIB_NAME(GetMenu)
+INT16       WINAPI GetMenuItemCount16(HMENU16);
+INT32       WINAPI GetMenuItemCount32(HMENU32);
+#define     GetMenuItemCount WINELIB_NAME(GetMenuItemCount)
+UINT16      WINAPI GetMenuItemID16(HMENU16,INT16);
+UINT32      WINAPI GetMenuItemID32(HMENU32,INT32);
+#define     GetMenuItemID WINELIB_NAME(GetMenuItemID)
+UINT16      WINAPI GetMenuState16(HMENU16,UINT16,UINT16);
+UINT32      WINAPI GetMenuState32(HMENU32,UINT32,UINT32);
+#define     GetMenuState WINELIB_NAME(GetMenuState)
+INT16       WINAPI GetMenuString16(HMENU16,UINT16,LPSTR,INT16,UINT16);
+INT32       WINAPI GetMenuString32A(HMENU32,UINT32,LPSTR,INT32,UINT32);
+INT32       WINAPI GetMenuString32W(HMENU32,UINT32,LPWSTR,INT32,UINT32);
+#define     GetMenuString WINELIB_NAME_AW(GetMenuString)
+BOOL16      WINAPI GetMessage16(SEGPTR,HWND16,UINT16,UINT16);
+BOOL32      WINAPI GetMessage32A(LPMSG32,HWND32,UINT32,UINT32);
+BOOL32      WINAPI GetMessage32W(LPMSG32,HWND32,UINT32,UINT32);
+#define     GetMessage WINELIB_NAME_AW(GetMessage)
+HMETAFILE16 WINAPI GetMetaFile16(LPCSTR);
+HMETAFILE32 WINAPI GetMetaFile32A(LPCSTR);
+HMETAFILE32 WINAPI GetMetaFile32W(LPCWSTR);
+#define     GetMetaFile WINELIB_NAME_AW(GetMetaFile)
+INT16       WINAPI GetModuleFileName16(HINSTANCE16,LPSTR,INT16);
+DWORD       WINAPI GetModuleFileName32A(HMODULE32,LPSTR,DWORD);
+DWORD       WINAPI GetModuleFileName32W(HMODULE32,LPWSTR,DWORD);
+#define     GetModuleFileName WINELIB_NAME_AW(GetModuleFileName)
+HMODULE16   WINAPI GetModuleHandle16(LPCSTR);
+HMODULE32   WINAPI GetModuleHandle32A(LPCSTR);
+HMODULE32   WINAPI GetModuleHandle32W(LPCSTR);
+#define     GetModuleHandle WINELIB_NAME_AW(GetModuleHandle)
+DWORD       WINAPI GetNearestColor16(HDC16,DWORD);
+DWORD       WINAPI GetNearestColor32(HDC32,DWORD);
+#define     GetNearestColor WINELIB_NAME(GetNearestColor)
+UINT16      WINAPI GetNearestPaletteIndex16(HPALETTE16,COLORREF);
+UINT32      WINAPI GetNearestPaletteIndex32(HPALETTE32,COLORREF);
+#define     GetNearestPaletteIndex WINELIB_NAME(GetNearestPaletteIndex)
+HWND16      WINAPI GetNextDlgGroupItem16(HWND16,HWND16,BOOL16);
+HWND32      WINAPI GetNextDlgGroupItem32(HWND32,HWND32,BOOL32);
+#define     GetNextDlgGroupItem WINELIB_NAME(GetNextDlgGroupItem)
+HWND16      WINAPI GetNextDlgTabItem16(HWND16,HWND16,BOOL16);
+HWND32      WINAPI GetNextDlgTabItem32(HWND32,HWND32,BOOL32);
+#define     GetNextDlgTabItem WINELIB_NAME(GetNextDlgTabItem)
+HWND16      WINAPI GetNextWindow16(HWND16,WORD);
+#define     GetNextWindow32 GetWindow32
+#define     GetNextWindow WINELIB_NAME(GetNextWindow)
+INT16       WINAPI GetObject16(HANDLE16,INT16,LPVOID);
+INT32       WINAPI GetObject32A(HANDLE32,INT32,LPVOID);
+INT32       WINAPI GetObject32W(HANDLE32,INT32,LPVOID);
+#define     GetObject WINELIB_NAME_AW(GetObject)
+HWND16      WINAPI GetOpenClipboardWindow16(void);
+HWND32      WINAPI GetOpenClipboardWindow32(void);
+#define     GetOpenClipboardWindow WINELIB_NAME(GetOpenClipboardWindow)
+UINT16      WINAPI GetPaletteEntries16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
+UINT32      WINAPI GetPaletteEntries32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
+#define     GetPaletteEntries WINELIB_NAME(GetPaletteEntries)
+HWND16      WINAPI GetParent16(HWND16);
+HWND32      WINAPI GetParent32(HWND32);
+#define     GetParent WINELIB_NAME(GetParent)
+COLORREF    WINAPI GetPixel16(HDC16,INT16,INT16);
+COLORREF    WINAPI GetPixel32(HDC32,INT32,INT32);
+#define     GetPixel WINELIB_NAME(GetPixel)
+INT16       WINAPI GetPolyFillMode16(HDC16);
+INT32       WINAPI GetPolyFillMode32(HDC32);
+#define     GetPolyFillMode WINELIB_NAME(GetPolyFillMode)
+INT16       WINAPI GetPriorityClipboardFormat16(UINT16*,INT16);
+INT32       WINAPI GetPriorityClipboardFormat32(UINT32*,INT32);
+#define     GetPriorityClipboardFormat WINELIB_NAME(GetPriorityClipboardFormat)
+UINT16      WINAPI GetPrivateProfileInt16(LPCSTR,LPCSTR,INT16,LPCSTR);
+UINT32      WINAPI GetPrivateProfileInt32A(LPCSTR,LPCSTR,INT32,LPCSTR);
+UINT32      WINAPI GetPrivateProfileInt32W(LPCWSTR,LPCWSTR,INT32,LPCWSTR);
+#define     GetPrivateProfileInt WINELIB_NAME_AW(GetPrivateProfileInt)
+INT16       WINAPI GetPrivateProfileString16(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT16,LPCSTR);
+INT32       WINAPI GetPrivateProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT32,LPCSTR);
+INT32       WINAPI GetPrivateProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,INT32,LPCWSTR);
+#define     GetPrivateProfileString WINELIB_NAME_AW(GetPrivateProfileString)
+FARPROC16   WINAPI GetProcAddress16(HMODULE16,SEGPTR);
+FARPROC32   WINAPI GetProcAddress32(HMODULE32,LPCSTR);
+#define     GetProcAddress WINELIB_NAME(GetProcAddress)
+UINT16      WINAPI GetProfileInt16(LPCSTR,LPCSTR,INT16);
+UINT32      WINAPI GetProfileInt32A(LPCSTR,LPCSTR,INT32);
+UINT32      WINAPI GetProfileInt32W(LPCWSTR,LPCWSTR,INT32);
+#define     GetProfileInt WINELIB_NAME_AW(GetProfileInt)
+INT16       WINAPI GetProfileString16(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT16);
+INT32       WINAPI GetProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPSTR,INT32);
+INT32       WINAPI GetProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,INT32);
+#define     GetProfileString WINELIB_NAME_AW(GetProfileString)
+HANDLE16    WINAPI GetProp16(HWND16,LPCSTR);
+HANDLE32    WINAPI GetProp32A(HWND32,LPCSTR);
+HANDLE32    WINAPI GetProp32W(HWND32,LPCWSTR);
+#define     GetProp WINELIB_NAME_AW(GetProp)
+DWORD       WINAPI GetQueueStatus16(UINT16);
+DWORD       WINAPI GetQueueStatus32(UINT32);
+#define     GetQueueStatus WINELIB_NAME(GetQueueStatus)
+BOOL16      WINAPI GetRasterizerCaps16(LPRASTERIZER_STATUS,UINT16);
+BOOL32      WINAPI GetRasterizerCaps32(LPRASTERIZER_STATUS,UINT32);
+#define     GetRasterizerCaps WINELIB_NAME(GetRasterizerCaps)
+INT16       WINAPI GetRelAbs16(HDC16);
+INT32       WINAPI GetRelAbs32(HDC32);
+#define     GetRelAbs WINELIB_NAME(GetRelAbs)
+INT16       WINAPI GetRgnBox16(HRGN16,LPRECT16);
+INT32       WINAPI GetRgnBox32(HRGN32,LPRECT32);
+#define     GetRgnBox WINELIB_NAME(GetRgnBox)
+INT16       WINAPI GetROP216(HDC16);
+INT32       WINAPI GetROP232(HDC32);
+#define     GetROP2 WINELIB_NAME(GetROP2)
+BOOL16      WINAPI GetScrollInfo16(HWND16,INT16,LPSCROLLINFO);
+BOOL32      WINAPI GetScrollInfo32(HWND32,INT32,LPSCROLLINFO);
+#define     GetScrollInfo WINELIB_NAME(GetScrollInfo)
+INT16       WINAPI GetScrollPos16(HWND16,INT16);
+INT32       WINAPI GetScrollPos32(HWND32,INT32);
+#define     GetScrollPos WINELIB_NAME(GetScrollPos)
+BOOL16      WINAPI GetScrollRange16(HWND16,INT16,LPINT16,LPINT16);
+BOOL32      WINAPI GetScrollRange32(HWND32,INT32,LPINT32,LPINT32);
+#define     GetScrollRange WINELIB_NAME(GetScrollRange)
+HGDIOBJ16   WINAPI GetStockObject16(INT16);
+HGDIOBJ32   WINAPI GetStockObject32(INT32);
+#define     GetStockObject WINELIB_NAME(GetStockObject)
+INT16       WINAPI GetStretchBltMode16(HDC16);
+INT32       WINAPI GetStretchBltMode32(HDC32);
+#define     GetStretchBltMode WINELIB_NAME(GetStretchBltMode)
+BOOL16      WINAPI GetStringType16(LCID,DWORD,LPCSTR,INT16,LPWORD);
+BOOL32      WINAPI GetStringType32A(LCID,DWORD,LPCSTR,INT32,LPWORD);
+BOOL32      WINAPI GetStringType32W(DWORD,LPCWSTR,INT32,LPWORD);
+#define     GetStringType WINELIB_NAME_AW(GetStringType)
+HMENU16     WINAPI GetSubMenu16(HMENU16,INT16);
+HMENU32     WINAPI GetSubMenu32(HMENU32,INT32);
+#define     GetSubMenu WINELIB_NAME(GetSubMenu)
+COLORREF    WINAPI GetSysColor16(INT16);
+COLORREF    WINAPI GetSysColor32(INT32);
+#define     GetSysColor WINELIB_NAME(GetSysColor)
+HBRUSH16    WINAPI GetSysColorBrush16(INT16);
+HBRUSH32    WINAPI GetSysColorBrush32(INT32);
+#define     GetSysColorBrush WINELIB_NAME(GetSysColorBrush)
+HWND16      WINAPI GetSysModalWindow16(void);
+#define     GetSysModalWindow32() ((HWND32)0)
+#define     GetSysModalWindow WINELIB_NAME(GetSysModalWindow)
+UINT16      WINAPI GetSystemDirectory16(LPSTR,UINT16);
+UINT32      WINAPI GetSystemDirectory32A(LPSTR,UINT32);
+UINT32      WINAPI GetSystemDirectory32W(LPWSTR,UINT32);
+#define     GetSystemDirectory WINELIB_NAME_AW(GetSystemDirectory)
+HMENU16     WINAPI GetSystemMenu16(HWND16,BOOL16);
+HMENU32     WINAPI GetSystemMenu32(HWND32,BOOL32);
+#define     GetSystemMenu WINELIB_NAME(GetSystemMenu)
+INT16       WINAPI GetSystemMetrics16(INT16);
+INT32       WINAPI GetSystemMetrics32(INT32);
+#define     GetSystemMetrics WINELIB_NAME(GetSystemMetrics)
+UINT16      WINAPI GetSystemPaletteEntries16(HDC16,UINT16,UINT16,LPPALETTEENTRY);
+UINT32      WINAPI GetSystemPaletteEntries32(HDC32,UINT32,UINT32,LPPALETTEENTRY);
+#define     GetSystemPaletteEntries WINELIB_NAME(GetSystemPaletteEntries)
+UINT16      WINAPI GetSystemPaletteUse16(HDC16);
+UINT32      WINAPI GetSystemPaletteUse32(HDC32);
+#define     GetSystemPaletteUse WINELIB_NAME(GetSystemPaletteUse)
+DWORD       WINAPI GetTabbedTextExtent16(HDC16,LPCSTR,INT16,INT16,const INT16*);
+DWORD       WINAPI GetTabbedTextExtent32A(HDC32,LPCSTR,INT32,INT32,const INT32*);
+DWORD       WINAPI GetTabbedTextExtent32W(HDC32,LPCWSTR,INT32,INT32,const INT32*);
+#define     GetTabbedTextExtent WINELIB_NAME_AW(GetTabbedTextExtent)
+UINT16      WINAPI GetTempFileName16(BYTE,LPCSTR,UINT16,LPSTR);
+UINT32      WINAPI GetTempFileName32A(LPCSTR,LPCSTR,UINT32,LPSTR);
+UINT32      WINAPI GetTempFileName32W(LPCWSTR,LPCWSTR,UINT32,LPWSTR);
+#define     GetTempFileName WINELIB_NAME_AW(GetTempFileName)
+UINT32      WINAPI GetTempPath32A(UINT32,LPSTR);
+UINT32      WINAPI GetTempPath32W(UINT32,LPWSTR);
+#define     GetTempPath WINELIB_NAME_AW(GetTempPath)
+UINT16      WINAPI GetTextAlign16(HDC16);
+UINT32      WINAPI GetTextAlign32(HDC32);
+#define     GetTextAlign WINELIB_NAME(GetTextAlign)
+INT16       WINAPI GetTextCharacterExtra16(HDC16);
+INT32       WINAPI GetTextCharacterExtra32(HDC32);
+#define     GetTextCharacterExtra WINELIB_NAME(GetTextCharacterExtra)
+COLORREF    WINAPI GetTextColor16(HDC16);
+COLORREF    WINAPI GetTextColor32(HDC32);
+#define     GetTextColor WINELIB_NAME(GetTextColor)
+BOOL16      WINAPI GetTextExtentPoint16(HDC16,LPCSTR,INT16,LPSIZE16);
+BOOL32      WINAPI GetTextExtentPoint32A(HDC32,LPCSTR,INT32,LPSIZE32);
+BOOL32      WINAPI GetTextExtentPoint32W(HDC32,LPCWSTR,INT32,LPSIZE32);
+#define     GetTextExtentPoint WINELIB_NAME_AW(GetTextExtentPoint)
+INT16       WINAPI GetTextFace16(HDC16,INT16,LPSTR);
+INT32       WINAPI GetTextFace32A(HDC32,INT32,LPSTR);
+INT32       WINAPI GetTextFace32W(HDC32,INT32,LPWSTR);
+#define     GetTextFace WINELIB_NAME_AW(GetTextFace)
+BOOL16      WINAPI GetTextMetrics16(HDC16,LPTEXTMETRIC16);
+BOOL32      WINAPI GetTextMetrics32A(HDC32,LPTEXTMETRIC32A);
+BOOL32      WINAPI GetTextMetrics32W(HDC32,LPTEXTMETRIC32W);
+#define     GetTextMetrics WINELIB_NAME_AW(GetTextMetrics)
+LPINT16     WINAPI GetThresholdEvent16(void);
+LPDWORD     WINAPI GetThresholdEvent32(void);
+#define     GetThresholdEvent WINELIB_NAME(GetThresholdEvent)
+INT16       WINAPI GetThresholdStatus16(void);
+DWORD       WINAPI GetThresholdStatus32(void);
+#define     GetThresholdStatus WINELIB_NAME(GetThresholdStatus)
+HWND16      WINAPI GetTopWindow16(HWND16);
+HWND32      WINAPI GetTopWindow32(HWND32);
+#define     GetTopWindow WINELIB_NAME(GetTopWindow)
+BOOL16      WINAPI GetUpdateRect16(HWND16,LPRECT16,BOOL16);
+BOOL32      WINAPI GetUpdateRect32(HWND32,LPRECT32,BOOL32);
+#define     GetUpdateRect WINELIB_NAME(GetUpdateRect)
+INT16       WINAPI GetUpdateRgn16(HWND16,HRGN16,BOOL16);
+INT32       WINAPI GetUpdateRgn32(HWND32,HRGN32,BOOL32);
+#define     GetUpdateRgn WINELIB_NAME(GetUpdateRgn)
+LONG        WINAPI GetVersion16(void);
+LONG        WINAPI GetVersion32(void);
+#define     GetVersion WINELIB_NAME(GetVersion)
+BOOL16      WINAPI GetViewportExtEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetViewportExtEx32(HDC32,LPPOINT32);
+#define     GetViewportExtEx WINELIB_NAME(GetViewportExtEx)
+BOOL16      WINAPI GetViewportOrgEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetViewportOrgEx32(HDC32,LPPOINT32);
+#define     GetViewportOrgEx WINELIB_NAME(GetViewportOrgEx)
+BOOL32      WINAPI GetVolumeInformation32A(LPCSTR,LPSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPSTR,DWORD);
+BOOL32      WINAPI GetVolumeInformation32W(LPCWSTR,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR,DWORD);
+#define     GetVolumeInformation WINELIB_NAME_AW(GetVolumeInformation)
+HWND16      WINAPI GetWindow16(HWND16,WORD);
+HWND32      WINAPI GetWindow32(HWND32,WORD);
+#define     GetWindow WINELIB_NAME(GetWindow)
+HDC16       WINAPI GetWindowDC16(HWND16);
+HDC32       WINAPI GetWindowDC32(HWND32);
+#define     GetWindowDC WINELIB_NAME(GetWindowDC)
+BOOL16      WINAPI GetWindowExtEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetWindowExtEx32(HDC32,LPPOINT32);
+#define     GetWindowExtEx WINELIB_NAME(GetWindowExtEx)
+LONG        WINAPI GetWindowLong16(HWND16,INT16);
+LONG        WINAPI GetWindowLong32A(HWND32,INT32);
+LONG        WINAPI GetWindowLong32W(HWND32,INT32);
+#define     GetWindowLong WINELIB_NAME_AW(GetWindowLong)
+BOOL16      WINAPI GetWindowOrgEx16(HDC16,LPPOINT16);
+BOOL32      WINAPI GetWindowOrgEx32(HDC32,LPPOINT32);
+#define     GetWindowOrgEx WINELIB_NAME(GetWindowOrgEx)
+BOOL16      WINAPI GetWindowPlacement16(HWND16,LPWINDOWPLACEMENT16);
+BOOL32      WINAPI GetWindowPlacement32(HWND32,LPWINDOWPLACEMENT32);
+#define     GetWindowPlacement WINELIB_NAME(GetWindowPlacement)
+void        WINAPI GetWindowRect16(HWND16,LPRECT16);
+void        WINAPI GetWindowRect32(HWND32,LPRECT32);
+#define     GetWindowRect WINELIB_NAME(GetWindowRect)
+UINT16      WINAPI GetWindowsDirectory16(LPSTR,UINT16);
+UINT32      WINAPI GetWindowsDirectory32A(LPSTR,UINT32);
+UINT32      WINAPI GetWindowsDirectory32W(LPWSTR,UINT32);
+#define     GetWindowsDirectory WINELIB_NAME_AW(GetWindowsDirectory)
+HTASK16     WINAPI GetWindowTask16(HWND16);
+#define     GetWindowTask32(hwnd) ((HTASK32)GetWindowThreadProcessId(hwnd,NULL))
+#define     GetWindowTask WINELIB_NAME(GetWindowTask)
+INT16       WINAPI GetWindowText16(HWND16,SEGPTR,INT16);
+INT32       WINAPI GetWindowText32A(HWND32,LPSTR,INT32);
+INT32       WINAPI GetWindowText32W(HWND32,LPWSTR,INT32);
+#define     GetWindowText WINELIB_NAME_AW(GetWindowText)
+INT16       WINAPI GetWindowTextLength16(HWND16);
+INT32       WINAPI GetWindowTextLength32A(HWND32);
+INT32       WINAPI GetWindowTextLength32W(HWND32);
+#define     GetWindowTextLength WINELIB_NAME_AW(GetWindowTextLength)
+WORD        WINAPI GetWindowWord16(HWND16,INT16);
+WORD        WINAPI GetWindowWord32(HWND32,INT32);
+#define     GetWindowWord WINELIB_NAME(GetWindowWord)
+ATOM        WINAPI GlobalAddAtom16(SEGPTR);
+ATOM        WINAPI GlobalAddAtom32A(LPCSTR);
+ATOM        WINAPI GlobalAddAtom32W(LPCWSTR);
+#define     GlobalAddAtom WINELIB_NAME_AW(GlobalAddAtom)
+HGLOBAL16   WINAPI GlobalAlloc16(UINT16,DWORD);
+HGLOBAL32   WINAPI GlobalAlloc32(UINT32,DWORD);
+#define     GlobalAlloc WINELIB_NAME(GlobalAlloc)
+DWORD       WINAPI GlobalCompact16(DWORD);
+DWORD       WINAPI GlobalCompact32(DWORD);
+#define     GlobalCompact WINELIB_NAME(GlobalCompact)
+UINT16      WINAPI GlobalFlags16(HGLOBAL16);
+UINT32      WINAPI GlobalFlags32(HGLOBAL32);
+#define     GlobalFlags WINELIB_NAME(GlobalFlags)
+ATOM        WINAPI GlobalFindAtom16(SEGPTR);
+ATOM        WINAPI GlobalFindAtom32A(LPCSTR);
+ATOM        WINAPI GlobalFindAtom32W(LPCWSTR);
+#define     GlobalFindAtom WINELIB_NAME_AW(GlobalFindAtom)
+HGLOBAL16   WINAPI GlobalFree16(HGLOBAL16);
+HGLOBAL32   WINAPI GlobalFree32(HGLOBAL32);
+#define     GlobalFree WINELIB_NAME(GlobalFree)
+UINT16      WINAPI GlobalGetAtomName16(ATOM,LPSTR,INT16);
+UINT32      WINAPI GlobalGetAtomName32A(ATOM,LPSTR,INT32);
+UINT32      WINAPI GlobalGetAtomName32W(ATOM,LPWSTR,INT32);
+#define     GlobalGetAtomName WINELIB_NAME_AW(GlobalGetAtomName)
+DWORD       WINAPI GlobalHandle16(WORD);
+HGLOBAL32   WINAPI GlobalHandle32(LPCVOID);
+#define     GlobalHandle WINELIB_NAME(GlobalHandle)
+VOID        WINAPI GlobalFix16(HGLOBAL16);
+VOID        WINAPI GlobalFix32(HGLOBAL32);
+#define     GlobalFix WINELIB_NAME(GlobalFix)
+LPVOID      WINAPI GlobalLock16(HGLOBAL16);
+LPVOID      WINAPI GlobalLock32(HGLOBAL32);
+#define     GlobalLock WINELIB_NAME(GlobalLock)
+HGLOBAL16   WINAPI GlobalReAlloc16(HGLOBAL16,DWORD,UINT16);
+HGLOBAL32   WINAPI GlobalReAlloc32(HGLOBAL32,DWORD,UINT32);
+#define     GlobalReAlloc WINELIB_NAME(GlobalReAlloc)
+DWORD       WINAPI GlobalSize16(HGLOBAL16);
+DWORD       WINAPI GlobalSize32(HGLOBAL32);
+#define     GlobalSize WINELIB_NAME(GlobalSize)
+VOID        WINAPI GlobalUnfix16(HGLOBAL16);
+VOID        WINAPI GlobalUnfix32(HGLOBAL32);
+#define     GlobalUnfix WINELIB_NAME(GlobalUnfix)
+BOOL16      WINAPI GlobalUnlock16(HGLOBAL16);
+BOOL32      WINAPI GlobalUnlock32(HGLOBAL32);
+#define     GlobalUnlock WINELIB_NAME(GlobalUnlock)
+BOOL16      WINAPI GlobalUnWire16(HGLOBAL16);
+BOOL32      WINAPI GlobalUnWire32(HGLOBAL32);
+#define     GlobalUnWire WINELIB_NAME(GlobalUnWire)
+SEGPTR      WINAPI GlobalWire16(HGLOBAL16);
+LPVOID      WINAPI GlobalWire32(HGLOBAL32);
+#define     GlobalWire WINELIB_NAME(GlobalWire)
+BOOL16      WINAPI GrayString16(HDC16,HBRUSH16,GRAYSTRINGPROC16,LPARAM,
+                                INT16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI GrayString32A(HDC32,HBRUSH32,GRAYSTRINGPROC32,LPARAM,
+                                 INT32,INT32,INT32,INT32,INT32);
+BOOL32      WINAPI GrayString32W(HDC32,HBRUSH32,GRAYSTRINGPROC32,LPARAM,
+                                 INT32,INT32,INT32,INT32,INT32);
+#define     GrayString WINELIB_NAME_AW(GrayString)
+VOID        WINAPI HideCaret16(HWND16);
+BOOL32      WINAPI HideCaret32(HWND32);
+#define     HideCaret WINELIB_NAME(HideCaret)
+BOOL16      WINAPI HiliteMenuItem16(HWND16,HMENU16,UINT16,UINT16);
+BOOL32      WINAPI HiliteMenuItem32(HWND32,HMENU32,UINT32,UINT32);
+#define     HiliteMenuItem WINELIB_NAME(HiliteMenuItem)
+void        WINAPI InflateRect16(LPRECT16,INT16,INT16);
+void        WINAPI InflateRect32(LPRECT32,INT32,INT32);
+#define     InflateRect WINELIB_NAME(InflateRect)
+WORD        WINAPI InitAtomTable16(WORD);
+BOOL32      WINAPI InitAtomTable32(DWORD);
+#define     InitAtomTable WINELIB_NAME(InitAtomTable)
+BOOL16      WINAPI InSendMessage16(void);
+BOOL32      WINAPI InSendMessage32(void);
+#define     InSendMessage WINELIB_NAME(InSendMessage)
+BOOL16      WINAPI InsertMenu16(HMENU16,UINT16,UINT16,UINT16,SEGPTR);
+BOOL32      WINAPI InsertMenu32A(HMENU32,UINT32,UINT32,UINT32,LPCSTR);
+BOOL32      WINAPI InsertMenu32W(HMENU32,UINT32,UINT32,UINT32,LPCWSTR);
+#define     InsertMenu WINELIB_NAME_AW(InsertMenu)
+BOOL16      WINAPI InsertMenuItem16(HMENU16,UINT16,BOOL16,const MENUITEMINFO16*);
+BOOL32      WINAPI InsertMenuItem32A(HMENU32,UINT32,BOOL32,const MENUITEMINFO32A*);
+BOOL32      WINAPI InsertMenuItem32W(HMENU32,UINT32,BOOL32,const MENUITEMINFO32W*);
+#define     InsertMenuItem WINELIB_NAME_AW(InsertMenuItem)
+INT16       WINAPI IntersectClipRect16(HDC16,INT16,INT16,INT16,INT16);
+INT32       WINAPI IntersectClipRect32(HDC32,INT32,INT32,INT32,INT32);
+#define     IntersectClipRect WINELIB_NAME(IntersectClipRect)
+BOOL16      WINAPI IntersectRect16(LPRECT16,const RECT16*,const RECT16*);
+BOOL32      WINAPI IntersectRect32(LPRECT32,const RECT32*,const RECT32*);
+#define     IntersectRect WINELIB_NAME(IntersectRect)
+void        WINAPI InvalidateRect16(HWND16,const RECT16*,BOOL16);
+void        WINAPI InvalidateRect32(HWND32,const RECT32*,BOOL32);
+#define     InvalidateRect WINELIB_NAME(InvalidateRect)
+void        WINAPI InvalidateRgn16(HWND16,HRGN16,BOOL16);
+void        WINAPI InvalidateRgn32(HWND32,HRGN32,BOOL32);
+#define     InvalidateRgn WINELIB_NAME(InvalidateRgn)
+void        WINAPI InvertRect16(HDC16,const RECT16*);
+void        WINAPI InvertRect32(HDC32,const RECT32*);
+#define     InvertRect WINELIB_NAME(InvertRect)
+BOOL16      WINAPI InvertRgn16(HDC16,HRGN16);
+BOOL32      WINAPI InvertRgn32(HDC32,HRGN32);
+#define     InvertRgn WINELIB_NAME(InvertRgn)
+BOOL16      WINAPI IsBadCodePtr16(SEGPTR);
+BOOL32      WINAPI IsBadCodePtr32(FARPROC32);
+#define     IsBadCodePtr WINELIB_NAME(IsBadCodePtr)
+BOOL16      WINAPI IsBadHugeReadPtr16(SEGPTR,DWORD);
+BOOL32      WINAPI IsBadHugeReadPtr32(LPCVOID,UINT32);
+#define     IsBadHugeReadPtr WINELIB_NAME(IsBadHugeReadPtr)
+BOOL16      WINAPI IsBadHugeWritePtr16(SEGPTR,DWORD);
+BOOL32      WINAPI IsBadHugeWritePtr32(LPVOID,UINT32);
+#define     IsBadHugeWritePtr WINELIB_NAME(IsBadHugeWritePtr)
+BOOL16      WINAPI IsBadReadPtr16(SEGPTR,UINT16);
+BOOL32      WINAPI IsBadReadPtr32(LPCVOID,UINT32);
+#define     IsBadReadPtr WINELIB_NAME(IsBadReadPtr)
+BOOL16      WINAPI IsBadStringPtr16(SEGPTR,UINT16);
+BOOL32      WINAPI IsBadStringPtr32A(LPCSTR,UINT32);
+BOOL32      WINAPI IsBadStringPtr32W(LPCWSTR,UINT32);
+#define     IsBadStringPtr WINELIB_NAME_AW(IsBadStringPtr)
+BOOL16      WINAPI IsBadWritePtr16(SEGPTR,UINT16);
+BOOL32      WINAPI IsBadWritePtr32(LPVOID,UINT32);
+#define     IsBadWritePtr WINELIB_NAME(IsBadWritePtr)
+BOOL16      WINAPI IsCharAlpha16(CHAR);
+BOOL32      WINAPI IsCharAlpha32A(CHAR);
+BOOL32      WINAPI IsCharAlpha32W(WCHAR);
+#define     IsCharAlpha WINELIB_NAME_AW(IsCharAlpha)
+BOOL16      WINAPI IsCharAlphaNumeric16(CHAR);
+BOOL32      WINAPI IsCharAlphaNumeric32A(CHAR);
+BOOL32      WINAPI IsCharAlphaNumeric32W(WCHAR);
+#define     IsCharAlphaNumeric WINELIB_NAME_AW(IsCharAlphaNumeric)
+BOOL16      WINAPI IsCharLower16(CHAR);
+BOOL32      WINAPI IsCharLower32A(CHAR);
+BOOL32      WINAPI IsCharLower32W(WCHAR);
+#define     IsCharLower WINELIB_NAME_AW(IsCharLower)
+BOOL16      WINAPI IsCharUpper16(CHAR);
+BOOL32      WINAPI IsCharUpper32A(CHAR);
+BOOL32      WINAPI IsCharUpper32W(WCHAR);
+#define     IsCharUpper WINELIB_NAME_AW(IsCharUpper)
+BOOL16      WINAPI IsChild16(HWND16,HWND16);
+BOOL32      WINAPI IsChild32(HWND32,HWND32);
+#define     IsChild WINELIB_NAME(IsChild)
+BOOL16      WINAPI IsClipboardFormatAvailable16(UINT16);
+BOOL32      WINAPI IsClipboardFormatAvailable32(UINT32);
+#define     IsClipboardFormatAvailable WINELIB_NAME(IsClipboardFormatAvailable)
+BOOL16      WINAPI IsDBCSLeadByte16(BYTE);
+BOOL32      WINAPI IsDBCSLeadByte32(BYTE);
+#define     IsDBCSLeadByte WINELIB_NAME(IsDBCSLeadByte)
+BOOL16      WINAPI IsDialogMessage16(HWND16,LPMSG16);
+BOOL32      WINAPI IsDialogMessage32A(HWND32,LPMSG32);
+BOOL32      WINAPI IsDialogMessage32W(HWND32,LPMSG32);
+#define     IsDialogMessage WINELIB_NAME(IsDialogMessage)
+UINT16      WINAPI IsDlgButtonChecked16(HWND16,UINT16);
+UINT32      WINAPI IsDlgButtonChecked32(HWND32,UINT32);
+#define     IsDlgButtonChecked WINELIB_NAME(IsDlgButtonChecked)
+BOOL16      WINAPI IsIconic16(HWND16);
+BOOL32      WINAPI IsIconic32(HWND32);
+#define     IsIconic WINELIB_NAME(IsIconic)
+BOOL16      WINAPI IsMenu16(HMENU16);
+BOOL32      WINAPI IsMenu32(HMENU32);
+#define     IsMenu WINELIB_NAME(IsMenu)
+BOOL16      WINAPI IsRectEmpty16(const RECT16*);
+BOOL32      WINAPI IsRectEmpty32(const RECT32*);
+#define     IsRectEmpty WINELIB_NAME(IsRectEmpty)
+BOOL16      WINAPI IsWindow16(HWND16);
+BOOL32      WINAPI IsWindow32(HWND32);
+#define     IsWindow WINELIB_NAME(IsWindow)
+BOOL16      WINAPI IsWindowEnabled16(HWND16);
+BOOL32      WINAPI IsWindowEnabled32(HWND32);
+#define     IsWindowEnabled WINELIB_NAME(IsWindowEnabled)
+BOOL16      WINAPI IsWindowVisible16(HWND16);
+BOOL32      WINAPI IsWindowVisible32(HWND32);
+#define     IsWindowVisible WINELIB_NAME(IsWindowVisible)
+BOOL16      WINAPI IsZoomed16(HWND16);
+BOOL32      WINAPI IsZoomed32(HWND32);
+#define     IsZoomed WINELIB_NAME(IsZoomed)
+BOOL16      WINAPI KillSystemTimer16(HWND16,UINT16);
+BOOL32      WINAPI KillSystemTimer32(HWND32,UINT32);
+#define     KillSystemTimer WINELIB_NAME(KillSystemTimer)
+BOOL16      WINAPI KillTimer16(HWND16,UINT16);
+BOOL32      WINAPI KillTimer32(HWND32,UINT32);
+#define     KillTimer WINELIB_NAME(KillTimer)
+HFILE16     WINAPI LZOpenFile16(LPCSTR,LPOFSTRUCT,UINT16);
+HFILE32     WINAPI LZOpenFile32A(LPCSTR,LPOFSTRUCT,UINT32);
+HFILE32     WINAPI LZOpenFile32W(LPCWSTR,LPOFSTRUCT,UINT32);
+#define     LZOpenFile WINELIB_NAME_AW(LZOpenFile)
+INT16       WINAPI LZRead16(HFILE16,LPVOID,UINT16); 
+INT32       WINAPI LZRead32(HFILE32,LPVOID,UINT32); 
+#define     LZRead WINELIB_NAME(LZRead)
+INT16       WINAPI LZStart16(void);
+INT32       WINAPI LZStart32(void);
+#define     LZStart WINELIB_NAME(LZStart)
+VOID        WINAPI LineDDA16(INT16,INT16,INT16,INT16,LINEDDAPROC16,LPARAM);
+BOOL32      WINAPI LineDDA32(INT32,INT32,INT32,INT32,LINEDDAPROC32,LPARAM);
+#define     LineDDA WINELIB_NAME(LineDDA)
+BOOL16      WINAPI LineTo16(HDC16,INT16,INT16);
+BOOL32      WINAPI LineTo32(HDC32,INT32,INT32);
+#define     LineTo WINELIB_NAME(LineTo)
+HACCEL16    WINAPI LoadAccelerators16(HINSTANCE16,SEGPTR);
+HACCEL32    WINAPI LoadAccelerators32A(HINSTANCE32,LPCSTR);
+HACCEL32    WINAPI LoadAccelerators32W(HINSTANCE32,LPCWSTR);
+#define     LoadAccelerators WINELIB_NAME_AW(LoadAccelerators)
+HBITMAP16   WINAPI LoadBitmap16(HANDLE16,SEGPTR);
+HBITMAP32   WINAPI LoadBitmap32A(HANDLE32,LPCSTR);
+HBITMAP32   WINAPI LoadBitmap32W(HANDLE32,LPCWSTR);
+#define     LoadBitmap WINELIB_NAME(LoadBitmap)
+HCURSOR16   WINAPI LoadCursor16(HINSTANCE16,SEGPTR);
+HCURSOR32   WINAPI LoadCursor32A(HINSTANCE32,LPCSTR);
+HCURSOR32   WINAPI LoadCursor32W(HINSTANCE32,LPCWSTR);
+#define     LoadCursor WINELIB_NAME_AW(LoadCursor)
+HICON16     WINAPI LoadIcon16(HINSTANCE16,SEGPTR);
+HICON32     WINAPI LoadIcon32A(HINSTANCE32,LPCSTR);
+HICON32     WINAPI LoadIcon32W(HINSTANCE32,LPCWSTR);
+#define     LoadIcon WINELIB_NAME_AW(LoadIcon)
+HINSTANCE16 WINAPI LoadLibrary16(LPCSTR);
+HINSTANCE32 WINAPI LoadLibrary32A(LPCSTR);
+HINSTANCE32 WINAPI LoadLibrary32W(LPCWSTR);
+#define     LoadLibrary WINELIB_NAME_AW(LoadLibrary)
+HMENU16     WINAPI LoadMenu16(HINSTANCE16,SEGPTR);
+HMENU32     WINAPI LoadMenu32A(HINSTANCE32,LPCSTR);
+HMENU32     WINAPI LoadMenu32W(HINSTANCE32,LPCWSTR);
+#define     LoadMenu WINELIB_NAME_AW(LoadMenu)
+HMENU16     WINAPI LoadMenuIndirect16(LPCVOID);
+HMENU32     WINAPI LoadMenuIndirect32A(LPCVOID);
+HMENU32     WINAPI LoadMenuIndirect32W(LPCVOID);
+#define     LoadMenuIndirect WINELIB_NAME_AW(LoadMenuIndirect)
+HINSTANCE16 WINAPI LoadModule16(LPCSTR,LPVOID);
+DWORD       WINAPI LoadModule32(LPCSTR,LPVOID);
+#define     LoadModule WINELIB_NAME(LoadModule)
+HGLOBAL16   WINAPI LoadResource16(HINSTANCE16,HRSRC16);
+HGLOBAL32   WINAPI LoadResource32(HINSTANCE32,HRSRC32);
+#define     LoadResource WINELIB_NAME(LoadResource)
+INT16       WINAPI LoadString16(HINSTANCE16,UINT16,LPSTR,INT16);
+INT32       WINAPI LoadString32A(HINSTANCE32,UINT32,LPSTR,INT32);
+INT32       WINAPI LoadString32W(HINSTANCE32,UINT32,LPWSTR,INT32);
+#define     LoadString WINELIB_NAME_AW(LoadString)
+HLOCAL16    WINAPI LocalAlloc16(UINT16,WORD);
+HLOCAL32    WINAPI LocalAlloc32(UINT32,DWORD);
+#define     LocalAlloc WINELIB_NAME(LocalAlloc)
+UINT16      WINAPI LocalCompact16(UINT16);
+UINT32      WINAPI LocalCompact32(UINT32);
+#define     LocalCompact WINELIB_NAME(LocalCompact)
+UINT16      WINAPI LocalFlags16(HLOCAL16);
+UINT32      WINAPI LocalFlags32(HLOCAL32);
+#define     LocalFlags WINELIB_NAME(LocalFlags)
+HLOCAL16    WINAPI LocalFree16(HLOCAL16);
+HLOCAL32    WINAPI LocalFree32(HLOCAL32);
+#define     LocalFree WINELIB_NAME(LocalFree)
+HLOCAL16    WINAPI LocalHandle16(WORD);
+HLOCAL32    WINAPI LocalHandle32(LPCVOID);
+#define     LocalHandle WINELIB_NAME(LocalHandle)
+SEGPTR      WINAPI LocalLock16(HLOCAL16);
+LPVOID      WINAPI LocalLock32(HLOCAL32);
+#define     LocalLock WINELIB_NAME(LocalLock)
+HLOCAL16    WINAPI LocalReAlloc16(HLOCAL16,WORD,UINT16);
+HLOCAL32    WINAPI LocalReAlloc32(HLOCAL32,DWORD,UINT32);
+#define     LocalReAlloc WINELIB_NAME(LocalReAlloc)
+UINT16      WINAPI LocalShrink16(HGLOBAL16,UINT16);
+UINT32      WINAPI LocalShrink32(HGLOBAL32,UINT32);
+#define     LocalShrink WINELIB_NAME(LocalShrink)
+UINT16      WINAPI LocalSize16(HLOCAL16);
+UINT32      WINAPI LocalSize32(HLOCAL32);
+#define     LocalSize WINELIB_NAME(LocalSize)
+BOOL16      WINAPI LocalUnlock16(HLOCAL16);
+BOOL32      WINAPI LocalUnlock32(HLOCAL32);
+#define     LocalUnlock WINELIB_NAME(LocalUnlock)
+LPVOID      WINAPI LockResource16(HGLOBAL16);
+LPVOID      WINAPI LockResource32(HGLOBAL32);
+#define     LockResource WINELIB_NAME(LockResource)
+HGLOBAL16   WINAPI LockSegment16(HGLOBAL16);
+#define     LockSegment32(handle) GlobalFix32((HANDLE32)(handle))
+#define     LockSegment WINELIB_NAME(LockSegment)
+BOOL16      WINAPI LockWindowUpdate16(HWND16);
+BOOL32      WINAPI LockWindowUpdate32(HWND32);
+#define     LockWindowUpdate WINELIB_NAME(LockWindowUpdate)
+BOOL16      WINAPI LPtoDP16(HDC16,LPPOINT16,INT16);
+BOOL32      WINAPI LPtoDP32(HDC32,LPPOINT32,INT32);
+#define     LPtoDP WINELIB_NAME(LPtoDP)
+void        WINAPI LZClose16(HFILE16);
+void        WINAPI LZClose32(HFILE32);
+#define     LZClose WINELIB_NAME(LZClose)
+LONG        WINAPI LZCopy16(HFILE16,HFILE16);
+LONG        WINAPI LZCopy32(HFILE32,HFILE32);
+#define     LZCopy WINELIB_NAME(LZCopy)
+HFILE16     WINAPI LZInit16(HFILE16);
+HFILE32     WINAPI LZInit32(HFILE32);
+#define     LZInit WINELIB_NAME(LZInit)
+LONG        WINAPI LZSeek16(HFILE16,LONG,INT16);
+LONG        WINAPI LZSeek32(HFILE32,LONG,INT32);
+#define     LZSeek WINELIB_NAME(LZSeek)
+UINT16      WINAPI MapVirtualKey16(UINT16,UINT16);
+UINT32      WINAPI MapVirtualKey32A(UINT32,UINT32);
+UINT32      WINAPI MapVirtualKey32W(UINT32,UINT32);
+#define     MapVirtualKey WINELIB_NAME_AW(MapVirtualKey)
+FARPROC16   WINAPI MakeProcInstance16(FARPROC16,HANDLE16);
+#define     MakeProcInstance32(proc,inst) (proc)
+#define     MakeProcInstance WINELIB_NAME(MakeProcInstance)
+void        WINAPI MapDialogRect16(HWND16,LPRECT16);
+void        WINAPI MapDialogRect32(HWND32,LPRECT32);
+#define     MapDialogRect WINELIB_NAME(MapDialogRect)
+void        WINAPI MapWindowPoints16(HWND16,HWND16,LPPOINT16,UINT16);
+void        WINAPI MapWindowPoints32(HWND32,HWND32,LPPOINT32,UINT32);
+#define     MapWindowPoints WINELIB_NAME(MapWindowPoints)
+VOID        WINAPI MessageBeep16(UINT16);
+BOOL32      WINAPI MessageBeep32(UINT32);
+#define     MessageBeep WINELIB_NAME(MessageBeep)
+INT16       WINAPI MessageBox16(HWND16,LPCSTR,LPCSTR,UINT16);
+INT32       WINAPI MessageBox32A(HWND32,LPCSTR,LPCSTR,UINT32);
+INT32       WINAPI MessageBox32W(HWND32,LPCWSTR,LPCWSTR,UINT32);
+#define     MessageBox WINELIB_NAME_AW(MessageBox)
+BOOL16      WINAPI ModifyMenu16(HMENU16,UINT16,UINT16,UINT16,SEGPTR);
+BOOL32      WINAPI ModifyMenu32A(HMENU32,UINT32,UINT32,UINT32,LPCSTR);
+BOOL32      WINAPI ModifyMenu32W(HMENU32,UINT32,UINT32,UINT32,LPCWSTR);
+#define     ModifyMenu WINELIB_NAME_AW(ModifyMenu)
+BOOL16      WINAPI MoveToEx16(HDC16,INT16,INT16,LPPOINT16);
+BOOL32      WINAPI MoveToEx32(HDC32,INT32,INT32,LPPOINT32);
+#define     MoveToEx WINELIB_NAME(MoveToEx)
+BOOL16      WINAPI MoveWindow16(HWND16,INT16,INT16,INT16,INT16,BOOL16);
+BOOL32      WINAPI MoveWindow32(HWND32,INT32,INT32,INT32,INT32,BOOL32);
+#define     MoveWindow WINELIB_NAME(MoveWindow)
+INT16       WINAPI MulDiv16(INT16,INT16,INT16);
+INT32       WINAPI MulDiv32(INT32,INT32,INT32);
+#define     MulDiv WINELIB_NAME(MulDiv)
+INT16       WINAPI OemToAnsi16(LPCSTR,LPSTR);
+#define     OemToAnsi32A OemToChar32A
+#define     OemToAnsi32W OemToChar32W
+#define     OemToAnsi WINELIB_NAME_AW(OemToAnsi)
+VOID        WINAPI OemToAnsiBuff16(LPCSTR,LPSTR,UINT16);
+#define     OemToAnsiBuff32A OemToCharBuff32A
+#define     OemToAnsiBuff32W OemToCharBuff32W
+#define     OemToAnsiBuff WINELIB_NAME_AW(OemToAnsiBuff)
+BOOL32      WINAPI OemToChar32A(LPCSTR,LPSTR);
+BOOL32      WINAPI OemToChar32W(LPCSTR,LPWSTR);
+#define     OemToChar WINELIB_NAME_AW(OemToChar)
+BOOL32      WINAPI OemToCharBuff32A(LPCSTR,LPSTR,DWORD);
+BOOL32      WINAPI OemToCharBuff32W(LPCSTR,LPWSTR,DWORD);
+#define     OemToCharBuff WINELIB_NAME_AW(OemToCharBuff)
+INT16       WINAPI OffsetClipRgn16(HDC16,INT16,INT16);
+INT32       WINAPI OffsetClipRgn32(HDC32,INT32,INT32);
+#define     OffsetClipRgn WINELIB_NAME(OffsetClipRgn)
+void        WINAPI OffsetRect16(LPRECT16,INT16,INT16);
+void        WINAPI OffsetRect32(LPRECT32,INT32,INT32);
+#define     OffsetRect WINELIB_NAME(OffsetRect)
+INT16       WINAPI OffsetRgn16(HRGN16,INT16,INT16);
+INT32       WINAPI OffsetRgn32(HRGN32,INT32,INT32);
+#define     OffsetRgn WINELIB_NAME(OffsetRgn)
+BOOL16      WINAPI OffsetViewportOrgEx16(HDC16,INT16,INT16,LPPOINT16);
+BOOL32      WINAPI OffsetViewportOrgEx32(HDC32,INT32,INT32,LPPOINT32);
+#define     OffsetViewportOrgEx WINELIB_NAME(OffsetViewportOrgEx)
+BOOL16      WINAPI OffsetWindowOrgEx16(HDC16,INT16,INT16,LPPOINT16);
+BOOL32      WINAPI OffsetWindowOrgEx32(HDC32,INT32,INT32,LPPOINT32);
+#define     OffsetWindowOrgEx WINELIB_NAME(OffsetWindowOrgEx)
+BOOL16      WINAPI OpenClipboard16(HWND16);
+BOOL32      WINAPI OpenClipboard32(HWND32);
+#define     OpenClipboard WINELIB_NAME(OpenClipboard)
+HFILE16     WINAPI OpenFile16(LPCSTR,OFSTRUCT*,UINT16);
+HFILE32     WINAPI OpenFile32(LPCSTR,OFSTRUCT*,UINT32);
+#define     OpenFile WINELIB_NAME(OpenFile)
+BOOL16      WINAPI OpenIcon16(HWND16);
+BOOL32      WINAPI OpenIcon32(HWND32);
+#define     OpenIcon WINELIB_NAME(OpenIcon)
+INT16       WINAPI OpenSound16(void);
+VOID        WINAPI OpenSound32(void);
+#define     OpenSound WINELIB_NAME(OpenSound)
+VOID        WINAPI OutputDebugString16(LPCSTR);
+VOID        WINAPI OutputDebugString32A(LPCSTR);
+VOID        WINAPI OutputDebugString32W(LPCWSTR);
+#define     OutputDebugString WINELIB_NAME_AW(OutputDebugString)
+BOOL16      WINAPI PaintRgn16(HDC16,HRGN16);
+BOOL32      WINAPI PaintRgn32(HDC32,HRGN32);
+#define     PaintRgn WINELIB_NAME(PaintRgn)
+BOOL16      WINAPI PatBlt16(HDC16,INT16,INT16,INT16,INT16,DWORD);
+BOOL32      WINAPI PatBlt32(HDC32,INT32,INT32,INT32,INT32,DWORD);
+#define     PatBlt WINELIB_NAME(PatBlt)
+BOOL16      WINAPI PeekMessage16(LPMSG16,HWND16,UINT16,UINT16,UINT16);
+BOOL32      WINAPI PeekMessage32A(LPMSG32,HWND32,UINT32,UINT32,UINT32);
+BOOL32      WINAPI PeekMessage32W(LPMSG32,HWND32,UINT32,UINT32,UINT32);
+#define     PeekMessage WINELIB_NAME_AW(PeekMessage)
+BOOL16      WINAPI Pie16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI Pie32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
+#define     Pie WINELIB_NAME(Pie)
+BOOL16      WINAPI PlayMetaFile16(HDC16,HMETAFILE16);
+BOOL32      WINAPI PlayMetaFile32(HDC32,HMETAFILE32);
+#define     PlayMetaFile WINELIB_NAME(PlayMetaFile)
+VOID        WINAPI PlayMetaFileRecord16(HDC16,LPHANDLETABLE16,LPMETARECORD,UINT16);
+BOOL32      WINAPI PlayMetaFileRecord32(HDC32,LPHANDLETABLE32,LPMETARECORD,UINT32);
+#define     PlayMetaFileRecord WINELIB_NAME(PlayMetaFileRecord)
+BOOL16      WINAPI PolyPolygon16(HDC16,LPPOINT16,LPINT16,UINT16);
+BOOL32      WINAPI PolyPolygon32(HDC32,LPPOINT32,LPINT32,UINT32);
+#define     PolyPolygon WINELIB_NAME(PolyPolygon)
+BOOL16      WINAPI Polygon16(HDC16,LPPOINT16,INT16);
+BOOL32      WINAPI Polygon32(HDC32,LPPOINT32,INT32);
+#define     Polygon WINELIB_NAME(Polygon)
+BOOL16      WINAPI Polyline16(HDC16,LPPOINT16,INT16);
+BOOL32      WINAPI Polyline32(HDC32,LPPOINT32,INT32);
+#define     Polyline WINELIB_NAME(Polyline)
+BOOL16      WINAPI PostAppMessage16(HTASK16,UINT16,WPARAM16,LPARAM);
+#define     PostAppMessage32A(thread,msg,wparam,lparam) \
+            PostThreadMessage32A((DWORD)(thread),msg,wparam,lparam)
+#define     PostAppMessage32W(thread,msg,wparam,lparam) \
+            PostThreadMessage32W((DWORD)(thread),msg,wparam,lparam)
+#define     PostAppMessage WINELIB_NAME_AW(PostAppMessage)
+BOOL16      WINAPI PostMessage16(HWND16,UINT16,WPARAM16,LPARAM);
+BOOL32      WINAPI PostMessage32A(HWND32,UINT32,WPARAM32,LPARAM);
+BOOL32      WINAPI PostMessage32W(HWND32,UINT32,WPARAM32,LPARAM);
+#define     PostMessage WINELIB_NAME_AW(PostMessage)
+void        WINAPI PostQuitMessage16(INT16);
+void        WINAPI PostQuitMessage32(INT32);
+#define     PostQuitMessage WINELIB_NAME(PostQuitMessage)
+BOOL16      WINAPI PtInRect16(const RECT16*,POINT16);
+BOOL32      WINAPI PtInRect32(const RECT32*,POINT32);
+#define     PtInRect WINELIB_NAME(PtInRect)
+BOOL16      WINAPI PtInRegion16(HRGN16,INT16,INT16);
+BOOL32      WINAPI PtInRegion32(HRGN32,INT32,INT32);
+#define     PtInRegion WINELIB_NAME(PtInRegion)
+BOOL16      WINAPI PtVisible16(HDC16,INT16,INT16);
+BOOL32      WINAPI PtVisible32(HDC32,INT32,INT32);
+#define     PtVisible WINELIB_NAME(PtVisible)
+UINT16      WINAPI RealizePalette16(HDC16);
+UINT32      WINAPI RealizePalette32(HDC32);
+#define     RealizePalette WINELIB_NAME(RealizePalette)
+BOOL16      WINAPI Rectangle16(HDC16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI Rectangle32(HDC32,INT32,INT32,INT32,INT32);
+#define     Rectangle WINELIB_NAME(Rectangle)
+BOOL16      WINAPI RectInRegion16(HRGN16,const RECT16 *);
+BOOL32      WINAPI RectInRegion32(HRGN32,const RECT32 *);
+#define     RectInRegion WINELIB_NAME(RectInRegion)
+BOOL16      WINAPI RectVisible16(HDC16,LPRECT16);
+BOOL32      WINAPI RectVisible32(HDC32,LPRECT32);
+#define     RectVisible WINELIB_NAME(RectVisible)
+BOOL16      WINAPI RedrawWindow16(HWND16,const RECT16*,HRGN16,UINT16);
+BOOL32      WINAPI RedrawWindow32(HWND32,const RECT32*,HRGN32,UINT32);
+#define     RedrawWindow WINELIB_NAME(RedrawWindow)
+DWORD       WINAPI RegCreateKey16(HKEY,LPCSTR,LPHKEY);
+DWORD       WINAPI RegCreateKey32A(HKEY,LPCSTR,LPHKEY);
+DWORD       WINAPI RegCreateKey32W(HKEY,LPCWSTR,LPHKEY);
+#define     RegCreateKey WINELIB_NAME_AW(RegCreateKey)
+DWORD       WINAPI RegDeleteKey16(HKEY,LPCSTR);
+DWORD       WINAPI RegDeleteKey32A(HKEY,LPCSTR);
+DWORD       WINAPI RegDeleteKey32W(HKEY,LPWSTR);
+#define     RegDeleteKey WINELIB_NAME_AW(RegDeleteKey)
+DWORD       WINAPI RegDeleteValue16(HKEY,LPSTR);
+DWORD       WINAPI RegDeleteValue32A(HKEY,LPSTR);
+DWORD       WINAPI RegDeleteValue32W(HKEY,LPWSTR);
+#define     RegDeleteValue WINELIB_NAME_AW(RegDeleteValue)
+DWORD       WINAPI RegEnumKey16(HKEY,DWORD,LPSTR,DWORD);
+DWORD       WINAPI RegEnumKey32A(HKEY,DWORD,LPSTR,DWORD);
+DWORD       WINAPI RegEnumKey32W(HKEY,DWORD,LPWSTR,DWORD);
+#define     RegEnumKey WINELIB_NAME_AW(RegEnumKey)
+DWORD       WINAPI RegEnumValue16(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+DWORD       WINAPI RegEnumValue32A(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+DWORD       WINAPI RegEnumValue32W(HKEY,DWORD,LPWSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+#define     RegEnumValue WINELIB_NAME_AW(RegEnumValue)
+ATOM        WINAPI RegisterClass16(const WNDCLASS16*);
+ATOM        WINAPI RegisterClass32A(const WNDCLASS32A *);
+ATOM        WINAPI RegisterClass32W(const WNDCLASS32W *);
+#define     RegisterClass WINELIB_NAME_AW(RegisterClass)
+ATOM        WINAPI RegisterClassEx16(const WNDCLASSEX16*);
+ATOM        WINAPI RegisterClassEx32A(const WNDCLASSEX32A *);
+ATOM        WINAPI RegisterClassEx32W(const WNDCLASSEX32W *);
+#define     RegisterClassEx WINELIB_NAME_AW(RegisterClassEx)
+UINT16      WINAPI RegisterClipboardFormat16(LPCSTR);
+UINT32      WINAPI RegisterClipboardFormat32A(LPCSTR);
+UINT32      WINAPI RegisterClipboardFormat32W(LPCWSTR);
+#define     RegisterClipboardFormat WINELIB_NAME_AW(RegisterClipboardFormat)
+WORD        WINAPI RegisterWindowMessage16(SEGPTR);
+WORD        WINAPI RegisterWindowMessage32A(LPCSTR);
+WORD        WINAPI RegisterWindowMessage32W(LPCWSTR);
+#define     RegisterWindowMessage WINELIB_NAME_AW(RegisterWindowMessage)
+DWORD       WINAPI RegOpenKey16(HKEY,LPCSTR,LPHKEY);
+DWORD       WINAPI RegOpenKey32A(HKEY,LPCSTR,LPHKEY);
+DWORD       WINAPI RegOpenKey32W(HKEY,LPCWSTR,LPHKEY);
+#define     RegOpenKey WINELIB_NAME_AW(RegOpenKey)
+DWORD       WINAPI RegQueryValue16(HKEY,LPSTR,LPSTR,LPDWORD);
+DWORD       WINAPI RegQueryValue32A(HKEY,LPSTR,LPSTR,LPDWORD);
+DWORD       WINAPI RegQueryValue32W(HKEY,LPWSTR,LPWSTR,LPDWORD);
+#define     RegQueryValue WINELIB_NAME_AW(RegQueryValue)
+DWORD       WINAPI RegQueryValueEx16(HKEY,LPSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+DWORD       WINAPI RegQueryValueEx32A(HKEY,LPSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+DWORD       WINAPI RegQueryValueEx32W(HKEY,LPWSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
+#define     RegQueryValueEx WINELIB_NAME_AW(RegQueryValueEx)
+DWORD       WINAPI RegSetValue16(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
+DWORD       WINAPI RegSetValue32A(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
+DWORD       WINAPI RegSetValue32W(HKEY,LPCWSTR,DWORD,LPCWSTR,DWORD);
+#define     RegSetValue WINELIB_NAME_AW(RegSetValue)
+DWORD       WINAPI RegSetValueEx16(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD);
+DWORD       WINAPI RegSetValueEx32A(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD);
+DWORD       WINAPI RegSetValueEx32W(HKEY,LPWSTR,DWORD,DWORD,LPBYTE,DWORD);
+#define     RegSetValueEx WINELIB_NAME_AW(RegSetValueEx)
+INT16       WINAPI ReleaseDC16(HWND16,HDC16);
+INT32       WINAPI ReleaseDC32(HWND32,HDC32);
+#define     ReleaseDC WINELIB_NAME(ReleaseDC)
+BOOL16      WINAPI RemoveDirectory16(LPCSTR);
+BOOL32      WINAPI RemoveDirectory32A(LPCSTR);
+BOOL32      WINAPI RemoveDirectory32W(LPCWSTR);
+#define     RemoveDirectory WINELIB_NAME_AW(RemoveDirectory)
+BOOL16      WINAPI RemoveFontResource16(SEGPTR);
+BOOL32      WINAPI RemoveFontResource32A(LPCSTR);
+BOOL32      WINAPI RemoveFontResource32W(LPCWSTR);
+#define     RemoveFontResource WINELIB_NAME_AW(RemoveFontResource)
+BOOL16      WINAPI RemoveMenu16(HMENU16,UINT16,UINT16);
+BOOL32      WINAPI RemoveMenu32(HMENU32,UINT32,UINT32);
+#define     RemoveMenu WINELIB_NAME(RemoveMenu)
+HANDLE16    WINAPI RemoveProp16(HWND16,LPCSTR);
+HANDLE32    WINAPI RemoveProp32A(HWND32,LPCSTR);
+HANDLE32    WINAPI RemoveProp32W(HWND32,LPCWSTR);
+#define     RemoveProp WINELIB_NAME_AW(RemoveProp)
+VOID        WINAPI ReplyMessage16(LRESULT);
+BOOL32      WINAPI ReplyMessage32(LRESULT);
+#define     ReplyMessage WINELIB_NAME(ReplyMessage)
+HDC16       WINAPI ResetDC16(HDC16,const DEVMODE16 *);
+HDC32       WINAPI ResetDC32A(HDC32,const DEVMODE32A *);
+HDC32       WINAPI ResetDC32W(HDC32,const DEVMODE32W *);
+#define     ResetDC WINELIB_NAME_AW(ResetDC)
+BOOL16      WINAPI ResizePalette16(HPALETTE16,UINT16);
+BOOL32      WINAPI ResizePalette32(HPALETTE32,UINT32);
+#define     ResizePalette WINELIB_NAME(ResizePalette)
+BOOL16      WINAPI RestoreDC16(HDC16,INT16);
+BOOL32      WINAPI RestoreDC32(HDC32,INT32);
+#define     RestoreDC WINELIB_NAME(RestoreDC)
+BOOL16      WINAPI RoundRect16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16);
+BOOL32      WINAPI RoundRect32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32);
+#define     RoundRect WINELIB_NAME(RoundRect)
+INT16       WINAPI SaveDC16(HDC16);
+INT32       WINAPI SaveDC32(HDC32);
+#define     SaveDC WINELIB_NAME(SaveDC)
+BOOL16      WINAPI ScaleViewportExtEx16(HDC16,INT16,INT16,INT16,INT16,LPSIZE16);
+BOOL32      WINAPI ScaleViewportExtEx32(HDC32,INT32,INT32,INT32,INT32,LPSIZE32);
+#define     ScaleViewportExtEx WINELIB_NAME(ScaleViewportExtEx)
+BOOL16      WINAPI ScaleWindowExtEx16(HDC16,INT16,INT16,INT16,INT16,LPSIZE16);
+BOOL32      WINAPI ScaleWindowExtEx32(HDC32,INT32,INT32,INT32,INT32,LPSIZE32);
+#define     ScaleWindowExtEx WINELIB_NAME(ScaleWindowExtEx)
+void        WINAPI ScreenToClient16(HWND16,LPPOINT16);
+void        WINAPI ScreenToClient32(HWND32,LPPOINT32);
+#define     ScreenToClient WINELIB_NAME(ScreenToClient)
+VOID        WINAPI ScrollChildren16(HWND16,UINT16,WPARAM16,LPARAM);
+VOID        WINAPI ScrollChildren32(HWND32,UINT32,WPARAM32,LPARAM);
+#define     ScrollChildren WINELIB_NAME(ScrollChildren)
+BOOL16      WINAPI ScrollDC16(HDC16,INT16,INT16,const RECT16*,const RECT16*,
                       HRGN16,LPRECT16);
-BOOL32     ScrollDC32(HDC32,INT32,INT32,const RECT32*,const RECT32*,
+BOOL32      WINAPI ScrollDC32(HDC32,INT32,INT32,const RECT32*,const RECT32*,
                       HRGN32,LPRECT32);
-#define    ScrollDC WINELIB_NAME(ScrollDC)
-void       ScrollWindow16(HWND16,INT16,INT16,const RECT16*,const RECT16*);
-BOOL32     ScrollWindow32(HWND32,INT32,INT32,const RECT32*,const RECT32*);
-#define    ScrollWindow WINELIB_NAME(ScrollWindow)
-INT16      ScrollWindowEx16(HWND16,INT16,INT16,const RECT16*,const RECT16*,
-                            HRGN16,LPRECT16,UINT16);
-INT32      ScrollWindowEx32(HWND32,INT32,INT32,const RECT32*,const RECT32*,
-                            HRGN32,LPRECT32,UINT32);
-#define    ScrollWindowEx WINELIB_NAME(ScrollWindowEx)
-INT16      SelectClipRgn16(HDC16,HRGN16);
-INT32      SelectClipRgn32(HDC32,HRGN32);
-#define    SelectClipRgn WINELIB_NAME(SelectClipRgn)
-HGDIOBJ16  SelectObject16(HDC16,HGDIOBJ16);
-HGDIOBJ32  SelectObject32(HDC32,HGDIOBJ32);
-#define    SelectObject WINELIB_NAME(SelectObject)
-HPALETTE16 SelectPalette16(HDC16,HPALETTE16,BOOL16);
-HPALETTE32 SelectPalette32(HDC32,HPALETTE32,BOOL32);
-#define    SelectPalette WINELIB_NAME(SelectPalette)
-LRESULT    SendDlgItemMessage16(HWND16,INT16,UINT16,WPARAM16,LPARAM);
-LRESULT    SendDlgItemMessage32A(HWND32,INT32,UINT32,WPARAM32,LPARAM);
-LRESULT    SendDlgItemMessage32W(HWND32,INT32,UINT32,WPARAM32,LPARAM);
-#define    SendDlgItemMessage WINELIB_NAME_AW(SendDlgItemMessage)
-LRESULT    SendMessage16(HWND16,UINT16,WPARAM16,LPARAM);
-LRESULT    SendMessage32A(HWND32,UINT32,WPARAM32,LPARAM);
-LRESULT    SendMessage32W(HWND32,UINT32,WPARAM32,LPARAM);
-#define    SendMessage WINELIB_NAME_AW(SendMessage)
-HWND16     SetActiveWindow16(HWND16);
-HWND32     SetActiveWindow32(HWND32);
-#define    SetActiveWindow WINELIB_NAME(SetActiveWindow)
-LONG       SetBitmapBits16(HBITMAP16,LONG,LPCVOID);
-LONG       SetBitmapBits32(HBITMAP32,LONG,LPCVOID);
-#define    SetBitmapBits WINELIB_NAME(SetBitmapBits)
-BOOL16     SetBitmapDimensionEx16(HBITMAP16,INT16,INT16,LPSIZE16);
-BOOL32     SetBitmapDimensionEx32(HBITMAP32,INT32,INT32,LPSIZE32);
-#define    SetBitmapDimensionEx WINELIB_NAME(SetBitmapDimensionEx)
-COLORREF   SetBkColor16(HDC16,COLORREF);
-COLORREF   SetBkColor32(HDC32,COLORREF);
-#define    SetBkColor WINELIB_NAME(SetBkColor)
-INT16      SetBkMode16(HDC16,INT16);
-INT32      SetBkMode32(HDC32,INT32);
-#define    SetBkMode WINELIB_NAME(SetBkMode)
-HWND16     SetCapture16(HWND16);
-HWND32     SetCapture32(HWND32);
-#define    SetCapture WINELIB_NAME(SetCapture)
-VOID       SetCaretBlinkTime16(UINT16);
-BOOL32     SetCaretBlinkTime32(UINT32);
-#define    SetCaretBlinkTime WINELIB_NAME(SetCaretBlinkTime)
-VOID       SetCaretPos16(INT16,INT16);
-BOOL32     SetCaretPos32(INT32,INT32);
-#define    SetCaretPos WINELIB_NAME(SetCaretPos)
-LONG       SetClassLong16(HWND16,INT16,LONG);
-LONG       SetClassLong32A(HWND32,INT32,LONG);
-LONG       SetClassLong32W(HWND32,INT32,LONG);
-#define    SetClassLong WINELIB_NAME_AW(SetClassLong)
-WORD       SetClassWord16(HWND16,INT16,WORD);
-WORD       SetClassWord32(HWND32,INT32,WORD);
-#define    SetClassWord WINELIB_NAME(SetClassWord)
-HANDLE16   SetClipboardData16(UINT16,HANDLE16);
-HANDLE32   SetClipboardData32(UINT32,HANDLE32);
-#define    SetClipboardData WINELIB_NAME(SetClipboardData)
-HWND16     SetClipboardViewer16(HWND16);
-HWND32     SetClipboardViewer32(HWND32);
-#define    SetClipboardViewer WINELIB_NAME(SetClipboardViewer)
-INT16      SetCommBreak16(INT16);
-BOOL32     SetCommBreak32(INT32);
-#define    SetCommBreak WINELIB_NAME(SetCommBreak)
-INT16      SetCommState16(LPDCB16);
-BOOL32     SetCommState32(INT32,LPDCB32);
-#define    SetCommState WINELIB_NAME(SetCommState)
-BOOL16     SetCurrentDirectory16(LPCSTR);
-BOOL32     SetCurrentDirectory32A(LPCSTR);
-BOOL32     SetCurrentDirectory32W(LPCWSTR);
-#define    SetCurrentDirectory WINELIB_NAME_AW(SetCurrentDirectory)
-HCURSOR16  SetCursor16(HCURSOR16);
-HCURSOR32  SetCursor32(HCURSOR32);
-#define    SetCursor WINELIB_NAME(SetCursor)
-void       SetCursorPos16(INT16,INT16);
-BOOL32     SetCursorPos32(INT32,INT32);
-#define    SetCursorPos WINELIB_NAME(SetCursorPos)
-BOOL16     SetDeskWallPaper16(LPCSTR);
-BOOL32     SetDeskWallPaper32(LPCSTR);
-#define    SetDeskWallPaper WINELIB_NAME(SetDeskWallPaper)
-INT16      SetDIBits16(HDC16,HBITMAP16,UINT16,UINT16,LPCVOID,const BITMAPINFO*,UINT16);
-INT32      SetDIBits32(HDC32,HBITMAP32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
-#define    SetDIBits WINELIB_NAME(SetDIBits)
-INT16      SetDIBitsToDevice16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,
-                               UINT16,UINT16,LPCVOID,const BITMAPINFO*,UINT16);
-INT32      SetDIBitsToDevice32(HDC32,INT32,INT32,DWORD,DWORD,INT32,INT32,
-                               UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
-#define    SetDIBitsToDevice WINELIB_NAME(SetDIBitsToDevice)
-void       SetDlgItemInt16(HWND16,INT16,UINT16,BOOL16);
-void       SetDlgItemInt32(HWND32,INT32,UINT32,BOOL32);
-#define    SetDlgItemInt WINELIB_NAME(SetDlgItemInt)
-void       SetDlgItemText16(HWND16,INT16,SEGPTR);
-void       SetDlgItemText32A(HWND32,INT32,LPCSTR);
-void       SetDlgItemText32W(HWND32,INT32,LPCWSTR);
-#define    SetDlgItemText WINELIB_NAME_AW(SetDlgItemText)
-VOID       SetDoubleClickTime16(UINT16);
-BOOL32     SetDoubleClickTime32(UINT32);
-#define    SetDoubleClickTime WINELIB_NAME(SetDoubleClickTime)
-UINT16     SetErrorMode16(UINT16);
-UINT32     SetErrorMode32(UINT32);
-#define    SetErrorMode WINELIB_NAME(SetErrorMode)
-BOOL16     SetFileAttributes16(LPCSTR,DWORD);
-BOOL32     SetFileAttributes32A(LPCSTR,DWORD);
-BOOL32     SetFileAttributes32W(LPCWSTR,DWORD);
-#define    SetFileAttributes WINELIB_NAME_AW(SetFileAttributes)
-HWND16     SetFocus16(HWND16);
-HWND32     SetFocus32(HWND32);
-#define    SetFocus WINELIB_NAME(SetFocus)
-UINT16     SetHandleCount16(UINT16);
-UINT32     SetHandleCount32(UINT32);
-#define    SetHandleCount WINELIB_NAME(SetHandleCount)
-void       SetInternalWindowPos16(HWND16,UINT16,LPRECT16,LPPOINT16);
-void       SetInternalWindowPos32(HWND32,UINT32,LPRECT32,LPPOINT32);
-#define    SetInternalWindowPos WINELIB_NAME(SetInternalWindowPos)
-INT16      SetMapMode16(HDC16,INT16);
-INT32      SetMapMode32(HDC32,INT32);
-#define    SetMapMode WINELIB_NAME(SetMapMode)
-DWORD      SetMapperFlags16(HDC16,DWORD);
-DWORD      SetMapperFlags32(HDC32,DWORD);
-#define    SetMapperFlags WINELIB_NAME(SetMapperFlags)
-BOOL16     SetMenu16(HWND16,HMENU16);
-BOOL32     SetMenu32(HWND32,HMENU32);
-#define    SetMenu WINELIB_NAME(SetMenu)
-BOOL16     SetMenuItemBitmaps16(HMENU16,UINT16,UINT16,HBITMAP16,HBITMAP16);
-BOOL32     SetMenuItemBitmaps32(HMENU32,UINT32,UINT32,HBITMAP32,HBITMAP32);
-#define    SetMenuItemBitmaps WINELIB_NAME(SetMenuItemBitmaps)
-BOOL16     SetMessageQueue16(INT16);
-BOOL32     SetMessageQueue32(INT32);
-#define    SetMessageQueue WINELIB_NAME(SetMessageQueue)
-UINT16     SetPaletteEntries16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
-UINT32     SetPaletteEntries32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
-#define    SetPaletteEntries WINELIB_NAME(SetPaletteEntries)
-HWND16     SetParent16(HWND16,HWND16);
-HWND32     SetParent32(HWND32,HWND32);
-#define    SetParent WINELIB_NAME(SetParent)
-COLORREF   SetPixel16(HDC16,INT16,INT16,COLORREF);
-COLORREF   SetPixel32(HDC32,INT32,INT32,COLORREF);
-#define    SetPixel WINELIB_NAME(SetPixel)
-INT16      SetPolyFillMode16(HDC16,INT16);
-INT32      SetPolyFillMode32(HDC32,INT32);
-#define    SetPolyFillMode WINELIB_NAME(SetPolyFillMode)
-BOOL16     SetProp16(HWND16,LPCSTR,HANDLE16);
-BOOL32     SetProp32A(HWND32,LPCSTR,HANDLE32);
-BOOL32     SetProp32W(HWND32,LPCWSTR,HANDLE32);
-#define    SetProp WINELIB_NAME_AW(SetProp)
-void       SetRect16(LPRECT16,INT16,INT16,INT16,INT16);
-void       SetRect32(LPRECT32,INT32,INT32,INT32,INT32);
-#define    SetRect WINELIB_NAME(SetRect)
-void       SetRectEmpty16(LPRECT16);
-void       SetRectEmpty32(LPRECT32);
-#define    SetRectEmpty WINELIB_NAME(SetRectEmpty)
-VOID       SetRectRgn16(HRGN16,INT16,INT16,INT16,INT16);
-VOID       SetRectRgn32(HRGN32,INT32,INT32,INT32,INT32);
-#define    SetRectRgn WINELIB_NAME(SetRectRgn)
-INT16      SetRelAbs16(HDC16,INT16);
-INT32      SetRelAbs32(HDC32,INT32);
-#define    SetRelAbs WINELIB_NAME(SetRelAbs)
-INT16      SetROP216(HDC16,INT16);
-INT32      SetROP232(HDC32,INT32);
-#define    SetROP2 WINELIB_NAME(SetROP2)
-INT16      SetScrollInfo16(HWND16,INT16,const SCROLLINFO*,BOOL16);
-INT32      SetScrollInfo32(HWND32,INT32,const SCROLLINFO*,BOOL32);
-#define    SetScrollInfo WINELIB_NAME(SetScrollInfo)
-INT16      SetScrollPos16(HWND16,INT16,INT16,BOOL16);
-INT32      SetScrollPos32(HWND32,INT32,INT32,BOOL32);
-#define    SetScrollPos WINELIB_NAME(SetScrollPos)
-void       SetScrollRange16(HWND16,INT16,INT16,INT16,BOOL16);
-BOOL32     SetScrollRange32(HWND32,INT32,INT32,INT32,BOOL32);
-#define    SetScrollRange WINELIB_NAME(SetScrollRange)
-INT16      SetSoundNoise16(INT16,INT16);
-DWORD      SetSoundNoise32(DWORD,DWORD);
-#define    SetSoundNoise WINELIB_NAME(SetSoundNoise)
-INT16      SetStretchBltMode16(HDC16,INT16);
-INT32      SetStretchBltMode32(HDC32,INT32);
-#define    SetStretchBltMode WINELIB_NAME(SetStretchBltMode)
-VOID       SetSysColors16(INT16,const INT16*,const COLORREF*);
-BOOL32     SetSysColors32(INT32,const INT32*,const COLORREF*);
-#define    SetSysColors WINELIB_NAME(SetSysColors)
-HWND16     SetSysModalWindow16(HWND16);
-#define    SetSysModalWindow32(hwnd) ((HWND32)0)
-#define    SetSysModalWindow WINELIB_NAME(SetSysModalWindow)
-BOOL16     SetSystemMenu16(HWND16,HMENU16);
-BOOL32     SetSystemMenu32(HWND32,HMENU32);
-#define    SetSystemMenu WINELIB_NAME(SetSystemMenu)
-UINT16     SetSystemPaletteUse16(HDC16,UINT16);
-UINT32     SetSystemPaletteUse32(HDC32,UINT32);
-#define    SetSystemPaletteUse WINELIB_NAME(SetSystemPaletteUse)
-UINT16     SetSystemTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
-UINT32     SetSystemTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
-#define    SetSystemTimer WINELIB_NAME(SetSystemTimer)
-UINT16     SetTextAlign16(HDC16,UINT16);
-UINT32     SetTextAlign32(HDC32,UINT32);
-#define    SetTextAlign WINELIB_NAME(SetTextAlign)
-INT16      SetTextCharacterExtra16(HDC16,INT16);
-INT32      SetTextCharacterExtra32(HDC32,INT32);
-#define    SetTextCharacterExtra WINELIB_NAME(SetTextCharacterExtra)
-COLORREF   SetTextColor16(HDC16,COLORREF);
-COLORREF   SetTextColor32(HDC32,COLORREF);
-#define    SetTextColor WINELIB_NAME(SetTextColor)
-INT16      SetTextJustification16(HDC16,INT16,INT16);
-BOOL32     SetTextJustification32(HDC32,INT32,INT32);
-#define    SetTextJustification WINELIB_NAME(SetTextJustification)
-UINT16     SetTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
-UINT32     SetTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
-#define    SetTimer WINELIB_NAME(SetTimer)
-BOOL16     SetViewportExtEx16(HDC16,INT16,INT16,LPSIZE16);
-BOOL32     SetViewportExtEx32(HDC32,INT32,INT32,LPSIZE32);
-#define    SetViewportExtEx WINELIB_NAME(SetViewportExtEx)
-BOOL16     SetViewportOrgEx16(HDC16,INT16,INT16,LPPOINT16);
-BOOL32     SetViewportOrgEx32(HDC32,INT32,INT32,LPPOINT32);
-#define    SetViewportOrgEx WINELIB_NAME(SetViewportOrgEx)
-INT16      SetVoiceAccent16(INT16,INT16,INT16,INT16,INT16);
-DWORD      SetVoiceAccent32(DWORD,DWORD,DWORD,DWORD,DWORD);
-#define    SetVoiceAccent WINELIB_NAME(SetVoiceAccent)
-INT16      SetVoiceEnvelope16(INT16,INT16,INT16);
-DWORD      SetVoiceEnvelope32(DWORD,DWORD,DWORD);
-#define    SetVoiceEnvelope WINELIB_NAME(SetVoiceEnvelope)
-INT16      SetVoiceNote16(INT16,INT16,INT16,INT16);
-DWORD      SetVoiceNote32(DWORD,DWORD,DWORD,DWORD);
-#define    SetVoiceNote WINELIB_NAME(SetVoiceNote)
-INT16      SetVoiceQueueSize16(INT16,INT16);
-DWORD      SetVoiceQueueSize32(DWORD,DWORD);
-#define    SetVoiceQueueSize WINELIB_NAME(SetVoiceQueueSize)
-INT16      SetVoiceSound16(INT16,DWORD,INT16);
-DWORD      SetVoiceSound32(DWORD,DWORD,DWORD);
-#define    SetVoiceSound WINELIB_NAME(SetVoiceSound)
-INT16      SetVoiceThreshold16(INT16,INT16);
-DWORD      SetVoiceThreshold32(DWORD,DWORD);
-#define    SetVoiceThreshold WINELIB_NAME(SetVoiceThreshold)
-BOOL16     SetWindowExtEx16(HDC16,INT16,INT16,LPSIZE16);
-BOOL32     SetWindowExtEx32(HDC32,INT32,INT32,LPSIZE32);
-#define    SetWindowExtEx WINELIB_NAME(SetWindowExtEx)
-LONG       SetWindowLong16(HWND16,INT16,LONG);
-LONG       SetWindowLong32A(HWND32,INT32,LONG);
-LONG       SetWindowLong32W(HWND32,INT32,LONG);
-#define    SetWindowLong WINELIB_NAME_AW(SetWindowLong)
-BOOL16     SetWindowOrgEx16(HDC16,INT16,INT16,LPPOINT16);
-BOOL32     SetWindowOrgEx32(HDC32,INT32,INT32,LPPOINT32);
-#define    SetWindowOrgEx WINELIB_NAME(SetWindowOrgEx)
-BOOL16     SetWindowPlacement16(HWND16,const WINDOWPLACEMENT16*);
-BOOL32     SetWindowPlacement32(HWND32,const WINDOWPLACEMENT32*);
-#define    SetWindowPlacement WINELIB_NAME(SetWindowPlacement)
-FARPROC16  SetWindowsHook16(INT16,HOOKPROC16);
-HHOOK      SetWindowsHook32A(INT32,HOOKPROC32);
-HHOOK      SetWindowsHook32W(INT32,HOOKPROC32);
-#define    SetWindowsHook WINELIB_NAME_AW(SetWindowsHook)
-HHOOK      SetWindowsHookEx16(INT16,HOOKPROC16,HINSTANCE16,HTASK16);
-HHOOK      SetWindowsHookEx32A(INT32,HOOKPROC32,HINSTANCE32,DWORD);
-HHOOK      SetWindowsHookEx32W(INT32,HOOKPROC32,HINSTANCE32,DWORD);
-#define    SetWindowsHookEx WINELIB_NAME_AW(SetWindowsHookEx)
-BOOL16     SetWindowPos16(HWND16,HWND16,INT16,INT16,INT16,INT16,WORD);
-BOOL32     SetWindowPos32(HWND32,HWND32,INT32,INT32,INT32,INT32,WORD);
-#define    SetWindowPos WINELIB_NAME(SetWindowPos)
-void       SetWindowText16(HWND16,SEGPTR);
-void       SetWindowText32A(HWND32,LPCSTR);
-void       SetWindowText32W(HWND32,LPCWSTR);
-#define    SetWindowText WINELIB_NAME_AW(SetWindowText)
-WORD       SetWindowWord16(HWND16,INT16,WORD);
-WORD       SetWindowWord32(HWND32,INT32,WORD);
-#define    SetWindowWord WINELIB_NAME(SetWindowWord)
-BOOL16     ShellAbout16(HWND16,LPCSTR,LPCSTR,HICON16);
-BOOL32     ShellAbout32A(HWND32,LPCSTR,LPCSTR,HICON32);
-BOOL32     ShellAbout32W(HWND32,LPCWSTR,LPCWSTR,HICON32);
-#define    ShellAbout WINELIB_NAME_AW(ShellAbout)
-HINSTANCE16 ShellExecute16(HWND16,LPCSTR,LPCSTR,LPCSTR,LPCSTR,INT16);
-HINSTANCE32 ShellExecute32A(HWND32,LPCSTR,LPCSTR,LPCSTR,LPCSTR,INT32);
-HINSTANCE32 ShellExecute32W(HWND32,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,INT32);
-#define    ShellExecute WINELIB_NAME_AW(ShellExecute)
-VOID       ShowCaret16(HWND16);
-BOOL32     ShowCaret32(HWND32);
-#define    ShowCaret WINELIB_NAME(ShowCaret)
-INT16      ShowCursor16(BOOL16);
-INT32      ShowCursor32(BOOL32);
-#define    ShowCursor WINELIB_NAME(ShowCursor)
-void       ShowScrollBar16(HWND16,INT16,BOOL16);
-BOOL32     ShowScrollBar32(HWND32,INT32,BOOL32);
-#define    ShowScrollBar WINELIB_NAME(ShowScrollBar)
-VOID       ShowOwnedPopups16(HWND16,BOOL16);
-BOOL32     ShowOwnedPopups32(HWND32,BOOL32);
-#define    ShowOwnedPopups WINELIB_NAME(ShowOwnedPopups)
-BOOL16     ShowWindow16(HWND16,INT16);
-BOOL32     ShowWindow32(HWND32,INT32);
-#define    ShowWindow WINELIB_NAME(ShowWindow)
-DWORD      SizeofResource16(HMODULE16,HRSRC16);
-DWORD      SizeofResource32(HMODULE32,HRSRC32);
-#define    SizeofResource WINELIB_NAME(SizeofResource)
-INT16      StartDoc16(HDC16,const DOCINFO16*);
-INT32      StartDoc32A(HDC32,const DOCINFO32A*);
-INT32      StartDoc32W(HDC32,const DOCINFO32W*);
-#define    StartDoc WINELIB_NAME_AW(StartDoc)
-INT16      StartSound16(void);
-VOID       StartSound32(void);
-#define    StartSound WINELIB_NAME(StartSound)
-INT16      StopSound16(void);
-VOID       StopSound32(void);
-#define    StopSound WINELIB_NAME(StopSound)
-BOOL16     StretchBlt16(HDC16,INT16,INT16,INT16,INT16,HDC16,INT16,INT16,
-                        INT16,INT16,DWORD);
-BOOL32     StretchBlt32(HDC32,INT32,INT32,INT32,INT32,HDC32,INT32,INT32,
-                        INT32,INT32,DWORD);
-#define    StretchBlt WINELIB_NAME(StretchBlt)
-INT16      StretchDIBits16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,INT16,
-                           INT16,const VOID*,const BITMAPINFO*,UINT16,DWORD);
-INT32      StretchDIBits32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,INT32,
-                           INT32,const VOID*,const BITMAPINFO*,UINT32,DWORD);
-#define    StretchDIBits WINELIB_NAME(StretchDIBits)
-BOOL16     SubtractRect16(LPRECT16,const RECT16*,const RECT16*);
-BOOL32     SubtractRect32(LPRECT32,const RECT32*,const RECT32*);
-#define    SubtractRect WINELIB_NAME(SubtractRect)
-BOOL16     SwapMouseButton16(BOOL16);
-BOOL32     SwapMouseButton32(BOOL32);
-#define    SwapMouseButton WINELIB_NAME(SwapMouseButton)
-VOID       SwitchToThisWindow16(HWND16,BOOL16);
-VOID       SwitchToThisWindow32(HWND32,BOOL32);
-#define    SwitchToThisWindow WINELIB_NAME(SwitchToThisWindow)
-INT16      SyncAllVoices16(void);
-DWORD      SyncAllVoices32(void);
-#define    SyncAllVoices WINELIB_NAME(SyncAllVoices)
-BOOL16     SystemParametersInfo16(UINT16,UINT16,LPVOID,UINT16);
-BOOL32     SystemParametersInfo32A(UINT32,UINT32,LPVOID,UINT32);
-BOOL32     SystemParametersInfo32W(UINT32,UINT32,LPVOID,UINT32);
-#define    SystemParametersInfo WINELIB_NAME_AW(SystemParametersInfo)
-LONG       TabbedTextOut16(HDC16,INT16,INT16,LPCSTR,INT16,INT16,const INT16*,INT16);
-LONG       TabbedTextOut32A(HDC32,INT32,INT32,LPCSTR,INT32,INT32,const INT32*,INT32);
-LONG       TabbedTextOut32W(HDC32,INT32,INT32,LPCWSTR,INT32,INT32,const INT32*,INT32);
-#define    TabbedTextOut WINELIB_NAME_AW(TabbedTextOut)
-BOOL16     TextOut16(HDC16,INT16,INT16,LPCSTR,INT16);
-BOOL32     TextOut32A(HDC32,INT32,INT32,LPCSTR,INT32);
-BOOL32     TextOut32W(HDC32,INT32,INT32,LPCWSTR,INT32);
-#define    TextOut WINELIB_NAME_AW(TextOut)
-INT16      ToAscii16(UINT16,UINT16,LPBYTE,LPVOID,UINT16);
-INT32      ToAscii32(UINT32,UINT32,LPBYTE,LPWORD,UINT32);
-#define    ToAscii WINELIB_NAME(ToAscii)
-BOOL16     TrackPopupMenu16(HMENU16,UINT16,INT16,INT16,INT16,HWND16,const RECT16*);
-BOOL32     TrackPopupMenu32(HMENU32,UINT32,INT32,INT32,INT32,HWND32,const RECT32*);
-#define    TrackPopupMenu WINELIB_NAME(TrackPopupMenu)
-INT16      TranslateAccelerator16(HWND16,HACCEL16,LPMSG16);
-INT32      TranslateAccelerator32(HWND32,HACCEL32,LPMSG32);
-#define    TranslateAccelerator WINELIB_NAME(TranslateAccelerator)
-BOOL16     TranslateMDISysAccel16(HWND16,LPMSG16);
-BOOL32     TranslateMDISysAccel32(HWND32,LPMSG32);
-#define    TranslateMDISysAccel WINELIB_NAME(TranslateMDISysAccel)
-BOOL16     TranslateMessage16(const MSG16*);
-BOOL32     TranslateMessage32(const MSG32*);
-#define    TranslateMessage WINELIB_NAME(TranslateMessage)
-INT16      TransmitCommChar16(INT16,CHAR);
-BOOL32     TransmitCommChar32(INT32,CHAR);
-#define    TransmitCommChar WINELIB_NAME(TransmitCommChar)
-BOOL16     UnhookWindowsHook16(INT16,HOOKPROC16);
-BOOL32     UnhookWindowsHook32(INT32,HOOKPROC32);
-#define    UnhookWindowsHook WINELIB_NAME(UnhookWindowsHook)
-BOOL16     UnhookWindowsHookEx16(HHOOK);
-BOOL32     UnhookWindowsHookEx32(HHOOK);
-#define    UnhookWindowsHookEx WINELIB_NAME(UnhookWindowsHookEx)
-BOOL16     UnionRect16(LPRECT16,const RECT16*,const RECT16*);
-BOOL32     UnionRect32(LPRECT32,const RECT32*,const RECT32*);
-#define    UnionRect WINELIB_NAME(UnionRect)
-void       UnlockSegment16(HGLOBAL16);
-#define    UnlockSegment32(handle) GlobalUnfix((HANDLE32)(handle))
-#define    UnlockSegment WINELIB_NAME(UnlockSegment)
-BOOL16     UnrealizeObject16(HGDIOBJ16);
-BOOL32     UnrealizeObject32(HGDIOBJ32);
-#define    UnrealizeObject WINELIB_NAME(UnrealizeObject)
-BOOL16     UnregisterClass16(SEGPTR,HINSTANCE16);
-BOOL32     UnregisterClass32A(LPCSTR,HINSTANCE32);
-BOOL32     UnregisterClass32W(LPCWSTR,HINSTANCE32);
-#define    UnregisterClass WINELIB_NAME_AW(UnregisterClass)
-INT16      UpdateColors16(HDC16);
-BOOL32     UpdateColors32(HDC32);
-#define    UpdateColors WINELIB_NAME(UpdateColors)
-VOID       UpdateWindow16(HWND16);
-VOID       UpdateWindow32(HWND32);
-#define    UpdateWindow WINELIB_NAME(UpdateWindow)
-VOID       ValidateRect16(HWND16,const RECT16*);
-VOID       ValidateRect32(HWND32,const RECT32*);
-#define    ValidateRect WINELIB_NAME(ValidateRect)
-VOID       ValidateRgn16(HWND16,HRGN16);
-VOID       ValidateRgn32(HWND32,HRGN32);
-#define    ValidateRgn WINELIB_NAME(ValidateRgn)
-DWORD      VerFindFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*,LPSTR,UINT16*);
-DWORD      VerFindFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*,LPSTR,UINT32*);
-DWORD      VerFindFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*,LPWSTR,UINT32*);
-#define    VerFindFile WINELIB_NAME_AW(VerFindFile)
-DWORD      VerInstallFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*);
-DWORD      VerInstallFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*);
-DWORD      VerInstallFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*);
-#define    VerInstallFile WINELIB_NAME_AW(VerInstallFile)
-DWORD      VerLanguageName16(UINT16,LPSTR,UINT16);
-DWORD      VerLanguageName32A(UINT32,LPSTR,UINT32);
-DWORD      VerLanguageName32W(UINT32,LPWSTR,UINT32);
-#define    VerLanguageName WINELIB_NAME_AW(VerLanguageName)
-DWORD      VerQueryValue16(SEGPTR,LPCSTR,SEGPTR*,UINT16*);
-DWORD      VerQueryValue32A(LPVOID,LPCSTR,LPVOID*,UINT32*);
-DWORD      VerQueryValue32W(LPVOID,LPCWSTR,LPVOID*,UINT32*);
-#define    VerQueryValue WINELIB_NAME_AW(VerQueryValue)
-WORD       VkKeyScan16(CHAR);
-WORD       VkKeyScan32A(CHAR);
-WORD       VkKeyScan32W(WCHAR);
-#define    VkKeyScan WINELIB_NAME_AW(VkKeyScan)
-INT16      WaitSoundState16(INT16);
-DWORD      WaitSoundState32(DWORD);
-#define    WaitSoundState WINELIB_NAME(WaitSoundState)
-HWND16     WindowFromDC16(HDC16);
-HWND32     WindowFromDC32(HDC32);
-#define    WindowFromDC WINELIB_NAME(WindowFromDC)
-HWND16     WindowFromPoint16(POINT16);
-HWND32     WindowFromPoint32(POINT32);
-#define    WindowFromPoint WINELIB_NAME(WindowFromPoint)
-BOOL16     WritePrivateProfileString16(LPCSTR,LPCSTR,LPCSTR,LPCSTR);
-BOOL32     WritePrivateProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPCSTR);
-BOOL32     WritePrivateProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR);
-#define    WritePrivateProfileString WINELIB_NAME_AW(WritePrivateProfileString)
-BOOL16     WriteProfileString16(LPCSTR,LPCSTR,LPCSTR);
-BOOL32     WriteProfileString32A(LPCSTR,LPCSTR,LPCSTR);
-BOOL32     WriteProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR);
-#define    WriteProfileString WINELIB_NAME_AW(WriteProfileString)
-SEGPTR     lstrcat16(SEGPTR,LPCSTR);
-LPSTR      lstrcat32A(LPSTR,LPCSTR);
-LPWSTR     lstrcat32W(LPWSTR,LPCWSTR);
-#define    lstrcat WINELIB_NAME_AW(lstrcat)
-SEGPTR     lstrcatn16(SEGPTR,LPCSTR,INT16);
-LPSTR      lstrcatn32A(LPSTR,LPCSTR,INT32);
-LPWSTR     lstrcatn32W(LPWSTR,LPCWSTR,INT32);
-#define    lstrcatn WINELIB_NAME_AW(lstrcatn)
-INT16      lstrcmp16(LPCSTR,LPCSTR);
-INT32      lstrcmp32A(LPCSTR,LPCSTR);
-INT32      lstrcmp32W(LPCWSTR,LPCWSTR);
-#define    lstrcmp WINELIB_NAME_AW(lstrcmp)
-INT16      lstrcmpi16(LPCSTR,LPCSTR);
-INT32      lstrcmpi32A(LPCSTR,LPCSTR);
-INT32      lstrcmpi32W(LPCWSTR,LPCWSTR);
-#define    lstrcmpi WINELIB_NAME_AW(lstrcmpi)
-SEGPTR     lstrcpy16(SEGPTR,LPCSTR);
-LPSTR      lstrcpy32A(LPSTR,LPCSTR);
-LPWSTR     lstrcpy32W(LPWSTR,LPCWSTR);
-#define    lstrcpy WINELIB_NAME_AW(lstrcpy)
-SEGPTR     lstrcpyn16(SEGPTR,LPCSTR,INT16);
-LPSTR      lstrcpyn32A(LPSTR,LPCSTR,INT32);
-LPWSTR     lstrcpyn32W(LPWSTR,LPCWSTR,INT32);
-#define    lstrcpyn WINELIB_NAME_AW(lstrcpyn)
-INT16      lstrlen16(LPCSTR);
-INT32      lstrlen32A(LPCSTR);
-INT32      lstrlen32W(LPCWSTR);
-#define    lstrlen WINELIB_NAME_AW(lstrlen)
-HINSTANCE16 WinExec16(LPCSTR,UINT16);
-HINSTANCE32 WinExec32(LPCSTR,UINT32);
-#define    WinExec WINELIB_NAME(WinExec)
-BOOL16     WinHelp16(HWND16,LPCSTR,UINT16,DWORD);
-BOOL32     WinHelp32A(HWND32,LPCSTR,UINT32,DWORD);
-BOOL32     WinHelp32W(HWND32,LPCWSTR,UINT32,DWORD);
-#define    WinHelp WINELIB_NAME_AW(WinHelp)
-INT16      wsnprintf16(LPSTR,UINT16,LPCSTR,...);
-INT32      wsnprintf32A(LPSTR,UINT32,LPCSTR,...);
-INT32      wsnprintf32W(LPWSTR,UINT32,LPCWSTR,...);
-#define    wsnprintf WINELIB_NAME_AW(wsnprintf)
-INT16      wsprintf16(LPSTR,LPCSTR,...);
-INT32      wsprintf32A(LPSTR,LPCSTR,...);
-INT32      wsprintf32W(LPWSTR,LPCWSTR,...);
-#define    wsprintf WINELIB_NAME_AW(wsprintf)
-INT16      wvsnprintf16(LPSTR,UINT16,LPCSTR,LPCVOID);
-INT32      wvsnprintf32A(LPSTR,UINT32,LPCSTR,LPCVOID);
-INT32      wvsnprintf32W(LPWSTR,UINT32,LPCWSTR,LPCVOID);
-#define    wvsnprintf WINELIB_NAME_AW(wvsnprintf)
-INT16      wvsprintf16(LPSTR,LPCSTR,LPCVOID);
-INT32      wvsprintf32A(LPSTR,LPCSTR,LPCVOID);
-INT32      wvsprintf32W(LPWSTR,LPCWSTR,LPCVOID);
-#define    wvsprintf WINELIB_NAME_AW(wvsprintf)
-LONG       _hread16(HFILE16,LPVOID,LONG);
-LONG       _hread32(HFILE32,LPVOID,LONG);
-#define    _hread WINELIB_NAME(_hread)
-LONG       _hwrite16(HFILE16,LPCSTR,LONG);
-LONG       _hwrite32(HFILE32,LPCSTR,LONG);
-#define    _hwrite WINELIB_NAME(_hwrite)
-HFILE16    _lcreat16(LPCSTR,INT16);
-HFILE32    _lcreat32(LPCSTR,INT32);
-#define    _lcreat WINELIB_NAME(_lcreat)
-HFILE16    _lclose16(HFILE16);
-HFILE32    _lclose32(HFILE32);
-#define    _lclose WINELIB_NAME(_lclose)
-LONG       _llseek16(HFILE16,LONG,INT16);
-LONG       _llseek32(HFILE32,LONG,INT32);
-#define    _llseek WINELIB_NAME(_llseek)
-HFILE16    _lopen16(LPCSTR,INT16);
-HFILE32    _lopen32(LPCSTR,INT32);
-#define    _lopen WINELIB_NAME(_lopen)
-UINT16     _lread16(HFILE16,LPVOID,UINT16);
-UINT32     _lread32(HFILE32,LPVOID,UINT32);
-#define    _lread WINELIB_NAME(_lread)
-UINT16     _lwrite16(HFILE16,LPCSTR,UINT16);
-UINT32     _lwrite32(HFILE32,LPCSTR,UINT32);
-#define    _lwrite WINELIB_NAME(_lwrite)
+#define     ScrollDC WINELIB_NAME(ScrollDC)
+void        WINAPI ScrollWindow16(HWND16,INT16,INT16,const RECT16*,const RECT16*);
+BOOL32      WINAPI ScrollWindow32(HWND32,INT32,INT32,const RECT32*,const RECT32*);
+#define     ScrollWindow WINELIB_NAME(ScrollWindow)
+INT16       WINAPI ScrollWindowEx16(HWND16,INT16,INT16,const RECT16*,
+                                    const RECT16*,HRGN16,LPRECT16,UINT16);
+INT32       WINAPI ScrollWindowEx32(HWND32,INT32,INT32,const RECT32*,
+                                    const RECT32*,HRGN32,LPRECT32,UINT32);
+#define     ScrollWindowEx WINELIB_NAME(ScrollWindowEx)
+INT16       WINAPI SelectClipRgn16(HDC16,HRGN16);
+INT32       WINAPI SelectClipRgn32(HDC32,HRGN32);
+#define     SelectClipRgn WINELIB_NAME(SelectClipRgn)
+HGDIOBJ16   WINAPI SelectObject16(HDC16,HGDIOBJ16);
+HGDIOBJ32   WINAPI SelectObject32(HDC32,HGDIOBJ32);
+#define     SelectObject WINELIB_NAME(SelectObject)
+HPALETTE16  WINAPI SelectPalette16(HDC16,HPALETTE16,BOOL16);
+HPALETTE32  WINAPI SelectPalette32(HDC32,HPALETTE32,BOOL32);
+#define     SelectPalette WINELIB_NAME(SelectPalette)
+LRESULT     WINAPI SendDlgItemMessage16(HWND16,INT16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI SendDlgItemMessage32A(HWND32,INT32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI SendDlgItemMessage32W(HWND32,INT32,UINT32,WPARAM32,LPARAM);
+#define     SendDlgItemMessage WINELIB_NAME_AW(SendDlgItemMessage)
+LRESULT     WINAPI SendMessage16(HWND16,UINT16,WPARAM16,LPARAM);
+LRESULT     WINAPI SendMessage32A(HWND32,UINT32,WPARAM32,LPARAM);
+LRESULT     WINAPI SendMessage32W(HWND32,UINT32,WPARAM32,LPARAM);
+#define     SendMessage WINELIB_NAME_AW(SendMessage)
+HWND16      WINAPI SetActiveWindow16(HWND16);
+HWND32      WINAPI SetActiveWindow32(HWND32);
+#define     SetActiveWindow WINELIB_NAME(SetActiveWindow)
+LONG        WINAPI SetBitmapBits16(HBITMAP16,LONG,LPCVOID);
+LONG        WINAPI SetBitmapBits32(HBITMAP32,LONG,LPCVOID);
+#define     SetBitmapBits WINELIB_NAME(SetBitmapBits)
+BOOL16      WINAPI SetBitmapDimensionEx16(HBITMAP16,INT16,INT16,LPSIZE16);
+BOOL32      WINAPI SetBitmapDimensionEx32(HBITMAP32,INT32,INT32,LPSIZE32);
+#define     SetBitmapDimensionEx WINELIB_NAME(SetBitmapDimensionEx)
+COLORREF    WINAPI SetBkColor16(HDC16,COLORREF);
+COLORREF    WINAPI SetBkColor32(HDC32,COLORREF);
+#define     SetBkColor WINELIB_NAME(SetBkColor)
+INT16       WINAPI SetBkMode16(HDC16,INT16);
+INT32       WINAPI SetBkMode32(HDC32,INT32);
+#define     SetBkMode WINELIB_NAME(SetBkMode)
+HWND16      WINAPI SetCapture16(HWND16);
+HWND32      WINAPI SetCapture32(HWND32);
+#define     SetCapture WINELIB_NAME(SetCapture)
+VOID        WINAPI SetCaretBlinkTime16(UINT16);
+BOOL32      WINAPI SetCaretBlinkTime32(UINT32);
+#define     SetCaretBlinkTime WINELIB_NAME(SetCaretBlinkTime)
+VOID        WINAPI SetCaretPos16(INT16,INT16);
+BOOL32      WINAPI SetCaretPos32(INT32,INT32);
+#define     SetCaretPos WINELIB_NAME(SetCaretPos)
+LONG        WINAPI SetClassLong16(HWND16,INT16,LONG);
+LONG        WINAPI SetClassLong32A(HWND32,INT32,LONG);
+LONG        WINAPI SetClassLong32W(HWND32,INT32,LONG);
+#define     SetClassLong WINELIB_NAME_AW(SetClassLong)
+WORD        WINAPI SetClassWord16(HWND16,INT16,WORD);
+WORD        WINAPI SetClassWord32(HWND32,INT32,WORD);
+#define     SetClassWord WINELIB_NAME(SetClassWord)
+HANDLE16    WINAPI SetClipboardData16(UINT16,HANDLE16);
+HANDLE32    WINAPI SetClipboardData32(UINT32,HANDLE32);
+#define     SetClipboardData WINELIB_NAME(SetClipboardData)
+HWND16      WINAPI SetClipboardViewer16(HWND16);
+HWND32      WINAPI SetClipboardViewer32(HWND32);
+#define     SetClipboardViewer WINELIB_NAME(SetClipboardViewer)
+INT16       WINAPI SetCommBreak16(INT16);
+BOOL32      WINAPI SetCommBreak32(INT32);
+#define     SetCommBreak WINELIB_NAME(SetCommBreak)
+INT16       WINAPI SetCommState16(LPDCB16);
+BOOL32      WINAPI SetCommState32(INT32,LPDCB32);
+#define     SetCommState WINELIB_NAME(SetCommState)
+BOOL16      WINAPI SetCurrentDirectory16(LPCSTR);
+BOOL32      WINAPI SetCurrentDirectory32A(LPCSTR);
+BOOL32      WINAPI SetCurrentDirectory32W(LPCWSTR);
+#define     SetCurrentDirectory WINELIB_NAME_AW(SetCurrentDirectory)
+HCURSOR16   WINAPI SetCursor16(HCURSOR16);
+HCURSOR32   WINAPI SetCursor32(HCURSOR32);
+#define     SetCursor WINELIB_NAME(SetCursor)
+void        WINAPI SetCursorPos16(INT16,INT16);
+BOOL32      WINAPI SetCursorPos32(INT32,INT32);
+#define     SetCursorPos WINELIB_NAME(SetCursorPos)
+BOOL16      WINAPI SetDeskWallPaper16(LPCSTR);
+BOOL32      WINAPI SetDeskWallPaper32(LPCSTR);
+#define     SetDeskWallPaper WINELIB_NAME(SetDeskWallPaper)
+INT16       WINAPI SetDIBits16(HDC16,HBITMAP16,UINT16,UINT16,LPCVOID,const BITMAPINFO*,UINT16);
+INT32       WINAPI SetDIBits32(HDC32,HBITMAP32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
+#define     SetDIBits WINELIB_NAME(SetDIBits)
+INT16       WINAPI SetDIBitsToDevice16(HDC16,INT16,INT16,INT16,INT16,INT16,
+                         INT16,UINT16,UINT16,LPCVOID,const BITMAPINFO*,UINT16);
+INT32       WINAPI SetDIBitsToDevice32(HDC32,INT32,INT32,DWORD,DWORD,INT32,
+                         INT32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
+#define     SetDIBitsToDevice WINELIB_NAME(SetDIBitsToDevice)
+void        WINAPI SetDlgItemInt16(HWND16,INT16,UINT16,BOOL16);
+void        WINAPI SetDlgItemInt32(HWND32,INT32,UINT32,BOOL32);
+#define     SetDlgItemInt WINELIB_NAME(SetDlgItemInt)
+void        WINAPI SetDlgItemText16(HWND16,INT16,SEGPTR);
+void        WINAPI SetDlgItemText32A(HWND32,INT32,LPCSTR);
+void        WINAPI SetDlgItemText32W(HWND32,INT32,LPCWSTR);
+#define     SetDlgItemText WINELIB_NAME_AW(SetDlgItemText)
+VOID        WINAPI SetDoubleClickTime16(UINT16);
+BOOL32      WINAPI SetDoubleClickTime32(UINT32);
+#define     SetDoubleClickTime WINELIB_NAME(SetDoubleClickTime)
+UINT16      WINAPI SetErrorMode16(UINT16);
+UINT32      WINAPI SetErrorMode32(UINT32);
+#define     SetErrorMode WINELIB_NAME(SetErrorMode)
+BOOL16      WINAPI SetFileAttributes16(LPCSTR,DWORD);
+BOOL32      WINAPI SetFileAttributes32A(LPCSTR,DWORD);
+BOOL32      WINAPI SetFileAttributes32W(LPCWSTR,DWORD);
+#define     SetFileAttributes WINELIB_NAME_AW(SetFileAttributes)
+HWND16      WINAPI SetFocus16(HWND16);
+HWND32      WINAPI SetFocus32(HWND32);
+#define     SetFocus WINELIB_NAME(SetFocus)
+UINT16      WINAPI SetHandleCount16(UINT16);
+UINT32      WINAPI SetHandleCount32(UINT32);
+#define     SetHandleCount WINELIB_NAME(SetHandleCount)
+void        WINAPI SetInternalWindowPos16(HWND16,UINT16,LPRECT16,LPPOINT16);
+void        WINAPI SetInternalWindowPos32(HWND32,UINT32,LPRECT32,LPPOINT32);
+#define     SetInternalWindowPos WINELIB_NAME(SetInternalWindowPos)
+INT16       WINAPI SetMapMode16(HDC16,INT16);
+INT32       WINAPI SetMapMode32(HDC32,INT32);
+#define     SetMapMode WINELIB_NAME(SetMapMode)
+DWORD       WINAPI SetMapperFlags16(HDC16,DWORD);
+DWORD       WINAPI SetMapperFlags32(HDC32,DWORD);
+#define     SetMapperFlags WINELIB_NAME(SetMapperFlags)
+BOOL16      WINAPI SetMenu16(HWND16,HMENU16);
+BOOL32      WINAPI SetMenu32(HWND32,HMENU32);
+#define     SetMenu WINELIB_NAME(SetMenu)
+BOOL16      WINAPI SetMenuItemBitmaps16(HMENU16,UINT16,UINT16,HBITMAP16,HBITMAP16);
+BOOL32      WINAPI SetMenuItemBitmaps32(HMENU32,UINT32,UINT32,HBITMAP32,HBITMAP32);
+#define     SetMenuItemBitmaps WINELIB_NAME(SetMenuItemBitmaps)
+BOOL16      WINAPI SetMessageQueue16(INT16);
+BOOL32      WINAPI SetMessageQueue32(INT32);
+#define     SetMessageQueue WINELIB_NAME(SetMessageQueue)
+UINT16      WINAPI SetPaletteEntries16(HPALETTE16,UINT16,UINT16,LPPALETTEENTRY);
+UINT32      WINAPI SetPaletteEntries32(HPALETTE32,UINT32,UINT32,LPPALETTEENTRY);
+#define     SetPaletteEntries WINELIB_NAME(SetPaletteEntries)
+HWND16      WINAPI SetParent16(HWND16,HWND16);
+HWND32      WINAPI SetParent32(HWND32,HWND32);
+#define     SetParent WINELIB_NAME(SetParent)
+COLORREF    WINAPI SetPixel16(HDC16,INT16,INT16,COLORREF);
+COLORREF    WINAPI SetPixel32(HDC32,INT32,INT32,COLORREF);
+#define     SetPixel WINELIB_NAME(SetPixel)
+INT16       WINAPI SetPolyFillMode16(HDC16,INT16);
+INT32       WINAPI SetPolyFillMode32(HDC32,INT32);
+#define     SetPolyFillMode WINELIB_NAME(SetPolyFillMode)
+BOOL16      WINAPI SetProp16(HWND16,LPCSTR,HANDLE16);
+BOOL32      WINAPI SetProp32A(HWND32,LPCSTR,HANDLE32);
+BOOL32      WINAPI SetProp32W(HWND32,LPCWSTR,HANDLE32);
+#define     SetProp WINELIB_NAME_AW(SetProp)
+void        WINAPI SetRect16(LPRECT16,INT16,INT16,INT16,INT16);
+void        WINAPI SetRect32(LPRECT32,INT32,INT32,INT32,INT32);
+#define     SetRect WINELIB_NAME(SetRect)
+void        WINAPI SetRectEmpty16(LPRECT16);
+void        WINAPI SetRectEmpty32(LPRECT32);
+#define     SetRectEmpty WINELIB_NAME(SetRectEmpty)
+VOID        WINAPI SetRectRgn16(HRGN16,INT16,INT16,INT16,INT16);
+VOID        WINAPI SetRectRgn32(HRGN32,INT32,INT32,INT32,INT32);
+#define     SetRectRgn WINELIB_NAME(SetRectRgn)
+INT16       WINAPI SetRelAbs16(HDC16,INT16);
+INT32       WINAPI SetRelAbs32(HDC32,INT32);
+#define     SetRelAbs WINELIB_NAME(SetRelAbs)
+INT16       WINAPI SetROP216(HDC16,INT16);
+INT32       WINAPI SetROP232(HDC32,INT32);
+#define     SetROP2 WINELIB_NAME(SetROP2)
+INT16       WINAPI SetScrollInfo16(HWND16,INT16,const SCROLLINFO*,BOOL16);
+INT32       WINAPI SetScrollInfo32(HWND32,INT32,const SCROLLINFO*,BOOL32);
+#define     SetScrollInfo WINELIB_NAME(SetScrollInfo)
+INT16       WINAPI SetScrollPos16(HWND16,INT16,INT16,BOOL16);
+INT32       WINAPI SetScrollPos32(HWND32,INT32,INT32,BOOL32);
+#define     SetScrollPos WINELIB_NAME(SetScrollPos)
+void        WINAPI SetScrollRange16(HWND16,INT16,INT16,INT16,BOOL16);
+BOOL32      WINAPI SetScrollRange32(HWND32,INT32,INT32,INT32,BOOL32);
+#define     SetScrollRange WINELIB_NAME(SetScrollRange)
+INT16       WINAPI SetSoundNoise16(INT16,INT16);
+DWORD       WINAPI SetSoundNoise32(DWORD,DWORD);
+#define     SetSoundNoise WINELIB_NAME(SetSoundNoise)
+INT16       WINAPI SetStretchBltMode16(HDC16,INT16);
+INT32       WINAPI SetStretchBltMode32(HDC32,INT32);
+#define     SetStretchBltMode WINELIB_NAME(SetStretchBltMode)
+VOID        WINAPI SetSysColors16(INT16,const INT16*,const COLORREF*);
+BOOL32      WINAPI SetSysColors32(INT32,const INT32*,const COLORREF*);
+#define     SetSysColors WINELIB_NAME(SetSysColors)
+HWND16      WINAPI SetSysModalWindow16(HWND16);
+#define     SetSysModalWindow32(hwnd) ((HWND32)0)
+#define     SetSysModalWindow WINELIB_NAME(SetSysModalWindow)
+BOOL16      WINAPI SetSystemMenu16(HWND16,HMENU16);
+BOOL32      WINAPI SetSystemMenu32(HWND32,HMENU32);
+#define     SetSystemMenu WINELIB_NAME(SetSystemMenu)
+UINT16      WINAPI SetSystemPaletteUse16(HDC16,UINT16);
+UINT32      WINAPI SetSystemPaletteUse32(HDC32,UINT32);
+#define     SetSystemPaletteUse WINELIB_NAME(SetSystemPaletteUse)
+UINT16      WINAPI SetSystemTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
+UINT32      WINAPI SetSystemTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
+#define     SetSystemTimer WINELIB_NAME(SetSystemTimer)
+UINT16      WINAPI SetTextAlign16(HDC16,UINT16);
+UINT32      WINAPI SetTextAlign32(HDC32,UINT32);
+#define     SetTextAlign WINELIB_NAME(SetTextAlign)
+INT16       WINAPI SetTextCharacterExtra16(HDC16,INT16);
+INT32       WINAPI SetTextCharacterExtra32(HDC32,INT32);
+#define     SetTextCharacterExtra WINELIB_NAME(SetTextCharacterExtra)
+COLORREF    WINAPI SetTextColor16(HDC16,COLORREF);
+COLORREF    WINAPI SetTextColor32(HDC32,COLORREF);
+#define     SetTextColor WINELIB_NAME(SetTextColor)
+INT16       WINAPI SetTextJustification16(HDC16,INT16,INT16);
+BOOL32      WINAPI SetTextJustification32(HDC32,INT32,INT32);
+#define     SetTextJustification WINELIB_NAME(SetTextJustification)
+UINT16      WINAPI SetTimer16(HWND16,UINT16,UINT16,TIMERPROC16);
+UINT32      WINAPI SetTimer32(HWND32,UINT32,UINT32,TIMERPROC32);
+#define     SetTimer WINELIB_NAME(SetTimer)
+BOOL16      WINAPI SetViewportExtEx16(HDC16,INT16,INT16,LPSIZE16);
+BOOL32      WINAPI SetViewportExtEx32(HDC32,INT32,INT32,LPSIZE32);
+#define     SetViewportExtEx WINELIB_NAME(SetViewportExtEx)
+BOOL16      WINAPI SetViewportOrgEx16(HDC16,INT16,INT16,LPPOINT16);
+BOOL32      WINAPI SetViewportOrgEx32(HDC32,INT32,INT32,LPPOINT32);
+#define     SetViewportOrgEx WINELIB_NAME(SetViewportOrgEx)
+INT16       WINAPI SetVoiceAccent16(INT16,INT16,INT16,INT16,INT16);
+DWORD       WINAPI SetVoiceAccent32(DWORD,DWORD,DWORD,DWORD,DWORD);
+#define     SetVoiceAccent WINELIB_NAME(SetVoiceAccent)
+INT16       WINAPI SetVoiceEnvelope16(INT16,INT16,INT16);
+DWORD       WINAPI SetVoiceEnvelope32(DWORD,DWORD,DWORD);
+#define     SetVoiceEnvelope WINELIB_NAME(SetVoiceEnvelope)
+INT16       WINAPI SetVoiceNote16(INT16,INT16,INT16,INT16);
+DWORD       WINAPI SetVoiceNote32(DWORD,DWORD,DWORD,DWORD);
+#define     SetVoiceNote WINELIB_NAME(SetVoiceNote)
+INT16       WINAPI SetVoiceQueueSize16(INT16,INT16);
+DWORD       WINAPI SetVoiceQueueSize32(DWORD,DWORD);
+#define     SetVoiceQueueSize WINELIB_NAME(SetVoiceQueueSize)
+INT16       WINAPI SetVoiceSound16(INT16,DWORD,INT16);
+DWORD       WINAPI SetVoiceSound32(DWORD,DWORD,DWORD);
+#define     SetVoiceSound WINELIB_NAME(SetVoiceSound)
+INT16       WINAPI SetVoiceThreshold16(INT16,INT16);
+DWORD       WINAPI SetVoiceThreshold32(DWORD,DWORD);
+#define     SetVoiceThreshold WINELIB_NAME(SetVoiceThreshold)
+BOOL16      WINAPI SetWindowExtEx16(HDC16,INT16,INT16,LPSIZE16);
+BOOL32      WINAPI SetWindowExtEx32(HDC32,INT32,INT32,LPSIZE32);
+#define     SetWindowExtEx WINELIB_NAME(SetWindowExtEx)
+LONG        WINAPI SetWindowLong16(HWND16,INT16,LONG);
+LONG        WINAPI SetWindowLong32A(HWND32,INT32,LONG);
+LONG        WINAPI SetWindowLong32W(HWND32,INT32,LONG);
+#define     SetWindowLong WINELIB_NAME_AW(SetWindowLong)
+BOOL16      WINAPI SetWindowOrgEx16(HDC16,INT16,INT16,LPPOINT16);
+BOOL32      WINAPI SetWindowOrgEx32(HDC32,INT32,INT32,LPPOINT32);
+#define     SetWindowOrgEx WINELIB_NAME(SetWindowOrgEx)
+BOOL16      WINAPI SetWindowPlacement16(HWND16,const WINDOWPLACEMENT16*);
+BOOL32      WINAPI SetWindowPlacement32(HWND32,const WINDOWPLACEMENT32*);
+#define     SetWindowPlacement WINELIB_NAME(SetWindowPlacement)
+FARPROC16   WINAPI SetWindowsHook16(INT16,HOOKPROC16);
+HHOOK       WINAPI SetWindowsHook32A(INT32,HOOKPROC32);
+HHOOK       WINAPI SetWindowsHook32W(INT32,HOOKPROC32);
+#define     SetWindowsHook WINELIB_NAME_AW(SetWindowsHook)
+HHOOK       WINAPI SetWindowsHookEx16(INT16,HOOKPROC16,HINSTANCE16,HTASK16);
+HHOOK       WINAPI SetWindowsHookEx32A(INT32,HOOKPROC32,HINSTANCE32,DWORD);
+HHOOK       WINAPI SetWindowsHookEx32W(INT32,HOOKPROC32,HINSTANCE32,DWORD);
+#define     SetWindowsHookEx WINELIB_NAME_AW(SetWindowsHookEx)
+BOOL16      WINAPI SetWindowPos16(HWND16,HWND16,INT16,INT16,INT16,INT16,WORD);
+BOOL32      WINAPI SetWindowPos32(HWND32,HWND32,INT32,INT32,INT32,INT32,WORD);
+#define     SetWindowPos WINELIB_NAME(SetWindowPos)
+void        WINAPI SetWindowText16(HWND16,SEGPTR);
+void        WINAPI SetWindowText32A(HWND32,LPCSTR);
+void        WINAPI SetWindowText32W(HWND32,LPCWSTR);
+#define     SetWindowText WINELIB_NAME_AW(SetWindowText)
+WORD        WINAPI SetWindowWord16(HWND16,INT16,WORD);
+WORD        WINAPI SetWindowWord32(HWND32,INT32,WORD);
+#define     SetWindowWord WINELIB_NAME(SetWindowWord)
+BOOL16      WINAPI ShellAbout16(HWND16,LPCSTR,LPCSTR,HICON16);
+BOOL32      WINAPI ShellAbout32A(HWND32,LPCSTR,LPCSTR,HICON32);
+BOOL32      WINAPI ShellAbout32W(HWND32,LPCWSTR,LPCWSTR,HICON32);
+#define     ShellAbout WINELIB_NAME_AW(ShellAbout)
+HINSTANCE16 WINAPI ShellExecute16(HWND16,LPCSTR,LPCSTR,LPCSTR,LPCSTR,INT16);
+HINSTANCE32 WINAPI ShellExecute32A(HWND32,LPCSTR,LPCSTR,LPCSTR,LPCSTR,INT32);
+HINSTANCE32 WINAPI ShellExecute32W(HWND32,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,INT32);
+#define     ShellExecute WINELIB_NAME_AW(ShellExecute)
+VOID        WINAPI ShowCaret16(HWND16);
+BOOL32      WINAPI ShowCaret32(HWND32);
+#define     ShowCaret WINELIB_NAME(ShowCaret)
+INT16       WINAPI ShowCursor16(BOOL16);
+INT32       WINAPI ShowCursor32(BOOL32);
+#define     ShowCursor WINELIB_NAME(ShowCursor)
+void        WINAPI ShowScrollBar16(HWND16,INT16,BOOL16);
+BOOL32      WINAPI ShowScrollBar32(HWND32,INT32,BOOL32);
+#define     ShowScrollBar WINELIB_NAME(ShowScrollBar)
+VOID        WINAPI ShowOwnedPopups16(HWND16,BOOL16);
+BOOL32      WINAPI ShowOwnedPopups32(HWND32,BOOL32);
+#define     ShowOwnedPopups WINELIB_NAME(ShowOwnedPopups)
+BOOL16      WINAPI ShowWindow16(HWND16,INT16);
+BOOL32      WINAPI ShowWindow32(HWND32,INT32);
+#define     ShowWindow WINELIB_NAME(ShowWindow)
+DWORD       WINAPI SizeofResource16(HMODULE16,HRSRC16);
+DWORD       WINAPI SizeofResource32(HMODULE32,HRSRC32);
+#define     SizeofResource WINELIB_NAME(SizeofResource)
+INT16       WINAPI StartDoc16(HDC16,const DOCINFO16*);
+INT32       WINAPI StartDoc32A(HDC32,const DOCINFO32A*);
+INT32       WINAPI StartDoc32W(HDC32,const DOCINFO32W*);
+#define     StartDoc WINELIB_NAME_AW(StartDoc)
+INT16       WINAPI StartSound16(void);
+VOID        WINAPI StartSound32(void);
+#define     StartSound WINELIB_NAME(StartSound)
+INT16       WINAPI StopSound16(void);
+VOID        WINAPI StopSound32(void);
+#define     StopSound WINELIB_NAME(StopSound)
+BOOL16      WINAPI StretchBlt16(HDC16,INT16,INT16,INT16,INT16,HDC16,INT16,
+                                INT16,INT16,INT16,DWORD);
+BOOL32      WINAPI StretchBlt32(HDC32,INT32,INT32,INT32,INT32,HDC32,INT32,
+                                INT32,INT32,INT32,DWORD);
+#define     StretchBlt WINELIB_NAME(StretchBlt)
+INT16       WINAPI StretchDIBits16(HDC16,INT16,INT16,INT16,INT16,INT16,INT16,
+                       INT16,INT16,const VOID*,const BITMAPINFO*,UINT16,DWORD);
+INT32       WINAPI StretchDIBits32(HDC32,INT32,INT32,INT32,INT32,INT32,INT32,
+                       INT32,INT32,const VOID*,const BITMAPINFO*,UINT32,DWORD);
+#define     StretchDIBits WINELIB_NAME(StretchDIBits)
+BOOL16      WINAPI SubtractRect16(LPRECT16,const RECT16*,const RECT16*);
+BOOL32      WINAPI SubtractRect32(LPRECT32,const RECT32*,const RECT32*);
+#define     SubtractRect WINELIB_NAME(SubtractRect)
+BOOL16      WINAPI SwapMouseButton16(BOOL16);
+BOOL32      WINAPI SwapMouseButton32(BOOL32);
+#define     SwapMouseButton WINELIB_NAME(SwapMouseButton)
+VOID        WINAPI SwitchToThisWindow16(HWND16,BOOL16);
+VOID        WINAPI SwitchToThisWindow32(HWND32,BOOL32);
+#define     SwitchToThisWindow WINELIB_NAME(SwitchToThisWindow)
+INT16       WINAPI SyncAllVoices16(void);
+DWORD       WINAPI SyncAllVoices32(void);
+#define     SyncAllVoices WINELIB_NAME(SyncAllVoices)
+BOOL16      WINAPI SystemParametersInfo16(UINT16,UINT16,LPVOID,UINT16);
+BOOL32      WINAPI SystemParametersInfo32A(UINT32,UINT32,LPVOID,UINT32);
+BOOL32      WINAPI SystemParametersInfo32W(UINT32,UINT32,LPVOID,UINT32);
+#define     SystemParametersInfo WINELIB_NAME_AW(SystemParametersInfo)
+LONG        WINAPI TabbedTextOut16(HDC16,INT16,INT16,LPCSTR,INT16,INT16,const INT16*,INT16);
+LONG        WINAPI TabbedTextOut32A(HDC32,INT32,INT32,LPCSTR,INT32,INT32,const INT32*,INT32);
+LONG        WINAPI TabbedTextOut32W(HDC32,INT32,INT32,LPCWSTR,INT32,INT32,const INT32*,INT32);
+#define     TabbedTextOut WINELIB_NAME_AW(TabbedTextOut)
+BOOL16      WINAPI TextOut16(HDC16,INT16,INT16,LPCSTR,INT16);
+BOOL32      WINAPI TextOut32A(HDC32,INT32,INT32,LPCSTR,INT32);
+BOOL32      WINAPI TextOut32W(HDC32,INT32,INT32,LPCWSTR,INT32);
+#define     TextOut WINELIB_NAME_AW(TextOut)
+INT16       WINAPI ToAscii16(UINT16,UINT16,LPBYTE,LPVOID,UINT16);
+INT32       WINAPI ToAscii32(UINT32,UINT32,LPBYTE,LPWORD,UINT32);
+#define     ToAscii WINELIB_NAME(ToAscii)
+BOOL16      WINAPI TrackPopupMenu16(HMENU16,UINT16,INT16,INT16,INT16,HWND16,const RECT16*);
+BOOL32      WINAPI TrackPopupMenu32(HMENU32,UINT32,INT32,INT32,INT32,HWND32,const RECT32*);
+#define     TrackPopupMenu WINELIB_NAME(TrackPopupMenu)
+INT16       WINAPI TranslateAccelerator16(HWND16,HACCEL16,LPMSG16);
+INT32       WINAPI TranslateAccelerator32(HWND32,HACCEL32,LPMSG32);
+#define     TranslateAccelerator WINELIB_NAME(TranslateAccelerator)
+BOOL16      WINAPI TranslateMDISysAccel16(HWND16,LPMSG16);
+BOOL32      WINAPI TranslateMDISysAccel32(HWND32,LPMSG32);
+#define     TranslateMDISysAccel WINELIB_NAME(TranslateMDISysAccel)
+BOOL16      WINAPI TranslateMessage16(const MSG16*);
+BOOL32      WINAPI TranslateMessage32(const MSG32*);
+#define     TranslateMessage WINELIB_NAME(TranslateMessage)
+INT16       WINAPI TransmitCommChar16(INT16,CHAR);
+BOOL32      WINAPI TransmitCommChar32(INT32,CHAR);
+#define     TransmitCommChar WINELIB_NAME(TransmitCommChar)
+BOOL16      WINAPI UnhookWindowsHook16(INT16,HOOKPROC16);
+BOOL32      WINAPI UnhookWindowsHook32(INT32,HOOKPROC32);
+#define     UnhookWindowsHook WINELIB_NAME(UnhookWindowsHook)
+BOOL16      WINAPI UnhookWindowsHookEx16(HHOOK);
+BOOL32      WINAPI UnhookWindowsHookEx32(HHOOK);
+#define     UnhookWindowsHookEx WINELIB_NAME(UnhookWindowsHookEx)
+BOOL16      WINAPI UnionRect16(LPRECT16,const RECT16*,const RECT16*);
+BOOL32      WINAPI UnionRect32(LPRECT32,const RECT32*,const RECT32*);
+#define     UnionRect WINELIB_NAME(UnionRect)
+void        WINAPI UnlockSegment16(HGLOBAL16);
+#define     UnlockSegment32(handle) GlobalUnfix((HANDLE32)(handle))
+#define     UnlockSegment WINELIB_NAME(UnlockSegment)
+BOOL16      WINAPI UnrealizeObject16(HGDIOBJ16);
+BOOL32      WINAPI UnrealizeObject32(HGDIOBJ32);
+#define     UnrealizeObject WINELIB_NAME(UnrealizeObject)
+BOOL16      WINAPI UnregisterClass16(SEGPTR,HINSTANCE16);
+BOOL32      WINAPI UnregisterClass32A(LPCSTR,HINSTANCE32);
+BOOL32      WINAPI UnregisterClass32W(LPCWSTR,HINSTANCE32);
+#define     UnregisterClass WINELIB_NAME_AW(UnregisterClass)
+INT16       WINAPI UpdateColors16(HDC16);
+BOOL32      WINAPI UpdateColors32(HDC32);
+#define     UpdateColors WINELIB_NAME(UpdateColors)
+VOID        WINAPI UpdateWindow16(HWND16);
+VOID        WINAPI UpdateWindow32(HWND32);
+#define     UpdateWindow WINELIB_NAME(UpdateWindow)
+VOID        WINAPI ValidateRect16(HWND16,const RECT16*);
+VOID        WINAPI ValidateRect32(HWND32,const RECT32*);
+#define     ValidateRect WINELIB_NAME(ValidateRect)
+VOID        WINAPI ValidateRgn16(HWND16,HRGN16);
+VOID        WINAPI ValidateRgn32(HWND32,HRGN32);
+#define     ValidateRgn WINELIB_NAME(ValidateRgn)
+DWORD       WINAPI VerFindFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*,LPSTR,UINT16*);
+DWORD       WINAPI VerFindFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*,LPSTR,UINT32*);
+DWORD       WINAPI VerFindFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*,LPWSTR,UINT32*);
+#define     VerFindFile WINELIB_NAME_AW(VerFindFile)
+DWORD       WINAPI VerInstallFile16(UINT16,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT16*);
+DWORD       WINAPI VerInstallFile32A(UINT32,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT32*);
+DWORD       WINAPI VerInstallFile32W(UINT32,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT32*);
+#define     VerInstallFile WINELIB_NAME_AW(VerInstallFile)
+DWORD       WINAPI VerLanguageName16(UINT16,LPSTR,UINT16);
+DWORD       WINAPI VerLanguageName32A(UINT32,LPSTR,UINT32);
+DWORD       WINAPI VerLanguageName32W(UINT32,LPWSTR,UINT32);
+#define     VerLanguageName WINELIB_NAME_AW(VerLanguageName)
+DWORD       WINAPI VerQueryValue16(SEGPTR,LPCSTR,SEGPTR*,UINT16*);
+DWORD       WINAPI VerQueryValue32A(LPVOID,LPCSTR,LPVOID*,UINT32*);
+DWORD       WINAPI VerQueryValue32W(LPVOID,LPCWSTR,LPVOID*,UINT32*);
+#define     VerQueryValue WINELIB_NAME_AW(VerQueryValue)
+WORD        WINAPI VkKeyScan16(CHAR);
+WORD        WINAPI VkKeyScan32A(CHAR);
+WORD        WINAPI VkKeyScan32W(WCHAR);
+#define     VkKeyScan WINELIB_NAME_AW(VkKeyScan)
+INT16       WINAPI WaitSoundState16(INT16);
+DWORD       WINAPI WaitSoundState32(DWORD);
+#define     WaitSoundState WINELIB_NAME(WaitSoundState)
+HWND16      WINAPI WindowFromDC16(HDC16);
+HWND32      WINAPI WindowFromDC32(HDC32);
+#define     WindowFromDC WINELIB_NAME(WindowFromDC)
+HWND16      WINAPI WindowFromPoint16(POINT16);
+HWND32      WINAPI WindowFromPoint32(POINT32);
+#define     WindowFromPoint WINELIB_NAME(WindowFromPoint)
+BOOL16      WINAPI WritePrivateProfileString16(LPCSTR,LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI WritePrivateProfileString32A(LPCSTR,LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI WritePrivateProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR);
+#define     WritePrivateProfileString WINELIB_NAME_AW(WritePrivateProfileString)
+BOOL16      WINAPI WriteProfileString16(LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI WriteProfileString32A(LPCSTR,LPCSTR,LPCSTR);
+BOOL32      WINAPI WriteProfileString32W(LPCWSTR,LPCWSTR,LPCWSTR);
+#define     WriteProfileString WINELIB_NAME_AW(WriteProfileString)
+SEGPTR      WINAPI lstrcat16(SEGPTR,LPCSTR);
+LPSTR       WINAPI lstrcat32A(LPSTR,LPCSTR);
+LPWSTR      WINAPI lstrcat32W(LPWSTR,LPCWSTR);
+#define     lstrcat WINELIB_NAME_AW(lstrcat)
+SEGPTR      WINAPI lstrcatn16(SEGPTR,LPCSTR,INT16);
+LPSTR       WINAPI lstrcatn32A(LPSTR,LPCSTR,INT32);
+LPWSTR      WINAPI lstrcatn32W(LPWSTR,LPCWSTR,INT32);
+#define     lstrcatn WINELIB_NAME_AW(lstrcatn)
+INT16       WINAPI lstrcmp16(LPCSTR,LPCSTR);
+INT32       WINAPI lstrcmp32A(LPCSTR,LPCSTR);
+INT32       WINAPI lstrcmp32W(LPCWSTR,LPCWSTR);
+#define     lstrcmp WINELIB_NAME_AW(lstrcmp)
+INT16       WINAPI lstrcmpi16(LPCSTR,LPCSTR);
+INT32       WINAPI lstrcmpi32A(LPCSTR,LPCSTR);
+INT32       WINAPI lstrcmpi32W(LPCWSTR,LPCWSTR);
+#define     lstrcmpi WINELIB_NAME_AW(lstrcmpi)
+SEGPTR      WINAPI lstrcpy16(SEGPTR,LPCSTR);
+LPSTR       WINAPI lstrcpy32A(LPSTR,LPCSTR);
+LPWSTR      WINAPI lstrcpy32W(LPWSTR,LPCWSTR);
+#define     lstrcpy WINELIB_NAME_AW(lstrcpy)
+SEGPTR      WINAPI lstrcpyn16(SEGPTR,LPCSTR,INT16);
+LPSTR       WINAPI lstrcpyn32A(LPSTR,LPCSTR,INT32);
+LPWSTR      WINAPI lstrcpyn32W(LPWSTR,LPCWSTR,INT32);
+#define     lstrcpyn WINELIB_NAME_AW(lstrcpyn)
+INT16       WINAPI lstrlen16(LPCSTR);
+INT32       WINAPI lstrlen32A(LPCSTR);
+INT32       WINAPI lstrlen32W(LPCWSTR);
+#define     lstrlen WINELIB_NAME_AW(lstrlen)
+HINSTANCE16 WINAPI WinExec16(LPCSTR,UINT16);
+HINSTANCE32 WINAPI WinExec32(LPCSTR,UINT32);
+#define     WinExec WINELIB_NAME(WinExec)
+BOOL16      WINAPI WinHelp16(HWND16,LPCSTR,UINT16,DWORD);
+BOOL32      WINAPI WinHelp32A(HWND32,LPCSTR,UINT32,DWORD);
+BOOL32      WINAPI WinHelp32W(HWND32,LPCWSTR,UINT32,DWORD);
+#define     WinHelp WINELIB_NAME_AW(WinHelp)
+INT16       WINAPIV wsnprintf16(LPSTR,UINT16,LPCSTR,...);
+INT32       WINAPIV wsnprintf32A(LPSTR,UINT32,LPCSTR,...);
+INT32       WINAPIV wsnprintf32W(LPWSTR,UINT32,LPCWSTR,...);
+#define     wsnprintf WINELIB_NAME_AW(wsnprintf)
+INT16       WINAPIV wsprintf16(LPSTR,LPCSTR,...);
+INT32       WINAPIV wsprintf32A(LPSTR,LPCSTR,...);
+INT32       WINAPIV wsprintf32W(LPWSTR,LPCWSTR,...);
+#define     wsprintf WINELIB_NAME_AW(wsprintf)
+INT16       WINAPI wvsnprintf16(LPSTR,UINT16,LPCSTR,LPCVOID);
+INT32       WINAPI wvsnprintf32A(LPSTR,UINT32,LPCSTR,LPCVOID);
+INT32       WINAPI wvsnprintf32W(LPWSTR,UINT32,LPCWSTR,LPCVOID);
+#define     wvsnprintf WINELIB_NAME_AW(wvsnprintf)
+INT16       WINAPI wvsprintf16(LPSTR,LPCSTR,LPCVOID);
+INT32       WINAPI wvsprintf32A(LPSTR,LPCSTR,LPCVOID);
+INT32       WINAPI wvsprintf32W(LPWSTR,LPCWSTR,LPCVOID);
+#define     wvsprintf WINELIB_NAME_AW(wvsprintf)
+LONG        WINAPI _hread16(HFILE16,LPVOID,LONG);
+LONG        WINAPI _hread32(HFILE32,LPVOID,LONG);
+#define     _hread WINELIB_NAME(_hread)
+LONG        WINAPI _hwrite16(HFILE16,LPCSTR,LONG);
+LONG        WINAPI _hwrite32(HFILE32,LPCSTR,LONG);
+#define     _hwrite WINELIB_NAME(_hwrite)
+HFILE16     WINAPI _lcreat16(LPCSTR,INT16);
+HFILE32     WINAPI _lcreat32(LPCSTR,INT32);
+#define     _lcreat WINELIB_NAME(_lcreat)
+HFILE16     WINAPI _lclose16(HFILE16);
+HFILE32     WINAPI _lclose32(HFILE32);
+#define     _lclose WINELIB_NAME(_lclose)
+LONG        WINAPI _llseek16(HFILE16,LONG,INT16);
+LONG        WINAPI _llseek32(HFILE32,LONG,INT32);
+#define     _llseek WINELIB_NAME(_llseek)
+HFILE16     WINAPI _lopen16(LPCSTR,INT16);
+HFILE32     WINAPI _lopen32(LPCSTR,INT32);
+#define     _lopen WINELIB_NAME(_lopen)
+UINT16      WINAPI _lread16(HFILE16,LPVOID,UINT16);
+UINT32      WINAPI _lread32(HFILE32,LPVOID,UINT32);
+#define     _lread WINELIB_NAME(_lread)
+UINT16      WINAPI _lwrite16(HFILE16,LPCSTR,UINT16);
+UINT32      WINAPI _lwrite32(HFILE32,LPCSTR,UINT32);
+#define     _lwrite WINELIB_NAME(_lwrite)
 
 /* Extra functions that don't exist in the Windows API */
 
-INT32      LoadMessage32A(HINSTANCE32,UINT32,WORD,LPSTR,INT32);
-INT32      LoadMessage32W(HINSTANCE32,UINT32,WORD,LPWSTR,INT32);
-SEGPTR     WIN16_GlobalLock16(HGLOBAL16);
-SEGPTR     WIN16_LockResource(HGLOBAL16);
-LONG       WIN16_hread(HFILE16,SEGPTR,LONG);
-INT32      lstrncmp32A(LPCSTR,LPCSTR,INT32);
-INT32      lstrncmp32W(LPCWSTR,LPCWSTR,INT32);
-INT32      lstrncmpi32A(LPCSTR,LPCSTR,INT32);
-INT32      lstrncmpi32W(LPCWSTR,LPCWSTR,INT32);
-LPWSTR     lstrcpyAtoW(LPWSTR,LPCSTR);
-LPSTR      lstrcpyWtoA(LPSTR,LPCWSTR);
-LPWSTR     lstrcpynAtoW(LPWSTR,LPCSTR,INT32);
-LPSTR      lstrcpynWtoA(LPSTR,LPCWSTR,INT32);
+INT32       WINAPI LoadMessage32A(HINSTANCE32,UINT32,WORD,LPSTR,INT32);
+INT32       WINAPI LoadMessage32W(HINSTANCE32,UINT32,WORD,LPWSTR,INT32);
+SEGPTR      WINAPI WIN16_GlobalLock16(HGLOBAL16);
+SEGPTR      WINAPI WIN16_LockResource(HGLOBAL16);
+LONG        WINAPI WIN16_hread(HFILE16,SEGPTR,LONG);
+INT32       WINAPI lstrncmp32A(LPCSTR,LPCSTR,INT32);
+INT32       WINAPI lstrncmp32W(LPCWSTR,LPCWSTR,INT32);
+INT32       WINAPI lstrncmpi32A(LPCSTR,LPCSTR,INT32);
+INT32       WINAPI lstrncmpi32W(LPCWSTR,LPCWSTR,INT32);
+LPWSTR      WINAPI lstrcpyAtoW(LPWSTR,LPCSTR);
+LPSTR       WINAPI lstrcpyWtoA(LPSTR,LPCWSTR);
+LPWSTR      WINAPI lstrcpynAtoW(LPWSTR,LPCSTR,INT32);
+LPSTR       WINAPI lstrcpynWtoA(LPSTR,LPCWSTR,INT32);
 
 #ifdef __cplusplus
 }
diff --git a/include/winnls.h b/include/winnls.h
index 04c92d4..b0bb86b 100644
--- a/include/winnls.h
+++ b/include/winnls.h
@@ -118,4 +118,15 @@
 #define WC_SEPCHARS					0x00000020
 #define WC_DEFAULTCHAR				0x00000040
 
+#define MAKELCID(l, s)    (MAKELONG(l, s))
+#define MAKELANGID(p, s)  ((((WORD)(s))<<10) | (WORD)(p))
+
+#define SORT_DEFAULT      0
+#define SUBLANG_DEFAULT   1
+
+#define LANG_SYSTEM_DEFAULT   (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
+#define LANG_USER_DEFAULT     (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
+#define LOCALE_SYSTEM_DEFAULT (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
+#define LOCALE_USER_DEFAULT   (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT)) 
+
 #endif  /* __WINE_WINNLS_H */
diff --git a/include/winnt.h b/include/winnt.h
index 4bd7387..dc6b7cd 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -139,6 +139,32 @@
 
 #endif  /* __WINE__ */
 
+/* ifdef _x86_ ... */
+typedef struct _LDT_ENTRY {
+    WORD	LimitLow;
+    WORD	BaseLow;
+    union {
+	struct {
+	    BYTE	BaseMid;
+	    BYTE	Flags1;/*Declare as bytes to avoid alignment problems */
+	    BYTE	Flags2; 
+	    BYTE	BaseHi;
+	} Bytes;
+	struct {
+	    DWORD	BaseMid		: 8;
+	    DWORD	Type		: 5;
+	    DWORD	Dpl		: 2;
+	    DWORD	Pres		: 1;
+	    DWORD	LimitHi		: 4;
+	    DWORD	Sys		: 1;
+	    DWORD	Reserved_0	: 1;
+	    DWORD	Default_Big	: 1;
+	    DWORD	Granularity	: 1;
+	    DWORD	BaseHi		: 8;
+	} Bits;
+    } HighWord;
+} LDT_ENTRY, *LPLDT_ENTRY;
+
 /*
  * Exception codes
  */
@@ -255,9 +281,9 @@
 typedef LONG (*PTOP_LEVEL_EXCEPTION_FILTER)(PEXCEPTION_POINTERS ExceptionInfo);
 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
 
-DWORD UnhandledExceptionFilter( PEXCEPTION_POINTERS epointers );
+DWORD WINAPI UnhandledExceptionFilter( PEXCEPTION_POINTERS epointers );
 LPTOP_LEVEL_EXCEPTION_FILTER
-SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter );
+WINAPI SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter );
 
 /* Language IDs */
 
diff --git a/include/winsock.h b/include/winsock.h
index ed813b7..cfd1ce5 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -21,6 +21,7 @@
 /* Win16 socket-related types */
 
 typedef UINT16		SOCKET16;
+typedef UINT32		SOCKET32;
 
 typedef struct ws_hostent
 {
@@ -64,7 +65,9 @@
 
 /* ws_fd_set operations */
 
-INT16   __WSAFDIsSet( SOCKET16, ws_fd_set * );
+INT16 WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set * );
+INT32 WINAPI __WSAFDIsSet32( SOCKET32, ws_fd_set * );
+#define __WSAFDIsSet WINELIB_NAME(__WSAFDIsSet);
 
 #define WS_FD_CLR(fd, set) do { \
     UINT16 __i; \
@@ -141,8 +144,12 @@
  * This is used instead of -1, since the
  * SOCKET type is unsigned.
  */
-#define INVALID_SOCKET  (SOCKET16)(~0)
-#define SOCKET_ERROR              (-1)
+#define INVALID_SOCKET16 	   (~0)
+#define INVALID_SOCKET32 	   (~0)
+#define SOCKET_ERROR               (-1)
+
+DECL_WINELIB_TYPE(INVALID_SOCKET);
+DECL_WINELIB_TYPE(SOCKET);
 
 /*
  * Types
@@ -221,16 +228,17 @@
 /*
  * Define flags to be used with the WSAAsyncSelect() call.
  */
-#define WS_FD_READ         0x01
-#define WS_FD_WRITE        0x02
-#define WS_FD_OOB          0x04
-#define WS_FD_ACCEPT       0x08
-#define WS_FD_CONNECT      0x10
-#define WS_FD_CLOSE        0x20
+#define WS_FD_READ         0x0001
+#define WS_FD_WRITE        0x0002
+#define WS_FD_OOB          0x0004
+#define WS_FD_ACCEPT       0x0008
+#define WS_FD_CONNECT      0x0010
+#define WS_FD_CLOSE        0x0020
 
 #define WS_FD_NONBLOCK	   0x10000000	/* internal per-socket flags */
 #define WS_FD_INACTIVE	   0x20000000
 #define WS_FD_CONNECTED	   0x40000000
+#define WS_FD_RAW	   0x80000000
 #define WS_FD_INTERNAL	   0xFFFF0000
 
 /*
@@ -332,35 +340,43 @@
 
 /* Microsoft Windows Extension function prototypes */
 
-INT16 	  WSAStartup(UINT16 wVersionRequired, LPWSADATA lpWSAData);
-INT16 	  WSACleanup(void);
-void 	  WSASetLastError(INT16 iError);
-INT16 	  WSAGetLastError(void);
-BOOL16 	  WSAIsBlocking(void);
-INT16 	  WSAUnhookBlockingHook(void);
-FARPROC16 WSASetBlockingHook(FARPROC16 lpBlockFunc);
-INT16 	  WSACancelBlockingCall(void);
-HANDLE16  WSAAsyncGetServByName(HWND16 hWnd, UINT16 wMsg,
-                                LPCSTR name, LPCSTR proto,
-                                SEGPTR buf, INT16 buflen);
+INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData);
+INT32     WINAPI WSAStartup32(UINT32 wVersionRequired, LPWSADATA lpWSAData);
+#define   WSAStartup WINELIB_NAME(WSAStartup);
+void      WINAPI WSASetLastError16(INT16 iError);
+void      WINAPI WSASetLastError32(INT32 iError);
+#define   WSASetLastError WINELIB_NAME(WSASetLastError);
+INT32     WINAPI WSACleanup(void);
+INT32     WINAPI WSAGetLastError(void);
+BOOL32    WINAPI WSAIsBlocking(void);
+INT32     WINAPI WSACancelBlockingCall(void);
+INT16     WINAPI WSAUnhookBlockingHook16(void);
+INT32     WINAPI WSAUnhookBlockingHook32(void);
+#define   WSAUnhookBlockingHook WINELIB_NAME(WSAUnhookBlockingHook)
+FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
+FARPROC32 WINAPI WSASetBlockingHook32(FARPROC32 lpBlockFunc);
+#define   WSASetBlockingHook WINELIB_NAME(WSASetBlockingHook)
+HANDLE16  WINAPI WSAAsyncGetServByName(HWND16 hWnd, UINT16 wMsg,
+                                       LPCSTR name, LPCSTR proto,
+                                       SEGPTR buf, INT16 buflen);
 
-HANDLE16  WSAAsyncGetServByPort(HWND16 hWnd, UINT16 wMsg, INT16 port,
-                                LPCSTR proto, SEGPTR buf, INT16 buflen);
+HANDLE16  WINAPI WSAAsyncGetServByPort(HWND16 hWnd, UINT16 wMsg, INT16 port,
+                                       LPCSTR proto, SEGPTR buf, INT16 buflen);
 
-HANDLE16  WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 wMsg,
-                                 LPCSTR name, SEGPTR buf, INT16 buflen);
+HANDLE16  WINAPI WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 wMsg,
+                                        LPCSTR name, SEGPTR buf, INT16 buflen);
 
-HANDLE16  WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 wMsg,
-                                   INT16 number, SEGPTR buf, INT16 buflen);
+HANDLE16  WINAPI WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 wMsg,
+                                       INT16 number, SEGPTR buf, INT16 buflen);
 
-HANDLE16  WSAAsyncGetHostByName(HWND16 hWnd, UINT16 wMsg,
-                                LPCSTR name, SEGPTR buf, INT16 buflen);
+HANDLE16  WINAPI WSAAsyncGetHostByName(HWND16 hWnd, UINT16 wMsg,
+                                       LPCSTR name, SEGPTR buf, INT16 buflen);
 
-HANDLE16  WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 wMsg, LPCSTR addr, INT16 len,
-                                INT16 type, SEGPTR buf, INT16 buflen);
-
-INT16 	  WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle);
-INT16     WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, UINT32 lEvent);
+HANDLE16  WINAPI WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 wMsg, LPCSTR addr,
+                              INT16 len, INT16 type, SEGPTR buf, INT16 buflen);
+INT16 	  WINAPI WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle);
+INT16     WINAPI WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 wMsg,
+                                UINT32 lEvent);
 
 #ifdef __cplusplus
 }
@@ -417,9 +433,13 @@
 
 /* ----------------------------------- internal structures */
 
-#define WS_DUP_NATIVE           0x0
-#define WS_DUP_OFFSET           0x2
-#define WS_DUP_SEGPTR           0x4
+/* ws_... struct conversion flags */
+
+#define WS_DUP_NATIVE           0x0001		/* native structure format (not ws_..) */
+#define WS_DUP_OFFSET           0x0002		/* internal pointers are offsets */
+#define WS_DUP_SEGPTR           0x0004		/* internal pointers are SEGPTRs */
+						/* by default, internal pointers are linear */
+/* async DNS op flags */
 
 #define AOP_IO                  0x0000001	/* aop_control paramaters */
 
@@ -437,80 +457,60 @@
 
   /* custom data */
 
-  HWND16        hWnd;
-  UINT16        uMsg;
+  HWND16        hWnd;				/* hWnd to post */ 
+  UINT16        uMsg;				/* uMsg message to. */
 
-  unsigned	flags;
-  SEGPTR	buffer_base;
-  int           buflen;
+  SEGPTR	buffer_base;			/* buffer to copy result to */
+  UINT16        buflen;
+  UINT16	flags;				/* WSMSG_ASYNC_... */
 } ws_async_op;
 
-#define WSMSG_ASYNC_SELECT      0x0000001
-#define WSMSG_ASYNC_HOSTBYNAME  0x0000010
-#define WSMSG_ASYNC_HOSTBYADDR  0x0000020
-#define WSMSG_ASYNC_PROTOBYNAME 0x0000100
-#define WSMSG_ASYNC_PROTOBYNUM  0x0000200
-#define WSMSG_ASYNC_SERVBYNAME  0x0001000
-#define WSMSG_ASYNC_SERVBYPORT  0x0002000
+#define WSMSG_ASYNC_HOSTBYNAME  0x0001
+#define WSMSG_ASYNC_HOSTBYADDR  0x0002
+#define WSMSG_ASYNC_PROTOBYNAME 0x0010
+#define WSMSG_ASYNC_PROTOBYNUM  0x0020
+#define WSMSG_ASYNC_SERVBYNAME  0x0100
+#define WSMSG_ASYNC_SERVBYPORT  0x0200
+#define WSMSG_DEAD_AOP		0x8000
 
-#define MTYPE_PARENT            0x50505357
-#define MTYPE_CLIENT            0x50435357
-
-#pragma pack(1)
-typedef struct
+typedef struct __sop	/* WSAAsyncSelect() control struct */
 {
-  long          mtype;          /* WSMSG_... */
+  struct __sop *next, *prev;
 
-  UINT32        lParam;		/* WS_FD_... event */
-  UINT16        wParam;         /* socket handle - used only for MTYPE_CLIENT messages */
-} ipc_packet;
+  struct __ws*  pws;
+  HWND16        hWnd;
+  UINT16        uMsg;
+} ws_select_op;
 
-#define MTYPE_PARENT_SIZE \
-        (sizeof(UINT32))
-#define MTYPE_CLIENT_SIZE \
-        (sizeof(ipc_packet) - sizeof(long))
-#pragma pack(4)
-
-typedef struct
+typedef struct	__ws	/* socket */
 {
-  int                   fd;
-  unsigned              flags;
-  ws_async_op*          p_aop;	/* AsyncSelect() handler */
+  int		fd;
+  unsigned	flags;
+  ws_select_op*	psop;
 } ws_socket;
 
-typedef struct
-{
-  ws_async_op*  ws_aop;         /* init'ed for getXbyY */
-  ws_socket*    ws_sock;        /* init'ed for AsyncSelect */
-  int           lEvent;
-  int           lLength;
-  char*		buffer;
-  char*		init;
-  ipc_packet    ip;
-} ws_async_ctl;
-
 #define WS_MAX_SOCKETS_PER_THREAD       16
 #define WS_MAX_UDP_DATAGRAM             1024
 
 #define WSI_BLOCKINGCALL	0x00000001	/* per-thread info flags */
+#define WSI_BLOCKINGHOOK32	0x00000002	/* 32-bit callback */
 
-typedef struct __WSINFO
+typedef struct _WSINFO
 {
-  struct __WSINFO*      prev,*next;
+  struct _WSINFO*       prev,*next;
 
   unsigned		flags;
-  int			err;
-  INT16			num_startup;
+  INT32			err;			/* WSAGetLastError() return value */
+  INT16			num_startup;		/* reference counter */
   INT16			num_async_rq;
-  INT16			last_free;
+  INT16			last_free;		/* entry in the socket table */
   UINT16		buflen;
   char*			buffer;			/* allocated from SEGPTR heap */
   char*			dbuffer;		/* buffer for dummies (32 bytes) */
 
   ws_socket		sock[WS_MAX_SOCKETS_PER_THREAD];
-  FARPROC16		blocking_hook;
-  HTASK16               tid;    		/* owning thread id - better switch
-                                 		 * to TLS when it gets fixed */
+  DWORD			blocking_hook;
+  HTASK16               tid;    		/* owning task id - process might be better */
 } WSINFO, *LPWSINFO;
 
 int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
@@ -527,10 +527,12 @@
 int  WINSOCK_check_async_op(ws_async_op* p_aop);
 void WINSOCK_link_async_op(ws_async_op* p_aop);
 void WINSOCK_unlink_async_op(ws_async_op* p_aop);
-void WINSOCK_cancel_async_op(HTASK16 tid);
-void WINSOCK_do_async_select(void);
-void WINSOCK_Shutdown(void);
+int  WINSOCK_cancel_async_op(ws_async_op* p_aop);
 
+void WINSOCK_cancel_task_aops(HTASK16, void (*__memfree)(void*) );
+
+BOOL32 WINSOCK_HandleIO(int* fd_max, int num_pending, fd_set io_set[3] );
+void   WINSOCK_Shutdown(void);
 UINT16 wsaErrno(void);
 UINT16 wsaHerrno(void);
 
diff --git a/include/wintypes.h b/include/wintypes.h
index 05d3869..2626921 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -63,6 +63,40 @@
 # define DECL_WINELIB_TYPE_AW(type)  typedef WINELIB_NAME_AW(type) type
 #endif  /* __WINE__ */
 
+
+/* Calling conventions definitions */
+
+#ifdef not_used_yet
+
+#ifdef __i386__
+# if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)
+#  define __stdcall __attribute__((__stdcall__))
+#  define __cdecl   __attribute__((__cdecl__))
+# else
+#  error You need gcc >= 2.7 to build Wine on a 386
+# endif  /* __GNUC__ */
+#else  /* __i386__ */
+#  define __stdcall /* nothing */
+#  define __cdecl   /* nothing */
+#endif  /* __i386__ */
+
+#else  /* not_used_yet */
+
+# define __stdcall /* nothing */
+# define __cdecl   /* nothing */
+
+#endif  /* not_used_yet */
+
+#define CALLBACK    __stdcall
+#define WINAPI      __stdcall
+#define APIPRIVATE  __stdcall
+#define PASCAL      __stdcall
+#define _pascal     __stdcall
+#define __export    __stdcall
+#define WINAPIV     __cdecl
+#define APIENTRY    WINAPI
+
+
 /* Standard data types. These are the same for emulator and library. */
 
 typedef void            VOID;
@@ -165,46 +199,46 @@
 
 /* Callback function pointers types */
 
-typedef LRESULT (*DLGPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
-typedef LRESULT (*DLGPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
+typedef LRESULT (CALLBACK *DLGPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
+typedef LRESULT (CALLBACK *DLGPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
 DECL_WINELIB_TYPE(DLGPROC);
-typedef LRESULT (*DRIVERPROC16)(DWORD,HDRVR16,UINT16,LPARAM,LPARAM);
-typedef LRESULT (*DRIVERPROC32)(DWORD,HDRVR32,UINT32,LPARAM,LPARAM);
+typedef LRESULT (CALLBACK *DRIVERPROC16)(DWORD,HDRVR16,UINT16,LPARAM,LPARAM);
+typedef LRESULT (CALLBACK *DRIVERPROC32)(DWORD,HDRVR32,UINT32,LPARAM,LPARAM);
 DECL_WINELIB_TYPE(DRIVERPROC);
-typedef INT16   (*EDITWORDBREAKPROC16)(LPSTR,INT16,INT16,INT16);
-typedef INT32   (*EDITWORDBREAKPROC32A)(LPSTR,INT32,INT32,INT32);
-typedef INT32   (*EDITWORDBREAKPROC32W)(LPWSTR,INT32,INT32,INT32);
+typedef INT16   (CALLBACK *EDITWORDBREAKPROC16)(LPSTR,INT16,INT16,INT16);
+typedef INT32   (CALLBACK *EDITWORDBREAKPROC32A)(LPSTR,INT32,INT32,INT32);
+typedef INT32   (CALLBACK *EDITWORDBREAKPROC32W)(LPWSTR,INT32,INT32,INT32);
 DECL_WINELIB_TYPE_AW(EDITWORDBREAKPROC);
-typedef LRESULT (*FARPROC16)();
-typedef LRESULT (*FARPROC32)();
+typedef LRESULT (CALLBACK *FARPROC16)();
+typedef LRESULT (CALLBACK *FARPROC32)();
 DECL_WINELIB_TYPE(FARPROC);
-typedef INT16   (*GOBJENUMPROC16)(SEGPTR,LPARAM);
-typedef INT32   (*GOBJENUMPROC32)(LPVOID,LPARAM);
+typedef INT16   (CALLBACK *GOBJENUMPROC16)(SEGPTR,LPARAM);
+typedef INT32   (CALLBACK *GOBJENUMPROC32)(LPVOID,LPARAM);
 DECL_WINELIB_TYPE(GOBJENUMPROC);
-typedef BOOL16  (*GRAYSTRINGPROC16)(HDC16,LPARAM,INT16);
-typedef BOOL32  (*GRAYSTRINGPROC32)(HDC32,LPARAM,INT32);
+typedef BOOL16  (CALLBACK *GRAYSTRINGPROC16)(HDC16,LPARAM,INT16);
+typedef BOOL32  (CALLBACK *GRAYSTRINGPROC32)(HDC32,LPARAM,INT32);
 DECL_WINELIB_TYPE(GRAYSTRINGPROC);
-typedef LRESULT (*HOOKPROC16)(INT16,WPARAM16,LPARAM);
-typedef LRESULT (*HOOKPROC32)(INT32,WPARAM32,LPARAM);
+typedef LRESULT (CALLBACK *HOOKPROC16)(INT16,WPARAM16,LPARAM);
+typedef LRESULT (CALLBACK *HOOKPROC32)(INT32,WPARAM32,LPARAM);
 DECL_WINELIB_TYPE(HOOKPROC);
-typedef VOID    (*LINEDDAPROC16)(INT16,INT16,LPARAM);
-typedef VOID    (*LINEDDAPROC32)(INT32,INT32,LPARAM);
+typedef VOID    (CALLBACK *LINEDDAPROC16)(INT16,INT16,LPARAM);
+typedef VOID    (CALLBACK *LINEDDAPROC32)(INT32,INT32,LPARAM);
 DECL_WINELIB_TYPE(LINEDDAPROC);
-typedef BOOL16  (*PROPENUMPROC16)(HWND16,SEGPTR,HANDLE16);
-typedef BOOL32  (*PROPENUMPROC32A)(HWND32,LPCSTR,HANDLE32);
-typedef BOOL32  (*PROPENUMPROC32W)(HWND32,LPCWSTR,HANDLE32);
+typedef BOOL16  (CALLBACK *PROPENUMPROC16)(HWND16,SEGPTR,HANDLE16);
+typedef BOOL32  (CALLBACK *PROPENUMPROC32A)(HWND32,LPCSTR,HANDLE32);
+typedef BOOL32  (CALLBACK *PROPENUMPROC32W)(HWND32,LPCWSTR,HANDLE32);
 DECL_WINELIB_TYPE_AW(PROPENUMPROC);
-typedef BOOL32  (*PROPENUMPROCEX32A)(HWND32,LPCSTR,HANDLE32,LPARAM);
-typedef BOOL32  (*PROPENUMPROCEX32W)(HWND32,LPCWSTR,HANDLE32,LPARAM);
+typedef BOOL32  (CALLBACK *PROPENUMPROCEX32A)(HWND32,LPCSTR,HANDLE32,LPARAM);
+typedef BOOL32  (CALLBACK *PROPENUMPROCEX32W)(HWND32,LPCWSTR,HANDLE32,LPARAM);
 DECL_WINELIB_TYPE_AW(PROPENUMPROCEX);
-typedef VOID    (*TIMERPROC16)(HWND16,UINT16,UINT16,DWORD);
-typedef VOID    (*TIMERPROC32)(HWND32,UINT32,UINT32,DWORD);
+typedef VOID    (CALLBACK *TIMERPROC16)(HWND16,UINT16,UINT16,DWORD);
+typedef VOID    (CALLBACK *TIMERPROC32)(HWND32,UINT32,UINT32,DWORD);
 DECL_WINELIB_TYPE(TIMERPROC);
-typedef LRESULT (*WNDENUMPROC16)(HWND16,LPARAM);
-typedef LRESULT (*WNDENUMPROC32)(HWND32,LPARAM);
+typedef LRESULT (CALLBACK *WNDENUMPROC16)(HWND16,LPARAM);
+typedef LRESULT (CALLBACK *WNDENUMPROC32)(HWND32,LPARAM);
 DECL_WINELIB_TYPE(WNDENUMPROC);
-typedef LRESULT (*WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
-typedef LRESULT (*WNDPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
+typedef LRESULT (CALLBACK *WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
+typedef LRESULT (CALLBACK *WNDPROC32)(HWND32,UINT32,WPARAM32,LPARAM);
 DECL_WINELIB_TYPE(WNDPROC);
 
 /* TCHAR data types definitions for Winelib. */
@@ -286,15 +320,10 @@
 /* Define some empty macros for compatibility with Windows code. */
 
 #ifndef __WINE__
-#define CALLBACK
 #define NEAR
 #define FAR
-#define PASCAL
-#define WINAPI
 #define _far
 #define _near
-#define _pascal
-#define __export
 #endif  /* __WINE__ */
 
 /* Macro for structure packing. */
diff --git a/include/x11font.h b/include/x11font.h
index c87064e..aed042c 100644
--- a/include/x11font.h
+++ b/include/x11font.h
@@ -55,9 +55,10 @@
 #define FI_VARIABLEPITCH    0x0040
 #define FI_FIXEDPITCH       0x0080
 
-#define FI_ENC_ISO8859	    0x0100
-#define FI_ENC_ISO646	    0x0200
-#define FI_ENC_ANSI	    0x0400
+#define FI_ENC_ISO8859	    0x0100	/* iso8859-* 	*/
+#define FI_ENC_ISO646	    0x0200	/* iso646* 	*/
+#define FI_ENC_ANSI	    0x0400	/* ansi-0 	*/
+#define FI_ENC_MSCODEPAGE   0x0800	/* cp125-* 	*/
 
 #define FI_FIXEDEX	    0x1000
 #define FI_NORMAL	    0x2000
diff --git a/library/miscstubs.c b/library/miscstubs.c
index 045f25a..c472441 100644
--- a/library/miscstubs.c
+++ b/library/miscstubs.c
@@ -17,34 +17,6 @@
 void CallFrom16_long_wwwll(void) {}
 void CallFrom32_stdcall_5(void) {}
 
-int CallTo32_LargeStack( int (*func)(), int nbargs, ...)
-{
-  va_list arglist;
-  int i,a[32];
-
-  va_start(arglist,nbargs);
-
-  for(i=0; i<nbargs; i++) a[i]=va_arg(arglist,int);
-
-  switch(nbargs) /* Ewww... Icky.  But what can I do? */
-  {
-  case 5: return func(a[0],a[1],a[2],a[3],a[4]);
-  case 6: return func(a[0],a[1],a[2],a[3],a[4],a[5]);
-  case 8: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
-  case 10: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
-                a[7],a[8],a[9]);
-  case 11: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
-                a[7],a[8],a[9],a[10]);
-  case 14: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
-                a[7],a[8],a[9],a[10],a[11],a[12],a[13]);
-  case 16: return func(a[0],a[1],a[2],a[3],a[4],a[5],a[6],
-                a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]);
-  default: fprintf(stderr,"JBP: CallTo32_LargeStack called with unsupported "
-                          "number of arguments (%d).  Ignored.\n",nbargs);
-           return 0;
-  }
-}
-
 extern LRESULT ColorDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
 extern LRESULT FileOpenDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
 extern LRESULT FileSaveDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
diff --git a/library/winestub.c b/library/winestub.c
index d1c53e6..39946b3 100644
--- a/library/winestub.c
+++ b/library/winestub.c
@@ -4,16 +4,23 @@
 #include "windows.h"
 #include "xmalloc.h"
 
-extern int WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
+extern int PASCAL WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
 extern int MAIN_Init(void);
 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
 extern void TASK_Reschedule(void);
 
+/* Most Windows C/C++ compilers use something like this to */
+/* access argc and argv globally: */
+int _ARGC;
+char **_ARGV;
+
 int main( int argc, char *argv [] )
 {
   HINSTANCE16 hInstance;
   LPSTR lpszCmdParam;
   int i, len = 0;
+  _ARGC = argc;
+  _ARGV = (char **)argv;
 
   MAIN_WineInit( &argc, argv );
 
@@ -35,51 +42,3 @@
 		  lpszCmdParam, /* lpszCmdParam */
 		  SW_NORMAL);   /* nCmdShow */
 }
-
-#if 0
-
-extern int WinMain(HINSTANCE32,HINSTANCE32,LPSTR,int);
-/* This is the renamed main() subroutine in misc/main.c. */
-/* Note that the libdll `init()' won't work: */
-extern HINSTANCE32 _wine_main(int, char *[]);
-
-int main (int argc, char *argv [])
-{
-  HINSTANCE32 hInstance;
-  char szCmdParam[256] = {0};
-  int index, buffer_pos;
-  char *arg_holder;
-  /* "Wired-in" command-line options for Wine: */
-  /*char *wine_argv[] = {argv[0], "-managed", "-dll", "+commdlg",
-  			"-dll", "+shell", ""};*/
-  char *wine_argv[] = {argv[0], ""};
-
-  /* Initialize the library dll: */
-  hInstance = (HINSTANCE32)_wine_main((sizeof(wine_argv)/sizeof(char *))-1, wine_argv);
-
-#ifdef WIN_DEBUG
-  fprintf(stderr,"In winestub, reporting hInstance = %d\n", hInstance);
-#endif
-
-  /* Move things from argv to the szCmdParam that WinMain expects: */
-    for (index = 1, buffer_pos = 0;
-  	(index < argc) && (buffer_pos < 255);
-  	index++, buffer_pos++)
-  	{
-	for (arg_holder = argv[index]; ; buffer_pos++, arg_holder++)
-	 if ((szCmdParam[buffer_pos] = *arg_holder) == '\0') break;
-	szCmdParam[buffer_pos] = ' ';
-	};
-  szCmdParam[buffer_pos] = '\0';
-
-#ifdef WIN_DEBUG
-  fprintf(stderr,"In winestub, Program Name: %s, Parameters: %s\n",
-  	progname, szCmdParam);
-#endif
-
-  return WinMain (hInstance,		/* hInstance */
-		  0,			/* hPrevInstance */
-		  (LPSTR)szCmdParam,	/* lpszCmdParam */
-		  SW_NORMAL);		/* nCmdShow */
-}
-#endif
diff --git a/libtest/expand.c b/libtest/expand.c
index 656a3d6..cb2e31a 100644
--- a/libtest/expand.c
+++ b/libtest/expand.c
@@ -11,34 +11,29 @@
 {
   OFSTRUCT SourceOpenStruct1, SourceOpenStruct2;
   char OriginalName[256], WriteBuf[256];
-  char FAR *lpzDestFile,
-  			FAR *lpzHolder = lpCmdLine,
-  			FAR *arrgv[2] = {0};
-  int wargs;
+  char FAR *lpzDestFile;
   DWORD dwreturn;
   HFILE hSourceFile, hDestFile;
+  /* Most Windows compilers have something like this: */
+  extern int _ARGC;
+  extern char **_ARGV;
 
-  for (wargs = 1; wargs < 3; wargs++)
-  {arrgv[wargs] = lpzHolder;
-  for (; *lpzHolder != '\0'; lpzHolder++)
-	if (*lpzHolder == ' ') {*lpzHolder++ = '\0'; break;};
-	};
 
-MessageBox((HWND)NULL, (LPCSTR)arrgv[1], (LPCSTR)"arrgv[1]:", MB_OK);
-MessageBox((HWND)NULL, (LPCSTR)arrgv[2], (LPCSTR)"arrgv[2]:", MB_OK);
+MessageBox((HWND)NULL, (LPCSTR)_ARGV[1], (LPCSTR)"_ARGV[1]:", MB_OK);
+MessageBox((HWND)NULL, (LPCSTR)_ARGV[2], (LPCSTR)"_ARGV[2]:", MB_OK);
 
-  hSourceFile = LZOpenFile(arrgv[1], (LPOFSTRUCT) &SourceOpenStruct1,
+  hSourceFile = LZOpenFile(_ARGV[1], (LPOFSTRUCT) &SourceOpenStruct1,
 			OF_READ);
 
 wsprintf(WriteBuf, "Source File Handle: %d\nNo. of args: %d",
-	   hSourceFile, wargs);
+	   hSourceFile, _ARGC);
 MessageBox((HWND)NULL, (LPCSTR)WriteBuf, (LPCSTR)NULL, MB_OK);
 
-  if ((wargs == 3) && (arrgv[2] != NULL)) lpzDestFile = arrgv[2];
+  if ((_ARGC == 3) && (_ARGV[2] != NULL)) lpzDestFile = _ARGV[2];
   else
   {
   lpzDestFile = OriginalName;
-  GetExpandedName(arrgv[1], lpzDestFile);
+  GetExpandedName(_ARGV[1], lpzDestFile);
   };
 
  MessageBox((HWND)NULL, (LPCSTR)lpzDestFile, (LPCSTR)"Destination File",
@@ -47,7 +42,7 @@
   hDestFile = LZOpenFile(lpzDestFile, (LPOFSTRUCT) &SourceOpenStruct2,
 			OF_CREATE | OF_WRITE);
 wsprintf(WriteBuf, "Destination File Handle: %d\nNo. of args: %d",
-	   hDestFile, wargs-1);
+	   hDestFile, _ARGC-1);
 MessageBox((HWND)NULL, (LPCSTR)WriteBuf, (LPCSTR)NULL, MB_OK);
 
   dwreturn = LZCopy(hSourceFile, hDestFile);
@@ -68,7 +63,7 @@
   	MessageBox((HWND)NULL,  (LPCSTR)"LZERROR_WRITE\n", (LPCSTR)NULL, MB_OK);
   if ((long)dwreturn > 0L)
    {wsprintf((LPSTR)WriteBuf, (LPCSTR)"Successful decompression from %s to %s\n",
-    			   arrgv[1], lpzDestFile);
+    			   _ARGV[1], lpzDestFile);
 	MessageBox((HWND)NULL, (LPSTR)WriteBuf, (LPCSTR)NULL, MB_OK);
 	};
   LZClose(hSourceFile); LZClose(hDestFile);
diff --git a/loader/main.c b/loader/main.c
index 4ac8026..b3e4f8b 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -54,6 +54,7 @@
  */
 int MAIN_Init(void)
 {
+    extern BOOL32 EVENT_Init(void);
     extern BOOL32 RELAY_Init(void);
     extern BOOL32 WIN16DRV_Init(void);
     extern BOOL32 VIRTUAL_Init(void);
@@ -77,6 +78,9 @@
       /* Initialize signal handling */
     if (!SIGNAL_Init()) return 0;
 
+      /* Initialize event handling */
+    if (!EVENT_Init()) return 0;
+
 #ifdef WINELIB
     /* Create USER and GDI heap */
     USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
diff --git a/loader/module.c b/loader/module.c
index bd12830..a41ce37 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -265,7 +265,7 @@
  *           MODULE_AllocateSegment (WPROCS.26)
  */
 
-DWORD MODULE_AllocateSegment(WORD wFlags, WORD wSize, WORD wElem)
+DWORD WINAPI MODULE_AllocateSegment(WORD wFlags, WORD wSize, WORD wElem)
 {
     WORD size = wSize << wElem;
     HANDLE16 hMem = GlobalAlloc16( MODULE_Ne2MemFlags(wFlags), size);
@@ -478,6 +478,10 @@
     if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21;  /* win32 exe */
     if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11;  /* invalid exe */
 
+    if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
+      fprintf(stderr, "Sorry, this is an OS/2 linear executable (LX) file !\n");
+      return (HMODULE16)11;
+    }
     /* We now have a valid NE header */
 
     size = sizeof(NE_MODULE) +
@@ -805,6 +809,15 @@
 
 
 /***********************************************************************
+ *           EntryAddrProc   (WPROCS.27)
+ */
+FARPROC16 WINAPI EntryAddrProc( HMODULE16 hModule, WORD ordinal )
+{
+    return MODULE_GetEntryPoint( hModule, ordinal );
+}
+
+
+/***********************************************************************
  *           MODULE_SetEntryPoint
  *
  * Change the value of an entry point. Use with caution!
@@ -1286,7 +1299,7 @@
 /**********************************************************************
  *	    FreeModule16    (KERNEL.46)
  */
-BOOL16 FreeModule16( HMODULE16 hModule )
+BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
 {
     NE_MODULE *pModule;
 
@@ -1303,13 +1316,13 @@
 /**********************************************************************
  *	    GetModuleHandle16    (KERNEL.47)
  */
-HMODULE16 WIN16_GetModuleHandle( SEGPTR name )
+HMODULE16 WINAPI WIN16_GetModuleHandle( SEGPTR name )
 {
     if (HIWORD(name) == 0) return GetExePtr( (HINSTANCE16)name );
     return MODULE_FindModule( PTR_SEG_TO_LIN(name) );
 }
 
-HMODULE16 GetModuleHandle16( LPCSTR name )
+HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
 {
     return MODULE_FindModule( name );
 }
@@ -1318,7 +1331,7 @@
 /**********************************************************************
  *	    GetModuleUsage    (KERNEL.48)
  */
-INT16 GetModuleUsage( HINSTANCE16 hModule )
+INT16 WINAPI GetModuleUsage( HINSTANCE16 hModule )
 {
     NE_MODULE *pModule;
 
@@ -1333,7 +1346,8 @@
 /**********************************************************************
  *	    GetModuleFileName16    (KERNEL.49)
  */
-INT16 GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName, INT16 nSize )
+INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
+                                  INT16 nSize )
 {
     NE_MODULE *pModule;
 
@@ -1349,7 +1363,8 @@
 /***********************************************************************
  *              GetModuleFileName32A      (KERNEL32.235)
  */
-DWORD GetModuleFileName32A( HMODULE32 hModule, LPSTR lpFileName, DWORD size )
+DWORD WINAPI GetModuleFileName32A( HMODULE32 hModule, LPSTR lpFileName,
+                                   DWORD size )
 {                   
     NE_MODULE *pModule;
            
@@ -1369,7 +1384,8 @@
 /***********************************************************************
  *              GetModuleFileName32W      (KERNEL32.236)
  */
-DWORD GetModuleFileName32W( HMODULE32 hModule, LPWSTR lpFileName, DWORD size )
+DWORD WINAPI GetModuleFileName32W( HMODULE32 hModule, LPWSTR lpFileName,
+                                   DWORD size )
 {
     LPSTR fnA = (char*)HeapAlloc( GetProcessHeap(), 0, size );
     DWORD res = GetModuleFileName32A( hModule, fnA, size );
@@ -1382,7 +1398,7 @@
 /**********************************************************************
  *	    GetModuleName    (KERNEL.27)
  */
-BOOL16 GetModuleName( HINSTANCE16 hinst, LPSTR buf, INT16 nSize )
+BOOL16 WINAPI GetModuleName( HINSTANCE16 hinst, LPSTR buf, INT16 nSize )
 {
     LPSTR name = MODULE_GetModuleName(hinst);
 
@@ -1395,7 +1411,8 @@
 /***********************************************************************
  *           LoadLibraryEx32W   (KERNEL.513)
  */
-HINSTANCE16 LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf, DWORD flags )
+HINSTANCE16 WINAPI LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf,
+                                       DWORD flags )
 {
     fprintf(stderr,"LoadLibraryEx32W(%s,%d,%08lx)\n",libname,hf,flags);
     if (!flags && !hf)
@@ -1406,7 +1423,7 @@
 /***********************************************************************
  *           LoadLibrary   (KERNEL.95)
  */
-HINSTANCE16 LoadLibrary16( LPCSTR libname )
+HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
 {
     HINSTANCE16 handle;
 
@@ -1436,7 +1453,7 @@
 /***********************************************************************
  *           FreeLibrary16   (KERNEL.96)
  */
-void FreeLibrary16( HINSTANCE16 handle )
+void WINAPI FreeLibrary16( HINSTANCE16 handle )
 {
     dprintf_module( stddeb,"FreeLibrary: %04x\n", handle );
     FreeModule16( handle );
@@ -1446,7 +1463,7 @@
 /***********************************************************************
  *           WinExec16   (KERNEL.166)
  */
-HINSTANCE16 WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
+HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
 {
     return WinExec32( lpCmdLine, nCmdShow );
 }
@@ -1455,7 +1472,7 @@
 /***********************************************************************
  *           WinExec32   (KERNEL32.566)
  */
-HINSTANCE32 WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
+HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
 {
     LOADPARAMS params;
     HGLOBAL16 cmdShowHandle, cmdLineHandle;
@@ -1581,7 +1598,7 @@
 		    argptr = argv;
 		    if (iconic) *argptr++ = "-iconic";
 		    *argptr++ = unixfilename;
-		    p = cmdline;
+		    p = cmdline + 1;
 		    while (1)
 		    {
 			while (*p && (*p == ' ' || *p == '\t')) *p++ = '\0';
@@ -1628,7 +1645,7 @@
  *           WIN32_GetProcAddress16   (KERNEL32.36)
  * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
  */
-FARPROC16 WIN32_GetProcAddress16( HMODULE16 hModule, LPSTR name )
+FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE16 hModule, LPSTR name )
 {
     WORD	ordinal;
     FARPROC16	ret;
@@ -1656,7 +1673,7 @@
 /***********************************************************************
  *           GetProcAddress16   (KERNEL.50)
  */
-FARPROC16 GetProcAddress16( HMODULE16 hModule, SEGPTR name )
+FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name )
 {
     WORD ordinal;
     FARPROC16 ret;
@@ -1688,7 +1705,7 @@
 /***********************************************************************
  *           GetProcAddress32   (KERNEL32.257)
  */
-FARPROC32 GetProcAddress32( HMODULE32 hModule, LPCSTR function )
+FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function )
 {
 #ifndef WINELIB
     NE_MODULE *pModule;
@@ -1713,8 +1730,7 @@
 /***********************************************************************
  *           RtlImageNtHeaders   (NTDLL)
  */
-LPIMAGE_NT_HEADERS
-RtlImageNtHeader(HMODULE32 hModule)
+LPIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE32 hModule)
 {
 #ifndef WINELIB
     NE_MODULE *pModule;
@@ -1734,7 +1750,7 @@
 /**********************************************************************
  *	    GetExpWinVer    (KERNEL.167)
  */
-WORD GetExpWinVer( HMODULE16 hModule )
+WORD WINAPI GetExpWinVer( HMODULE16 hModule )
 {
     NE_MODULE *pModule = MODULE_GetPtr( hModule );
     return pModule ? pModule->expected_version : 0;
@@ -1744,7 +1760,7 @@
 /**********************************************************************
  *	    IsSharedSelector    (KERNEL.345)
  */
-BOOL16 IsSharedSelector( HANDLE16 selector )
+BOOL16 WINAPI IsSharedSelector( HANDLE16 selector )
 {
     /* Check whether the selector belongs to a DLL */
     NE_MODULE *pModule = MODULE_GetPtr( GetExePtr( selector ));
@@ -1756,7 +1772,7 @@
 /**********************************************************************
  *	    ModuleFirst    (TOOLHELP.59)
  */
-BOOL16 ModuleFirst( MODULEENTRY *lpme )
+BOOL16 WINAPI ModuleFirst( MODULEENTRY *lpme )
 {
     lpme->wNext = hFirstModule;
     return ModuleNext( lpme );
@@ -1766,7 +1782,7 @@
 /**********************************************************************
  *	    ModuleNext    (TOOLHELP.60)
  */
-BOOL16 ModuleNext( MODULEENTRY *lpme )
+BOOL16 WINAPI ModuleNext( MODULEENTRY *lpme )
 {
     NE_MODULE *pModule;
 
@@ -1787,7 +1803,7 @@
 /**********************************************************************
  *	    ModuleFindName    (TOOLHELP.61)
  */
-BOOL16 ModuleFindName( MODULEENTRY *lpme, LPCSTR name )
+BOOL16 WINAPI ModuleFindName( MODULEENTRY *lpme, LPCSTR name )
 {
     lpme->wNext = GetModuleHandle16( name );
     return ModuleNext( lpme );
@@ -1797,7 +1813,7 @@
 /**********************************************************************
  *	    ModuleFindHandle    (TOOLHELP.62)
  */
-BOOL16 ModuleFindHandle( MODULEENTRY *lpme, HMODULE16 hModule )
+BOOL16 WINAPI ModuleFindHandle( MODULEENTRY *lpme, HMODULE16 hModule )
 {
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     lpme->wNext = hModule;
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 3536206..dd0ff09 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -550,7 +550,7 @@
  */
 
 /* It does nothing */
-void PatchCodeHandle(HANDLE16 hSel)
+void WINAPI PatchCodeHandle(HANDLE16 hSel)
 {
 }
 #endif /* WINELIB */
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 5f7660b..223348b 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -27,6 +27,7 @@
 #include "global.h"
 #include "task.h"
 #include "ldt.h"
+#include "options.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "debugger.h"
@@ -189,6 +190,8 @@
 	Module = (char *) RVA(pe_imp->Name);
 	dprintf_win32 (stddeb, "%s\n", Module);
 
+	/* FIXME: forwarder entries ... */
+
 	if (pe_imp->u.OriginalFirstThunk != 0) { /* original MS style */
 	    dprintf_win32 (stddeb, "Microsoft style imports used\n");
 	    import_list =(LPIMAGE_THUNK_DATA) RVA(pe_imp->u.OriginalFirstThunk);
@@ -402,16 +405,14 @@
 		fprintf(stderr,")\n");
 		return;
 	}
-
 /* FIXME: this is a *horrible* hack to make COMDLG32.DLL load OK. The
-problem needs to be fixed properly at some stage */
-
+ * problem needs to be fixed properly at some stage 
+ */
 	if (pe->pe_header->OptionalHeader.NumberOfRvaAndSizes != 16) {
 		printf("Short PE Header!!!\n");
 		lseek( fd, -(16 - pe->pe_header->OptionalHeader.NumberOfRvaAndSizes) * sizeof(IMAGE_DATA_DIRECTORY), SEEK_CUR);
 	}
 
-/* horrible hack ends !!! */
 	/* read sections */
 	pe->pe_seg = xmalloc(sizeof(IMAGE_SECTION_HEADER) * 
 				   pe->pe_header->FileHeader.NumberOfSections);
@@ -423,19 +424,8 @@
 	pe->vma_size=0;
 	dprintf_win32(stddeb, "Load addr is %x\n",load_addr);
 	calc_vma_size(pe);
-
-#if 0
-	/* We use malloc here, while a huge part of that address space does
-	   not be supported by actual memory. It has to be contiguous, though.
-	   I don't know if mmap("/dev/null"); would do any better.
-	   What I'd really like to do is a Win32 style VirtualAlloc/MapViewOfFile
-	   sequence */
-	load_addr = pe->load_addr = (int)xmalloc(pe->vma_size);
-	memset( load_addr, 0, pe->vma_size);
-#else
 	load_addr = (int) VirtualAlloc( (void*)pe->base_addr, pe->vma_size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE );
         pe->load_addr = load_addr;
-#endif
 
 	dprintf_win32(stddeb, "Load addr is really %x, range %x\n",
 		pe->load_addr, pe->vma_size);
@@ -476,7 +466,6 @@
 
 		if(strcmp(pe->pe_seg[i].Name, ".reloc") == 0)
 			pe->pe_reloc = (LPIMAGE_BASE_RELOCATION) result;
-
 	}
 
 	/* There is word that the actual loader does not care about the
@@ -538,11 +527,9 @@
 		[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size)
 		dprintf_win32(stdnimp,"Global Pointer (MIPS) ignored\n");
 
-#ifdef NOT	/* we initialize this later */
 	if(pe->pe_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_TLS].Size)
-		 dprintf_win32(stdnimp,"Thread local storage ignored\n");
-#endif
+		 fprintf(stdnimp,"Thread local storage ignored\n");
 
 	if(pe->pe_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size)
@@ -658,6 +645,16 @@
     if (!(pModule->flags & NE_FFLAGS_WIN32) || !(pe = pModule->pe_module))
         return;
 
+    load_addr = pe->load_addr;
+
+#ifndef WINELIB
+    if (Options.debug) {
+            DBG_ADDR addr = { NULL, 0, RVA(pe->pe_header->OptionalHeader.AddressOfEntryPoint) };
+            DEBUG_AddBreakpoint( &addr );
+	    DEBUG_SetBreakpoints(TRUE);
+    }
+#endif
+
     /*  DLL_ATTACH_PROCESS:
      *		lpreserved is NULL for dynamic loads, not-NULL for static loads
      *  DLL_DETACH_PROCESS:
@@ -669,7 +666,6 @@
     if (	(pe->pe_header->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
 		(pe->pe_header->OptionalHeader.AddressOfEntryPoint)
     ) {
-        load_addr = pe->load_addr;
 	printf("InitPEDLL() called!\n");
 	CallDLLEntryProc32( 
 	    (FARPROC32)RVA(pe->pe_header->OptionalHeader.AddressOfEntryPoint),
diff --git a/loader/resource.c b/loader/resource.c
index 6e4ac03..31c6453 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -36,7 +36,7 @@
 /**********************************************************************
  *	    FindResource16    (KERNEL.60)
  */
-HRSRC16 FindResource16( HMODULE16 hModule, SEGPTR name, SEGPTR type )
+HRSRC16 WINAPI FindResource16( HMODULE16 hModule, SEGPTR name, SEGPTR type )
 {
     NE_MODULE *pModule;
 
@@ -70,7 +70,7 @@
 /**********************************************************************
  *	    FindResource32A    (KERNEL32.128)
  */
-HANDLE32 FindResource32A( HINSTANCE32 hModule, LPCSTR name, LPCSTR type )
+HANDLE32 WINAPI FindResource32A( HINSTANCE32 hModule, LPCSTR name, LPCSTR type)
 {
     return FindResourceEx32A(hModule,name,type,WINE_LanguageId);
 }
@@ -78,9 +78,9 @@
 /**********************************************************************
  *	    FindResourceEx32A    (KERNEL32.129)
  */
-HANDLE32 FindResourceEx32A(
-	HINSTANCE32 hModule,LPCSTR name,LPCSTR type,WORD lang
-) {
+HANDLE32 WINAPI FindResourceEx32A( HINSTANCE32 hModule, LPCSTR name,
+                                   LPCSTR type, WORD lang )
+{
     LPWSTR xname,xtype;
     HANDLE32 ret;
 
@@ -102,9 +102,9 @@
 /**********************************************************************
  *	    FindResourceEx32W    (KERNEL32.130)
  */
-HRSRC32 FindResourceEx32W(
-	HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type, WORD lang
-) {
+HRSRC32 WINAPI FindResourceEx32W( HINSTANCE32 hModule, LPCWSTR name,
+                                  LPCWSTR type, WORD lang )
+{
 #ifndef WINELIB
     NE_MODULE *pModule;
 
@@ -132,7 +132,7 @@
 /**********************************************************************
  *	    FindResource32W    (KERNEL32.131)
  */
-HRSRC32 FindResource32W( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
+HRSRC32 WINAPI FindResource32W(HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type)
 {
     return FindResourceEx32W(hModule,name,type,WINE_LanguageId);
 }
@@ -141,7 +141,7 @@
 /**********************************************************************
  *	    LoadResource16    (KERNEL.61)
  */
-HGLOBAL16 LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc )
+HGLOBAL16 WINAPI LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc )
 {
     NE_MODULE *pModule;
 
@@ -165,7 +165,7 @@
 /**********************************************************************
  *	    LoadResource32    (KERNEL32.370)
  */
-HGLOBAL32 LoadResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
+HGLOBAL32 WINAPI LoadResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
 #ifndef WINELIB
     NE_MODULE *pModule;
@@ -193,7 +193,7 @@
  *	    LockResource    (KERNEL.62)
  */
 /* 16-bit version */
-SEGPTR WIN16_LockResource16(HGLOBAL16 handle)
+SEGPTR WINAPI WIN16_LockResource16(HGLOBAL16 handle)
 {
 #ifndef WINELIB
     HMODULE16 hModule;
@@ -215,7 +215,7 @@
 }
 
 /* WINELIB 16-bit version */
-LPVOID LockResource16( HGLOBAL16 handle )
+LPVOID WINAPI LockResource16( HGLOBAL16 handle )
 {
 #ifndef WINELIB
     HMODULE16 hModule;
@@ -240,7 +240,7 @@
 /**********************************************************************
  *	    LockResource32    (KERNEL32.384)
  */
-LPVOID LockResource32( HGLOBAL32 handle )
+LPVOID WINAPI LockResource32( HGLOBAL32 handle )
 {
     return (LPVOID)handle;
 }
@@ -249,7 +249,7 @@
 /**********************************************************************
  *	    FreeResource16    (KERNEL.63)
  */
-BOOL16 FreeResource16( HGLOBAL16 handle )
+BOOL16 WINAPI FreeResource16( HGLOBAL16 handle )
 {
 #ifndef WINELIB
     HMODULE16 hModule;
@@ -273,7 +273,7 @@
 /**********************************************************************
  *	    FreeResource32    (KERNEL32.145)
  */
-BOOL32 FreeResource32( HGLOBAL32 handle )
+BOOL32 WINAPI FreeResource32( HGLOBAL32 handle )
 {
     /* no longer used in Win32 */
     return TRUE;
@@ -283,7 +283,7 @@
 /**********************************************************************
  *	    AccessResource16    (KERNEL.64)
  */
-INT16 AccessResource16( HINSTANCE16 hModule, HRSRC16 hRsrc )
+INT16 WINAPI AccessResource16( HINSTANCE16 hModule, HRSRC16 hRsrc )
 {
     NE_MODULE *pModule;
 
@@ -308,7 +308,7 @@
 /**********************************************************************
  *	    AccessResource32    (KERNEL32.64)
  */
-INT32 AccessResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
+INT32 WINAPI AccessResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "AccessResource: module=%04x res=%04x\n",
@@ -322,7 +322,7 @@
 /**********************************************************************
  *	    SizeofResource16    (KERNEL.65)
  */
-DWORD SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc )
+DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc )
 {
     NE_MODULE *pModule;
 
@@ -346,7 +346,7 @@
 /**********************************************************************
  *	    SizeofResource32    (KERNEL32.522)
  */
-DWORD SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
+DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
     hModule = GetExePtr( hModule );  /* In case we were passed an hInstance */
     dprintf_resource(stddeb, "SizeofResource32: module=%04x res=%04x\n",
@@ -363,7 +363,7 @@
 /**********************************************************************
  *	    AllocResource16    (KERNEL.66)
  */
-HGLOBAL16 AllocResource16( HMODULE16 hModule, HRSRC16 hRsrc, DWORD size )
+HGLOBAL16 WINAPI AllocResource16( HMODULE16 hModule, HRSRC16 hRsrc, DWORD size)
 {
     NE_MODULE *pModule;
 
@@ -389,7 +389,8 @@
  *
  * Check Schulman, p. 232 for details
  */
-HGLOBAL16 DirectResAlloc( HINSTANCE16 hInstance, WORD wType, UINT16 wSize )
+HGLOBAL16 WINAPI DirectResAlloc( HINSTANCE16 hInstance, WORD wType,
+                                 UINT16 wSize )
 {
     dprintf_resource(stddeb,"DirectResAlloc(%04x,%04x,%04x)\n",
                      hInstance, wType, wSize );
@@ -405,7 +406,7 @@
 /**********************************************************************
  *			LoadAccelerators16	[USER.177]
  */
-HACCEL16 LoadAccelerators16(HINSTANCE16 instance, SEGPTR lpTableName)
+HACCEL16 WINAPI LoadAccelerators16(HINSTANCE16 instance, SEGPTR lpTableName)
 {
     HACCEL16 	hAccel;
     HGLOBAL16 	rsc_mem;
@@ -458,7 +459,7 @@
  * 04:	WORD	IDval		
  * 06:	WORD	pad		(to DWORD boundary)
  */
-HACCEL32 LoadAccelerators32W(HINSTANCE32 instance,LPCWSTR lpTableName)
+HACCEL32 WINAPI LoadAccelerators32W(HINSTANCE32 instance,LPCWSTR lpTableName)
 {
     HACCEL32 	hAccel;
     HGLOBAL32 	rsc_mem;
@@ -504,7 +505,7 @@
     return hAccel;
 }
 
-HACCEL32 LoadAccelerators32A(HINSTANCE32 instance,LPCSTR lpTableName)
+HACCEL32 WINAPI LoadAccelerators32A(HINSTANCE32 instance,LPCSTR lpTableName)
 {
 	LPWSTR	 uni;
 	HACCEL32 result;
@@ -521,8 +522,8 @@
 /**********************************************************************
  *					LoadString16
  */
-INT16
-LoadString16(HINSTANCE16 instance,UINT16 resource_id,LPSTR buffer,INT16 buflen)
+INT16 WINAPI LoadString16( HINSTANCE16 instance, UINT16 resource_id,
+                           LPSTR buffer, INT16 buflen )
 {
     HGLOBAL16 hmem;
     HRSRC16 hrsrc;
@@ -568,8 +569,8 @@
 /**********************************************************************
  *	LoadString32W		(USER32.375)
  */
-INT32
-LoadString32W(HINSTANCE32 instance,UINT32 resource_id,LPWSTR buffer,int buflen)
+INT32 WINAPI LoadString32W( HINSTANCE32 instance, UINT32 resource_id,
+                            LPWSTR buffer, int buflen )
 {
     HGLOBAL32 hmem;
     HRSRC32 hrsrc;
@@ -618,8 +619,8 @@
 /**********************************************************************
  *	LoadString32A	(USER32.374)
  */
-INT32
-LoadString32A(HINSTANCE32 instance,UINT32 resource_id,LPSTR buffer,int buflen)
+INT32 WINAPI LoadString32A( HINSTANCE32 instance, UINT32 resource_id,
+                            LPSTR buffer,int buflen )
 {
     INT32 retval;
     LPWSTR buffer2 = NULL;
@@ -659,10 +660,9 @@
 /**********************************************************************
  *	LoadMessage32A		(internal)
  */
-INT32
-LoadMessage32A(
-	HINSTANCE32 instance,UINT32 id,WORD lang,LPSTR buffer,int buflen
-) {
+INT32 LoadMessage32A( HINSTANCE32 instance, UINT32 id, WORD lang,
+                      LPSTR buffer, int buflen )
+{
     HGLOBAL32	hmem;
     HRSRC32	hrsrc;
     BYTE	*p;
@@ -747,8 +747,8 @@
 /**********************************************************************
  *	SetResourceHandler	(KERNEL.43)
  */
-FARPROC16
-SetResourceHandler(HINSTANCE16 instance,SEGPTR s,FARPROC16 farproc)
+FARPROC16 WINAPI SetResourceHandler( HINSTANCE16 instance, SEGPTR s,
+                                     FARPROC16 farproc )
 {
     if (HIWORD(s))
 	fprintf(stderr,"SetResourceHandler(%04x,%s,%p), empty STUB!\n",
@@ -763,46 +763,54 @@
 /**********************************************************************
  *	EnumResourceTypesA	(KERNEL32.90)
  */
-BOOL32
-EnumResourceTypes32A(HMODULE32 hmodule,ENUMRESTYPEPROC32A lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceTypes32A( HMODULE32 hmodule,ENUMRESTYPEPROC32A lpfun,
+                                    LONG lParam)
+{
     return PE_EnumResourceTypes32A(hmodule,lpfun,lParam);
 }
 
 /**********************************************************************
  *	EnumResourceTypesW	(KERNEL32.91)
  */
-BOOL32
-EnumResourceTypes32W(HMODULE32 hmodule,ENUMRESTYPEPROC32W lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceTypes32W( HMODULE32 hmodule,ENUMRESTYPEPROC32W lpfun,
+                                    LONG lParam)
+{
     return PE_EnumResourceTypes32W(hmodule,lpfun,lParam);
 }
 
 /**********************************************************************
  *	EnumResourceNamesA	(KERNEL32.88)
  */
-BOOL32
-EnumResourceNames32A(HMODULE32 hmodule,LPCSTR type,ENUMRESNAMEPROC32A lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceNames32A( HMODULE32 hmodule, LPCSTR type,
+                                    ENUMRESNAMEPROC32A lpfun, LONG lParam )
+{
     return PE_EnumResourceNames32A(hmodule,type,lpfun,lParam);
 }
 /**********************************************************************
  *	EnumResourceNamesW	(KERNEL32.89)
  */
-BOOL32
-EnumResourceNames32W(HMODULE32 hmodule,LPCWSTR type,ENUMRESNAMEPROC32W lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceNames32W( HMODULE32 hmodule, LPCWSTR type,
+                                    ENUMRESNAMEPROC32W lpfun, LONG lParam )
+{
     return PE_EnumResourceNames32W(hmodule,type,lpfun,lParam);
 }
 
 /**********************************************************************
  *	EnumResourceLanguagesA	(KERNEL32.86)
  */
-BOOL32
-EnumResourceLanguages32A(HMODULE32 hmodule,LPCSTR type,LPCSTR name,ENUMRESLANGPROC32A lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceLanguages32A( HMODULE32 hmodule, LPCSTR type,
+                                        LPCSTR name, ENUMRESLANGPROC32A lpfun,
+                                        LONG lParam)
+{
     return PE_EnumResourceLanguages32A(hmodule,type,name,lpfun,lParam);
 }
 /**********************************************************************
  *	EnumResourceLanguagesW	(KERNEL32.87)
  */
-BOOL32
-EnumResourceLanguages32W(HMODULE32 hmodule,LPCWSTR type,LPCWSTR name,ENUMRESLANGPROC32W lpfun,LONG lParam) {
+BOOL32 WINAPI EnumResourceLanguages32W( HMODULE32 hmodule, LPCWSTR type,
+                                        LPCWSTR name, ENUMRESLANGPROC32W lpfun,
+                                        LONG lParam)
+{
     return PE_EnumResourceLanguages32W(hmodule,type,name,lpfun,lParam);
 }
 #endif  /* WINELIB */
diff --git a/loader/signal.c b/loader/signal.c
index 1257e33..d99dedc 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -46,12 +46,24 @@
 static __inline__ int wine_sigaction( int sig, struct kernel_sigaction *new,
                                       struct kernel_sigaction *old )
 {
+#ifdef __PIC__
+    __asm__ __volatile__( "pushl %%ebx\n\t"
+                          "movl %2,%%ebx\n\t"
+                          "int $0x80\n\t"
+                          "popl %%ebx"
+                          : "=a" (sig)
+                          : "0" (SYS_sigaction),
+                            "g" (sig),
+                            "c" (new),
+                            "d" (old) );
+#else
     __asm__ __volatile__( "int $0x80"
                           : "=a" (sig)
                           : "0" (SYS_sigaction),
                             "b" (sig),
                             "c" (new),
                             "d" (old) );
+#endif  /* __PIC__ */
     if (sig>=0)
         return 0;
     errno = -sig;
@@ -62,15 +74,7 @@
 
 /* Signal stack */
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-# define SIGNAL_STACK_SIZE  MINSIGSTKSZ
-#elif defined (__svr4__) || defined(_SCO_DS)
-# define SIGNAL_STACK_SIZE  SIGSTKSZ
-#else
-# define SIGNAL_STACK_SIZE  4096
-#endif
-
-static char SIGNAL_Stack[SIGNAL_STACK_SIZE];
+static char SIGNAL_Stack[16384];
 
 
 /**********************************************************************
@@ -102,7 +106,8 @@
 
     struct kernel_sigaction sig_act;
     sig_act.sa_handler = func;
-    sig_act.sa_flags = SA_RESTART | (flags) ? SA_NOMASK : 0;
+    sig_act.sa_flags   = SA_RESTART | (flags) ? SA_NOMASK : 0;
+    sig_act.sa_mask    = 0;
     /* Point to the top of the stack, minus 4 just in case, and make
        it aligned  */
     sig_act.sa_restorer = 
@@ -112,10 +117,8 @@
 #else  /* linux && __i386__ */
 
     struct sigaction sig_act;
-    sigset_t sig_mask;
-    sigemptyset(&sig_mask);
     sig_act.sa_handler = func;
-    sig_act.sa_mask = sig_mask;
+    sigemptyset( &sig_act.sa_mask );
 
 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
     sig_act.sa_flags = SA_ONSTACK;
@@ -179,7 +182,6 @@
 #ifdef SIGIO
   sigaddset(&set, SIGIO);
 #endif
-  sigaddset(&set, SIGUSR1);
 #ifdef CONFIG_IPC
   sigaddset(&set, SIGUSR2);
 #endif
diff --git a/loader/task.c b/loader/task.c
index 4094ee9..467548c 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -40,8 +40,9 @@
   /* Min. number of thunks allocated when creating a new segment */
 #define MIN_THUNKS  32
 
-extern void USER_AppExit( HTASK16, HINSTANCE16, HQUEUE16 );
-extern void PE_InitTls( PE_MODULE *module );
+extern INT32 WINSOCK_DeleteTaskWSI( TDB* pTask, struct _WSINFO* pwsi );
+extern void  USER_AppExit( HTASK16, HINSTANCE16, HQUEUE16 );
+extern void  PE_InitTls( PE_MODULE *module );
 
   /* Saved 16-bit stack for current process (Win16 only) */
 DWORD IF1632_Saved16_ss_sp = 0;
@@ -50,7 +51,10 @@
 DWORD IF1632_Saved32_esp = 0;
 
   /* Original Unix stack */
-DWORD IF1632_Original32_esp;
+DWORD IF1632_Original32_esp = 0;
+
+  /* Pointer to function to switch to a larger stack */
+int (*IF1632_CallLargeStack)( int (*func)(), void *arg ) = NULL;
 
 static HTASK16 hFirstTask = 0;
 static HTASK16 hCurrentTask = 0;
@@ -685,6 +689,16 @@
     TDB* pTask = (TDB*) GlobalLock16( hCurrentTask );
     if (!pTask) USER_ExitWindows();  /* No current task yet */
 
+    dprintf_task(stddeb, "Killing task %04x\n", hCurrentTask );
+
+    /* Clean up sockets */
+
+    if( pTask->pwsi ) 
+    {
+	dprintf_task(stddeb, "\tremoving socket table\n");
+	WINSOCK_DeleteTaskWSI( pTask, pTask->pwsi );
+    }
+
     /* Perform USER cleanup */
 
     USER_AppExit( hCurrentTask, pTask->hInstance, pTask->hQueue );
@@ -698,7 +712,7 @@
 
     if (nTaskCount <= 1)
     {
-        dprintf_task( stddeb, "Killing the last task, exiting\n" );
+        dprintf_task( stddeb, "\nthis is the last task, exiting\n" );
         USER_ExitWindows();
     }
 
@@ -767,7 +781,7 @@
 
     /* extract hardware events only! */
 
-    if (!hTask) EVENT_WaitXEvent( FALSE, TRUE );
+    if (!hTask) EVENT_WaitNetEvent( FALSE, TRUE );
 
     while (!hTask)
     {
@@ -788,7 +802,7 @@
 
         /* No task found, wait for some events to come in */
 
-        EVENT_WaitXEvent( TRUE, TRUE );
+        EVENT_WaitNetEvent( TRUE, TRUE );
     }
 
     if (hTask == hCurrentTask) 
@@ -845,7 +859,7 @@
 	    !(pQ->wakeBits & (QS_SENDMESSAGE | QS_SMRESULT)) )
     {
       pQ->flags &= ~QUEUE_FLAG_XEVENT;
-      EVENT_WaitXEvent( FALSE, FALSE );
+      EVENT_WaitNetEvent( FALSE, FALSE );
     }
   }
 }
@@ -854,7 +868,7 @@
 /***********************************************************************
  *           InitTask  (KERNEL.91)
  */
-void InitTask( CONTEXT *context )
+void WINAPI InitTask( CONTEXT *context )
 {
     TDB *pTask;
     NE_MODULE *pModule;
@@ -912,7 +926,7 @@
 /***********************************************************************
  *           WaitEvent  (KERNEL.30)
  */
-BOOL16 WaitEvent( HTASK16 hTask )
+BOOL16 WINAPI WaitEvent( HTASK16 hTask )
 {
     TDB *pTask;
 
@@ -935,7 +949,7 @@
 /***********************************************************************
  *           PostEvent  (KERNEL.31)
  */
-void PostEvent( HTASK16 hTask )
+void WINAPI PostEvent( HTASK16 hTask )
 {
     TDB *pTask;
 
@@ -948,7 +962,7 @@
 /***********************************************************************
  *           SetPriority  (KERNEL.32)
  */
-void SetPriority( HTASK16 hTask, INT16 delta )
+void WINAPI SetPriority( HTASK16 hTask, INT16 delta )
 {
     TDB *pTask;
     INT16 newpriority;
@@ -969,7 +983,7 @@
 /***********************************************************************
  *           LockCurrentTask  (KERNEL.33)
  */
-HTASK16 LockCurrentTask( BOOL16 bLock )
+HTASK16 WINAPI LockCurrentTask( BOOL16 bLock )
 {
     if (bLock) hLockedTask = hCurrentTask;
     else hLockedTask = 0;
@@ -980,7 +994,7 @@
 /***********************************************************************
  *           IsTaskLocked  (KERNEL.122)
  */
-HTASK16 IsTaskLocked(void)
+HTASK16 WINAPI IsTaskLocked(void)
 {
     return hLockedTask;
 }
@@ -989,7 +1003,7 @@
 /***********************************************************************
  *           OldYield  (KERNEL.117)
  */
-void OldYield(void)
+void WINAPI OldYield(void)
 {
     TDB *pCurTask;
 
@@ -1003,7 +1017,7 @@
 /***********************************************************************
  *           DirectedYield  (KERNEL.150)
  */
-void DirectedYield( HTASK16 hTask )
+void WINAPI DirectedYield( HTASK16 hTask )
 {
     TDB *pCurTask = (TDB *)GlobalLock16( hCurrentTask );
     pCurTask->hYieldTo = hTask;
@@ -1014,7 +1028,7 @@
 /***********************************************************************
  *           UserYield  (USER.332)
  */
-void UserYield(void)
+void WINAPI UserYield(void)
 {
     TDB *pCurTask = (TDB *)GlobalLock16( hCurrentTask );
     MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( pCurTask->hQueue );
@@ -1033,7 +1047,7 @@
 /***********************************************************************
  *           Yield  (KERNEL.29)
  */
-void Yield(void)
+void WINAPI Yield(void)
 {
     TDB *pCurTask = (TDB *)GlobalLock16( hCurrentTask );
     if (pCurTask) pCurTask->hYieldTo = 0;
@@ -1045,7 +1059,7 @@
 /***********************************************************************
  *           MakeProcInstance16  (KERNEL.51)
  */
-FARPROC16 MakeProcInstance16( FARPROC16 func, HANDLE16 hInstance )
+FARPROC16 WINAPI MakeProcInstance16( FARPROC16 func, HANDLE16 hInstance )
 {
     BYTE *thunk;
     SEGPTR thunkaddr;
@@ -1070,7 +1084,7 @@
 /***********************************************************************
  *           FreeProcInstance16  (KERNEL.52)
  */
-void FreeProcInstance16( FARPROC16 func )
+void WINAPI FreeProcInstance16( FARPROC16 func )
 {
     dprintf_task( stddeb, "FreeProcInstance(%08lx)\n", (DWORD)func );
     if (!__winelib) TASK_FreeThunk( hCurrentTask, (SEGPTR)func );
@@ -1080,7 +1094,7 @@
 /**********************************************************************
  *	    GetCodeHandle    (KERNEL.93)
  */
-HANDLE16 GetCodeHandle( FARPROC16 proc )
+HANDLE16 WINAPI GetCodeHandle( FARPROC16 proc )
 {
     HANDLE16 handle;
     BYTE *thunk = (BYTE *)PTR_SEG_TO_LIN( proc );
@@ -1103,7 +1117,7 @@
 /***********************************************************************
  *           SetTaskQueue  (KERNEL.34)
  */
-HQUEUE16 SetTaskQueue( HTASK16 hTask, HQUEUE16 hQueue )
+HQUEUE16 WINAPI SetTaskQueue( HTASK16 hTask, HQUEUE16 hQueue )
 {
     HQUEUE16 hPrev;
     TDB *pTask;
@@ -1123,7 +1137,7 @@
 /***********************************************************************
  *           GetTaskQueue  (KERNEL.35)
  */
-HQUEUE16 GetTaskQueue( HTASK16 hTask )
+HQUEUE16 WINAPI GetTaskQueue( HTASK16 hTask )
 {
     TDB *pTask;
 
@@ -1136,7 +1150,7 @@
 /***********************************************************************
  *           SwitchStackTo   (KERNEL.108)
  */
-void SwitchStackTo( WORD seg, WORD ptr, WORD top )
+void WINAPI SwitchStackTo( WORD seg, WORD ptr, WORD top )
 {
     TDB *pTask;
     STACK16FRAME *oldFrame, *newFrame;
@@ -1177,7 +1191,7 @@
  * to make sure all registers are preserved, but we don't use them in any
  * way, so we don't need a CONTEXT* argument.
  */
-void SwitchStackBack(void)
+void WINAPI SwitchStackBack(void)
 {
     TDB *pTask;
     STACK16FRAME *oldFrame, *newFrame;
@@ -1216,7 +1230,7 @@
 /***********************************************************************
  *           GetTaskQueueDS  (KERNEL.118)
  */
-void GetTaskQueueDS( CONTEXT *context )
+void WINAPI GetTaskQueueDS( CONTEXT *context )
 {
     DS_reg(context) = GlobalHandleToSel( GetTaskQueue(0) );
 }
@@ -1225,7 +1239,7 @@
 /***********************************************************************
  *           GetTaskQueueES  (KERNEL.119)
  */
-void GetTaskQueueES( CONTEXT *context )
+void WINAPI GetTaskQueueES( CONTEXT *context )
 {
     ES_reg(context) = GlobalHandleToSel( GetTaskQueue(0) );
 }
@@ -1234,12 +1248,12 @@
 /***********************************************************************
  *           GetCurrentTask   (KERNEL.36)
  */
-HTASK16 GetCurrentTask(void)
+HTASK16 WINAPI GetCurrentTask(void)
 {
     return hCurrentTask;
 }
 
-DWORD WIN16_GetCurrentTask(void)
+DWORD WINAPI WIN16_GetCurrentTask(void)
 {
     /* This is the version used by relay code; the first task is */
     /* returned in the high word of the result */
@@ -1250,7 +1264,7 @@
 /***********************************************************************
  *           GetCurrentPDB   (KERNEL.37)
  */
-HANDLE16 GetCurrentPDB(void)
+HANDLE16 WINAPI GetCurrentPDB(void)
 {
     TDB *pTask;
 
@@ -1262,7 +1276,7 @@
 /***********************************************************************
  *           GetInstanceData   (KERNEL.54)
  */
-INT16 GetInstanceData( HINSTANCE16 instance, WORD buffer, INT16 len )
+INT16 WINAPI GetInstanceData( HINSTANCE16 instance, WORD buffer, INT16 len )
 {
     char *ptr = (char *)GlobalLock16( instance );
     if (!ptr || !len) return 0;
@@ -1275,7 +1289,7 @@
 /***********************************************************************
  *           GetExeVersion   (KERNEL.105)
  */
-WORD GetExeVersion(void)
+WORD WINAPI GetExeVersion(void)
 {
     TDB *pTask;
 
@@ -1287,7 +1301,7 @@
 /***********************************************************************
  *           SetErrorMode16   (KERNEL.107)
  */
-UINT16 SetErrorMode16( UINT16 mode )
+UINT16 WINAPI SetErrorMode16( UINT16 mode )
 {
     TDB *pTask;
     UINT16 oldMode;
@@ -1303,7 +1317,7 @@
 /***********************************************************************
  *           SetErrorMode32   (KERNEL32.486)
  */
-UINT32 SetErrorMode32( UINT32 mode )
+UINT32 WINAPI SetErrorMode32( UINT32 mode )
 {
     return SetErrorMode16( (UINT16)mode );
 }
@@ -1312,7 +1326,7 @@
 /***********************************************************************
  *           GetDOSEnvironment   (KERNEL.131)
  */
-SEGPTR GetDOSEnvironment(void)
+SEGPTR WINAPI GetDOSEnvironment(void)
 {
     TDB *pTask;
 
@@ -1324,7 +1338,7 @@
 /***********************************************************************
  *           GetNumTasks   (KERNEL.152)
  */
-UINT16 GetNumTasks(void)
+UINT16 WINAPI GetNumTasks(void)
 {
     return nTaskCount;
 }
@@ -1336,7 +1350,7 @@
  * Note: this function apparently returns a DWORD with LOWORD == HIWORD.
  * I don't think we need to bother with this.
  */
-HINSTANCE16 GetTaskDS(void)
+HINSTANCE16 WINAPI GetTaskDS(void)
 {
     TDB *pTask;
 
@@ -1348,7 +1362,7 @@
 /***********************************************************************
  *           IsTask   (KERNEL.320)
  */
-BOOL16 IsTask( HTASK16 hTask )
+BOOL16 WINAPI IsTask( HTASK16 hTask )
 {
     TDB *pTask;
 
@@ -1361,7 +1375,7 @@
 /***********************************************************************
  *           SetTaskSignalProc   (KERNEL.38)
  */
-FARPROC16 SetTaskSignalProc( HTASK16 hTask, FARPROC16 proc )
+FARPROC16 WINAPI SetTaskSignalProc( HTASK16 hTask, FARPROC16 proc )
 {
     TDB *pTask;
     FARPROC16 oldProc;
@@ -1377,8 +1391,8 @@
 /***********************************************************************
  *           SetSigHandler   (KERNEL.140)
  */
-WORD SetSigHandler( FARPROC16 newhandler, FARPROC16* oldhandler,
-                    UINT16 *oldmode, UINT16 newmode, UINT16 flag )
+WORD WINAPI SetSigHandler( FARPROC16 newhandler, FARPROC16* oldhandler,
+                           UINT16 *oldmode, UINT16 newmode, UINT16 flag )
 {
     fprintf(stdnimp,"SetSigHandler(%p,%p,%p,%d,%d), unimplemented.\n",
             newhandler,oldhandler,oldmode,newmode,flag );
@@ -1402,7 +1416,7 @@
 /***********************************************************************
  *           GlobalNotify   (KERNEL.154)
  */
-VOID GlobalNotify( FARPROC16 proc )
+VOID WINAPI GlobalNotify( FARPROC16 proc )
 {
     TDB *pTask;
 
@@ -1414,7 +1428,7 @@
 /***********************************************************************
  *           GetExePtr   (KERNEL.133)
  */
-HMODULE16 GetExePtr( HANDLE16 handle )
+HMODULE16 WINAPI GetExePtr( HANDLE16 handle )
 {
     char *ptr;
     HTASK16 hTask;
@@ -1454,7 +1468,7 @@
 /***********************************************************************
  *           TaskFirst   (TOOLHELP.63)
  */
-BOOL16 TaskFirst( TASKENTRY *lpte )
+BOOL16 WINAPI TaskFirst( TASKENTRY *lpte )
 {
     lpte->hNext = hFirstTask;
     return TaskNext( lpte );
@@ -1464,7 +1478,7 @@
 /***********************************************************************
  *           TaskNext   (TOOLHELP.64)
  */
-BOOL16 TaskNext( TASKENTRY *lpte )
+BOOL16 WINAPI TaskNext( TASKENTRY *lpte )
 {
     TDB *pTask;
     INSTANCEDATA *pInstData;
@@ -1496,7 +1510,7 @@
 /***********************************************************************
  *           TaskFindHandle   (TOOLHELP.65)
  */
-BOOL16 TaskFindHandle( TASKENTRY *lpte, HTASK16 hTask )
+BOOL16 WINAPI TaskFindHandle( TASKENTRY *lpte, HTASK16 hTask )
 {
     lpte->hNext = hTask;
     return TaskNext( lpte );
@@ -1506,7 +1520,7 @@
 /***********************************************************************
  *           GetAppCompatFlags16   (KERNEL.354)
  */
-DWORD GetAppCompatFlags16( HTASK16 hTask )
+DWORD WINAPI GetAppCompatFlags16( HTASK16 hTask )
 {
     return GetAppCompatFlags32( hTask );
 }
@@ -1515,7 +1529,7 @@
 /***********************************************************************
  *           GetAppCompatFlags32   (USER32.205)
  */
-DWORD GetAppCompatFlags32( HTASK32 hTask )
+DWORD WINAPI GetAppCompatFlags32( HTASK32 hTask )
 {
     TDB *pTask;
 
diff --git a/memory/atom.c b/memory/atom.c
index 598c267..83d7a4c 100644
--- a/memory/atom.c
+++ b/memory/atom.c
@@ -263,7 +263,7 @@
 /***********************************************************************
  *           InitAtomTable16   (KERNEL.68)
  */
-WORD InitAtomTable16( WORD entries )
+WORD WINAPI InitAtomTable16( WORD entries )
 {
     return ATOM_InitTable( CURRENT_DS, entries );
 }
@@ -272,7 +272,7 @@
 /***********************************************************************
  *           GetAtomHandle   (KERNEL.73)
  */
-HANDLE16 GetAtomHandle( ATOM atom )
+HANDLE16 WINAPI GetAtomHandle( ATOM atom )
 {
     if (atom < MIN_STR_ATOM) return 0;
     return ATOMTOHANDLE( atom );
@@ -282,7 +282,7 @@
 /***********************************************************************
  *           AddAtom16   (KERNEL.70)
  */
-ATOM AddAtom16( SEGPTR str )
+ATOM WINAPI AddAtom16( SEGPTR str )
 {
     ATOM atom;
     HANDLE16 ds = CURRENT_DS;
@@ -304,7 +304,7 @@
 /***********************************************************************
  *           AddAtom32A   (KERNEL32.0)
  */
-ATOM AddAtom32A( LPCSTR str )
+ATOM WINAPI AddAtom32A( LPCSTR str )
 {
     return GlobalAddAtom32A( str );  /* FIXME */
 }
@@ -313,7 +313,7 @@
 /***********************************************************************
  *           AddAtom32W   (KERNEL32.1)
  */
-ATOM AddAtom32W( LPCWSTR str )
+ATOM WINAPI AddAtom32W( LPCWSTR str )
 {
     return GlobalAddAtom32W( str );  /* FIXME */
 }
@@ -322,7 +322,7 @@
 /***********************************************************************
  *           DeleteAtom16   (KERNEL.71)
  */
-ATOM DeleteAtom16( ATOM atom )
+ATOM WINAPI DeleteAtom16( ATOM atom )
 {
     return ATOM_DeleteAtom( CURRENT_DS, atom );
 }
@@ -331,7 +331,7 @@
 /***********************************************************************
  *           DeleteAtom32   (KERNEL32.69)
  */
-ATOM DeleteAtom32( ATOM atom )
+ATOM WINAPI DeleteAtom32( ATOM atom )
 {
     return GlobalDeleteAtom( atom );  /* FIXME */
 }
@@ -340,7 +340,7 @@
 /***********************************************************************
  *           FindAtom16   (KERNEL.69)
  */
-ATOM FindAtom16( SEGPTR str )
+ATOM WINAPI FindAtom16( SEGPTR str )
 {
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
     return ATOM_FindAtom( CURRENT_DS, (LPCSTR)PTR_SEG_TO_LIN(str) );
@@ -350,7 +350,7 @@
 /***********************************************************************
  *           FindAtom32A   (KERNEL32.117)
  */
-ATOM FindAtom32A( LPCSTR str )
+ATOM WINAPI FindAtom32A( LPCSTR str )
 {
     return GlobalFindAtom32A( str );  /* FIXME */
 }
@@ -359,7 +359,7 @@
 /***********************************************************************
  *           FindAtom32W   (KERNEL32.118)
  */
-ATOM FindAtom32W( LPCWSTR str )
+ATOM WINAPI FindAtom32W( LPCWSTR str )
 {
     return GlobalFindAtom32W( str );  /* FIXME */
 }
@@ -368,7 +368,7 @@
 /***********************************************************************
  *           GetAtomName16   (KERNEL.72)
  */
-UINT16 GetAtomName16( ATOM atom, LPSTR buffer, INT16 count )
+UINT16 WINAPI GetAtomName16( ATOM atom, LPSTR buffer, INT16 count )
 {
     return (UINT16)ATOM_GetAtomName( CURRENT_DS, atom, buffer, count );
 }
@@ -377,7 +377,7 @@
 /***********************************************************************
  *           GetAtomName32A   (KERNEL32.149)
  */
-UINT32 GetAtomName32A( ATOM atom, LPSTR buffer, INT32 count )
+UINT32 WINAPI GetAtomName32A( ATOM atom, LPSTR buffer, INT32 count )
 {
     return GlobalGetAtomName32A( atom, buffer, count );  /* FIXME */
 }
@@ -386,7 +386,7 @@
 /***********************************************************************
  *           GetAtomName32W   (KERNEL32.150)
  */
-UINT32 GetAtomName32W( ATOM atom, LPWSTR buffer, INT32 count )
+UINT32 WINAPI GetAtomName32W( ATOM atom, LPWSTR buffer, INT32 count )
 {
     return GlobalGetAtomName32W( atom, buffer, count );  /* FIXME */
 }
@@ -395,7 +395,7 @@
 /***********************************************************************
  *           GlobalAddAtom16   (USER.268)
  */
-ATOM GlobalAddAtom16( SEGPTR str )
+ATOM WINAPI GlobalAddAtom16( SEGPTR str )
 {
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
 #ifdef CONFIG_IPC
@@ -408,7 +408,7 @@
 /***********************************************************************
  *           GlobalAddAtom32A   (KERNEL32.313)
  */
-ATOM GlobalAddAtom32A( LPCSTR str )
+ATOM WINAPI GlobalAddAtom32A( LPCSTR str )
 {
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
     return ATOM_AddAtom( USER_HeapSel, str );
@@ -418,7 +418,7 @@
 /***********************************************************************
  *           GlobalAddAtom32W   (KERNEL32.314)
  */
-ATOM GlobalAddAtom32W( LPCWSTR str )
+ATOM WINAPI GlobalAddAtom32W( LPCWSTR str )
 {
     char buffer[MAX_ATOM_LEN+1];
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
@@ -430,7 +430,7 @@
 /***********************************************************************
  *           GlobalDeleteAtom   (USER.269) (KERNEL32.317)
  */
-ATOM GlobalDeleteAtom( ATOM atom )
+ATOM WINAPI GlobalDeleteAtom( ATOM atom )
 {
 #ifdef CONFIG_IPC
     if (Options.ipc) return DDE_GlobalDeleteAtom( atom );
@@ -442,7 +442,7 @@
 /***********************************************************************
  *           GlobalFindAtom16   (USER.270)
  */
-ATOM GlobalFindAtom16( SEGPTR str )
+ATOM WINAPI GlobalFindAtom16( SEGPTR str )
 {
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
 #ifdef CONFIG_IPC
@@ -455,7 +455,7 @@
 /***********************************************************************
  *           GlobalFindAtom32A   (KERNEL32.318)
  */
-ATOM GlobalFindAtom32A( LPCSTR str )
+ATOM WINAPI GlobalFindAtom32A( LPCSTR str )
 {
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
     return ATOM_FindAtom( USER_HeapSel, str );
@@ -465,7 +465,7 @@
 /***********************************************************************
  *           GlobalFindAtom32W   (KERNEL32.319)
  */
-ATOM GlobalFindAtom32W( LPCWSTR str )
+ATOM WINAPI GlobalFindAtom32W( LPCWSTR str )
 {
     char buffer[MAX_ATOM_LEN+1];
     if (!HIWORD(str)) return (ATOM)LOWORD(str);  /* Integer atom */
@@ -477,7 +477,7 @@
 /***********************************************************************
  *           GlobalGetAtomName16   (USER.271)
  */
-UINT16 GlobalGetAtomName16( ATOM atom, LPSTR buffer, INT16 count )
+UINT16 WINAPI GlobalGetAtomName16( ATOM atom, LPSTR buffer, INT16 count )
 {
 #ifdef CONFIG_IPC
     if (Options.ipc) return DDE_GlobalGetAtomName( atom, buffer, count );
@@ -489,7 +489,7 @@
 /***********************************************************************
  *           GlobalGetAtomName32A   (KERNEL32.323)
  */
-UINT32 GlobalGetAtomName32A( ATOM atom, LPSTR buffer, INT32 count )
+UINT32 WINAPI GlobalGetAtomName32A( ATOM atom, LPSTR buffer, INT32 count )
 {
     return ATOM_GetAtomName( USER_HeapSel, atom, buffer, count );
 }
@@ -497,7 +497,7 @@
 /***********************************************************************
  *           GlobalGetAtomName32W   (KERNEL32.324)
  */
-UINT32 GlobalGetAtomName32W( ATOM atom, LPWSTR buffer, INT32 count )
+UINT32 WINAPI GlobalGetAtomName32W( ATOM atom, LPWSTR buffer, INT32 count )
 {
     char tmp[MAX_ATOM_LEN+1];
     ATOM_GetAtomName( USER_HeapSel, atom, tmp, sizeof(tmp) );
diff --git a/memory/global.c b/memory/global.c
index 749d284..45088c2 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -269,7 +269,7 @@
 /***********************************************************************
  *           GlobalAlloc16   (KERNEL.15)
  */
-HGLOBAL16 GlobalAlloc16( UINT16 flags, DWORD size )
+HGLOBAL16 WINAPI GlobalAlloc16( UINT16 flags, DWORD size )
 {
     HANDLE16 owner = GetCurrentPDB();
 
@@ -282,7 +282,7 @@
 /***********************************************************************
  *           GlobalReAlloc16   (KERNEL.16)
  */
-HGLOBAL16 GlobalReAlloc16( HGLOBAL16 handle, DWORD size, UINT16 flags )
+HGLOBAL16 WINAPI GlobalReAlloc16( HGLOBAL16 handle, DWORD size, UINT16 flags )
 {
     WORD selcount;
     DWORD oldsize;
@@ -388,7 +388,7 @@
 /***********************************************************************
  *           GlobalFree16   (KERNEL.17)
  */
-HGLOBAL16 GlobalFree16( HGLOBAL16 handle )
+HGLOBAL16 WINAPI GlobalFree16( HGLOBAL16 handle )
 {
     void *ptr = GlobalLock16( handle );
 
@@ -407,7 +407,7 @@
  *
  * This is the GlobalLock16() function used by 16-bit code.
  */
-SEGPTR WIN16_GlobalLock16( HGLOBAL16 handle )
+SEGPTR WINAPI WIN16_GlobalLock16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "WIN16_GlobalLock16(%04x) -> %08lx\n",
                     handle, MAKELONG( 0, GlobalHandleToSel(handle)) );
@@ -428,7 +428,7 @@
  *
  * This is the GlobalLock16() function used by 32-bit code.
  */
-LPVOID GlobalLock16( HGLOBAL16 handle )
+LPVOID WINAPI GlobalLock16( HGLOBAL16 handle )
 {
     if (!handle) return 0;
 #ifdef CONFIG_IPC
@@ -441,7 +441,7 @@
 /***********************************************************************
  *           GlobalUnlock16   (KERNEL.19)
  */
-BOOL16 GlobalUnlock16( HGLOBAL16 handle )
+BOOL16 WINAPI GlobalUnlock16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalUnlock16: %04x\n", handle );
     return 0;
@@ -451,7 +451,7 @@
 /***********************************************************************
  *           GlobalSize16   (KERNEL.20)
  */
-DWORD GlobalSize16( HGLOBAL16 handle )
+DWORD WINAPI GlobalSize16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalSize16: %04x\n", handle );
     if (!handle) return 0;
@@ -462,7 +462,7 @@
 /***********************************************************************
  *           GlobalHandle16   (KERNEL.21)
  */
-DWORD GlobalHandle16( WORD sel )
+DWORD WINAPI GlobalHandle16( WORD sel )
 {
     dprintf_global( stddeb, "GlobalHandle16: %04x\n", sel );
     return MAKELONG( GET_ARENA_PTR(sel)->handle, GlobalHandleToSel(sel) );
@@ -472,7 +472,7 @@
 /***********************************************************************
  *           GlobalFlags16   (KERNEL.22)
  */
-UINT16 GlobalFlags16( HGLOBAL16 handle )
+UINT16 WINAPI GlobalFlags16( HGLOBAL16 handle )
 {
     GLOBALARENA *pArena;
 
@@ -487,7 +487,7 @@
 /***********************************************************************
  *           LockSegment16   (KERNEL.23)
  */
-HGLOBAL16 LockSegment16( HGLOBAL16 handle )
+HGLOBAL16 WINAPI LockSegment16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "LockSegment: %04x\n", handle );
     if (handle == (HGLOBAL16)-1) handle = CURRENT_DS;
@@ -499,7 +499,7 @@
 /***********************************************************************
  *           UnlockSegment16   (KERNEL.24)
  */
-void UnlockSegment16( HGLOBAL16 handle )
+void WINAPI UnlockSegment16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "UnlockSegment: %04x\n", handle );
     if (handle == (HGLOBAL16)-1) handle = CURRENT_DS;
@@ -511,7 +511,7 @@
 /***********************************************************************
  *           GlobalCompact16   (KERNEL.25)
  */
-DWORD GlobalCompact16( DWORD desired )
+DWORD WINAPI GlobalCompact16( DWORD desired )
 {
     return GLOBAL_MAX_ALLOC_SIZE;
 }
@@ -520,7 +520,7 @@
 /***********************************************************************
  *           GlobalFreeAll   (KERNEL.26)
  */
-void GlobalFreeAll( HGLOBAL16 owner )
+void WINAPI GlobalFreeAll( HGLOBAL16 owner )
 {
     DWORD i;
     GLOBALARENA *pArena;
@@ -537,7 +537,7 @@
 /***********************************************************************
  *           GlobalWire16   (KERNEL.111)
  */
-SEGPTR GlobalWire16( HGLOBAL16 handle )
+SEGPTR WINAPI GlobalWire16( HGLOBAL16 handle )
 {
     return WIN16_GlobalLock16( handle );
 }
@@ -546,7 +546,7 @@
 /***********************************************************************
  *           GlobalUnWire16   (KERNEL.112)
  */
-BOOL16 GlobalUnWire16( HGLOBAL16 handle )
+BOOL16 WINAPI GlobalUnWire16( HGLOBAL16 handle )
 {
     return GlobalUnlock16( handle );
 }
@@ -555,7 +555,7 @@
 /***********************************************************************
  *           SetSwapAreaSize   (KERNEL.106)
  */
-LONG SetSwapAreaSize( WORD size )
+LONG WINAPI SetSwapAreaSize( WORD size )
 {
     dprintf_global(stdnimp, "STUB: SetSwapAreaSize(%d)\n", size );
     return MAKELONG( size, 0xffff );
@@ -565,7 +565,7 @@
 /***********************************************************************
  *           GlobalLRUOldest   (KERNEL.163)
  */
-HGLOBAL16 GlobalLRUOldest( HGLOBAL16 handle )
+HGLOBAL16 WINAPI GlobalLRUOldest( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalLRUOldest: %04x\n", handle );
     if (handle == (HGLOBAL16)-1) handle = CURRENT_DS;
@@ -576,7 +576,7 @@
 /***********************************************************************
  *           GlobalLRUNewest   (KERNEL.164)
  */
-HGLOBAL16 GlobalLRUNewest( HGLOBAL16 handle )
+HGLOBAL16 WINAPI GlobalLRUNewest( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalLRUNewest: %04x\n", handle );
     if (handle == (HGLOBAL16)-1) handle = CURRENT_DS;
@@ -587,7 +587,7 @@
 /***********************************************************************
  *           GetFreeSpace16   (KERNEL.169)
  */
-DWORD GetFreeSpace16( UINT16 wFlags )
+DWORD WINAPI GetFreeSpace16( UINT16 wFlags )
 {
     MEMORYSTATUS ms;
     GlobalMemoryStatus( &ms );
@@ -597,7 +597,7 @@
 /***********************************************************************
  *           GlobalDOSAlloc   (KERNEL.184)
  */
-DWORD GlobalDOSAlloc(DWORD size)
+DWORD WINAPI GlobalDOSAlloc(DWORD size)
 {
    UINT16    uParagraph;
    LPVOID    lpBlock = DOSMEM_GetBlock( size, &uParagraph );
@@ -617,7 +617,7 @@
 /***********************************************************************
  *           GlobalDOSFree      (KERNEL.185)
  */
-WORD GlobalDOSFree(WORD sel)
+WORD WINAPI GlobalDOSFree(WORD sel)
 {
    DWORD   block = GetSelectorBase(sel);
 
@@ -634,7 +634,7 @@
 /***********************************************************************
  *           GlobalPageLock   (KERNEL.191)
  */
-WORD GlobalPageLock( HGLOBAL16 handle )
+WORD WINAPI GlobalPageLock( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalPageLock: %04x\n", handle );
     return ++(GET_ARENA_PTR(handle)->pageLockCount);
@@ -644,7 +644,7 @@
 /***********************************************************************
  *           GlobalPageUnlock   (KERNEL.192)
  */
-WORD GlobalPageUnlock( HGLOBAL16 handle )
+WORD WINAPI GlobalPageUnlock( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalPageUnlock: %04x\n", handle );
     return --(GET_ARENA_PTR(handle)->pageLockCount);
@@ -654,7 +654,7 @@
 /***********************************************************************
  *           GlobalFix16   (KERNEL.197)
  */
-void GlobalFix16( HGLOBAL16 handle )
+void WINAPI GlobalFix16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalFix16: %04x\n", handle );
     GET_ARENA_PTR(handle)->lockCount++;
@@ -664,7 +664,7 @@
 /***********************************************************************
  *           GlobalUnfix16   (KERNEL.198)
  */
-void GlobalUnfix16( HGLOBAL16 handle )
+void WINAPI GlobalUnfix16( HGLOBAL16 handle )
 {
     dprintf_global( stddeb, "GlobalUnfix16: %04x\n", handle );
     GET_ARENA_PTR(handle)->lockCount--;
@@ -674,7 +674,7 @@
 /***********************************************************************
  *           FarSetOwner   (KERNEL.403)
  */
-void FarSetOwner( HGLOBAL16 handle, HANDLE16 hOwner )
+void WINAPI FarSetOwner( HGLOBAL16 handle, HANDLE16 hOwner )
 {
     GET_ARENA_PTR(handle)->hOwner = hOwner;
 }
@@ -683,7 +683,7 @@
 /***********************************************************************
  *           FarGetOwner   (KERNEL.404)
  */
-HANDLE16 FarGetOwner( HGLOBAL16 handle )
+HANDLE16 WINAPI FarGetOwner( HGLOBAL16 handle )
 {
     return GET_ARENA_PTR(handle)->hOwner;
 }
@@ -692,7 +692,7 @@
 /***********************************************************************
  *           GlobalHandleToSel   (TOOLHELP.50)
  */
-WORD GlobalHandleToSel( HGLOBAL16 handle )
+WORD WINAPI GlobalHandleToSel( HGLOBAL16 handle )
 {
     dprintf_toolhelp( stddeb, "GlobalHandleToSel: %04x\n", handle );
     if (!handle) return 0;
@@ -711,7 +711,7 @@
 /***********************************************************************
  *           GlobalFirst   (TOOLHELP.51)
  */
-BOOL16 GlobalFirst( GLOBALENTRY *pGlobal, WORD wFlags )
+BOOL16 WINAPI GlobalFirst( GLOBALENTRY *pGlobal, WORD wFlags )
 {
     if (wFlags == GLOBAL_LRU) return FALSE;
     pGlobal->dwNext = 0;
@@ -722,7 +722,7 @@
 /***********************************************************************
  *           GlobalNext   (TOOLHELP.52)
  */
-BOOL16 GlobalNext( GLOBALENTRY *pGlobal, WORD wFlags)
+BOOL16 WINAPI GlobalNext( GLOBALENTRY *pGlobal, WORD wFlags)
 {
     GLOBALARENA *pArena;
 
@@ -755,7 +755,7 @@
 /***********************************************************************
  *           GlobalInfo   (TOOLHELP.53)
  */
-BOOL16 GlobalInfo( GLOBALINFO *pInfo )
+BOOL16 WINAPI GlobalInfo( GLOBALINFO *pInfo )
 {
     int i;
     GLOBALARENA *pArena;
@@ -772,7 +772,7 @@
 /***********************************************************************
  *           GlobalEntryHandle   (TOOLHELP.54)
  */
-BOOL16 GlobalEntryHandle( GLOBALENTRY *pGlobal, HGLOBAL16 hItem )
+BOOL16 WINAPI GlobalEntryHandle( GLOBALENTRY *pGlobal, HGLOBAL16 hItem )
 {
     return FALSE;
 }
@@ -781,7 +781,8 @@
 /***********************************************************************
  *           GlobalEntryModule   (TOOLHELP.55)
  */
-BOOL16 GlobalEntryModule( GLOBALENTRY *pGlobal, HMODULE16 hModule, WORD wSeg )
+BOOL16 WINAPI GlobalEntryModule( GLOBALENTRY *pGlobal, HMODULE16 hModule,
+                                 WORD wSeg )
 {
     return FALSE;
 }
@@ -790,7 +791,7 @@
 /***********************************************************************
  *           MemManInfo   (TOOLHELP.72)
  */
-BOOL16 MemManInfo( MEMMANINFO *info )
+BOOL16 WINAPI MemManInfo( MEMMANINFO *info )
 {
     MEMORYSTATUS status;
 
@@ -849,7 +850,7 @@
 /***********************************************************************
  *           GlobalAlloc32   (KERNEL32.315)
  */
-HGLOBAL32 GlobalAlloc32(UINT32 flags, DWORD size)
+HGLOBAL32 WINAPI GlobalAlloc32(UINT32 flags, DWORD size)
 {
    PGLOBAL32_INTERN     pintern;
    DWORD		hpflags;
@@ -892,7 +893,7 @@
 /***********************************************************************
  *           GlobalLock32   (KERNEL32.326)
  */
-LPVOID  GlobalLock32(HGLOBAL32 hmem)
+LPVOID WINAPI GlobalLock32(HGLOBAL32 hmem)
 {
    PGLOBAL32_INTERN pintern;
    LPVOID           palloc;
@@ -922,7 +923,7 @@
 /***********************************************************************
  *           GlobalUnlock32   (KERNEL32.332)
  */
-BOOL32 GlobalUnlock32(HGLOBAL32 hmem)
+BOOL32 WINAPI GlobalUnlock32(HGLOBAL32 hmem)
 {
    PGLOBAL32_INTERN       pintern;
    BOOL32                 locked;
@@ -953,7 +954,7 @@
 /***********************************************************************
  *           GlobalHandle32   (KERNEL32.325)
  */
-HGLOBAL32 GlobalHandle32(LPCVOID pmem)
+HGLOBAL32 WINAPI GlobalHandle32(LPCVOID pmem)
 {
    return (HGLOBAL32) POINTER_TO_HANDLE(pmem);
 }
@@ -962,7 +963,7 @@
 /***********************************************************************
  *           GlobalReAlloc32   (KERNEL32.328)
  */
-HGLOBAL32 GlobalReAlloc32(HGLOBAL32 hmem, DWORD size, UINT32 flags)
+HGLOBAL32 WINAPI GlobalReAlloc32(HGLOBAL32 hmem, DWORD size, UINT32 flags)
 {
    LPVOID               palloc;
    HGLOBAL32            hnew;
@@ -1045,7 +1046,7 @@
 /***********************************************************************
  *           GlobalFree32   (KERNEL32.322)
  */
-HGLOBAL32 GlobalFree32(HGLOBAL32 hmem)
+HGLOBAL32 WINAPI GlobalFree32(HGLOBAL32 hmem)
 {
    PGLOBAL32_INTERN pintern;
    HGLOBAL32        hreturned=NULL;
@@ -1080,7 +1081,7 @@
 /***********************************************************************
  *           GlobalSize32   (KERNEL32.329)
  */
-DWORD  GlobalSize32(HGLOBAL32 hmem)
+DWORD WINAPI GlobalSize32(HGLOBAL32 hmem)
 {
    DWORD                retval;
    PGLOBAL32_INTERN     pintern;
@@ -1113,7 +1114,7 @@
 /***********************************************************************
  *           GlobalWire32   (KERNEL32.333)
  */
-LPVOID  GlobalWire32(HGLOBAL32 hmem)
+LPVOID WINAPI GlobalWire32(HGLOBAL32 hmem)
 {
    return GlobalLock32( hmem );
 }
@@ -1122,7 +1123,7 @@
 /***********************************************************************
  *           GlobalUnWire32   (KERNEL32.330)
  */
-BOOL32  GlobalUnWire32(HGLOBAL32 hmem)
+BOOL32 WINAPI GlobalUnWire32(HGLOBAL32 hmem)
 {
    return GlobalUnlock32( hmem);
 }
@@ -1131,7 +1132,7 @@
 /***********************************************************************
  *           GlobalFix32   (KERNEL32.320)
  */
-VOID  GlobalFix32(HGLOBAL32 hmem)
+VOID WINAPI GlobalFix32(HGLOBAL32 hmem)
 {
     GlobalLock32( hmem );
 }
@@ -1140,7 +1141,7 @@
 /***********************************************************************
  *           GlobalUnfix32   (KERNEL32.331)
  */
-VOID  GlobalUnfix32(HGLOBAL32 hmem)
+VOID WINAPI GlobalUnfix32(HGLOBAL32 hmem)
 {
    GlobalUnlock32( hmem);
 }
@@ -1149,7 +1150,7 @@
 /***********************************************************************
  *           GlobalFlags32   (KERNEL32.321)
  */
-UINT32  GlobalFlags32(HGLOBAL32 hmem)
+UINT32 WINAPI GlobalFlags32(HGLOBAL32 hmem)
 {
    DWORD                retval;
    PGLOBAL32_INTERN     pintern;
@@ -1182,7 +1183,7 @@
 /***********************************************************************
  *           GlobalCompact32   (KERNEL32.316)
  */
-DWORD GlobalCompact32( DWORD minfree )
+DWORD WINAPI GlobalCompact32( DWORD minfree )
 {
     return 0;  /* GlobalCompact does nothing in Win32 */
 }
@@ -1191,7 +1192,7 @@
 /***********************************************************************
  *           GlobalMemoryStatus   (KERNEL32.327)
  */
-VOID GlobalMemoryStatus( LPMEMORYSTATUS lpmem )
+VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpmem )
 {
 #ifdef linux
     FILE *f = fopen( "/proc/meminfo", "r" );
@@ -1204,16 +1205,27 @@
         lpmem->dwTotalPageFile = lpmem->dwAvailPageFile = 0;
         while (fgets( buffer, sizeof(buffer), f ))
         {
+	    /* old style /proc/meminfo ... */
             if (sscanf( buffer, "Mem: %d %d %d", &total, &used, &free ))
             {
                 lpmem->dwTotalPhys += total;
                 lpmem->dwAvailPhys += free;
             }
-            else if (sscanf( buffer, "Swap: %d %d %d", &total, &used, &free ))
+            if (sscanf( buffer, "Swap: %d %d %d", &total, &used, &free ))
             {
                 lpmem->dwTotalPageFile += total;
                 lpmem->dwAvailPageFile += free;
             }
+
+	    /* new style /proc/meminfo ... */
+	    if (sscanf(buffer, "MemTotal: %d", &total))
+	    	lpmem->dwTotalPhys = total*1024;
+	    if (sscanf(buffer, "MemFree: %d", &free))
+	    	lpmem->dwAvailPhys = free*1024;
+	    if (sscanf(buffer, "SwapTotal: %d", &total))
+	        lpmem->dwTotalPageFile = total*1024;
+	    if (sscanf(buffer, "SwapFree: %d", &free))
+	        lpmem->dwAvailPageFile = free*1024;
         }
         fclose( f );
 
@@ -1236,3 +1248,16 @@
     lpmem->dwTotalVirtual  = 32*1024*1024;
     lpmem->dwAvailVirtual  = 32*1024*1024;
 }
+
+/**********************************************************************
+ *           WOWGlobalAllocLock (KERNEL32.62)
+ *
+ * Combined GlobalAlloc and GlobalLock.
+ */
+SEGPTR WINAPI WOWGlobalAllocLock16(DWORD flags,DWORD cb,HGLOBAL16 *hmem)
+{
+    HGLOBAL16 xhmem;
+    xhmem = GlobalAlloc16(flags,cb);
+    if (hmem) *hmem = xhmem;
+    return WIN16_GlobalLock16(xhmem);
+}
diff --git a/memory/heap.c b/memory/heap.c
index 75e5adc..990ebb9 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -780,7 +780,7 @@
 /***********************************************************************
  *           HeapCreate   (KERNEL32.336)
  */
-HANDLE32 HeapCreate( DWORD flags, DWORD initialSize, DWORD maxSize )
+HANDLE32 WINAPI HeapCreate( DWORD flags, DWORD initialSize, DWORD maxSize )
 {
     int i;
     HEAP *heap;
@@ -838,7 +838,7 @@
 /***********************************************************************
  *           HeapDestroy   (KERNEL32.337)
  */
-BOOL32 HeapDestroy( HANDLE32 heap )
+BOOL32 WINAPI HeapDestroy( HANDLE32 heap )
 {
     HEAP *heapPtr = HEAP_GetPtr( heap );
     SUBHEAP *subheap;
@@ -862,7 +862,7 @@
 /***********************************************************************
  *           HeapAlloc   (KERNEL32.334)
  */
-LPVOID HeapAlloc( HANDLE32 heap, DWORD flags, DWORD size )
+LPVOID WINAPI HeapAlloc( HANDLE32 heap, DWORD flags, DWORD size )
 {
     ARENA_FREE *pArena;
     ARENA_INUSE *pInUse;
@@ -922,7 +922,7 @@
 /***********************************************************************
  *           HeapFree   (KERNEL32.338)
  */
-BOOL32 HeapFree( HANDLE32 heap, DWORD flags, LPVOID ptr )
+BOOL32 WINAPI HeapFree( HANDLE32 heap, DWORD flags, LPVOID ptr )
 {
     ARENA_INUSE *pInUse;
     SUBHEAP *subheap;
@@ -961,7 +961,7 @@
 /***********************************************************************
  *           HeapReAlloc   (KERNEL32.340)
  */
-LPVOID HeapReAlloc( HANDLE32 heap, DWORD flags, LPVOID ptr, DWORD size )
+LPVOID WINAPI HeapReAlloc( HANDLE32 heap, DWORD flags, LPVOID ptr, DWORD size )
 {
     ARENA_INUSE *pArena;
     DWORD oldSize;
@@ -1077,7 +1077,7 @@
 /***********************************************************************
  *           HeapCompact   (KERNEL32.335)
  */
-DWORD HeapCompact( HANDLE32 heap, DWORD flags )
+DWORD WINAPI HeapCompact( HANDLE32 heap, DWORD flags )
 {
     return 0;
 }
@@ -1086,7 +1086,7 @@
 /***********************************************************************
  *           HeapLock   (KERNEL32.339)
  */
-BOOL32 HeapLock( HANDLE32 heap )
+BOOL32 WINAPI HeapLock( HANDLE32 heap )
 {
     HEAP *heapPtr = HEAP_GetPtr( heap );
 
@@ -1099,7 +1099,7 @@
 /***********************************************************************
  *           HeapUnlock   (KERNEL32.342)
  */
-BOOL32 HeapUnlock( HANDLE32 heap )
+BOOL32 WINAPI HeapUnlock( HANDLE32 heap )
 {
     HEAP *heapPtr = HEAP_GetPtr( heap );
 
@@ -1112,7 +1112,7 @@
 /***********************************************************************
  *           HeapSize   (KERNEL32.341)
  */
-DWORD HeapSize( HANDLE32 heap, DWORD flags, LPVOID ptr )
+DWORD WINAPI HeapSize( HANDLE32 heap, DWORD flags, LPVOID ptr )
 {
     DWORD ret;
     HEAP *heapPtr = HEAP_GetPtr( heap );
@@ -1142,7 +1142,7 @@
 /***********************************************************************
  *           HeapValidate   (KERNEL32.343)
  */
-BOOL32 HeapValidate( HANDLE32 heap, DWORD flags, LPVOID block )
+BOOL32 WINAPI HeapValidate( HANDLE32 heap, DWORD flags, LPVOID block )
 {
     SUBHEAP *subheap;
     HEAP *heapPtr = (HEAP *)heap;
@@ -1194,7 +1194,7 @@
 /***********************************************************************
  *           HeapWalk   (KERNEL32.344)
  */
-BOOL32 HeapWalk( HANDLE32 heap, void *entry )
+BOOL32 WINAPI HeapWalk( HANDLE32 heap, void *entry )
 {
     fprintf( stderr, "HeapWalk(%08x): not implemented\n", heap );
     return FALSE;
diff --git a/memory/ldt.c b/memory/ldt.c
index de1cad0..36da4e1 100644
--- a/memory/ldt.c
+++ b/memory/ldt.c
@@ -34,12 +34,24 @@
                                   unsigned long count )
 {
     int res;
+#ifdef __PIC__
+    __asm__ __volatile__( "pushl %%ebx\n\t"
+                          "movl %2,%%ebx\n\t"
+                          "int $0x80\n\t"
+                          "popl %%ebx"
+                          : "=a" (res)
+                          : "0" (SYS_modify_ldt),
+                            "g" (func),
+                            "c" (ptr),
+                            "d" (count) );
+#else
     __asm__ __volatile__("int $0x80"
                          : "=a" (res)
                          : "0" (SYS_modify_ldt),
                            "b" (func),
                            "c" (ptr),
                            "d" (count) );
+#endif  /* __PIC__ */
     if (res >= 0) return res;
     errno = -res;
     return -1;
diff --git a/memory/local.c b/memory/local.c
index e54c03a..894beba 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -302,7 +302,7 @@
 /***********************************************************************
  *           LocalInit   (KERNEL.4)
  */
-BOOL16 LocalInit( HANDLE16 selector, WORD start, WORD end )
+BOOL16 WINAPI LocalInit( HANDLE16 selector, WORD start, WORD end )
 {
     char *ptr;
     WORD heapInfoArena, freeArena, lastArena;
@@ -1460,7 +1460,7 @@
 /***********************************************************************
  *           LocalAlloc16   (KERNEL.5)
  */
-HLOCAL16 LocalAlloc16( UINT16 flags, WORD size )
+HLOCAL16 WINAPI LocalAlloc16( UINT16 flags, WORD size )
 {
     return LOCAL_Alloc( CURRENT_DS, flags, size );
 }
@@ -1469,7 +1469,7 @@
 /***********************************************************************
  *           LocalReAlloc16   (KERNEL.6)
  */
-HLOCAL16 LocalReAlloc16( HLOCAL16 handle, WORD size, UINT16 flags )
+HLOCAL16 WINAPI LocalReAlloc16( HLOCAL16 handle, WORD size, UINT16 flags )
 {
     return LOCAL_ReAlloc( CURRENT_DS, handle, size, flags );
 }
@@ -1478,7 +1478,7 @@
 /***********************************************************************
  *           LocalFree16   (KERNEL.7)
  */
-HLOCAL16 LocalFree16( HLOCAL16 handle )
+HLOCAL16 WINAPI LocalFree16( HLOCAL16 handle )
 {
     return LOCAL_Free( CURRENT_DS, handle );
 }
@@ -1489,7 +1489,7 @@
  *
  * Note: only the offset part of the pointer is returned by the relay code.
  */
-SEGPTR LocalLock16( HLOCAL16 handle )
+SEGPTR WINAPI LocalLock16( HLOCAL16 handle )
 {
     return LOCAL_LockSegptr( CURRENT_DS, handle );
 }
@@ -1498,7 +1498,7 @@
 /***********************************************************************
  *           LocalUnlock16   (KERNEL.9)
  */
-BOOL16 LocalUnlock16( HLOCAL16 handle )
+BOOL16 WINAPI LocalUnlock16( HLOCAL16 handle )
 {
     return LOCAL_Unlock( CURRENT_DS, handle );
 }
@@ -1507,7 +1507,7 @@
 /***********************************************************************
  *           LocalSize16   (KERNEL.10)
  */
-UINT16 LocalSize16( HLOCAL16 handle )
+UINT16 WINAPI LocalSize16( HLOCAL16 handle )
 {
     return LOCAL_Size( CURRENT_DS, handle );
 }
@@ -1516,7 +1516,7 @@
 /***********************************************************************
  *           LocalHandle16   (KERNEL.11)
  */
-HLOCAL16 LocalHandle16( WORD addr )
+HLOCAL16 WINAPI LocalHandle16( WORD addr )
 { 
     return LOCAL_Handle( CURRENT_DS, addr );
 }
@@ -1525,7 +1525,7 @@
 /***********************************************************************
  *           LocalFlags16   (KERNEL.12)
  */
-UINT16 LocalFlags16( HLOCAL16 handle )
+UINT16 WINAPI LocalFlags16( HLOCAL16 handle )
 {
     return LOCAL_Flags( CURRENT_DS, handle );
 }
@@ -1534,7 +1534,7 @@
 /***********************************************************************
  *           LocalCompact16   (KERNEL.13)
  */
-UINT16 LocalCompact16( UINT16 minfree )
+UINT16 WINAPI LocalCompact16( UINT16 minfree )
 {
     dprintf_local( stddeb, "LocalCompact: %04x\n", minfree );
     return LOCAL_Compact( CURRENT_DS, minfree, 0 );
@@ -1544,7 +1544,7 @@
 /***********************************************************************
  *           LocalNotify   (KERNEL.14)
  */
-FARPROC16 LocalNotify( FARPROC16 func )
+FARPROC16 WINAPI LocalNotify( FARPROC16 func )
 {
     LOCALHEAPINFO *pInfo;
     FARPROC16 oldNotify;
@@ -1567,7 +1567,7 @@
 /***********************************************************************
  *           LocalShrink16   (KERNEL.121)
  */
-UINT16 LocalShrink16( HGLOBAL16 handle, UINT16 newsize )
+UINT16 WINAPI LocalShrink16( HGLOBAL16 handle, UINT16 newsize )
 {
     dprintf_local( stddeb, "LocalShrink: %04x %04x\n", handle, newsize );
     return 0;
@@ -1577,7 +1577,7 @@
 /***********************************************************************
  *           GetHeapSpaces   (KERNEL.138)
  */
-DWORD GetHeapSpaces( HMODULE16 module )
+DWORD WINAPI GetHeapSpaces( HMODULE16 module )
 {
     NE_MODULE *pModule;
     WORD ds;
@@ -1592,7 +1592,7 @@
 /***********************************************************************
  *           LocalCountFree   (KERNEL.161)
  */
-WORD LocalCountFree(void)
+WORD WINAPI LocalCountFree(void)
 {
     return LOCAL_CountFree( CURRENT_DS );
 }
@@ -1601,7 +1601,7 @@
 /***********************************************************************
  *           LocalHeapSize   (KERNEL.162)
  */
-WORD LocalHeapSize()
+WORD WINAPI LocalHeapSize(void)
 {
     dprintf_local( stddeb, "LocalHeapSize:\n" );
     return LOCAL_HeapSize( CURRENT_DS );
@@ -1611,7 +1611,7 @@
 /***********************************************************************
  *           LocalHandleDelta   (KERNEL.310)
  */
-WORD LocalHandleDelta( WORD delta )
+WORD WINAPI LocalHandleDelta( WORD delta )
 {
     LOCALHEAPINFO *pInfo;
 
@@ -1630,7 +1630,7 @@
 /***********************************************************************
  *           LocalInfo   (TOOLHELP.56)
  */
-BOOL16 LocalInfo( LOCALINFO *pLocalInfo, HGLOBAL16 handle )
+BOOL16 WINAPI LocalInfo( LOCALINFO *pLocalInfo, HGLOBAL16 handle )
 {
     LOCALHEAPINFO *pInfo = LOCAL_GetHeap(SELECTOROF(WIN16_GlobalLock16(handle)));
     if (!pInfo) return FALSE;
@@ -1642,7 +1642,7 @@
 /***********************************************************************
  *           LocalFirst   (TOOLHELP.57)
  */
-BOOL16 LocalFirst( LOCALENTRY *pLocalEntry, HGLOBAL16 handle )
+BOOL16 WINAPI LocalFirst( LOCALENTRY *pLocalEntry, HGLOBAL16 handle )
 {
     WORD ds = GlobalHandleToSel( handle );
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
@@ -1665,7 +1665,7 @@
 /***********************************************************************
  *           LocalNext   (TOOLHELP.58)
  */
-BOOL16 LocalNext( LOCALENTRY *pLocalEntry )
+BOOL16 WINAPI LocalNext( LOCALENTRY *pLocalEntry )
 {
     WORD ds = GlobalHandleToSel( pLocalEntry->hHeap );
     char *ptr = PTR_SEG_OFF_TO_LIN( ds, 0 );
@@ -1692,7 +1692,7 @@
 /***********************************************************************
  *           LocalAlloc32   (KERNEL32.371)
  */
-HLOCAL32 LocalAlloc32( UINT32 flags, DWORD size )
+HLOCAL32 WINAPI LocalAlloc32( UINT32 flags, DWORD size )
 {
     return (HLOCAL32)GlobalAlloc32( flags, size );
 }
@@ -1701,7 +1701,7 @@
 /***********************************************************************
  *           LocalCompact32   (KERNEL32.372)
  */
-UINT32 LocalCompact32( UINT32 minfree )
+UINT32 WINAPI LocalCompact32( UINT32 minfree )
 {
     return 0;  /* LocalCompact does nothing in Win32 */
 }
@@ -1710,7 +1710,7 @@
 /***********************************************************************
  *           LocalFlags32   (KERNEL32.374)
  */
-UINT32 LocalFlags32( HLOCAL32 handle )
+UINT32 WINAPI LocalFlags32( HLOCAL32 handle )
 {
     return GlobalFlags32( (HGLOBAL32)handle );
 }
@@ -1719,7 +1719,7 @@
 /***********************************************************************
  *           LocalFree32   (KERNEL32.375)
  */
-HLOCAL32 LocalFree32( HLOCAL32 handle )
+HLOCAL32 WINAPI LocalFree32( HLOCAL32 handle )
 {
     return (HLOCAL32)GlobalFree32( (HGLOBAL32)handle );
 }
@@ -1728,7 +1728,7 @@
 /***********************************************************************
  *           LocalHandle32   (KERNEL32.376)
  */
-HLOCAL32 LocalHandle32( LPCVOID ptr )
+HLOCAL32 WINAPI LocalHandle32( LPCVOID ptr )
 {
     return (HLOCAL32)GlobalHandle32( ptr );
 }
@@ -1737,7 +1737,7 @@
 /***********************************************************************
  *           LocalLock32   (KERNEL32.377)
  */
-LPVOID LocalLock32( HLOCAL32 handle )
+LPVOID WINAPI LocalLock32( HLOCAL32 handle )
 {
     return GlobalLock32( (HGLOBAL32)handle );
 }
@@ -1746,7 +1746,7 @@
 /***********************************************************************
  *           LocalReAlloc32   (KERNEL32.378)
  */
-HLOCAL32 LocalReAlloc32( HLOCAL32 handle, DWORD size, UINT32 flags )
+HLOCAL32 WINAPI LocalReAlloc32( HLOCAL32 handle, DWORD size, UINT32 flags )
 {
     return (HLOCAL32)GlobalReAlloc32( (HGLOBAL32)handle, size, flags );
 }
@@ -1755,7 +1755,7 @@
 /***********************************************************************
  *           LocalShrink32   (KERNEL32.379)
  */
-UINT32 LocalShrink32( HGLOBAL32 handle, UINT32 newsize )
+UINT32 WINAPI LocalShrink32( HGLOBAL32 handle, UINT32 newsize )
 {
     return 0;  /* LocalShrink does nothing in Win32 */
 }
@@ -1764,7 +1764,7 @@
 /***********************************************************************
  *           LocalSize32   (KERNEL32.380)
  */
-UINT32 LocalSize32( HLOCAL32 handle )
+UINT32 WINAPI LocalSize32( HLOCAL32 handle )
 {
     return GlobalSize32( (HGLOBAL32)handle );
 }
@@ -1773,7 +1773,7 @@
 /***********************************************************************
  *           LocalUnlock32   (KERNEL32.381)
  */
-BOOL32 LocalUnlock32( HLOCAL32 handle )
+BOOL32 WINAPI LocalUnlock32( HLOCAL32 handle )
 {
     return GlobalUnlock32( (HGLOBAL32)handle );
 }
diff --git a/memory/selector.c b/memory/selector.c
index 06ed3ef..421cd99 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -20,7 +20,7 @@
 /***********************************************************************
  *           AllocSelectorArray   (KERNEL.206)
  */
-WORD AllocSelectorArray( WORD count )
+WORD WINAPI AllocSelectorArray( WORD count )
 {
     WORD i, size = 0;
 
@@ -40,7 +40,7 @@
 /***********************************************************************
  *           AllocSelector   (KERNEL.175)
  */
-WORD AllocSelector( WORD sel )
+WORD WINAPI AllocSelector( WORD sel )
 {
     WORD newsel, count, i;
 
@@ -63,7 +63,7 @@
 /***********************************************************************
  *           FreeSelector   (KERNEL.176)
  */
-WORD FreeSelector( WORD sel )
+WORD WINAPI FreeSelector( WORD sel )
 {
     if (IS_SELECTOR_FREE(sel)) return sel;  /* error */
     SELECTOR_FreeBlock( sel, 1 );
@@ -202,7 +202,7 @@
 /***********************************************************************
  *           PrestoChangoSelector   (KERNEL.177)
  */
-WORD PrestoChangoSelector( WORD selSrc, WORD selDst )
+WORD WINAPI PrestoChangoSelector( WORD selSrc, WORD selDst )
 {
     ldt_entry entry;
     LDT_GetEntry( SELECTOR_TO_ENTRY( selSrc ), &entry );
@@ -215,7 +215,7 @@
 /***********************************************************************
  *           AllocCStoDSAlias   (KERNEL.170)
  */
-WORD AllocCStoDSAlias( WORD sel )
+WORD WINAPI AllocCStoDSAlias( WORD sel )
 {
     WORD newsel;
     ldt_entry entry;
@@ -234,7 +234,7 @@
 /***********************************************************************
  *           AllocDStoCSAlias   (KERNEL.171)
  */
-WORD AllocDStoCSAlias( WORD sel )
+WORD WINAPI AllocDStoCSAlias( WORD sel )
 {
     WORD newsel;
     ldt_entry entry;
@@ -253,7 +253,7 @@
 /***********************************************************************
  *           LongPtrAdd   (KERNEL.180)
  */
-void LongPtrAdd( DWORD ptr, DWORD add )
+void WINAPI LongPtrAdd( DWORD ptr, DWORD add )
 {
     ldt_entry entry;
     LDT_GetEntry( SELECTOR_TO_ENTRY(SELECTOROF(ptr)), &entry );
@@ -265,7 +265,7 @@
 /***********************************************************************
  *           GetSelectorBase   (KERNEL.186)
  */
-DWORD GetSelectorBase( WORD sel )
+DWORD WINAPI GetSelectorBase( WORD sel )
 {
     DWORD base = GET_SEL_BASE(sel);
 
@@ -279,7 +279,7 @@
 /***********************************************************************
  *           SetSelectorBase   (KERNEL.187)
  */
-WORD SetSelectorBase( WORD sel, DWORD base )
+WORD WINAPI SetSelectorBase( WORD sel, DWORD base )
 {
     ldt_entry entry;
 
@@ -295,7 +295,7 @@
 /***********************************************************************
  *           GetSelectorLimit   (KERNEL.188)
  */
-DWORD GetSelectorLimit( WORD sel )
+DWORD WINAPI GetSelectorLimit( WORD sel )
 {
     return GET_SEL_LIMIT(sel);
 }
@@ -304,7 +304,7 @@
 /***********************************************************************
  *           SetSelectorLimit   (KERNEL.189)
  */
-WORD SetSelectorLimit( WORD sel, DWORD limit )
+WORD WINAPI SetSelectorLimit( WORD sel, DWORD limit )
 {
     ldt_entry entry;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
@@ -319,7 +319,7 @@
 /***********************************************************************
  *           SelectorAccessRights   (KERNEL.196)
  */
-WORD SelectorAccessRights( WORD sel, WORD op, WORD val )
+WORD WINAPI SelectorAccessRights( WORD sel, WORD op, WORD val )
 {
     ldt_entry entry;
     LDT_GetEntry( SELECTOR_TO_ENTRY(sel), &entry );
@@ -349,7 +349,7 @@
 /***********************************************************************
  *           IsBadCodePtr16   (KERNEL.336)
  */
-BOOL16 IsBadCodePtr16( SEGPTR lpfn )
+BOOL16 WINAPI IsBadCodePtr16( SEGPTR lpfn )
 {
     WORD sel;
     ldt_entry entry;
@@ -367,7 +367,7 @@
 /***********************************************************************
  *           IsBadStringPtr16   (KERNEL.337)
  */
-BOOL16 IsBadStringPtr16( SEGPTR ptr, UINT16 size )
+BOOL16 WINAPI IsBadStringPtr16( SEGPTR ptr, UINT16 size )
 {
     WORD sel;
     ldt_entry entry;
@@ -386,7 +386,7 @@
 /***********************************************************************
  *           IsBadHugeReadPtr16   (KERNEL.346)
  */
-BOOL16 IsBadHugeReadPtr16( SEGPTR ptr, DWORD size )
+BOOL16 WINAPI IsBadHugeReadPtr16( SEGPTR ptr, DWORD size )
 {
     WORD sel;
     ldt_entry entry;
@@ -404,7 +404,7 @@
 /***********************************************************************
  *           IsBadHugeWritePtr16   (KERNEL.347)
  */
-BOOL16 IsBadHugeWritePtr16( SEGPTR ptr, DWORD size )
+BOOL16 WINAPI IsBadHugeWritePtr16( SEGPTR ptr, DWORD size )
 {
     WORD sel;
     ldt_entry entry;
@@ -421,7 +421,7 @@
 /***********************************************************************
  *           IsBadReadPtr16   (KERNEL.334)
  */
-BOOL16 IsBadReadPtr16( SEGPTR ptr, UINT16 size )
+BOOL16 WINAPI IsBadReadPtr16( SEGPTR ptr, UINT16 size )
 {
     return IsBadHugeReadPtr16( ptr, size );
 }
@@ -430,7 +430,7 @@
 /***********************************************************************
  *           IsBadWritePtr16   (KERNEL.335)
  */
-BOOL16 IsBadWritePtr16( SEGPTR ptr, UINT16 size )
+BOOL16 WINAPI IsBadWritePtr16( SEGPTR ptr, UINT16 size )
 {
     return IsBadHugeWritePtr16( ptr, size );
 }
@@ -439,7 +439,7 @@
 /***********************************************************************
  *           MemoryRead   (TOOLHELP.78)
  */
-DWORD MemoryRead( WORD sel, DWORD offset, void *buffer, DWORD count )
+DWORD WINAPI MemoryRead( WORD sel, DWORD offset, void *buffer, DWORD count )
 {
     if (IS_SELECTOR_FREE(sel)) return 0;
     if (offset > GET_SEL_LIMIT(sel)) return 0;
@@ -453,7 +453,7 @@
 /***********************************************************************
  *           MemoryWrite   (TOOLHELP.79)
  */
-DWORD MemoryWrite( WORD sel, DWORD offset, void *buffer, DWORD count )
+DWORD WINAPI MemoryWrite( WORD sel, DWORD offset, void *buffer, DWORD count )
 {
     if (IS_SELECTOR_FREE(sel)) return 0;
     if (offset > GET_SEL_LIMIT(sel)) return 0;
@@ -475,7 +475,7 @@
  *
  * Maps fixed segmented pointer to linear.
  */
-LPVOID MapSL( SEGPTR sptr )
+LPVOID WINAPI MapSL( SEGPTR sptr )
 {
     return (LPVOID)PTR_SEG_TO_LIN(sptr);
 }
@@ -486,7 +486,7 @@
  *
  * Maps linear pointer to segmented.
  */
-SEGPTR MapLS( LPVOID ptr )
+SEGPTR WINAPI MapLS( LPVOID ptr )
 {
     WORD sel = SELECTOR_AllocBlock( ptr, 0x10000, SEGMENT_DATA, FALSE, FALSE );
     return PTR_SEG_OFF_TO_SEGPTR( sel, 0 );
@@ -498,7 +498,120 @@
  *
  * Free mapped selector.
  */
-void UnMapLS( SEGPTR sptr )
+void WINAPI UnMapLS( SEGPTR sptr )
 {
     if (!__winelib) SELECTOR_FreeBlock( SELECTOROF(sptr), 1 );
 }
+
+/***********************************************************************
+ *           GetThreadSelectorEntry   (KERNEL32)
+ * FIXME: add #ifdef i386 for non x86
+ */
+BOOL32 WINAPI GetThreadSelectorEntry( HANDLE32 hthread, DWORD sel,
+                                      LPLDT_ENTRY ldtent)
+{
+    ldt_entry	ldtentry;
+
+    LDT_GetEntry(SELECTOR_TO_ENTRY(sel),&ldtentry);
+    ldtent->BaseLow = ldtentry.base & 0x0000ffff;
+    ldtent->HighWord.Bits.BaseMid = (ldtentry.base & 0x00ff0000) >> 16;
+    ldtent->HighWord.Bits.BaseHi = (ldtentry.base & 0xff000000) >> 24;
+    ldtent->LimitLow = ldtentry.limit & 0x0000ffff;
+    ldtent->HighWord.Bits.LimitHi = (ldtentry.limit & 0x00ff0000) >> 16;
+    ldtent->HighWord.Bits.Dpl = 3;
+    ldtent->HighWord.Bits.Sys = 0;
+    ldtent->HighWord.Bits.Pres = 1;
+    ldtent->HighWord.Bits.Type = 0x10|(ldtentry.type << 2);
+    if (ldtentry.read_only)
+    	ldtent->HighWord.Bits.Type|=0x2;
+    ldtent->HighWord.Bits.Granularity = ldtentry.limit_in_pages;
+    ldtent->HighWord.Bits.Default_Big = ldtentry.seg_32bit;
+    return TRUE;
+}
+
+
+/**********************************************************************
+ * 		SMapLS*		(KERNEL32)
+ * These functions map linear pointers at [EBP+xxx] to segmented pointers
+ * and return them.
+ * Win95 uses some kind of alias structs, which it stores in [EBP+x] to
+ * unravel them at SUnMapLS. We just store the segmented pointer there.
+ */
+static void
+x_SMapLS_IP_EBP_x(CONTEXT *context,int argoff) {
+    DWORD	val,ptr; 
+
+    val =*(DWORD*)(EBP_reg(context)+argoff);
+    if (val<0x10000) {
+	ptr=val;
+	*(DWORD*)(EBP_reg(context)+argoff) = 0;
+    } else {
+    	ptr = MapLS((LPVOID)val);
+	*(DWORD*)(EBP_reg(context)+argoff) = ptr;
+    }
+    fprintf(stderr,"[EBP+%d] %08lx => %08lx\n",argoff,val,ptr);
+    EAX_reg(context) = ptr;
+}
+
+void WINAPI SMapLS_IP_EBP_8(CONTEXT *context)  {x_SMapLS_IP_EBP_x(context,8);}
+void WINAPI SMapLS_IP_EBP_12(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,12);}
+void WINAPI SMapLS_IP_EBP_16(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,16);}
+void WINAPI SMapLS_IP_EBP_20(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,20);}
+void WINAPI SMapLS_IP_EBP_24(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,24);}
+void WINAPI SMapLS_IP_EBP_28(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,28);}
+void WINAPI SMapLS_IP_EBP_32(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,32);}
+void WINAPI SMapLS_IP_EBP_36(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,36);}
+void WINAPI SMapLS_IP_EBP_40(CONTEXT *context) {x_SMapLS_IP_EBP_x(context,40);}
+
+void WINAPI SMapLS(CONTEXT *context,int argoff)
+{
+    if (EAX_reg(context)>=0x10000) {
+	EAX_reg(context) = MapLS((LPVOID)EAX_reg(context));
+	EDX_reg(context) = EAX_reg(context);
+    } else {
+	EDX_reg(context) = 0;
+    }
+}
+
+/**********************************************************************
+ *           WOWGetVDMPointer	(KERNEL32.55)
+ * Get linear from segmented pointer. (MSDN lib)
+ */
+LPVOID WINAPI WOWGetVDMPointer(DWORD vp,DWORD nrofbytes,BOOL32 protected)
+{
+    /* FIXME: add size check too */
+    fprintf(stdnimp,"WOWGetVDMPointer(%08lx,%ld,%d)\n",vp,nrofbytes,protected);
+    if (protected)
+	return PTR_SEG_TO_LIN(vp);
+    else
+	return DOSMEM_MapRealToLinear(vp);
+}
+
+/**********************************************************************
+ *           GetVDMPointer32W   (KERNEL.516)
+ */
+LPVOID WINAPI GetVDMPointer32W(DWORD vp,DWORD mode)
+{
+    return WOWGetVDMPointer(vp,0,mode);
+}
+
+/**********************************************************************
+ *           WOWGetVDMPointerFix (KERNEL32.55)
+ * Dito, but fix heapsegment (MSDN lib)
+ */
+LPVOID WINAPI WOWGetVDMPointerFix(DWORD vp,DWORD nrofbytes,BOOL32 protected)
+{
+    /* FIXME: fix heapsegment */
+    fprintf(stdnimp,"WOWGetVDMPointerFix(%08lx,%ld,%d)\n",vp,nrofbytes,protected);
+    return WOWGetVDMPointer(vp,nrofbytes,protected);
+}
+
+/**********************************************************************
+ *           WOWGetVDMPointerUnFix (KERNEL32.56)
+ */
+void WINAPI WOWGetVDMPointerUnfix(DWORD vp)
+{
+    fprintf(stdnimp,"WOWGetVDMPointerUnfix(%08lx), STUB\n",vp);
+    /* FIXME: unfix heapsegment */
+}
+
diff --git a/memory/string.c b/memory/string.c
index 05beae1..72efb86 100644
--- a/memory/string.c
+++ b/memory/string.c
@@ -55,7 +55,7 @@
 /***********************************************************************
  *           hmemcpy   (KERNEL.348)
  */
-void hmemcpy( LPVOID dst, LPCVOID src, LONG count )
+void WINAPI hmemcpy( LPVOID dst, LPCVOID src, LONG count )
 {
     memcpy( dst, src, count );
 }
@@ -64,7 +64,7 @@
 /***********************************************************************
  *           lstrcat16   (KERNEL.89)
  */
-SEGPTR lstrcat16( SEGPTR dst, LPCSTR src )
+SEGPTR WINAPI lstrcat16( SEGPTR dst, LPCSTR src )
 {
     lstrcat32A( (LPSTR)PTR_SEG_TO_LIN(dst), src );
     return dst;
@@ -74,7 +74,7 @@
 /***********************************************************************
  *           lstrcat32A   (KERNEL32.599)
  */
-LPSTR lstrcat32A( LPSTR dst, LPCSTR src )
+LPSTR WINAPI lstrcat32A( LPSTR dst, LPCSTR src )
 {
     dprintf_string(stddeb,"strcat: Append '%s' to '%s'\n",
 		 (src)?src:"NULL",(dst)?dst:"NULL");
@@ -86,7 +86,7 @@
 /***********************************************************************
  *           lstrcat32W   (KERNEL32.600)
  */
-LPWSTR lstrcat32W( LPWSTR dst, LPCWSTR src )
+LPWSTR WINAPI lstrcat32W( LPWSTR dst, LPCWSTR src )
 {
     register LPWSTR p = dst;
     while (*p) p++;
@@ -98,7 +98,7 @@
 /***********************************************************************
  *           lstrcatn16   (KERNEL.352)
  */
-SEGPTR lstrcatn16( SEGPTR dst, LPCSTR src, INT16 n )
+SEGPTR WINAPI lstrcatn16( SEGPTR dst, LPCSTR src, INT16 n )
 {
     lstrcatn32A( (LPSTR)PTR_SEG_TO_LIN(dst), src, n );
     return dst;
@@ -108,7 +108,7 @@
 /***********************************************************************
  *           lstrcatn32A   (Not a Windows API)
  */
-LPSTR lstrcatn32A( LPSTR dst, LPCSTR src, INT32 n )
+LPSTR WINAPI lstrcatn32A( LPSTR dst, LPCSTR src, INT32 n )
 {
     register LPSTR p = dst;
     dprintf_string(stddeb,"strcatn add %d chars from '%s' to '%s'\n",
@@ -123,7 +123,7 @@
 /***********************************************************************
  *           lstrcatn32W   (Not a Windows API)
  */
-LPWSTR lstrcatn32W( LPWSTR dst, LPCWSTR src, INT32 n )
+LPWSTR WINAPI lstrcatn32W( LPWSTR dst, LPCWSTR src, INT32 n )
 {
     register LPWSTR p = dst;
     while (*p) p++;
@@ -136,7 +136,7 @@
 /***********************************************************************
  *           lstrcmp16   (USER.430)
  */
-INT16 lstrcmp16( LPCSTR str1, LPCSTR str2 )
+INT16 WINAPI lstrcmp16( LPCSTR str1, LPCSTR str2 )
 {
     return (INT16)lstrcmp32A( str1, str2 );
 }
@@ -145,7 +145,7 @@
 /***********************************************************************
  *           lstrcmp32A   (KERNEL.602)
  */
-INT32 lstrcmp32A( LPCSTR str1, LPCSTR str2 )
+INT32 WINAPI lstrcmp32A( LPCSTR str1, LPCSTR str2 )
 {
     dprintf_string(stddeb,"strcmp: '%s' and '%s'\n",
 		 (str1)?str1:"NULL",(str2)?str2:"NULL");
@@ -156,7 +156,7 @@
 /***********************************************************************
  *           lstrcmp32W   (KERNEL.603)
  */
-INT32 lstrcmp32W( LPCWSTR str1, LPCWSTR str2 )
+INT32 WINAPI lstrcmp32W( LPCWSTR str1, LPCWSTR str2 )
 {
     while (*str1 && (*str1 == *str2)) { str1++; str2++; }
     return (INT32)(*str1 - *str2);
@@ -166,7 +166,7 @@
 /***********************************************************************
  *           lstrcmpi16   (USER.471)
  */
-INT16 lstrcmpi16( LPCSTR str1, LPCSTR str2 )
+INT16 WINAPI lstrcmpi16( LPCSTR str1, LPCSTR str2 )
 {
     return (INT16)lstrcmpi32A( str1, str2 );
 }
@@ -175,7 +175,7 @@
 /***********************************************************************
  *           lstrcmpi32A   (KERNEL32.605)
  */
-INT32 lstrcmpi32A( LPCSTR str1, LPCSTR str2 )
+INT32 WINAPI lstrcmpi32A( LPCSTR str1, LPCSTR str2 )
 {
     INT32 res;
 
@@ -194,7 +194,7 @@
 /***********************************************************************
  *           lstrcmpi32W   (KERNEL32.606)
  */
-INT32 lstrcmpi32W( LPCWSTR str1, LPCWSTR str2 )
+INT32 WINAPI lstrcmpi32W( LPCWSTR str1, LPCWSTR str2 )
 {
     INT32 res;
 
@@ -212,7 +212,7 @@
 /***********************************************************************
  *           lstrcpy16   (KERNEL.88)
  */
-SEGPTR lstrcpy16( SEGPTR dst, LPCSTR src )
+SEGPTR WINAPI lstrcpy16( SEGPTR dst, LPCSTR src )
 {
     lstrcpy32A( (LPSTR)PTR_SEG_TO_LIN(dst), src );
     return dst;
@@ -222,7 +222,7 @@
 /***********************************************************************
  *           lstrcpy32A   (KERNEL32.608)
  */
-LPSTR lstrcpy32A( LPSTR dst, LPCSTR src )
+LPSTR WINAPI lstrcpy32A( LPSTR dst, LPCSTR src )
 {
     dprintf_string(stddeb,"strcpy '%s'\n",
 		 (src)?src:"NULL");
@@ -235,7 +235,7 @@
 /***********************************************************************
  *           lstrcpy32W   (KERNEL32.609)
  */
-LPWSTR lstrcpy32W( LPWSTR dst, LPCWSTR src )
+LPWSTR WINAPI lstrcpy32W( LPWSTR dst, LPCWSTR src )
 {
     register LPWSTR p = dst;
     while ((*p++ = *src++));
@@ -246,7 +246,7 @@
 /***********************************************************************
  *           lstrcpyn16   (KERNEL.353)
  */
-SEGPTR lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n )
+SEGPTR WINAPI lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n )
 {
     lstrcpyn32A( (LPSTR)PTR_SEG_TO_LIN(dst), src, n );
     return dst;
@@ -256,7 +256,7 @@
 /***********************************************************************
  *           lstrcpyn32A   (KERNEL32.611)
  */
-LPSTR lstrcpyn32A( LPSTR dst, LPCSTR src, INT32 n )
+LPSTR WINAPI lstrcpyn32A( LPSTR dst, LPCSTR src, INT32 n )
 {
     LPSTR p = dst;
     dprintf_string(stddeb,"strcpyn '%s' for %d chars\n",
@@ -270,7 +270,7 @@
 /***********************************************************************
  *           lstrcpyn32W   (KERNEL32.612)
  */
-LPWSTR lstrcpyn32W( LPWSTR dst, LPCWSTR src, INT32 n )
+LPWSTR WINAPI lstrcpyn32W( LPWSTR dst, LPCWSTR src, INT32 n )
 {
     LPWSTR p = dst;
     while ((n-- > 1) && *src) *p++ = *src++;
@@ -282,7 +282,7 @@
 /***********************************************************************
  *           lstrlen16   (KERNEL.90)
  */
-INT16 lstrlen16( LPCSTR str )
+INT16 WINAPI lstrlen16( LPCSTR str )
 {
     return (INT16)lstrlen32A( str );
 }
@@ -291,7 +291,7 @@
 /***********************************************************************
  *           lstrlen32A   (KERNEL32.614)
  */
-INT32 lstrlen32A( LPCSTR str )
+INT32 WINAPI lstrlen32A( LPCSTR str )
 {
     /* looks weird, but win3.1 KERNEL got a GeneralProtection handler
      * in lstrlen() ... we check only for NULL pointer reference.
@@ -306,7 +306,7 @@
 /***********************************************************************
  *           lstrlen32W   (KERNEL32.615)
  */
-INT32 lstrlen32W( LPCWSTR str )
+INT32 WINAPI lstrlen32W( LPCWSTR str )
 {
     INT32 len = 0;
     if (!str) return 0;
@@ -318,7 +318,7 @@
 /***********************************************************************
  *           lstrncmp32A   (Not a Windows API)
  */
-INT32 lstrncmp32A( LPCSTR str1, LPCSTR str2, INT32 n )
+INT32 WINAPI lstrncmp32A( LPCSTR str1, LPCSTR str2, INT32 n )
 {
     dprintf_string(stddeb,"strncmp '%s' and '%s' for %d chars\n",
 		 (str1)?str1:"NULL",(str2)?str2:"NULL",n);
@@ -329,7 +329,7 @@
 /***********************************************************************
  *           lstrncmp32W   (Not a Windows API)
  */
-INT32 lstrncmp32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
+INT32 WINAPI lstrncmp32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
 {
     if (!n) return 0;
     while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
@@ -340,7 +340,7 @@
 /***********************************************************************
  *           lstrncmpi32A   (Not a Windows API)
  */
-INT32 lstrncmpi32A( LPCSTR str1, LPCSTR str2, INT32 n )
+INT32 WINAPI lstrncmpi32A( LPCSTR str1, LPCSTR str2, INT32 n )
 {
     INT32 res;
 
@@ -357,7 +357,7 @@
 /***********************************************************************
  *           lstrncmpi32W   (Not a Windows API)
  */
-INT32 lstrncmpi32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
+INT32 WINAPI lstrncmpi32W( LPCWSTR str1, LPCWSTR str2, INT32 n )
 {
     INT32 res;
 
@@ -376,7 +376,7 @@
 /***********************************************************************
  *           lstrcpyAtoW   (Not a Windows API)
  */
-LPWSTR lstrcpyAtoW( LPWSTR dst, LPCSTR src )
+LPWSTR WINAPI lstrcpyAtoW( LPWSTR dst, LPCSTR src )
 {
     register LPWSTR p = dst;
     while ((*p++ = (WCHAR)(unsigned char)*src++));
@@ -387,7 +387,7 @@
 /***********************************************************************
  *           lstrcpyWtoA   (Not a Windows API)
  */
-LPSTR lstrcpyWtoA( LPSTR dst, LPCWSTR src )
+LPSTR WINAPI lstrcpyWtoA( LPSTR dst, LPCWSTR src )
 {
     register LPSTR p = dst;
     while ((*p++ = (CHAR)*src++));
@@ -398,7 +398,7 @@
 /***********************************************************************
  *           lstrcpynAtoW   (Not a Windows API)
  */
-LPWSTR lstrcpynAtoW( LPWSTR dst, LPCSTR src, INT32 n )
+LPWSTR WINAPI lstrcpynAtoW( LPWSTR dst, LPCSTR src, INT32 n )
 {
     LPWSTR p = dst;
     while ((n-- > 1) && *src) *p++ = (WCHAR)(unsigned char)*src++;
@@ -410,7 +410,7 @@
 /***********************************************************************
  *           lstrcpynWtoA   (Not a Windows API)
  */
-LPSTR lstrcpynWtoA( LPSTR dst, LPCWSTR src, INT32 n )
+LPSTR WINAPI lstrcpynWtoA( LPSTR dst, LPCWSTR src, INT32 n )
 {
     LPSTR p = dst;
     while ((n-- > 1) && *src) *p++ = (CHAR)*src++;
@@ -422,7 +422,7 @@
 /***********************************************************************
  *           Copy   (GDI.250)
  */
-void Copy( LPVOID src, LPVOID dst, WORD size )
+void WINAPI Copy( LPVOID src, LPVOID dst, WORD size )
 {
     memcpy( dst, src, size );
 }
@@ -431,7 +431,7 @@
 /***********************************************************************
  *           RtlFillMemory   (KERNEL32.441)
  */
-VOID RtlFillMemory( LPVOID ptr, UINT32 len, UINT32 fill )
+VOID WINAPI RtlFillMemory( LPVOID ptr, UINT32 len, UINT32 fill )
 {
     memset( ptr, fill, len );
 }
@@ -440,7 +440,7 @@
 /***********************************************************************
  *           RtlMoveMemory   (KERNEL32.442)
  */
-VOID RtlMoveMemory( LPVOID dst, LPCVOID src, UINT32 len )
+VOID WINAPI RtlMoveMemory( LPVOID dst, LPCVOID src, UINT32 len )
 {
     memmove( dst, src, len );
 }
@@ -449,7 +449,7 @@
 /***********************************************************************
  *           RtlZeroMemory   (KERNEL32.444)
  */
-VOID RtlZeroMemory( LPVOID ptr, UINT32 len )
+VOID WINAPI RtlZeroMemory( LPVOID ptr, UINT32 len )
 {
     memset( ptr, 0, len );
 }
@@ -458,7 +458,7 @@
 /***********************************************************************
  *           AnsiToOem16   (KEYBOARD.5)
  */
-INT16 AnsiToOem16( LPCSTR s, LPSTR d )
+INT16 WINAPI AnsiToOem16( LPCSTR s, LPSTR d )
 {
     CharToOem32A( s, d );
     return -1;
@@ -468,7 +468,7 @@
 /***********************************************************************
  *           OemToAnsi16   (KEYBOARD.6)
  */
-INT16 OemToAnsi16( LPCSTR s, LPSTR d )
+INT16 WINAPI OemToAnsi16( LPCSTR s, LPSTR d )
 {
     OemToChar32A( s, d );
     return -1;
@@ -478,7 +478,7 @@
 /***********************************************************************
  *           AnsiToOemBuff16   (KEYBOARD.134)
  */
-void AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len )
+void WINAPI AnsiToOemBuff16( LPCSTR s, LPSTR d, UINT16 len )
 {
     CharToOemBuff32A( s, d, len ? len : 65536 );
 }
@@ -487,7 +487,7 @@
 /***********************************************************************
  *           OemToAnsiBuff16   (KEYBOARD.135)
  */
-void OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len )
+void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len )
 {
     OemToCharBuff32A( s, d, len ? len : 65536 );
 }
@@ -496,7 +496,7 @@
 /***********************************************************************
  *           CharToOem32A   (USER32.36)
  */
-BOOL32 CharToOem32A( LPCSTR s, LPSTR d )
+BOOL32 WINAPI CharToOem32A( LPCSTR s, LPSTR d )
 {
     if (!s || !d) return TRUE;
     dprintf_string(stddeb,"CharToOem '%s'\n", (s)?s:"NULL");
@@ -509,7 +509,7 @@
 /***********************************************************************
  *           CharToOemBuff32A   (USER32.37)
  */
-BOOL32 CharToOemBuff32A( LPCSTR s, LPSTR d, DWORD len )
+BOOL32 WINAPI CharToOemBuff32A( LPCSTR s, LPSTR d, DWORD len )
 {
     while (len--) *d++ = ANSI_TO_OEM(*s++);
     return TRUE;
@@ -519,7 +519,7 @@
 /***********************************************************************
  *           CharToOemBuff32W   (USER32.38)
  */
-BOOL32 CharToOemBuff32W( LPCWSTR s, LPSTR d, DWORD len )
+BOOL32 WINAPI CharToOemBuff32W( LPCWSTR s, LPSTR d, DWORD len )
 {
     while (len--) *d++ = ANSI_TO_OEM(*s++);
     return TRUE;
@@ -529,7 +529,7 @@
 /***********************************************************************
  *           CharToOem32W   (USER32.39)
  */
-BOOL32 CharToOem32W( LPCWSTR s, LPSTR d )
+BOOL32 WINAPI CharToOem32W( LPCWSTR s, LPSTR d )
 {
     while ((*d++ = ANSI_TO_OEM(*s++)));
     return TRUE;
@@ -539,7 +539,7 @@
 /***********************************************************************
  *           OemToChar32A   (USER32.401)
  */
-BOOL32 OemToChar32A( LPCSTR s, LPSTR d )
+BOOL32 WINAPI OemToChar32A( LPCSTR s, LPSTR d )
 {
     dprintf_string(stddeb,"OemToChar '%s'\n", (s)?s:"NULL");
     while ((*d++ = OEM_TO_ANSI(*s++)));
@@ -551,7 +551,7 @@
 /***********************************************************************
  *           OemToCharBuff32A   (USER32.402)
  */
-BOOL32 OemToCharBuff32A( LPCSTR s, LPSTR d, DWORD len )
+BOOL32 WINAPI OemToCharBuff32A( LPCSTR s, LPSTR d, DWORD len )
 {
     dprintf_string(stddeb,"OemToCharBuff '%s' for %ld chars\n", (s)?s:"NULL",len);
     while (len--) *d++ = OEM_TO_ANSI(*s++);
@@ -562,7 +562,7 @@
 /***********************************************************************
  *           OemToCharBuff32W   (USER32.403)
  */
-BOOL32 OemToCharBuff32W( LPCSTR s, LPWSTR d, DWORD len )
+BOOL32 WINAPI OemToCharBuff32W( LPCSTR s, LPWSTR d, DWORD len )
 {
     while (len--) *d++ = (WCHAR)OEM_TO_ANSI(*s++);
     return TRUE;
@@ -572,7 +572,7 @@
 /***********************************************************************
  *           OemToChar32W   (USER32.404)
  */
-BOOL32 OemToChar32W( LPCSTR s, LPWSTR d )
+BOOL32 WINAPI OemToChar32W( LPCSTR s, LPWSTR d )
 {
     while ((*d++ = (WCHAR)OEM_TO_ANSI(*s++)));
     return TRUE;
diff --git a/memory/virtual.c b/memory/virtual.c
index 2aa42ba..f3765b2 100644
--- a/memory/virtual.c
+++ b/memory/virtual.c
@@ -416,7 +416,7 @@
 /***********************************************************************
  *             VirtualAlloc   (KERNEL32.548)
  */
-LPVOID VirtualAlloc( LPVOID addr, DWORD size, DWORD type, DWORD protect )
+LPVOID WINAPI VirtualAlloc( LPVOID addr, DWORD size, DWORD type, DWORD protect)
 {
     FILE_VIEW *view;
     UINT32 base, ptr, view_size;
@@ -517,7 +517,7 @@
 /***********************************************************************
  *             VirtualFree   (KERNEL32.550)
  */
-BOOL32 VirtualFree( LPVOID addr, DWORD size, DWORD type )
+BOOL32 WINAPI VirtualFree( LPVOID addr, DWORD size, DWORD type )
 {
     FILE_VIEW *view;
     UINT32 base;
@@ -567,7 +567,7 @@
 /***********************************************************************
  *             VirtualLock   (KERNEL32.551)
  */
-BOOL32 VirtualLock( LPVOID addr, DWORD size )
+BOOL32 WINAPI VirtualLock( LPVOID addr, DWORD size )
 {
     return TRUE;
 }
@@ -576,7 +576,7 @@
 /***********************************************************************
  *             VirtualUnlock   (KERNEL32.556)
  */
-BOOL32 VirtualUnlock( LPVOID addr, DWORD size )
+BOOL32 WINAPI VirtualUnlock( LPVOID addr, DWORD size )
 {
     return TRUE;
 }
@@ -585,8 +585,8 @@
 /***********************************************************************
  *             VirtualProtect   (KERNEL32.552)
  */
-BOOL32 VirtualProtect( LPVOID addr, DWORD size, DWORD new_prot,
-                       LPDWORD old_prot )
+BOOL32 WINAPI VirtualProtect( LPVOID addr, DWORD size, DWORD new_prot,
+                              LPDWORD old_prot )
 {
     FILE_VIEW *view;
     UINT32 base, i;
@@ -628,8 +628,8 @@
 /***********************************************************************
  *             VirtualProtectEx   (KERNEL32.553)
  */
-BOOL32 VirtualProtectEx( HANDLE32 handle, LPVOID addr, DWORD size,
-                         DWORD new_prot, LPDWORD old_prot )
+BOOL32 WINAPI VirtualProtectEx( HANDLE32 handle, LPVOID addr, DWORD size,
+                                DWORD new_prot, LPDWORD old_prot )
 {
     BOOL32 ret = FALSE;
 
@@ -649,7 +649,8 @@
 /***********************************************************************
  *             VirtualQuery   (KERNEL32.554)
  */
-BOOL32 VirtualQuery( LPCVOID addr, LPMEMORY_BASIC_INFORMATION info, DWORD len )
+BOOL32 WINAPI VirtualQuery( LPCVOID addr, LPMEMORY_BASIC_INFORMATION info,
+                            DWORD len )
 {
     FILE_VIEW *view = VIRTUAL_FirstView;
     UINT32 base = ROUND_ADDR( addr );
@@ -710,8 +711,8 @@
 /***********************************************************************
  *             VirtualQueryEx   (KERNEL32.555)
  */
-BOOL32 VirtualQueryEx( HANDLE32 handle, LPCVOID addr,
-                       LPMEMORY_BASIC_INFORMATION info, DWORD len )
+BOOL32 WINAPI VirtualQueryEx( HANDLE32 handle, LPCVOID addr,
+                              LPMEMORY_BASIC_INFORMATION info, DWORD len )
 {
     BOOL32 ret = FALSE;
 
@@ -731,7 +732,7 @@
 /***********************************************************************
  *             IsBadReadPtr32   (KERNEL32.354)
  */
-BOOL32 IsBadReadPtr32( LPCVOID ptr, UINT32 size )
+BOOL32 WINAPI IsBadReadPtr32( LPCVOID ptr, UINT32 size )
 {
     return !VIRTUAL_CheckFlags( (UINT32)ptr, size,
                                 VPROT_READ | VPROT_COMMITTED );
@@ -741,7 +742,7 @@
 /***********************************************************************
  *             IsBadWritePtr32   (KERNEL32.357)
  */
-BOOL32 IsBadWritePtr32( LPVOID ptr, UINT32 size )
+BOOL32 WINAPI IsBadWritePtr32( LPVOID ptr, UINT32 size )
 {
     return !VIRTUAL_CheckFlags( (UINT32)ptr, size,
                                 VPROT_WRITE | VPROT_COMMITTED );
@@ -751,7 +752,7 @@
 /***********************************************************************
  *             IsBadHugeReadPtr32   (KERNEL32.352)
  */
-BOOL32 IsBadHugeReadPtr32( LPCVOID ptr, UINT32 size )
+BOOL32 WINAPI IsBadHugeReadPtr32( LPCVOID ptr, UINT32 size )
 {
     return IsBadReadPtr32( ptr, size );
 }
@@ -760,7 +761,7 @@
 /***********************************************************************
  *             IsBadHugeWritePtr32   (KERNEL32.353)
  */
-BOOL32 IsBadHugeWritePtr32( LPVOID ptr, UINT32 size )
+BOOL32 WINAPI IsBadHugeWritePtr32( LPVOID ptr, UINT32 size )
 {
     return IsBadWritePtr32( ptr, size );
 }
@@ -769,7 +770,7 @@
 /***********************************************************************
  *             IsBadCodePtr32   (KERNEL32.351)
  */
-BOOL32 IsBadCodePtr32( FARPROC32 ptr )
+BOOL32 WINAPI IsBadCodePtr32( FARPROC32 ptr )
 {
     return !VIRTUAL_CheckFlags( (UINT32)ptr, 1, VPROT_EXEC | VPROT_COMMITTED );
 }
@@ -778,7 +779,7 @@
 /***********************************************************************
  *             IsBadStringPtr32A   (KERNEL32.355)
  */
-BOOL32 IsBadStringPtr32A( LPCSTR str, UINT32 max )
+BOOL32 WINAPI IsBadStringPtr32A( LPCSTR str, UINT32 max )
 {
     FILE_VIEW *view;
     UINT32 page, count;
@@ -806,7 +807,7 @@
 /***********************************************************************
  *             IsBadStringPtr32W   (KERNEL32.356)
  */
-BOOL32 IsBadStringPtr32W( LPCWSTR str, UINT32 max )
+BOOL32 WINAPI IsBadStringPtr32W( LPCWSTR str, UINT32 max )
 {
     FILE_VIEW *view;
     UINT32 page, count;
@@ -834,9 +835,9 @@
 /***********************************************************************
  *             CreateFileMapping32A   (KERNEL32.46)
  */
-HANDLE32 CreateFileMapping32A( HFILE32 hFile, LPSECURITY_ATTRIBUTES attr,
-                               DWORD protect, DWORD size_high, DWORD size_low,
-                               LPCSTR name )
+HANDLE32 WINAPI CreateFileMapping32A(HFILE32 hFile, LPSECURITY_ATTRIBUTES attr,
+                                     DWORD protect, DWORD size_high,
+                                     DWORD size_low, LPCSTR name )
 {
     FILE_MAPPING *mapping = NULL;
     HANDLE32 handle;
@@ -930,9 +931,9 @@
 /***********************************************************************
  *             CreateFileMapping32W   (KERNEL32.47)
  */
-HANDLE32 CreateFileMapping32W( HFILE32 hFile, LPSECURITY_ATTRIBUTES attr,
-                               DWORD protect, DWORD size_high, DWORD size_low,
-                               LPCWSTR name )
+HANDLE32 WINAPI CreateFileMapping32W(HFILE32 hFile, LPSECURITY_ATTRIBUTES attr,
+                                     DWORD protect, DWORD size_high,
+                                     DWORD size_low, LPCWSTR name )
 {
     LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     HANDLE32 ret = CreateFileMapping32A( hFile, attr, protect,
@@ -945,7 +946,7 @@
 /***********************************************************************
  *             OpenFileMapping32A   (KERNEL32.397)
  */
-HANDLE32 OpenFileMapping32A( DWORD access, BOOL32 inherit, LPCSTR name )
+HANDLE32 WINAPI OpenFileMapping32A( DWORD access, BOOL32 inherit, LPCSTR name )
 {
     K32OBJ *obj = K32OBJ_FindNameType( name, K32OBJ_MEM_MAPPED_FILE );
     if (!obj) return 0;
@@ -956,7 +957,7 @@
 /***********************************************************************
  *             OpenFileMapping32W   (KERNEL32.398)
  */
-HANDLE32 OpenFileMapping32W( DWORD access, BOOL32 inherit, LPCWSTR name )
+HANDLE32 WINAPI OpenFileMapping32W( DWORD access, BOOL32 inherit, LPCWSTR name)
 {
     LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     HANDLE32 ret = OpenFileMapping32A( access, inherit, nameA );
@@ -984,8 +985,8 @@
 /***********************************************************************
  *             MapViewOfFile   (KERNEL32.385)
  */
-LPVOID MapViewOfFile( HANDLE32 mapping, DWORD access, DWORD offset_high,
-                      DWORD offset_low, DWORD count )
+LPVOID WINAPI MapViewOfFile( HANDLE32 mapping, DWORD access, DWORD offset_high,
+                             DWORD offset_low, DWORD count )
 {
     return MapViewOfFileEx( mapping, access, offset_high,
                             offset_low, count, NULL );
@@ -995,8 +996,8 @@
 /***********************************************************************
  *             MapViewOfFileEx   (KERNEL32.386)
  */
-LPVOID MapViewOfFileEx( HANDLE32 handle, DWORD access, DWORD offset_high,
-                        DWORD offset_low, DWORD count, LPVOID addr )
+LPVOID WINAPI MapViewOfFileEx(HANDLE32 handle, DWORD access, DWORD offset_high,
+                              DWORD offset_low, DWORD count, LPVOID addr )
 {
     FILE_MAPPING *mapping;
     FILE_VIEW *view;
@@ -1082,7 +1083,7 @@
 /***********************************************************************
  *             UnmapViewOfFile   (KERNEL32.540)
  */
-BOOL32 UnmapViewOfFile( LPVOID addr )
+BOOL32 WINAPI UnmapViewOfFile( LPVOID addr )
 {
     FILE_VIEW *view;
     UINT32 base = ROUND_ADDR( addr );
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 8677044..92dc1c3 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -36,7 +36,7 @@
 	ver.c \
 	w32sys.c \
 	winsock.c \
-	winsock_async.c \
+	winsock_dns.c \
 	wsprintf.c \
 	xmalloc.c
 
diff --git a/misc/comm.c b/misc/comm.c
index d119200..f23666f 100644
--- a/misc/comm.c
+++ b/misc/comm.c
@@ -21,7 +21,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <sys/stat.h>
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__svr4__)
 #include <sys/filio.h>
 #endif
 #include <sys/ioctl.h>
@@ -148,7 +148,7 @@
 /**************************************************************************
  *         BuildCommDCB		(USER.213)
  */
-BOOL16 BuildCommDCB16(LPCSTR device, LPDCB16 lpdcb)
+BOOL16 WINAPI BuildCommDCB16(LPCSTR device, LPDCB16 lpdcb)
 {
 	/* "COM1:9600,n,8,1"	*/
 	/*  012345		*/
@@ -173,6 +173,8 @@
 			return -1;
 		}
 		
+		memset(lpdcb, 0, sizeof(DCB16)); /* initialize */
+
 		if (!COM[port].fd) {
 		    OpenComm(device, 0, 0);
 		}
@@ -243,14 +245,17 @@
 /**************************************************************************
  *         BuildCommDCBA		(KERNEL32.14)
  */
-BOOL32 BuildCommDCB32A(LPCSTR device,LPDCB32 lpdcb) {
+BOOL32 WINAPI BuildCommDCB32A(LPCSTR device,LPDCB32 lpdcb)
+{
 	return BuildCommDCBAndTimeouts32A(device,lpdcb,NULL);
 }
 
 /**************************************************************************
  *         BuildCommDCBAndTimeoutsA	(KERNEL32.15)
  */
-BOOL32 BuildCommDCBAndTimeouts32A(LPCSTR device, LPDCB32 lpdcb,LPCOMMTIMEOUTS lptimeouts) {
+BOOL32 WINAPI BuildCommDCBAndTimeouts32A(LPCSTR device, LPDCB32 lpdcb,
+                                         LPCOMMTIMEOUTS lptimeouts)
+{
 	int	port;
 	char	*ptr,*temp;
 
@@ -270,6 +275,9 @@
 		temp=(LPSTR)(device+5);
 	} else
 		temp=(LPSTR)device;
+
+	memset(lpdcb, 0, sizeof(DCB32)); /* initialize */
+
 	lpdcb->DCBlength	= sizeof(DCB32);
 	if (strchr(temp,',')) {	/* old style */
 		DCB16	dcb16;
@@ -372,9 +380,9 @@
 /**************************************************************************
  *         BuildCommDCBAndTimeoutsW		(KERNEL32.16)
  */
-BOOL32 BuildCommDCBAndTimeouts32W(
-	LPCWSTR devid,LPDCB32 lpdcb,LPCOMMTIMEOUTS lptimeouts
-) {
+BOOL32 WINAPI BuildCommDCBAndTimeouts32W( LPCWSTR devid, LPDCB32 lpdcb,
+                                          LPCOMMTIMEOUTS lptimeouts )
+{
 	LPSTR	devidA;
 	BOOL32	ret;
 
@@ -388,14 +396,15 @@
 /**************************************************************************
  *         BuildCommDCBW		(KERNEL32.17)
  */
-BOOL32 BuildCommDCB32W(LPCWSTR devid,LPDCB32 lpdcb) {
+BOOL32 WINAPI BuildCommDCB32W(LPCWSTR devid,LPDCB32 lpdcb)
+{
 	return BuildCommDCBAndTimeouts32W(devid,lpdcb,NULL);
 }
 
 /*****************************************************************************
  *	OpenComm		(USER.200)
  */
-INT16 OpenComm(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
+INT16 WINAPI OpenComm(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
 {
 	int port,fd;
 
@@ -459,7 +468,7 @@
 /*****************************************************************************
  *	CloseComm		(USER.207)
  */
-INT16 CloseComm(INT16 fd)
+INT16 WINAPI CloseComm(INT16 fd)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -483,7 +492,7 @@
 /*****************************************************************************
  *	SetCommBreak		(USER.210)
  */
-INT16 SetCommBreak16(INT16 fd)
+INT16 WINAPI SetCommBreak16(INT16 fd)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -501,7 +510,7 @@
 /*****************************************************************************
  *	SetCommBreak		(KERNEL32.449)
  */
-BOOL32 SetCommBreak32(INT32 fd)
+BOOL32 WINAPI SetCommBreak32(INT32 fd)
 {
 
 	struct DosDeviceStruct *ptr;
@@ -520,7 +529,7 @@
 /*****************************************************************************
  *	ClearCommBreak		(USER.211)
  */
-INT16 ClearCommBreak16(INT16 fd)
+INT16 WINAPI ClearCommBreak16(INT16 fd)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -538,7 +547,7 @@
 /*****************************************************************************
  *	ClearCommBreak		(KERNEL32.20)
  */
-BOOL32 ClearCommBreak32(INT32 fd)
+BOOL32 WINAPI ClearCommBreak32(INT32 fd)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -556,7 +565,7 @@
 /*****************************************************************************
  *	EscapeCommFunction	(USER.214)
  */
-LONG EscapeCommFunction16(UINT16 fd,UINT16 nFunction)
+LONG WINAPI EscapeCommFunction16(UINT16 fd,UINT16 nFunction)
 {
 	int	max;
 	struct termios port;
@@ -632,7 +641,7 @@
 /*****************************************************************************
  *	EscapeCommFunction	(KERNEL32.214)
  */
-BOOL32 EscapeCommFunction32(INT32 fd,UINT32 nFunction)
+BOOL32 WINAPI EscapeCommFunction32(INT32 fd,UINT32 nFunction)
 {
 	struct termios	port;
 	struct DosDeviceStruct *ptr;
@@ -705,7 +714,7 @@
 /*****************************************************************************
  *	FlushComm	(USER.215)
  */
-INT16 FlushComm(INT16 fd,INT16 fnQueue)
+INT16 WINAPI FlushComm(INT16 fd,INT16 fnQueue)
 {
 	int queue;
 
@@ -720,7 +729,7 @@
 				fd, fnQueue);
 			return -1;
 		}
-	if (tcflush(fd, fnQueue)) {
+	if (tcflush(fd, queue)) {
 		commerror = WinError();
 		return -1;	
 	} else {
@@ -732,7 +741,7 @@
 /*****************************************************************************
  *	GetCommError	(USER.203)
  */
-INT16 GetCommError(INT16 fd,LPCOMSTAT lpStat)
+INT16 WINAPI GetCommError(INT16 fd,LPCOMSTAT lpStat)
 {
 	int		temperror;
 	unsigned long	cnt;
@@ -771,7 +780,7 @@
 /*****************************************************************************
  *	ClearCommError	(KERNEL32.21)
  */
-BOOL32 ClearCommError(INT32 fd,LPDWORD errors,LPCOMSTAT lpStat)
+BOOL32 WINAPI ClearCommError(INT32 fd,LPDWORD errors,LPCOMSTAT lpStat)
 {
 	int temperror;
 
@@ -785,7 +794,7 @@
 /*****************************************************************************
  *	SetCommEventMask	(USER.208)
  */
-UINT16	*SetCommEventMask(INT16 fd,UINT16 fuEvtMask)
+UINT16* WINAPI SetCommEventMask(INT16 fd,UINT16 fuEvtMask)
 {
     	dprintf_comm(stddeb,"SetCommEventMask:fd %d,mask %d\n",fd,fuEvtMask);
 	eventmask |= fuEvtMask;
@@ -795,7 +804,7 @@
 /*****************************************************************************
  *	GetCommEventMask	(USER.209)
  */
-UINT16 GetCommEventMask(INT16 fd,UINT16 fnEvtClear)
+UINT16 WINAPI GetCommEventMask(INT16 fd,UINT16 fnEvtClear)
 {
 	int	events = 0;
 
@@ -839,7 +848,7 @@
 /*****************************************************************************
  *	GetCommMask	(KERNEL32.156)
  */
-BOOL32 GetCommMask(INT32 fd,LPDWORD evtmask)
+BOOL32 WINAPI GetCommMask(INT32 fd,LPDWORD evtmask)
 {
     	dprintf_comm(stddeb,
 		"GetCommMask: fd %d, mask %p\n", fd, evtmask);
@@ -850,7 +859,7 @@
 /*****************************************************************************
  *	SetCommMask	(KERNEL32.451)
  */
-BOOL32 SetCommMask(INT32 fd,DWORD evtmask)
+BOOL32 WINAPI SetCommMask(INT32 fd,DWORD evtmask)
 {
     	dprintf_comm(stddeb,
 		"SetCommMask: fd %d, mask %lx\n", fd, evtmask);
@@ -861,7 +870,7 @@
 /*****************************************************************************
  *	SetCommState16	(USER.201)
  */
-INT16 SetCommState16(LPDCB16 lpdcb)
+INT16 WINAPI SetCommState16(LPDCB16 lpdcb)
 {
 	struct termios port;
 	struct DosDeviceStruct *ptr;
@@ -1048,8 +1057,12 @@
 #endif	
 	if (lpdcb->fInX)
 		port.c_iflag |= IXON;
+	else
+		port.c_iflag &= ~IXON;
 	if (lpdcb->fOutX)
 		port.c_iflag |= IXOFF;
+	else
+		port.c_iflag &= ~IXOFF;
 
 	if (tcsetattr(lpdcb->Id, TCSADRAIN, &port) == -1) {
 		commerror = WinError();	
@@ -1063,7 +1076,7 @@
 /*****************************************************************************
  *	SetCommState32	(KERNEL32.452)
  */
-BOOL32 SetCommState32(INT32 fd,LPDCB32 lpdcb)
+BOOL32 WINAPI SetCommState32(INT32 fd,LPDCB32 lpdcb)
 {
 	struct termios port;
 	struct DosDeviceStruct *ptr;
@@ -1251,8 +1264,12 @@
 #endif	
 	if (lpdcb->fInX)
 		port.c_iflag |= IXON;
+	else
+		port.c_iflag &= ~IXON;
 	if (lpdcb->fOutX)
 		port.c_iflag |= IXOFF;
+	else
+		port.c_iflag &= ~IXOFF;
 
 	if (tcsetattr(fd,TCSADRAIN,&port)==-1) {
 		commerror = WinError();	
@@ -1267,7 +1284,7 @@
 /*****************************************************************************
  *	GetCommState	(USER.202)
  */
-INT16 GetCommState16(INT16 fd, LPDCB16 lpdcb)
+INT16 WINAPI GetCommState16(INT16 fd, LPDCB16 lpdcb)
 {
 	struct termios port;
 
@@ -1386,7 +1403,7 @@
 /*****************************************************************************
  *	GetCommState	(KERNEL32.159)
  */
-BOOL32 GetCommState32(INT32 fd, LPDCB32 lpdcb)
+BOOL32 WINAPI GetCommState32(INT32 fd, LPDCB32 lpdcb)
 {
 	struct termios	port;
 
@@ -1502,7 +1519,7 @@
 /*****************************************************************************
  *	TransmitCommChar	(USER.206)
  */
-INT16 TransmitCommChar16(INT16 fd,CHAR chTransmit)
+INT16 WINAPI TransmitCommChar16(INT16 fd,CHAR chTransmit)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -1530,7 +1547,7 @@
 /*****************************************************************************
  *	TransmitCommChar	(KERNEL32.535)
  */
-BOOL32 TransmitCommChar32(INT32 fd,CHAR chTransmit)
+BOOL32 WINAPI TransmitCommChar32(INT32 fd,CHAR chTransmit)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -1556,7 +1573,7 @@
 /*****************************************************************************
  *	UngetCommChar	(USER.212)
  */
-INT16 UngetCommChar(INT16 fd,CHAR chUnget)
+INT16 WINAPI UngetCommChar(INT16 fd,CHAR chUnget)
 {
 	struct DosDeviceStruct *ptr;
 
@@ -1580,7 +1597,7 @@
 /*****************************************************************************
  *	ReadComm	(USER.204)
  */
-INT16 ReadComm(INT16 fd,LPSTR lpvBuf,INT16 cbRead)
+INT16 WINAPI ReadComm(INT16 fd,LPSTR lpvBuf,INT16 cbRead)
 {
 	int status, length;
 	struct DosDeviceStruct *ptr;
@@ -1625,7 +1642,7 @@
 /*****************************************************************************
  *	WriteComm	(USER.205)
  */
-INT16 WriteComm(INT16 fd, LPSTR lpvBuf, INT16 cbWrite)
+INT16 WINAPI WriteComm(INT16 fd, LPSTR lpvBuf, INT16 cbWrite)
 {
 	int x, length;
 	struct DosDeviceStruct *ptr;
@@ -1660,7 +1677,8 @@
 /*****************************************************************************
  *	GetCommTimeouts		(KERNEL32.160)
  */
-BOOL32 GetCommTimeouts(INT32 fd,LPCOMMTIMEOUTS lptimeouts) {
+BOOL32 WINAPI GetCommTimeouts(INT32 fd,LPCOMMTIMEOUTS lptimeouts)
+{
 	fprintf(stderr,"GetCommTimeouts(%x,%p), empty stub.\n",
 		fd,lptimeouts
 	);
@@ -1670,7 +1688,7 @@
 /*****************************************************************************
  *	SetCommTimeouts		(KERNEL32.453)
  */
-BOOL32 SetCommTimeouts(INT32 fd,LPCOMMTIMEOUTS lptimeouts) {
+BOOL32 WINAPI SetCommTimeouts(INT32 fd,LPCOMMTIMEOUTS lptimeouts) {
 	fprintf(stderr,"SetCommTimeouts(%x,%p), empty stub.\n",
 		fd,lptimeouts
 	);
@@ -1680,8 +1698,8 @@
 /***********************************************************************
  *           EnableCommNotification   (USER.246)
  */
-BOOL16 EnableCommNotification( INT16 fd, HWND16 hwnd, INT16 cbWriteNotify,
-                               INT16 cbOutQueue )
+BOOL16 WINAPI EnableCommNotification( INT16 fd, HWND16 hwnd,
+                                      INT16 cbWriteNotify, INT16 cbOutQueue )
 {
 	fprintf(stderr, "EnableCommNotification(%d, %x, %d, %d), empty stub.\n", fd, hwnd, cbWriteNotify, cbOutQueue);
 	return TRUE;
diff --git a/misc/commdlg.c b/misc/commdlg.c
index 4a4af0b..34f91a7 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -56,7 +56,7 @@
 /***********************************************************************
  *           GetOpenFileName   (COMMDLG.1)
  */
-BOOL16 GetOpenFileName16( SEGPTR ofn )
+BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
 {
     HINSTANCE16 hInst;
     HANDLE32 hDlgTmpl = 0, hResInfo;
@@ -146,7 +146,7 @@
 /***********************************************************************
  *           GetSaveFileName   (COMMDLG.2)
  */
-BOOL16 GetSaveFileName16( SEGPTR ofn)
+BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
 {
     HINSTANCE16 hInst;
     HANDLE32 hDlgTmpl = 0;
@@ -296,7 +296,7 @@
 	  return fptr;
 	fptr += strlen(fptr) + 1;
     }
-  return NULL;
+  return "*.*"; /* FIXME */
 }
 
 /***********************************************************************
@@ -417,22 +417,51 @@
  return 0;   
 } 
 
+/***********************************************************************
+ *                              FILEDLG_CallWindowProc             [internal]
+ *
+ * Adapt the structures back for win32 calls so the callee can read lpCustData
+ */
 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
 	UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
+
 ) {
+	BOOL32	needstruct;
+
+	needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
+
 	if (!(lpofn->Flags & OFN_WINE32))
 		return (BOOL32)CallWindowProc16(
 			lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
 		);
 	/* |OFN_WINE32 */
-	if (lpofn->Flags & OFN_UNICODE)
-		return (BOOL32)CallWindowProc32W(
+	if (lpofn->Flags & OFN_UNICODE) {
+		if (needstruct) {
+		    OPENFILENAME32W ofnw;
+
+		    /* FIXME: probably needs more converted */
+		    ofnw.lCustData = lpofn->lCustData;
+		    return (BOOL32)CallWindowProc32W(
+			    (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
+		    );
+		} else
+		    return (BOOL32)CallWindowProc32W(
+			    (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
+		    );
+	}
+	/* ! |OFN_UNICODE */
+	if (needstruct) {
+		OPENFILENAME32A ofna;
+
+		/* FIXME: probably needs more converted */
+		ofna.lCustData = lpofn->lCustData;
+		return (BOOL32)CallWindowProc32A(
+			(WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
+		);
+	} else
+		return (BOOL32)CallWindowProc32A(
 			(WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
 		);
-	/* ! |OFN_UNICODE */
-	return (BOOL32)CallWindowProc32A(
-		(WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
-	);
 
 }
 
@@ -718,7 +747,8 @@
 /***********************************************************************
  *           FileOpenDlgProc   (COMMDLG.6)
  */
-LRESULT FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                               LPARAM lParam)
 {  
  LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
  
@@ -761,7 +791,8 @@
 /***********************************************************************
  *           FileSaveDlgProc   (COMMDLG.7)
  */
-LRESULT FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                               LPARAM lParam)
 {
  LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
  
@@ -808,7 +839,7 @@
 /***********************************************************************
  *           FindTextDlg   (COMMDLG.11)
  */
-HWND16 FindText( SEGPTR find )
+HWND16 WINAPI FindText( SEGPTR find )
 {
     HANDLE16 hInst;
     LPCVOID ptr;
@@ -833,7 +864,7 @@
 /***********************************************************************
  *           ReplaceText   (COMMDLG.12)
  */
-HWND16 ReplaceText( SEGPTR find )
+HWND16 WINAPI ReplaceText( SEGPTR find )
 {
     HANDLE16 hInst;
     LPCVOID ptr;
@@ -946,7 +977,8 @@
 /***********************************************************************
  *           FindTextDlgProc   (COMMDLG.13)
  */
-LRESULT FindTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI FindTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                               LPARAM lParam)
 {
     switch (wMsg) {
 	case WM_INITDIALOG:
@@ -1066,7 +1098,8 @@
 /***********************************************************************
  *           ReplaceTextDlgProc   (COMMDLG.14)
  */
-LRESULT ReplaceTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI ReplaceTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                                  LPARAM lParam)
 {
     switch (wMsg) {
 	case WM_INITDIALOG:
@@ -1081,7 +1114,7 @@
 /***********************************************************************
  *           PrintDlg   (COMMDLG.20)
  */
-BOOL16 PrintDlg( SEGPTR printdlg )
+BOOL16 WINAPI PrintDlg( SEGPTR printdlg )
 {
     HANDLE16 hInst;
     BOOL16 bRet = FALSE;
@@ -1115,7 +1148,8 @@
 /***********************************************************************
  *           PrintDlgProc   (COMMDLG.21)
  */
-LRESULT PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                            LPARAM lParam)
 {
   switch (wMsg)
     {
@@ -1142,7 +1176,8 @@
 /***********************************************************************
  *           PrintSetupDlgProc   (COMMDLG.22)
  */
-LRESULT PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
+                                 LPARAM lParam)
 {
   switch (wMsg)
     {
@@ -1168,7 +1203,7 @@
 /***********************************************************************
  *           CommDlgExtendedError   (COMMDLG.26)
  */
-DWORD CommDlgExtendedError(void)
+DWORD WINAPI CommDlgExtendedError(void)
 {
   return CommDlgLastError;
 }
@@ -1176,7 +1211,7 @@
 /***********************************************************************
  *           GetFileTitleA   (COMDLG32.8)
  */
-short GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
+short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
 {
     int i, len;
     dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
@@ -1210,7 +1245,7 @@
 /***********************************************************************
  *           GetFileTitleA   (COMDLG32.8)
  */
-short GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
+short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
 {
 	LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
 	LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
@@ -1226,7 +1261,8 @@
 /***********************************************************************
  *           GetFileTitle   (COMMDLG.27)
  */
-short GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf) {
+short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
+{
     return GetFileTitle32A(lpFile,lpTitle,cbBuf);
 }
 
@@ -1236,7 +1272,7 @@
 /***********************************************************************
  *           ChooseColor   (COMMDLG.5)
  */
-BOOL16 ChooseColor(LPCHOOSECOLOR lpChCol)
+BOOL16 WINAPI ChooseColor(LPCHOOSECOLOR lpChCol)
 {
     HINSTANCE16 hInst;
     HANDLE16 hDlgTmpl = 0;
@@ -2272,8 +2308,8 @@
 /***********************************************************************
  *           ColorDlgProc   (COMMDLG.8)
  */
-LRESULT ColorDlgProc(HWND16 hDlg, UINT16 message,
-                     WPARAM16 wParam, LONG lParam)
+LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
+                            WPARAM16 wParam, LONG lParam)
 {
  int res;
  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER); 
@@ -2331,7 +2367,7 @@
 /***********************************************************************
  *                        ChooseFont   (COMMDLG.15)     
  */
-BOOL16 ChooseFont(LPCHOOSEFONT lpChFont)
+BOOL16 WINAPI ChooseFont(LPCHOOSEFONT lpChFont)
 {
     HINSTANCE16 hInst;
     HANDLE16 hDlgTmpl = 0;
@@ -2411,8 +2447,8 @@
 /***********************************************************************
  *                FontFamilyEnumProc                       (COMMDLG.19)
  */
-INT16 FontFamilyEnumProc( SEGPTR logfont, SEGPTR metrics,
-                          UINT16 nFontType, LPARAM lParam )
+INT16 WINAPI FontFamilyEnumProc( SEGPTR logfont, SEGPTR metrics,
+                                 UINT16 nFontType, LPARAM lParam )
 {
   int i;
   WORD w;
@@ -2529,8 +2565,8 @@
 /***********************************************************************
  *                 FontStyleEnumProc                     (COMMDLG.18)
  */
-INT16 FontStyleEnumProc( SEGPTR logfont, SEGPTR metrics,
-                         UINT16 nFontType, LPARAM lParam )
+INT16 WINAPI FontStyleEnumProc( SEGPTR logfont, SEGPTR metrics,
+                                UINT16 nFontType, LPARAM lParam )
 {
   HWND16 hcmb2=LOWORD(lParam);
   HWND16 hcmb3=HIWORD(lParam);
@@ -2947,7 +2983,8 @@
                     2. some CF_.. flags are not supported
                     3. some TType extensions
  */
-LRESULT FormatCharDlgProc(HWND16 hDlg, UINT16 message, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI FormatCharDlgProc(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
+                                 LPARAM lParam)
 {
   LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);  
   if (message!=WM_INITDIALOG)
@@ -2983,7 +3020,7 @@
 
 
 #define GET_XXX_FILENAME(xxx) 						\
-BOOL32 xxx##32A( LPOPENFILENAME32A ofn )				\
+BOOL32 WINAPI xxx##32A( LPOPENFILENAME32A ofn )				\
 {									\
 	BOOL16 ret;							\
 	LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));	\
@@ -3062,7 +3099,7 @@
 	return ret;							\
 }									\
 									\
-BOOL32 xxx##32W( LPOPENFILENAME32W ofn )				\
+BOOL32 WINAPI xxx##32W( LPOPENFILENAME32W ofn )				\
 {									\
 	BOOL16 ret;							\
 	LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));	\
diff --git a/misc/compobj.c b/misc/compobj.c
index 45decf8..6fa4010 100644
--- a/misc/compobj.c
+++ b/misc/compobj.c
@@ -21,7 +21,7 @@
 /***********************************************************************
  *           CoBuildVersion [COMPOBJ.1]
  */
-DWORD CoBuildVersion()
+DWORD WINAPI CoBuildVersion()
 {
 	dprintf_ole(stddeb,"CoBuildVersion()\n");
 	return (rmm<<16)+rup;
@@ -31,7 +31,7 @@
  *           CoInitialize	[COMPOBJ.2]
  * lpReserved is an IMalloc pointer in 16bit OLE. We just stored it as-is.
  */
-HRESULT CoInitialize(DWORD lpReserved)
+HRESULT WINAPI CoInitialize(DWORD lpReserved)
 {
 	dprintf_ole(stdnimp,"CoInitialize\n");
 	/* remember the LPMALLOC, maybe somebody wants to read it later on */
@@ -42,7 +42,7 @@
 /***********************************************************************
  *           CoUnitialize   [COMPOBJ.3]
  */
-void CoUnitialize()
+void WINAPI CoUnitialize()
 {
 	dprintf_ole(stdnimp,"CoUnitialize()\n");
 }
@@ -50,7 +50,7 @@
 /***********************************************************************
  *           CoGetMalloc    [COMPOBJ.4]
  */
-HRESULT CoGetMalloc(DWORD dwMemContext, DWORD * lpMalloc)
+HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, DWORD * lpMalloc)
 {
 	if(currentMalloc)
 	{
@@ -65,7 +65,7 @@
 /***********************************************************************
  *           CoDisconnectObject
  */
-OLESTATUS CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
+OLESTATUS WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
 {
     dprintf_ole(stdnimp,"CoDisconnectObject:%p %lx\n",lpUnk,reserved);
     return OLE_OK;
@@ -77,8 +77,7 @@
 
 /* Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6] */
 
-OLESTATUS
-CLSIDFromString(const LPCSTR idstr, CLSID *id)
+OLESTATUS WINAPI CLSIDFromString(const LPCSTR idstr, CLSID *id)
 {
   BYTE *s = (BYTE *) idstr;
   BYTE *p;
@@ -146,8 +145,7 @@
  *           CLSIDFromString [COMPOBJ.19]
  */
 
-OLESTATUS
-StringFromCLSID(const CLSID *id, LPSTR idstr)
+OLESTATUS WINAPI StringFromCLSID(const CLSID *id, LPSTR idstr)
 {
   static const char *hex = "0123456789ABCDEF";
   char *s;
diff --git a/misc/cpu.c b/misc/cpu.c
index d30032f..9fd96cb 100644
--- a/misc/cpu.c
+++ b/misc/cpu.c
@@ -10,8 +10,7 @@
 #include <string.h>
 #include "windows.h"
 
-VOID
-GetSystemInfo(LPSYSTEM_INFO si)
+VOID WINAPI GetSystemInfo(LPSYSTEM_INFO si)
 {
 	static int cache = 0;
 	static SYSTEM_INFO cachedsi;
diff --git a/misc/crtdll.c b/misc/crtdll.c
index 0015d92..707e479 100644
--- a/misc/crtdll.c
+++ b/misc/crtdll.c
@@ -284,6 +284,7 @@
  */
 INT32 CRTDLL_atoi(LPCSTR x)
 {
+    if (!x) return 0;
     return atoi(x);
 }
 
@@ -293,6 +294,7 @@
  */
 LONG CRTDLL_atol(LPCSTR x)
 {
+    if (!x) return 0;
     return atol(x);
 }
 
@@ -498,7 +500,7 @@
 /*********************************************************************
  *                  sqrt          (CRTDLL.459)
  */
-float CRTDLL_sqrt(float x)
+double CRTDLL_sqrt(double x)
 {
     return sqrt(x);
 }
diff --git a/misc/error.c b/misc/error.c
index f4f2837..fc2e124 100644
--- a/misc/error.c
+++ b/misc/error.c
@@ -147,7 +147,8 @@
 /***********************************************************************
 *	LogError (KERNEL.324)
 */
-VOID LogError(UINT16 uErr, LPVOID lpvInfo) {
+VOID WINAPI LogError(UINT16 uErr, LPVOID lpvInfo)
+{
 	fprintf(stddeb, "LogError(%s, %p)\n", 
 		GetErrorString(uErr), lpvInfo);
 }
@@ -156,7 +157,8 @@
 /***********************************************************************
 *	LogParamError (KERNEL.325)
 */
-void LogParamError(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam) {
+void WINAPI LogParamError(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam)
+{
 	/* FIXME: is it possible to get the module name/function
 	 * from the lpfn param?
 	 */
diff --git a/misc/lstr.c b/misc/lstr.c
index 7228e67..64190c3 100644
--- a/misc/lstr.c
+++ b/misc/lstr.c
@@ -26,25 +26,25 @@
 /* Funny to divide them between user and kernel. */
 
 /* IsCharAlpha USER 433 */
-BOOL16 IsCharAlpha16(CHAR ch)
+BOOL16 WINAPI IsCharAlpha16(CHAR ch)
 {
   return isalpha(ch);   /* This is probably not right for NLS */
 }
 
 /* IsCharAlphanumeric USER 434 */
-BOOL16 IsCharAlphanumeric16(CHAR ch)
+BOOL16 WINAPI IsCharAlphaNumeric16(CHAR ch)
 {
     return isalnum(ch);
 }
 
 /* IsCharUpper USER 435 */
-BOOL16 IsCharUpper16(CHAR ch)
+BOOL16 WINAPI IsCharUpper16(CHAR ch)
 {
   return isupper(ch);
 }
 
 /* IsCharLower USER 436 */
-BOOL16 IsCharLower16(CHAR ch)
+BOOL16 WINAPI IsCharLower16(CHAR ch)
 {
   return islower(ch);
 }
@@ -52,7 +52,7 @@
 /***********************************************************************
  *           AnsiUpper16   (USER.431)
  */
-SEGPTR AnsiUpper16( SEGPTR strOrChar )
+SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
 {
   /* I am not sure if the locale stuff works with toupper, but then again 
      I am not sure if the Linux libc locale stuffs works at all */
@@ -71,7 +71,7 @@
 /***********************************************************************
  *           AnsiUpperBuff16   (USER.437)
  */
-UINT16 AnsiUpperBuff16( LPSTR str, UINT16 len )
+UINT16 WINAPI AnsiUpperBuff16( LPSTR str, UINT16 len )
 {
     UINT32 count = len ? len : 65536;
     for (; count; count--, str++) *str = toupper(*str);
@@ -81,7 +81,7 @@
 /***********************************************************************
  *           AnsiLower16   (USER.432)
  */
-SEGPTR AnsiLower16( SEGPTR strOrChar )
+SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
 {
   /* I am not sure if the locale stuff works with toupper, but then again 
      I am not sure if the Linux libc locale stuffs works at all */
@@ -100,7 +100,7 @@
 /***********************************************************************
  *           AnsiLowerBuff16   (USER.438)
  */
-UINT16 AnsiLowerBuff16( LPSTR str, UINT16 len )
+UINT16 WINAPI AnsiLowerBuff16( LPSTR str, UINT16 len )
 {
     UINT32 count = len ? len : 65536;
     for (; count; count--, str++) *str = tolower(*str);
@@ -111,7 +111,7 @@
 /***********************************************************************
  *           AnsiNext16   (USER.472)
  */
-SEGPTR AnsiNext16(SEGPTR current)
+SEGPTR WINAPI AnsiNext16(SEGPTR current)
 {
     return (*(char *)PTR_SEG_TO_LIN(current)) ? current + 1 : current;
 }
@@ -120,7 +120,7 @@
 /***********************************************************************
  *           AnsiPrev16   (USER.473)
  */
-SEGPTR AnsiPrev16( SEGPTR start, SEGPTR current )
+SEGPTR WINAPI AnsiPrev16( SEGPTR start, SEGPTR current )
 {
     return (current == start) ? start : current - 1;
 }
@@ -129,7 +129,7 @@
 /***********************************************************************
  *           OutputDebugString16   (KERNEL.115)
  */
-void OutputDebugString16( LPCSTR str )
+void WINAPI OutputDebugString16( LPCSTR str )
 {
     char *module;
     char *p, *buffer = HeapAlloc( GetProcessHeap(), 0, strlen(str)+1 );
@@ -147,7 +147,7 @@
 /***********************************************************************
  *           OutputDebugString32A   (KERNEL32
  */
-void OutputDebugString32A( LPCSTR str )
+void WINAPI OutputDebugString32A( LPCSTR str )
 {
     OutputDebugString16( str );
 }
@@ -157,7 +157,7 @@
 /***********************************************************************
  *           OutputDebugString32W   (KERNEL32
  */
-void OutputDebugString32W( LPCWSTR str )
+void WINAPI OutputDebugString32W( LPCWSTR str )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
     OutputDebugString32A( p );
@@ -169,7 +169,7 @@
 /***********************************************************************
  *           CharNext32A   (USER32.28)
  */
-LPSTR CharNext32A( LPCSTR ptr )
+LPSTR WINAPI CharNext32A( LPCSTR ptr )
 {
     if (!*ptr) return (LPSTR)ptr;
     if (IsDBCSLeadByte32( *ptr )) return (LPSTR)(ptr + 2);
@@ -180,7 +180,7 @@
 /***********************************************************************
  *           CharNextEx32A   (USER32.29)
  */
-LPSTR CharNextEx32A( WORD codepage, LPCSTR ptr, DWORD flags )
+LPSTR WINAPI CharNextEx32A( WORD codepage, LPCSTR ptr, DWORD flags )
 {
     if (!*ptr) return (LPSTR)ptr;
     if (IsDBCSLeadByteEx( codepage, *ptr )) return (LPSTR)(ptr + 2);
@@ -191,7 +191,7 @@
 /***********************************************************************
  *           CharNextExW   (USER32.30)
  */
-LPWSTR CharNextEx32W(WORD codepage,LPCWSTR x,DWORD flags)
+LPWSTR WINAPI CharNextEx32W(WORD codepage,LPCWSTR x,DWORD flags)
 {
     /* FIXME: add DBCS / codepage stuff */
     if (*x) return (LPWSTR)(x+1);
@@ -201,7 +201,7 @@
 /***********************************************************************
  *           CharNextW   (USER32.31)
  */
-LPWSTR CharNext32W(LPCWSTR x)
+LPWSTR WINAPI CharNext32W(LPCWSTR x)
 {
     if (*x) return (LPWSTR)(x+1);
     else return (LPWSTR)x;
@@ -210,7 +210,7 @@
 /***********************************************************************
  *           CharPrev32A   (USER32.32)
  */
-LPSTR CharPrev32A( LPCSTR start, LPCSTR ptr )
+LPSTR WINAPI CharPrev32A( LPCSTR start, LPCSTR ptr )
 {
     while (*start && (start < ptr))
     {
@@ -225,7 +225,7 @@
 /***********************************************************************
  *           CharPrevEx32A   (USER32.33)
  */
-LPSTR CharPrevEx32A( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
+LPSTR WINAPI CharPrevEx32A( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags )
 {
     while (*start && (start < ptr))
     {
@@ -240,7 +240,7 @@
 /***********************************************************************
  *           CharPrevExW   (USER32.34)
  */
-LPWSTR CharPrevEx32W(WORD codepage,LPCWSTR start,LPCWSTR x,DWORD flags)
+LPWSTR WINAPI CharPrevEx32W(WORD codepage,LPCWSTR start,LPCWSTR x,DWORD flags)
 {
     /* FIXME: add DBCS / codepage stuff */
     if (x>start) return (LPWSTR)(x-1);
@@ -250,7 +250,7 @@
 /***********************************************************************
  *           CharPrevW   (USER32.35)
  */
-LPWSTR CharPrev32W(LPCWSTR start,LPCWSTR x)
+LPWSTR WINAPI CharPrev32W(LPCWSTR start,LPCWSTR x)
 {
     if (x>start) return (LPWSTR)(x-1);
     else return (LPWSTR)x;
@@ -260,7 +260,7 @@
  *           CharLowerA   (USER32.24)
  * FIXME: handle current locale
  */
-LPSTR CharLower32A(LPSTR x)
+LPSTR WINAPI CharLower32A(LPSTR x)
 {
     LPSTR	s;
 
@@ -281,7 +281,7 @@
  *           CharLowerBuffA   (USER32.25)
  * FIXME: handle current locale
  */
-DWORD CharLowerBuff32A(LPSTR x,DWORD buflen)
+DWORD WINAPI CharLowerBuff32A(LPSTR x,DWORD buflen)
 {
     DWORD done=0;
 
@@ -298,7 +298,7 @@
  *           CharLowerBuffW   (USER32.26)
  * FIXME: handle current locale
  */
-DWORD CharLowerBuff32W(LPWSTR x,DWORD buflen)
+DWORD WINAPI CharLowerBuff32W(LPWSTR x,DWORD buflen)
 {
     DWORD done=0;
 
@@ -315,7 +315,7 @@
  *           CharLowerW   (USER32.27)
  * FIXME: handle current locale
  */
-LPWSTR CharLower32W(LPWSTR x)
+LPWSTR WINAPI CharLower32W(LPWSTR x)
 {
     if (HIWORD(x))
     {
@@ -334,7 +334,7 @@
  *           CharUpper32A   (USER32.40)
  * FIXME: handle current locale
  */
-LPSTR CharUpper32A(LPSTR x)
+LPSTR WINAPI CharUpper32A(LPSTR x)
 {
     if (HIWORD(x))
     {
@@ -353,7 +353,7 @@
  *           CharUpperBuffA   (USER32.41)
  * FIXME: handle current locale
  */
-DWORD CharUpperBuff32A(LPSTR x,DWORD buflen)
+DWORD WINAPI CharUpperBuff32A(LPSTR x,DWORD buflen)
 {
     DWORD done=0;
 
@@ -370,7 +370,7 @@
  *           CharUpperBuffW   (USER32.42)
  * FIXME: handle current locale
  */
-DWORD CharUpperBuff32W(LPWSTR x,DWORD buflen)
+DWORD WINAPI CharUpperBuff32W(LPWSTR x,DWORD buflen)
 {
     DWORD done=0;
 
@@ -387,7 +387,7 @@
  *           CharUpperW   (USER32.43)
  * FIXME: handle current locale
  */
-LPWSTR CharUpper32W(LPWSTR x)
+LPWSTR WINAPI CharUpper32W(LPWSTR x)
 {
     if (HIWORD(x))
     {
@@ -406,7 +406,7 @@
  *           IsCharAlphaA   (USER32.330)
  * FIXME: handle current locale
  */
-BOOL32 IsCharAlpha32A(CHAR x)
+BOOL32 WINAPI IsCharAlpha32A(CHAR x)
 {
     return isalpha(x);
 }
@@ -415,7 +415,7 @@
  *           IsCharAlphaNumericA   (USER32.331)
  * FIXME: handle current locale
  */
-BOOL32 IsCharAlphaNumeric32A(CHAR x)
+BOOL32 WINAPI IsCharAlphaNumeric32A(CHAR x)
 {
     return isalnum(x);
 }
@@ -424,7 +424,7 @@
  *           IsCharAlphaNumericW   (USER32.332)
  * FIXME: handle current locale
  */
-BOOL32 IsCharAlphaNumeric32W(WCHAR x)
+BOOL32 WINAPI IsCharAlphaNumeric32W(WCHAR x)
 {
     return isalnum(x);
 }
@@ -433,7 +433,7 @@
  *           IsCharAlphaW   (USER32.333)
  * FIXME: handle current locale
  */
-BOOL32 IsCharAlpha32W(WCHAR x)
+BOOL32 WINAPI IsCharAlpha32W(WCHAR x)
 {
     return isalpha(x);
 }
@@ -442,7 +442,7 @@
  *           IsCharLower32A   (USER32.334)
  * FIXME: handle current locale
  */
-BOOL32 IsCharLower32A(CHAR x)
+BOOL32 WINAPI IsCharLower32A(CHAR x)
 {
     return islower(x);
 }
@@ -451,7 +451,7 @@
  *           IsCharLower32W   (USER32.335)
  * FIXME: handle current locale
  */
-BOOL32 IsCharLower32W(WCHAR x)
+BOOL32 WINAPI IsCharLower32W(WCHAR x)
 {
     return islower(x);
 }
@@ -460,7 +460,7 @@
  *           IsCharUpper32A   (USER32.336)
  * FIXME: handle current locale
  */
-BOOL32 IsCharUpper32A(CHAR x)
+BOOL32 WINAPI IsCharUpper32A(CHAR x)
 {
     return isupper(x);
 }
@@ -469,7 +469,7 @@
  *           IsCharUpper32W   (USER32.337)
  * FIXME: handle current locale
  */
-BOOL32 IsCharUpper32W(WCHAR x)
+BOOL32 WINAPI IsCharUpper32W(WCHAR x)
 {
     return isupper(x);
 }
@@ -478,8 +478,7 @@
  *           FormatMessageA   (KERNEL32.138) Library Version
  * FIXME: missing wrap,FROM_SYSTEM message-loading,
  */
-DWORD
-FormatMessage32A(
+DWORD WINAPI FormatMessage32A(
 	DWORD	dwFlags,
 	LPCVOID	lpSource,
 	DWORD	dwMessageId,
@@ -647,8 +646,8 @@
 /***********************************************************************
  *           FormatMessageA   (KERNEL32.138) Emulator Version
  */
-DWORD
-WIN32_FormatMessage32A(DWORD *args) {
+DWORD WINAPI WIN32_FormatMessage32A(DWORD *args)
+{
 	DWORD	dwFlags		= args[0];
 	LPCVOID	lpSource	= (LPCVOID)args[1];
 	DWORD	dwMessageId	= args[2];
@@ -682,8 +681,7 @@
 	);
 }
 
-DWORD
-FormatMessage32W(
+DWORD WINAPI FormatMessage32W(
 	DWORD	dwFlags,
 	LPCVOID	lpSource,
 	DWORD	dwMessageId,
@@ -851,10 +849,10 @@
 #undef ADD_TO_T
 
 /***********************************************************************
- *           FormatMessageA   (KERNEL32.138) Emulator Version
+ *           FormatMessageW   (KERNEL32.138) Emulator Version
  */
-DWORD
-WIN32_FormatMessage32W(DWORD *args) {
+DWORD WINAPI WIN32_FormatMessage32W(DWORD *args)
+{
 	DWORD	dwFlags		= args[0];
 	LPCVOID	lpSource	= (LPCVOID)args[1];
 	DWORD	dwMessageId	= args[2];
diff --git a/misc/lzexpand.c b/misc/lzexpand.c
index 384096e..ba2b02d 100644
--- a/misc/lzexpand.c
+++ b/misc/lzexpand.c
@@ -118,7 +118,7 @@
 /***********************************************************************
  *           LZStart16   (LZEXPAND.7)
  */
-INT16 LZStart16(void)
+INT16 WINAPI LZStart16(void)
 {
     dprintf_file(stddeb,"LZStart16(void)\n");
     return 1;
@@ -128,7 +128,7 @@
 /***********************************************************************
  *           LZStart32   (LZ32.6)
  */
-INT32 LZStart32(void)
+INT32 WINAPI LZStart32(void)
 {
     dprintf_file(stddeb,"LZStart32(void)\n");
     return 1;
@@ -138,7 +138,7 @@
 /***********************************************************************
  *           LZInit16   (LZEXPAND.3)
  */
-HFILE16 LZInit16( HFILE16 hfSrc )
+HFILE16 WINAPI LZInit16( HFILE16 hfSrc )
 {
     return LZInit32( hfSrc );
 }
@@ -156,7 +156,7 @@
  * since _llseek uses the same types as libc.lseek, we just use the macros of 
  *  libc
  */
-HFILE32 LZInit32( HFILE32 hfSrc )
+HFILE32 WINAPI LZInit32( HFILE32 hfSrc )
 {
 
 	struct	lzfileheader	head;
@@ -193,7 +193,7 @@
 /***********************************************************************
  *           LZDone   (LZEXPAND.9) (LZ32.8)
  */
-void LZDone(void)
+void WINAPI LZDone(void)
 {
     dprintf_file(stddeb,"LZDone()\n");
 }
@@ -202,7 +202,7 @@
 /***********************************************************************
  *           GetExpandedName16   (LZEXPAND.10)
  */
-INT16 GetExpandedName16( LPCSTR in, LPSTR out )
+INT16 WINAPI GetExpandedName16( LPCSTR in, LPSTR out )
 {
     return (INT16)GetExpandedName32A( in, out );
 }
@@ -219,7 +219,7 @@
  * "FILE.BL_" (with lastchar 'a') is being translated to "FILE.BLA"
  */
 
-INT32 GetExpandedName32A( LPCSTR in, LPSTR out )
+INT32 WINAPI GetExpandedName32A( LPCSTR in, LPSTR out )
 {
 	struct lzfileheader	head;
 	HFILE32		fd;
@@ -289,7 +289,7 @@
 /***********************************************************************
  *           GetExpandedName32W   (LZ32.11)
  */
-INT32 GetExpandedName32W( LPCWSTR in, LPWSTR out )
+INT32 WINAPI GetExpandedName32W( LPCWSTR in, LPWSTR out )
 {
 	char	*xin,*xout;
 	INT32	ret;
@@ -307,7 +307,7 @@
 /***********************************************************************
  *           LZRead16   (LZEXPAND.5)
  */
-INT16 LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
+INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
 {
     return LZRead32(fd,buf,toread);
 }
@@ -316,7 +316,7 @@
 /***********************************************************************
  *           LZRead32   (LZ32.4)
  */
-INT32 LZRead32( HFILE32 fd, LPVOID vbuf, UINT32 toread )
+INT32 WINAPI LZRead32( HFILE32 fd, LPVOID vbuf, UINT32 toread )
 {
 	int	i,howmuch;
 	BYTE	b,*buf;
@@ -412,7 +412,7 @@
 /***********************************************************************
  *           LZSeek16   (LZEXPAND.4)
  */
-LONG LZSeek16( HFILE16 fd, LONG off, INT16 type )
+LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type )
 {
     return LZSeek32( fd, off, type );
 }
@@ -421,7 +421,7 @@
 /***********************************************************************
  *           LZSeek32   (LZ32.3)
  */
-LONG LZSeek32( HFILE32 fd, LONG off, INT32 type )
+LONG WINAPI LZSeek32( HFILE32 fd, LONG off, INT32 type )
 {
 	int	i;
 	struct	lzstate	*lzs;
@@ -459,7 +459,7 @@
 /***********************************************************************
  *           LZCopy16   (LZEXPAND.1)
  */
-LONG LZCopy16( HFILE16 src, HFILE16 dest )
+LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
 {
     return LZCopy32( src, dest );
 }
@@ -472,7 +472,7 @@
  * if src is a LZ compressed file, it will be uncompressed.
  * will return the number of bytes written to dest or errors.
  */
-LONG LZCopy32( HFILE32 src, HFILE32 dest )
+LONG WINAPI LZCopy32( HFILE32 src, HFILE32 dest )
 {
 	int	i,ret,wret;
 	LONG	len;
@@ -530,7 +530,7 @@
 /***********************************************************************
  *           LZOpenFile16   (LZEXPAND.2)
  */
-HFILE16 LZOpenFile16( LPCSTR fn, LPOFSTRUCT ofs, UINT16 mode )
+HFILE16 WINAPI LZOpenFile16( LPCSTR fn, LPOFSTRUCT ofs, UINT16 mode )
 {
     return LZOpenFile32A( fn, ofs, mode );
 }
@@ -541,7 +541,7 @@
  *
  * Opens a file. If not compressed, open it as a normal file.
  */
-HFILE32 LZOpenFile32A( LPCSTR fn, LPOFSTRUCT ofs, UINT32 mode )
+HFILE32 WINAPI LZOpenFile32A( LPCSTR fn, LPOFSTRUCT ofs, UINT32 mode )
 {
 	HFILE32	fd,cfd;
 
@@ -568,7 +568,7 @@
 /***********************************************************************
  *           LZOpenFile32W   (LZ32.10)
  */
-HFILE32 LZOpenFile32W( LPCWSTR fn, LPOFSTRUCT ofs, UINT32 mode )
+HFILE32 WINAPI LZOpenFile32W( LPCWSTR fn, LPOFSTRUCT ofs, UINT32 mode )
 {
 	LPSTR	xfn;
 	LPWSTR	yfn;
@@ -590,7 +590,7 @@
 /***********************************************************************
  *           LZClose16   (LZEXPAND.6)
  */
-void LZClose16( HFILE16 fd )
+void WINAPI LZClose16( HFILE16 fd )
 {
     return LZClose32( fd );
 }
@@ -599,7 +599,7 @@
 /***********************************************************************
  *           LZClose32   (LZ32.5)
  */
-void LZClose32( HFILE32 fd )
+void WINAPI LZClose32( HFILE32 fd )
 {
 	int	i;
 
@@ -622,7 +622,7 @@
 /***********************************************************************
  *           CopyLZFile16   (LZEXPAND.8)
  */
-LONG CopyLZFile16( HFILE16 src, HFILE16 dest )
+LONG WINAPI CopyLZFile16( HFILE16 src, HFILE16 dest )
 {
     dprintf_file(stddeb,"CopyLZFile16(%d,%d)\n",src,dest);
     return LZCopy32(src,dest);
@@ -635,7 +635,7 @@
  * Copy src to dest (including uncompressing src).
  * NOTE: Yes. This is exactly the same function as LZCopy.
  */
-LONG CopyLZFile32( HFILE32 src, HFILE32 dest )
+LONG WINAPI CopyLZFile32( HFILE32 src, HFILE32 dest )
 {
     dprintf_file(stddeb,"CopyLZFile32(%d,%d)\n",src,dest);
     return LZCopy32(src,dest);
diff --git a/misc/main.c b/misc/main.c
index 01cc321..3ef3384 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -102,9 +102,12 @@
 int screenWidth = 0, screenHeight = 0;  /* Desktop window dimensions */
 int screenDepth = 0;  /* Screen depth to use */
 int desktopX = 0, desktopY = 0;  /* Desktop window position (if any) */
-int getVersion16 = 0;
-int getVersion32 = 0;
-OSVERSIONINFO32A getVersionEx;
+
+/* Default version is the same as -winver win31 */
+static LONG getVersion16 = MAKELONG( WINVERSION, 0x0616 ); /* DOS 6.22 */
+static LONG getVersion32 = MAKELONG( 4, 0x1606 ); /* DOS 6.22 */
+static OSVERSIONINFO32A getVersionEx = { sizeof(OSVERSIONINFO32A), 3, 10, 0,
+                                         VER_PLATFORM_WIN32s, "Win32s 1.3" };
 
 struct options Options =
 {  /* default options */
@@ -692,7 +695,7 @@
 /***********************************************************************
  *           MessageBeep16   (USER.104)
  */
-void MessageBeep16( UINT16 i )
+void WINAPI MessageBeep16( UINT16 i )
 {
     MessageBeep32( i );
 }
@@ -701,7 +704,7 @@
 /***********************************************************************
  *           MessageBeep32   (USER32.389)
  */
-BOOL32 MessageBeep32( UINT32 i )
+BOOL32 WINAPI MessageBeep32( UINT32 i )
 {
     XBell( display, 100 );
     return TRUE;
@@ -711,7 +714,7 @@
 /***********************************************************************
  *           Beep   (KERNEL32.11)
  */
-BOOL32 Beep( DWORD dwFreq, DWORD dwDur )
+BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
 {
     /* dwFreq and dwDur are ignored by Win95 */
     XBell(display, 100);
@@ -722,43 +725,31 @@
 /***********************************************************************
  *      GetVersion16   (KERNEL.3)
  */
-LONG GetVersion16(void)
+LONG WINAPI GetVersion16(void)
 {
-    if (getVersion16) return getVersion16;
-    return MAKELONG( WINVERSION, WINDOSVER );
+    return getVersion16;
 }
 
 
 /***********************************************************************
  *      GetVersion32
  */
-LONG GetVersion32(void)
+LONG WINAPI GetVersion32(void)
 {
-    if (getVersion32) return getVersion32;
-    return MAKELONG( 4, DOSVERSION);
+    return getVersion32;
 }
 
 
 /***********************************************************************
  *      GetVersionExA
  */
-BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
+BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
 {
     if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
     {
         fprintf(stddeb,"wrong OSVERSIONINFO size from app");
         return FALSE;
     }
-    if(!getVersion32)
-    {
-        /* Return something like NT 3.5 */
-        v->dwMajorVersion = 3;
-        v->dwMinorVersion = 5;
-        v->dwBuildNumber = 42;
-        v->dwPlatformId = VER_PLATFORM_WIN32_NT;
-        strcpy(v->szCSDVersion, "Wine is not an emulator");
-        return TRUE;
-    }
     v->dwMajorVersion = getVersionEx.dwMajorVersion;
     v->dwMinorVersion = getVersionEx.dwMinorVersion;
     v->dwBuildNumber = getVersionEx.dwBuildNumber;
@@ -771,7 +762,7 @@
 /***********************************************************************
  *     GetVersionExW
  */
-BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
+BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
 {
 	OSVERSIONINFO32A v1;
 	if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
@@ -792,7 +783,7 @@
 /***********************************************************************
  *	GetWinFlags (KERNEL.132)
  */
-DWORD GetWinFlags(void)
+DWORD WINAPI GetWinFlags(void)
 {
   static const long cpuflags[5] =
     { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
@@ -827,7 +818,7 @@
 /***********************************************************************
  *          SetEnvironment   (GDI.132)
  */
-INT16 SetEnvironment( LPCSTR lpPortName, LPCSTR lpEnviron, UINT16 nCount )
+INT16 WINAPI SetEnvironment(LPCSTR lpPortName, LPCSTR lpEnviron, UINT16 nCount)
 {
     LPENVENTRY	lpNewEnv;
     LPENVENTRY	lpEnv = lpEnvList;
@@ -896,7 +887,7 @@
 /***********************************************************************
  *           GetEnvironment   (GDI.134)
  */
-INT16 GetEnvironment( LPCSTR lpPortName, LPSTR lpEnviron, UINT16 nMaxSiz )
+INT16 WINAPI GetEnvironment(LPCSTR lpPortName, LPSTR lpEnviron, UINT16 nMaxSiz)
 {
     WORD       nCount;
     LPENVENTRY lpEnv = lpEnvList;
@@ -921,7 +912,7 @@
 /***********************************************************************
  *	GetTimerResolution (USER.14)
  */
-LONG GetTimerResolution(void)
+LONG WINAPI GetTimerResolution(void)
 {
 	return (1000);
 }
@@ -929,8 +920,8 @@
 /***********************************************************************
  *	SystemParametersInfo32A   (USER32.539)
  */
-BOOL32 SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
-                                LPVOID lpvParam, UINT32 fuWinIni )
+BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
+                                       LPVOID lpvParam, UINT32 fuWinIni )
 {
 	int timeout, temp;
 	XKeyboardState		keyboard_state;
@@ -1007,7 +998,9 @@
 	case SPI_GETICONTITLELOGFONT: {
 		LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
 
-		GetProfileString32A("Desktop", "IconTitleFaceName", "Helvetica", 
+		/* from now on we always have an alias for MS Sans Serif */
+
+		GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif", 
 			lpLogFont->lfFaceName, LF_FACESIZE );
 		lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
 
@@ -1029,16 +1022,26 @@
 			GetSystemMetrics32( SM_CYSCREEN )
 		);
 		break;
-	case SPI_GETNONCLIENTMETRICS: {
-		/* FIXME: implement correctly */
-		LPNONCLIENTMETRICS32A	lpnm=(LPNONCLIENTMETRICS32A)lpvParam;
+	case SPI_GETNONCLIENTMETRICS: 
 
-		SystemParametersInfo32A(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
-		SystemParametersInfo32A(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
-		SystemParametersInfo32A(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
-		SystemParametersInfo32A(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
+#define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
+		
+		if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
+		{
+		    /* FIXME: initialize geometry entries */
+
+		    SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfCaptionFont),0);
+		    SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfMenuFont),0);
+		    SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfStatusFont),0);
+		    SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfMessageFont),0);
+		}
+#undef lpnm
 		break;
-	}
+
 	default:
 		return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
 	}
@@ -1049,8 +1052,8 @@
 /***********************************************************************
  *	SystemParametersInfo16   (USER.483)
  */
-BOOL16 SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
-                               LPVOID lpvParam, UINT16 fuWinIni )
+BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
+                                      LPVOID lpvParam, UINT16 fuWinIni )
 {
 	int timeout, temp;
 	char buffer[256];
@@ -1174,7 +1177,7 @@
 	        {
                     LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
 
-		    GetProfileString32A("Desktop", "IconTitleFaceName", "Helvetica", 
+		    GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif", 
 					lpLogFont->lfFaceName, LF_FACESIZE );
                     lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
 
@@ -1190,16 +1193,25 @@
                     lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
                     break;
                 }
-		case SPI_GETNONCLIENTMETRICS: {
-		/* FIXME: implement correctly */
-			LPNONCLIENTMETRICS16	lpnm=(LPNONCLIENTMETRICS16)lpvParam;
+		case SPI_GETNONCLIENTMETRICS:
 
-			SystemParametersInfo16(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
-			SystemParametersInfo16(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
-			SystemParametersInfo16(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
-			SystemParametersInfo16(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
-			break;
-		}
+#define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
+		    if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
+		    {
+			/* FIXME: initialize geometry entries */
+			SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0, 
+							(LPVOID)&(lpnm->lfCaptionFont),0);
+			SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfMenuFont),0);
+			SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfStatusFont),0);
+			SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
+							(LPVOID)&(lpnm->lfMessageFont),0);
+		    }
+		    else /* winfile 95 sets sbSize to 340 */
+		        SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
+#undef lpnm
+		    break;
 
 		case SPI_LANGDRIVER:
 		case SPI_SETBORDER:
@@ -1228,8 +1240,8 @@
 /***********************************************************************
  *	SystemParametersInfo32W   (USER32.540)
  */
-BOOL32 SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
-                                LPVOID lpvParam, UINT32 fuWinIni )
+BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
+                                       LPVOID lpvParam, UINT32 fuWinIni )
 {
     char buffer[256];
 
@@ -1295,7 +1307,7 @@
 /***********************************************************************
 *	FileCDR (KERNEL.130)
 */
-void FileCDR(FARPROC16 x)
+void WINAPI FileCDR(FARPROC16 x)
 {
 	printf("FileCDR(%8x)\n", (int) x);
 }
@@ -1303,7 +1315,7 @@
 /***********************************************************************
 *	GetWinDebugInfo (KERNEL.355)
 */
-BOOL16 GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
+BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
 {
 	printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
 	/* 0 means not in debugging mode/version */
@@ -1315,7 +1327,7 @@
 /***********************************************************************
 *	GetWinDebugInfo (KERNEL.355)
 */
-BOOL16 SetWinDebugInfo(WINDEBUGINFO *lpwdi)
+BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
 {
 	printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
 	/* 0 means not in debugging mode/version */
diff --git a/misc/mpr.c b/misc/mpr.c
index 6c7b674..3679aff 100644
--- a/misc/mpr.c
+++ b/misc/mpr.c
@@ -8,8 +8,7 @@
 #include "stddebug.h"
 #include "debug.h"
 
-DWORD
-WNetGetCachedPassword(
+DWORD WINAPI WNetGetCachedPassword(
 	LPSTR	pbResource,
 	WORD	cbResource,
 	LPSTR	pbPassword,
@@ -22,8 +21,7 @@
 	return 0;
 }
 
-DWORD
-MultinetGetConnectionPerformance32A(
+DWORD WINAPI MultinetGetConnectionPerformance32A(
 	LPNETRESOURCE32A lpNetResource,
 	LPNETCONNECTINFOSTRUCT lpNetConnectInfoStruct
 ) {
diff --git a/misc/network.c b/misc/network.c
index 5c1eace..3768fc9 100644
--- a/misc/network.c
+++ b/misc/network.c
@@ -35,7 +35,7 @@
 /**************************************************************************
  *              WNetErrorText       [USER.499]
  */
-int WNetErrorText(WORD nError,LPSTR lpszText,WORD cbText)
+int WINAPI WNetErrorText(WORD nError,LPSTR lpszText,WORD cbText)
 {
 	printf("EMPTY STUB !!! WNetErrorText(%x,%p,%x)\n",
 		nError,lpszText,cbText);
@@ -45,7 +45,7 @@
 /**************************************************************************
  *              WNetOpenJob       [USER.501]
  */
-int WNetOpenJob(LPSTR szQueue,LPSTR szJobTitle,WORD nCopies,LPWORD pfh)
+int WINAPI WNetOpenJob(LPSTR szQueue,LPSTR szJobTitle,WORD nCopies,LPWORD pfh)
 {
 	printf("EMPTY STUB !!! WNetOpenJob('%s','%s',%x,%p)\n",
 		szQueue,szJobTitle,nCopies,pfh);
@@ -55,7 +55,7 @@
 /**************************************************************************
  *              WNetCloseJob       [USER.502]
  */
-int WNetCloseJob(WORD fh,LPWORD pidJob,LPSTR szQueue)
+int WINAPI WNetCloseJob(WORD fh,LPWORD pidJob,LPSTR szQueue)
 {
 	printf("EMPTY STUB !!! WNetCloseJob(%x,%p,'%s')\n",
 		fh,pidJob,szQueue);
@@ -65,7 +65,7 @@
 /**************************************************************************
  *              WNetAbortJob       [USER.503]
  */
-int WNetAbortJob(LPSTR szQueue,WORD wJobId)
+int WINAPI WNetAbortJob(LPSTR szQueue,WORD wJobId)
 {
 	printf("EMPTY STUB !!! WNetAbortJob('%s',%x)\n",
 		szQueue,wJobId);
@@ -75,7 +75,7 @@
 /**************************************************************************
  *              WNetHoldJob       [USER.504]
  */
-int WNetHoldJob(LPSTR szQueue,WORD wJobId)
+int WINAPI WNetHoldJob(LPSTR szQueue,WORD wJobId)
 {
 	printf("EMPTY STUB !!! WNetHoldJob('%s',%x)\n",
 		szQueue,wJobId);
@@ -85,7 +85,7 @@
 /**************************************************************************
  *              WNetReleaseJob       [USER.505]
  */
-int WNetReleaseJob(LPSTR szQueue,WORD wJobId)
+int WINAPI WNetReleaseJob(LPSTR szQueue,WORD wJobId)
 {
 	printf("EMPTY STUB !!! WNetReleaseJob('%s',%x)\n",
 		szQueue,wJobId);
@@ -95,7 +95,7 @@
 /**************************************************************************
  *              WNetCancelJob       [USER.506]
  */
-int WNetCancelJob(LPSTR szQueue,WORD wJobId)
+int WINAPI WNetCancelJob(LPSTR szQueue,WORD wJobId)
 {
 	printf("EMPTY STUB !!! WNetCancelJob('%s',%x)\n",
 		szQueue,wJobId);
@@ -105,7 +105,7 @@
 /**************************************************************************
  *              WNetSetJobCopies       [USER.507]
  */
-int WNetSetJobCopies(LPSTR szQueue,WORD wJobId,WORD nCopies)
+int WINAPI WNetSetJobCopies(LPSTR szQueue,WORD wJobId,WORD nCopies)
 {
 	printf("EMPTY STUB !!! WNetSetJobCopies('%s',%x,%x)\n",
 		szQueue,wJobId,nCopies);
@@ -115,7 +115,7 @@
 /**************************************************************************
  *              WNetWatchQueue       [USER.508]
  */
-int WNetWatchQueue(HWND16 hWnd,LPSTR szLocal,LPSTR szUser,WORD nQueue)
+int WINAPI WNetWatchQueue(HWND16 hWnd,LPSTR szLocal,LPSTR szUser,WORD nQueue)
 {
 	printf("EMPTY STUB !!! WNetWatchQueue(%04x,'%s','%s',%x)\n",
 		hWnd,szLocal,szUser,nQueue);
@@ -125,7 +125,7 @@
 /**************************************************************************
  *              WNetUnwatchQueue       [USER.509]
  */
-int WNetUnwatchQueue(LPSTR szQueue)
+int WINAPI WNetUnwatchQueue(LPSTR szQueue)
 {
 	printf("EMPTY STUB !!! WNetUnwatchQueue('%s')\n", szQueue);
 	return WN_NET_ERROR;
@@ -134,7 +134,7 @@
 /**************************************************************************
  *              WNetLockQueueData       [USER.510]
  */
-int WNetLockQueueData(LPSTR szQueue,LPSTR szUser,void *lplpQueueStruct)
+int WINAPI WNetLockQueueData(LPSTR szQueue,LPSTR szUser,void *lplpQueueStruct)
 {
 	printf("EMPTY STUB !!! WNetLockQueueData('%s','%s',%p)\n",
 		szQueue,szUser,lplpQueueStruct);
@@ -144,7 +144,7 @@
 /**************************************************************************
  *              WNetUnlockQueueData       [USER.511]
  */
-int WNetUnlockQueueData(LPSTR szQueue)
+int WINAPI WNetUnlockQueueData(LPSTR szQueue)
 {
 	printf("EMPTY STUB !!! WNetUnlockQueueData('%s')\n",szQueue);
 	return WN_NET_ERROR;
@@ -153,8 +153,8 @@
 /**************************************************************************
  *				WNetGetConnection	[USER.512]
  */
-int WNetGetConnection(LPSTR lpLocalName, 
-	LPSTR lpRemoteName, UINT16 *cbRemoteName)
+int WINAPI WNetGetConnection(LPSTR lpLocalName, 
+                             LPSTR lpRemoteName, UINT16 *cbRemoteName)
 {
     const char *path;
 
@@ -183,7 +183,7 @@
 /**************************************************************************
  *				WNetGetCaps		[USER.513]
  */
-int WNetGetCaps(WORD capability)
+int WINAPI WNetGetCaps(WORD capability)
 {
 	return 0;
 }
@@ -191,7 +191,7 @@
 /**************************************************************************
  *              WNetDeviceMode       [USER.514]
  */
-int WNetDeviceMode(HWND16 hWndOwner)
+int WINAPI WNetDeviceMode(HWND16 hWndOwner)
 {
 	printf("EMPTY STUB !!! WNetDeviceMode(%04x)\n",hWndOwner);
 	return WN_NET_ERROR;
@@ -200,7 +200,7 @@
 /**************************************************************************
  *              WNetBrowseDialog       [USER.515]
  */
-int WNetBrowseDialog(HWND16 hParent,WORD nType,LPSTR szPath)
+int WINAPI WNetBrowseDialog(HWND16 hParent,WORD nType,LPSTR szPath)
 {
 	printf("EMPTY STUB !!! WNetBrowseDialog(%04x,%x,'%s')\n",
 		hParent,nType,szPath);
@@ -210,7 +210,7 @@
 /**************************************************************************
  *				WNetGetUser			[USER.516]
  */
-UINT16 WNetGetUser(LPSTR lpLocalName, LPSTR lpUserName, DWORD *lpSize)
+UINT16 WINAPI WNetGetUser(LPSTR lpLocalName, LPSTR lpUserName, DWORD *lpSize)
 {
 	printf("EMPTY STUB !!! WNetGetUser(%p, %p, %p);\n", 
 							lpLocalName, lpUserName, lpSize);
@@ -220,7 +220,8 @@
 /**************************************************************************
  *				WNetAddConnection	[USER.517]
  */
-UINT16 WNetAddConnection(LPSTR lpNetPath, LPSTR lpPassWord, LPSTR lpLocalName)
+UINT16 WINAPI WNetAddConnection(LPSTR lpNetPath, LPSTR lpPassWord,
+                                LPSTR lpLocalName)
 {
 	printf("EMPTY STUB !!! WNetAddConnection('%s', %p, '%s');\n",
 							lpNetPath, lpPassWord, lpLocalName);
@@ -231,7 +232,7 @@
 /**************************************************************************
  *				WNetCancelConnection	[USER.518]
  */
-UINT16 WNetCancelConnection(LPSTR lpName, BOOL16 bForce)
+UINT16 WINAPI WNetCancelConnection(LPSTR lpName, BOOL16 bForce)
 {
     printf("EMPTY STUB !!! WNetCancelConnection('%s', %04X);\n",
            lpName, bForce);
@@ -241,7 +242,7 @@
 /**************************************************************************
  *              WNetGetError       [USER.519]
  */
-int WNetGetError(LPWORD nError)
+int WINAPI WNetGetError(LPWORD nError)
 {
 	printf("EMPTY STUB !!! WNetGetError(%p)\n",nError);
 	return WN_NET_ERROR;
@@ -250,7 +251,7 @@
 /**************************************************************************
  *              WNetGetErrorText       [USER.520]
  */
-int WNetGetErrorText(WORD nError, LPSTR lpBuffer, LPWORD nBufferSize)
+int WINAPI WNetGetErrorText(WORD nError, LPSTR lpBuffer, LPWORD nBufferSize)
 {
 	printf("EMPTY STUB !!! WNetGetErrorText(%x,%p,%p)\n",
 		nError,lpBuffer,nBufferSize);
@@ -260,7 +261,7 @@
 /**************************************************************************
  *              WNetRestoreConnection       [USER.523]
  */
-int WNetRestoreConnection(HWND16 hwndOwner,LPSTR lpszDevice)
+int WINAPI WNetRestoreConnection(HWND16 hwndOwner,LPSTR lpszDevice)
 {
 	printf("EMPTY STUB !!! WNetRestoreConnection(%04x,'%s')\n",
 		hwndOwner,lpszDevice);
@@ -270,7 +271,7 @@
 /**************************************************************************
  *              WNetWriteJob       [USER.524]
  */
-int WNetWriteJob(HANDLE16 hJob,void *lpData,LPWORD lpcbData)
+int WINAPI WNetWriteJob(HANDLE16 hJob,void *lpData,LPWORD lpcbData)
 {
 	printf("EMPTY STUB !!! WNetWriteJob(%04x,%p,%p)\n",
 		hJob,lpData,lpcbData);
@@ -280,7 +281,7 @@
 /**************************************************************************
  *              WnetConnectDialog       [USER.525]
  */
-UINT16 WNetConnectDialog(HWND16 hWndParent, WORD iType)
+UINT16 WINAPI WNetConnectDialog(HWND16 hWndParent, WORD iType)
 {
 	printf("EMPTY STUB !!! WNetConnectDialog(%04x, %4X)\n", hWndParent, iType);
 	return WN_SUCCESS;
@@ -289,7 +290,7 @@
 /**************************************************************************
  *              WNetDisconnectDialog       [USER.526]
  */
-int WNetDisconnectDialog(HWND16 hwndOwner, WORD iType)
+int WINAPI WNetDisconnectDialog(HWND16 hwndOwner, WORD iType)
 {
 	printf("EMPTY STUB !!! WNetDisconnectDialog(%04x,%x)\n",
 		hwndOwner,iType);
@@ -299,7 +300,7 @@
 /**************************************************************************
  *              WnetConnectionDialog     [USER.527]
  */
-UINT16 WNetConnectionDialog(HWND16 hWndParent, WORD iType)
+UINT16 WINAPI WNetConnectionDialog(HWND16 hWndParent, WORD iType)
 {
 	printf("EMPTY STUB !!! WNetConnectionDialog(%04x, %4X)\n", 
 		hWndParent, iType);
@@ -309,7 +310,7 @@
 /**************************************************************************
  *              WNetViewQueueDialog       [USER.528]
  */
-int WNetViewQueueDialog(HWND16 hwndOwner,LPSTR lpszQueue)
+int WINAPI WNetViewQueueDialog(HWND16 hwndOwner,LPSTR lpszQueue)
 {
 	printf("EMPTY STUB !!! WNetViewQueueDialog(%04x,'%s')\n",
 		hwndOwner,lpszQueue);
@@ -319,8 +320,8 @@
 /**************************************************************************
  *              WNetPropertyDialog       [USER.529]
  */
-int WNetPropertyDialog(HWND16 hwndParent,WORD iButton,
-	WORD nPropSel,LPSTR lpszName,WORD nType)
+int WINAPI WNetPropertyDialog(HWND16 hwndParent,WORD iButton,
+                              WORD nPropSel,LPSTR lpszName,WORD nType)
 {
 	printf("EMPTY STUB !!! WNetPropertyDialog(%04x,%x,%x,'%s',%x)\n",
 		hwndParent,iButton,nPropSel,lpszName,nType);
@@ -330,7 +331,7 @@
 /**************************************************************************
  *              WNetGetDirectoryType       [USER.530]
  */
-int WNetGetDirectoryType(LPSTR lpName,void *lpType)
+int WINAPI WNetGetDirectoryType(LPSTR lpName,void *lpType)
 {
 	printf("EMPTY STUB !!! WNetGetDirectoryType('%s',%p)\n",
 		lpName,lpType);
@@ -340,7 +341,7 @@
 /**************************************************************************
  *              WNetDirectoryNotify       [USER.531]
  */
-int WNetDirectoryNotify(HWND16 hwndOwner,void *lpDir,WORD wOper)
+int WINAPI WNetDirectoryNotify(HWND16 hwndOwner,void *lpDir,WORD wOper)
 {
 	printf("EMPTY STUB !!! WNetDirectoryNotify(%04x,%p,%x)\n",
 		hwndOwner,lpDir,wOper);
@@ -350,8 +351,8 @@
 /**************************************************************************
  *              WNetGetPropertyText       [USER.532]
  */
-int WNetGetPropertyText(HWND16 hwndParent,WORD iButton,WORD nPropSel,
-	LPSTR lpszName,WORD nType)
+int WINAPI WNetGetPropertyText(HWND16 hwndParent,WORD iButton,WORD nPropSel,
+                               LPSTR lpszName,WORD nType)
 {
 	printf("EMPTY STUB !!! WNetGetPropertyText(%04x,%x,%x,'%s',%x)\n",
 		hwndParent,iButton,nPropSel,lpszName,nType);
@@ -361,8 +362,8 @@
 /**************************************************************************
  *				WNetAddConnection2	[USER.???]
  */
-UINT16 WNetAddConnection2(LPSTR lpNetPath, LPSTR lpPassWord, 
-		LPSTR lpLocalName, LPSTR lpUserName)
+UINT16 WINAPI WNetAddConnection2(LPSTR lpNetPath, LPSTR lpPassWord, 
+                                 LPSTR lpLocalName, LPSTR lpUserName)
 {
 	printf("EMPTY STUB !!! WNetAddConnection2('%s', %p, '%s', '%s');\n",
 					lpNetPath, lpPassWord, lpLocalName, lpUserName);
@@ -372,7 +373,7 @@
 /**************************************************************************
  *				WNetCloseEnum		[USER.???]
  */
-UINT16 WNetCloseEnum(HANDLE16 hEnum)
+UINT16 WINAPI WNetCloseEnum(HANDLE16 hEnum)
 {
 	printf("EMPTY STUB !!! WNetCloseEnum(%04x);\n", hEnum);
 	return WN_NET_ERROR;
@@ -381,8 +382,8 @@
 /**************************************************************************
  *				WNetEnumResource	[USER.???]
  */
-UINT16 WNetEnumResource(HANDLE16 hEnum, DWORD cRequ, 
-				DWORD *lpCount, LPVOID lpBuf)
+UINT16 WINAPI WNetEnumResource(HANDLE16 hEnum, DWORD cRequ, 
+                               DWORD *lpCount, LPVOID lpBuf)
 {
 	printf("EMPTY STUB !!! WNetEnumResource(%04x, %08lX, %p, %p);\n", 
 							hEnum, cRequ, lpCount, lpBuf);
@@ -392,8 +393,8 @@
 /**************************************************************************
  *				WNetOpenEnum		[USER.???]
  */
-UINT16 WNetOpenEnum(DWORD dwScope, DWORD dwType, 
-                    LPNETRESOURCE lpNet, HANDLE16 *lphEnum)
+UINT16 WINAPI WNetOpenEnum(DWORD dwScope, DWORD dwType, 
+                           LPNETRESOURCE lpNet, HANDLE16 *lphEnum)
 {
 	printf("EMPTY STUB !!! WNetOpenEnum(%08lX, %08lX, %p, %p);\n",
                dwScope, dwType, lpNet, lphEnum);
diff --git a/misc/ntdll.c b/misc/ntdll.c
index cd430dc..43b6a5d 100644
--- a/misc/ntdll.c
+++ b/misc/ntdll.c
@@ -22,24 +22,24 @@
 /**************************************************************************
  *                 RtlLengthRequiredSid			[NTDLL]
  */
-DWORD
-RtlLengthRequiredSid(DWORD nrofsubauths) {
+DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
+{
 	return sizeof(DWORD)*nrofsubauths+sizeof(SID);
 }
 
 /**************************************************************************
  *                 RtlLengthSid				[NTDLL]
  */
-DWORD
-RtlLengthSid(LPSID sid) {
+DWORD WINAPI RtlLengthSid(LPSID sid)
+{
 	return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
 }
 
 /**************************************************************************
  *                 RtlCreateAcl				[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlCreateAcl(LPACL acl,DWORD size,DWORD rev) {
+DWORD /* NTSTATUS */ WINAPI RtlCreateAcl(LPACL acl,DWORD size,DWORD rev)
+{
 	if (rev!=ACL_REVISION)
 		return STATUS_INVALID_PARAMETER;
 	if (size<sizeof(ACL))
@@ -59,8 +59,8 @@
  * looks for the AceCount+1 ACE, and if it is still within the alloced
  * ACL, return a pointer to it
  */
-BOOL32
-RtlFirstFreeAce(LPACL acl,LPACE_HEADER *x) {
+BOOL32 WINAPI RtlFirstFreeAce(LPACL acl,LPACE_HEADER *x)
+{
 	LPACE_HEADER	ace;
 	int		i;
 
@@ -80,8 +80,9 @@
 /**************************************************************************
  *                 RtlAddAce				[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlAddAce(LPACL acl,DWORD rev,DWORD xnrofaces,LPACE_HEADER acestart,DWORD acelen){
+DWORD /* NTSTATUS */  WINAPI RtlAddAce(LPACL acl,DWORD rev,DWORD xnrofaces,
+                                       LPACE_HEADER acestart,DWORD acelen)
+{
 	LPACE_HEADER	ace,targetace;
 	int		nrofaces;
 
@@ -104,8 +105,8 @@
 /**************************************************************************
  *                 RtlCreateSecurityDescriptor		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd,DWORD rev) {
+DWORD /* NTSTATUS */ WINAPI RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd,DWORD rev)
+{
 	if (rev!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	memset(lpsd,'\0',sizeof(*lpsd));
@@ -116,10 +117,8 @@
 /**************************************************************************
  *                 RtlSetDaclSecurityDescriptor		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlSetDaclSecurityDescriptor (
-LPSECURITY_DESCRIPTOR lpsd,BOOL32 daclpresent,LPACL dacl,BOOL32 dacldefaulted
-) {
+DWORD /* NTSTATUS */ WINAPI RtlSetDaclSecurityDescriptor ( LPSECURITY_DESCRIPTOR lpsd,BOOL32 daclpresent,LPACL dacl,BOOL32 dacldefaulted )
+{
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	if (lpsd->Control & SE_SELF_RELATIVE)
@@ -140,10 +139,10 @@
 /**************************************************************************
  *                 RtlSetSaclSecurityDescriptor		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlSetSaclSecurityDescriptor (
+DWORD /* NTSTATUS */ WINAPI RtlSetSaclSecurityDescriptor (
 LPSECURITY_DESCRIPTOR lpsd,BOOL32 saclpresent,LPACL sacl,BOOL32 sacldefaulted
-) {
+)
+{
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	if (lpsd->Control & SE_SELF_RELATIVE)
@@ -164,8 +163,8 @@
 /**************************************************************************
  *                 RtlSetOwnerSecurityDescriptor		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID owner,BOOL32 ownerdefaulted) {
+DWORD /* NTSTATUS */ WINAPI RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID owner,BOOL32 ownerdefaulted)
+{
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	if (lpsd->Control & SE_SELF_RELATIVE)
@@ -182,8 +181,8 @@
 /**************************************************************************
  *                 RtlSetOwnerSecurityDescriptor		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID group,BOOL32 groupdefaulted) {
+DWORD /* NTSTATUS */ WINAPI RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID group,BOOL32 groupdefaulted)
+{
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	if (lpsd->Control & SE_SELF_RELATIVE)
@@ -201,8 +200,7 @@
 /**************************************************************************
  *                 RtlNormalizeProcessParams		[NTDLL]
  */
-LPVOID
-RtlNormalizeProcessParams(LPVOID x)
+LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
 {
     fprintf(stdnimp,"RtlNormalizeProcessParams(%p), stub.\n",x);
     return x;
@@ -211,8 +209,9 @@
 /**************************************************************************
  *                 RtlInitializeSid			[NTDLL]
  */
-DWORD
-RtlInitializeSid(LPSID lpsid,LPSID_IDENTIFIER_AUTHORITY lpsidauth,DWORD c) {
+DWORD WINAPI RtlInitializeSid(LPSID lpsid,LPSID_IDENTIFIER_AUTHORITY lpsidauth,
+                              DWORD c)
+{
 	BYTE	a = c&0xff;
 
 	if (a>=SID_MAX_SUB_AUTHORITIES)
@@ -226,24 +225,24 @@
 /**************************************************************************
  *                 RtlSubAuthoritySid			[NTDLL]
  */
-LPDWORD
-RtlSubAuthoritySid(LPSID lpsid,DWORD nr) {
+LPDWORD WINAPI RtlSubAuthoritySid(LPSID lpsid,DWORD nr)
+{
 	return &(lpsid->SubAuthority[nr]);
 }
 
 /**************************************************************************
  *                 RtlSubAuthorityCountSid		[NTDLL]
  */
-LPBYTE
-RtlSubAuthorityCountSid(LPSID lpsid) {
+LPBYTE WINAPI RtlSubAuthorityCountSid(LPSID lpsid)
+{
 	return ((LPBYTE)lpsid)+1;
 }
 
 /**************************************************************************
  *                 RtlCopySid				[NTDLL]
  */
-DWORD
-RtlCopySid(DWORD len,LPSID to,LPSID from) {
+DWORD WINAPI RtlCopySid(DWORD len,LPSID to,LPSID from)
+{
 	if (len<(from->SubAuthorityCount*4+8))
 		return STATUS_BUFFER_TOO_SMALL;
 	memmove(to,from,from->SubAuthorityCount*4+8);
@@ -253,8 +252,8 @@
 /**************************************************************************
  *                 RtlAnsiStringToUnicodeString		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni,LPANSI_STRING ansi,BOOL32 doalloc) {
+DWORD /* NTSTATUS */ WINAPI RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni,LPANSI_STRING ansi,BOOL32 doalloc)
+{
 	DWORD	unilen = (ansi->Length+1)*sizeof(WCHAR);
 
 	if (unilen>0xFFFF)
@@ -275,8 +274,8 @@
 /**************************************************************************
  *                 RtlOemStringToUnicodeString		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlOemStringToUnicodeString(LPUNICODE_STRING uni,LPSTRING ansi,BOOL32 doalloc) {
+DWORD /* NTSTATUS */ WINAPI RtlOemStringToUnicodeString(LPUNICODE_STRING uni,LPSTRING ansi,BOOL32 doalloc)
+{
 	DWORD	unilen = (ansi->Length+1)*sizeof(WCHAR);
 
 	if (unilen>0xFFFF)
@@ -297,8 +296,8 @@
  *                 RtlMultiByteToUnicodeN		[NTDLL]
  * FIXME: multibyte support
  */
-DWORD /* NTSTATUS */
-RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen) {
+DWORD /* NTSTATUS */ WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
+{
 	DWORD	len;
 	LPWSTR	x;
 
@@ -315,8 +314,8 @@
 /**************************************************************************
  *                 RtlOemToUnicodeN			[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen) {
+DWORD /* NTSTATUS */ WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
+{
 	DWORD	len;
 	LPWSTR	x;
 
@@ -333,8 +332,8 @@
 /**************************************************************************
  *                 RtlInitString			[NTDLL]
  */
-VOID
-RtlInitAnsiString(LPANSI_STRING target,LPCSTR source) {
+VOID WINAPI RtlInitAnsiString(LPANSI_STRING target,LPCSTR source)
+{
 	target->Length = target->MaximumLength = 0;
 	target->Buffer = (LPSTR)source;
 	if (!source)
@@ -345,8 +344,8 @@
 /**************************************************************************
  *                 RtlInitString			[NTDLL]
  */
-VOID
-RtlInitString(LPSTRING target,LPCSTR source) {
+VOID WINAPI RtlInitString(LPSTRING target,LPCSTR source)
+{
 	target->Length = target->MaximumLength = 0;
 	target->Buffer = (LPSTR)source;
 	if (!source)
@@ -358,8 +357,8 @@
 /**************************************************************************
  *                 RtlInitUnicodeString			[NTDLL]
  */
-VOID
-RtlInitUnicodeString(LPUNICODE_STRING target,LPCWSTR source) {
+VOID WINAPI RtlInitUnicodeString(LPUNICODE_STRING target,LPCWSTR source)
+{
 	target->Length = target->MaximumLength = 0;
 	target->Buffer = (LPWSTR)source;
 	if (!source)
@@ -371,8 +370,8 @@
 /**************************************************************************
  *                 RtlFreeUnicodeString			[NTDLL]
  */
-VOID
-RtlFreeUnicodeString(LPUNICODE_STRING str) {
+VOID WINAPI RtlFreeUnicodeString(LPUNICODE_STRING str)
+{
 	if (str->Buffer)
 		HeapFree(GetProcessHeap(),0,str->Buffer);
 }
@@ -380,8 +379,8 @@
 /**************************************************************************
  *                 RtlUnicodeToOemN			[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen) {
+DWORD /* NTSTATUS */ WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen)
+{
 	DWORD	len;
 	LPSTR	x;
 
@@ -398,8 +397,7 @@
 /**************************************************************************
  *                 RtlUnicodeStringToOemString		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlUnicodeStringToOemString(LPANSI_STRING oem,LPUNICODE_STRING uni,BOOL32 alloc)
+DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToOemString(LPANSI_STRING oem,LPUNICODE_STRING uni,BOOL32 alloc)
 {
 	if (alloc) {
 		oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
@@ -413,8 +411,7 @@
 /**************************************************************************
  *                 RtlUnicodeStringToAnsiString		[NTDLL]
  */
-DWORD /* NTSTATUS */
-RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni,LPANSI_STRING oem,BOOL32 alloc)
+DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni,LPANSI_STRING oem,BOOL32 alloc)
 {
 	if (alloc) {
 		oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
@@ -428,8 +425,8 @@
 /**************************************************************************
  *                 RtlNtStatusToDosErro			[NTDLL]
  */
-DWORD
-RtlNtStatusToDosError(DWORD error) {
+DWORD WINAPI RtlNtStatusToDosError(DWORD error)
+{
 	/* FIXME: map STATUS_ to ERROR_ */
 	return error;
 }
@@ -437,8 +434,8 @@
 /**************************************************************************
  *                 RtlGetNtProductType			[NTDLL]
  */
-DWORD
-RtlGetNtProductType(LPVOID x) {
+DWORD WINAPI RtlGetNtProductType(LPVOID x)
+{
 	/* FIXME : find documentation for this one */
 	return 0;
 }
@@ -446,8 +443,8 @@
 /**************************************************************************
  *                 RtlUpcaseUnicodeString		[NTDLL]
  */
-DWORD
-RtlUpcaseUnicodeString(LPUNICODE_STRING dest,LPUNICODE_STRING src,BOOL32 doalloc) {
+DWORD WINAPI RtlUpcaseUnicodeString(LPUNICODE_STRING dest,LPUNICODE_STRING src,BOOL32 doalloc)
+{
 	LPWSTR	s,t;
 	DWORD	i,len;
 
@@ -471,16 +468,16 @@
 /**************************************************************************
  *                 RtlxOemStringToUnicodeSize		[NTDLL]
  */
-UINT32
-RtlxOemStringToUnicodeSize(LPSTRING str) {
+UINT32 WINAPI RtlxOemStringToUnicodeSize(LPSTRING str)
+{
 	return str->Length*2+2;
 }
 
 /**************************************************************************
  *                 RtlxAnsiStringToUnicodeSize		[NTDLL]
  */
-UINT32
-RtlxAnsiStringToUnicodeSize(LPANSI_STRING str) {
+UINT32 WINAPI RtlxAnsiStringToUnicodeSize(LPANSI_STRING str)
+{
 	return str->Length*2+2;
 }
 
@@ -489,10 +486,9 @@
  *
  * FIXME: convert to UNC or whatever is expected here
  */
-BOOL32 
-RtlDosPathNameToNtPathName_U(
-	LPWSTR from,LPUNICODE_STRING us,DWORD x2,DWORD x3
-) {
+BOOL32  WINAPI RtlDosPathNameToNtPathName_U(
+	LPWSTR from,LPUNICODE_STRING us,DWORD x2,DWORD x3)
+{
 	LPSTR	fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
 
 	fprintf(stderr,"RtlDosPathNameToNtPathName_U(%s,%p,%08lx,%08lx)\n",
@@ -506,8 +502,8 @@
 /**************************************************************************
  *                 NtOpenFile				[NTDLL]
  */
-DWORD
-NtOpenFile(DWORD x1,DWORD flags,DWORD x3,DWORD x4,DWORD alignment,DWORD x6) {
+DWORD WINAPI NtOpenFile(DWORD x1,DWORD flags,DWORD x3,DWORD x4,DWORD alignment,DWORD x6)
+{
 	fprintf(stderr,"NtOpenFile(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx)\n",
 		x1,flags,x3,x4,alignment,x6
 	);
diff --git a/misc/ole2.c b/misc/ole2.c
index 3ca5010..5f65195 100644
--- a/misc/ole2.c
+++ b/misc/ole2.c
@@ -15,7 +15,7 @@
 /***********************************************************************
  *           OleBuildVersion     [OLE.1]
  */
-DWORD OleBuildVersion()
+DWORD WINAPI OleBuildVersion()
 {
 	dprintf_ole(stddeb,"OleBuildVersion()\n");
 	return (rmm<<16)+rup;
@@ -24,7 +24,7 @@
 /***********************************************************************
  *           OleInitialize       [OLE2.2]
  */
-HRESULT OleInitialize(LPVOID reserved)
+HRESULT WINAPI OleInitialize(LPVOID reserved)
 {
     dprintf_ole(stdnimp,"OleInitialize\n");
 	return S_OK;
@@ -33,7 +33,7 @@
 /***********************************************************************
  *           OleUnitialize       [OLE2.3]
  */
-void OleUninitialize()
+void WINAPI OleUninitialize()
 {
 	dprintf_ole(stdnimp,"OleUninitialize()\n");
 }
diff --git a/misc/ole2disp.c b/misc/ole2disp.c
index 69a08bf..76f6181 100644
--- a/misc/ole2disp.c
+++ b/misc/ole2disp.c
@@ -36,7 +36,7 @@
 /***********************************************************************
  *           SysAllocString         [OLE2DISP.2]
  */
-BSTR SysAllocString(char *in)
+BSTR WINAPI SysAllocString(char *in)
 {
 	BSTR out=BSTR_AllocBytes(strlen(in)+1);
 	if(!out)return 0;
@@ -47,7 +47,7 @@
 /***********************************************************************
  *           SysReAllocString       [OLE2DISP.3]
  */
-int SysReAllocString(BSTR *old,char *in)
+int WINAPI SysReAllocString(BSTR *old,char *in)
 {
 	BSTR new=SysAllocString(in);
 	BSTR_Free(*old);
@@ -58,7 +58,7 @@
 /***********************************************************************
  *           SysAllocStringLen      [OLE2DISP.4]
  */
-BSTR SysAllocStringLen(char *in, int len)
+BSTR WINAPI SysAllocStringLen(char *in, int len)
 {
 	BSTR out=BSTR_AllocBytes(len+1);
 	if(!out)return 0;
@@ -69,7 +69,7 @@
 /***********************************************************************
  *           SysReAllocStringLen    [OLE2DISP.5]
  */
-int SysReAllocStringLen(BSTR *old,char *in,int len)
+int WINAPI SysReAllocStringLen(BSTR *old,char *in,int len)
 {
 	BSTR new=SysAllocStringLen(in,len);
 	BSTR_Free(*old);
@@ -80,7 +80,7 @@
 /***********************************************************************
  *           SysFreeString          [OLE2DISP.6]
  */
-void SysFreeString(BSTR in)
+void WINAPI SysFreeString(BSTR in)
 {
 	BSTR_Free(in);
 }
@@ -88,7 +88,7 @@
 /***********************************************************************
  *           SysStringLen           [OLE2DISP.7]
  */
-int SysStringLen(BSTR str)
+int WINAPI SysStringLen(BSTR str)
 {
 	return strlen(BSTR_GetAddr(str));
 }
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index 53ad95ee..df08c93 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -183,7 +183,7 @@
 /***********************************************************************
  *           GetUserDefaultLCID       (OLE2NLS.1)
  */
-DWORD GetUserDefaultLCID()
+DWORD WINAPI GetUserDefaultLCID()
 {
 /* Default sorting, neutral sublanguage */
     switch(Options.language)
@@ -224,7 +224,7 @@
 /***********************************************************************
  *         GetSystemDefaultLCID       (OLE2NLS.2)
  */
-DWORD GetSystemDefaultLCID()
+DWORD WINAPI GetSystemDefaultLCID()
 {
 	return GetUserDefaultLCID();
 }
@@ -232,7 +232,7 @@
 /***********************************************************************
  *         GetUserDefaultLangID       (OLE2NLS.3)
  */
-WORD GetUserDefaultLangID()
+WORD WINAPI GetUserDefaultLangID()
 {
 	return (WORD)GetUserDefaultLCID();
 }
@@ -240,7 +240,7 @@
 /***********************************************************************
  *         GetSystemDefaultLangID     (OLE2NLS.4)
  */
-WORD GetSystemDefaultLangID()
+WORD WINAPI GetSystemDefaultLangID()
 {
 	return GetUserDefaultLangID();
 }
@@ -249,12 +249,12 @@
  *         GetLocaleInfoA             (OLE2NLS.5)
  * Is the last parameter really WORD for Win16?
  */
-INT16 GetLocaleInfo16(LCID lcid,LCTYPE LCType,LPSTR buf,INT16 len)
+INT16 WINAPI GetLocaleInfo16(LCID lcid,LCTYPE LCType,LPSTR buf,INT16 len)
 {
 	return GetLocaleInfo32A(lcid,LCType,buf,len);
 }
 
-INT32 GetLocaleInfo32A(LCID lcid,LCTYPE LCType,LPSTR buf,INT32 len)
+INT32 WINAPI GetLocaleInfo32A(LCID lcid,LCTYPE LCType,LPSTR buf,INT32 len)
 {
 	char	*retString;
 	int	found,i;
@@ -1696,7 +1696,7 @@
  *         GetLocaleInfo32W             (KERNEL32.230)
  * Is the last parameter really WORD for Win16?
  */
-INT32 GetLocaleInfo32W(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT32 len)
+INT32 WINAPI GetLocaleInfo32W(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT32 len)
 {
 	LPSTR abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
 
@@ -1710,8 +1710,8 @@
 /***********************************************************************
  *           CompareString16       (OLE2NLS.8)
  */
-UINT16 CompareString16(DWORD lcid,DWORD fdwStyle,
-	LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
+UINT16 WINAPI CompareString16(DWORD lcid,DWORD fdwStyle,
+                              LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
 {
 	return (UINT16)CompareString32A(lcid,fdwStyle,s1,l1,s2,l2);
 }
@@ -1721,8 +1721,8 @@
  * This implementation ignores the locale
  * FIXME
  */
-UINT32 CompareString32A(DWORD lcid, DWORD fdwStyle, 
-	LPCSTR s1, DWORD l1, LPCSTR s2,DWORD l2)
+UINT32 WINAPI CompareString32A(DWORD lcid, DWORD fdwStyle, 
+                               LPCSTR s1, DWORD l1, LPCSTR s2,DWORD l2)
 {
 	int len,ret;
 	if(fdwStyle & NORM_IGNORENONSPACE)
@@ -1751,8 +1751,8 @@
  * This implementation ignores the locale
  * FIXME
  */
-UINT32 CompareString32W(DWORD lcid, DWORD fdwStyle, 
-	LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
+UINT32 WINAPI CompareString32W(DWORD lcid, DWORD fdwStyle, 
+                               LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
 {
 	int len,ret;
 	if(fdwStyle & NORM_IGNORENONSPACE)
@@ -1778,7 +1778,7 @@
 /***********************************************************************
  *           SetLocalInfoA       (KERNEL32.499)
  */
-BOOL16 SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
+BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
 {
     fprintf(stdnimp,"SetLocaleInfoA(%ld,%ld,%s)\n",lcid,lctype,data);
     return TRUE;
@@ -1787,7 +1787,8 @@
 /***********************************************************************
  *           IsValidLocale       (KERNEL32.361)
  */
-BOOL32 IsValidLocale(LCID lcid,DWORD flags) {
+BOOL32 WINAPI IsValidLocale(LCID lcid,DWORD flags)
+{
 	/* we support ANY language. Well, at least say that...*/
 	return TRUE;
 }
@@ -1795,7 +1796,8 @@
 /***********************************************************************
  *              EnumSystemLocales32W                (KERNEL32.93)
  */
-BOOL32 EnumSystemLocales32W( LOCALE_ENUMPROC32W lpfnLocaleEnum, DWORD flags )
+BOOL32 WINAPI EnumSystemLocales32W( LOCALE_ENUMPROC32W lpfnLocaleEnum,
+                                    DWORD flags )
 {
 	int	i;
 	BOOL32	ret;
@@ -1838,8 +1840,9 @@
 /***********************************************************************
  *              EnumSystemLocales32A                (KERNEL32.92)
  */
-BOOL32
-EnumSystemLocales32A(LOCALE_ENUMPROC32A lpfnLocaleEnum,DWORD flags) {
+BOOL32 WINAPI EnumSystemLocales32A(LOCALE_ENUMPROC32A lpfnLocaleEnum,
+                                   DWORD flags)
+{
 	int	i;
 	CHAR	buffer[200];
 	HKEY	xhkey;
@@ -1872,22 +1875,25 @@
 /***********************************************************************
  *              GetStringTypeA                (OLE2NLS.7)
  */
-BOOL16
-GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src,INT16 cchSrc,LPWORD chartype) {
+BOOL16 WINAPI GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src,
+                              INT16 cchSrc,LPWORD chartype)
+{
 	return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
 }
 /***********************************************************************
  *              GetStringTypeA                (KERNEL32.277)
  */
-BOOL32
-GetStringType32A(LCID locale,DWORD dwInfoType,LPCSTR src,INT32 cchSrc,LPWORD chartype) {
+BOOL32 WINAPI GetStringType32A(LCID locale,DWORD dwInfoType,LPCSTR src,
+                               INT32 cchSrc,LPWORD chartype)
+{
 	return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
 }
 /***********************************************************************
  *              GetStringTypeExA                (KERNEL32.276)
  */
-BOOL32
-GetStringTypeEx32A(LCID locale,DWORD dwInfoType,LPCSTR src,INT32 cchSrc,LPWORD chartype) {
+BOOL32 WINAPI GetStringTypeEx32A(LCID locale,DWORD dwInfoType,LPCSTR src,
+                                 INT32 cchSrc,LPWORD chartype)
+{
 	int	i;
 
 	switch (dwInfoType) {
@@ -1922,8 +1928,9 @@
  *              GetStringTypeW                (KERNEL32.279)
  * Yes, this is missing LCID locale. MS fault.
  */
-BOOL32
-GetStringType32W(DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,LPWORD chartype) {
+BOOL32 WINAPI GetStringType32W(DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,
+                               LPWORD chartype)
+{
 	return GetStringTypeEx32W(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
 }
 
@@ -1931,8 +1938,9 @@
  *              GetStringTypeW                (KERNEL32.278)
  * FIXME: unicode chars are assumed chars
  */
-BOOL32
-GetStringTypeEx32W(LCID locale,DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,LPWORD chartype) {
+BOOL32 WINAPI GetStringTypeEx32W(LCID locale,DWORD dwInfoType,LPCWSTR src,
+                                 INT32 cchSrc,LPWORD chartype)
+{
 	int	i;
 
 	switch (dwInfoType) {
@@ -1955,15 +1963,17 @@
 		if (isspace(src[i])) chartype[i]|=C1_SPACE;
 		if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
 		if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
-		if (isblank(src[i])) chartype[i]|=C1_BLANK;
+/* FIXME: isblank() is a GNU extension */
+/*		if (isblank(src[i])) chartype[i]|=C1_BLANK; */
+                if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
 		/* C1_XDIGIT */
 	}
 	return TRUE;
 }
 
 /* VerLanguageName				[VER.10] */
-DWORD
-VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen) {
+DWORD WINAPI VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen)
+{
 	int	i;
 	char	*buf;
 
@@ -1987,14 +1997,16 @@
 }
 
 /* VerLanguageNameA				[VERSION.9] */
-DWORD
-VerLanguageName32A(UINT32 langid,LPSTR langname,UINT32 langnamelen) {
+DWORD WINAPI VerLanguageName32A(UINT32 langid,LPSTR langname,
+                                UINT32 langnamelen)
+{
 	return VerLanguageName16(langid,langname,langnamelen);
 }
 
 /* VerLanguageNameW				[VERSION.10] */
-DWORD
-VerLanguageName32W(UINT32 langid,LPWSTR langname,UINT32 langnamelen) {
+DWORD WINAPI VerLanguageName32W(UINT32 langid,LPWSTR langname,
+                                UINT32 langnamelen)
+{
 	int	i;
 	char	buffer[80];
 	LPWSTR	keyname;
diff --git a/misc/olecli.c b/misc/olecli.c
index 2c7ab88..bdc2aae 100644
--- a/misc/olecli.c
+++ b/misc/olecli.c
@@ -18,8 +18,8 @@
 /***********************************************************************
  *           OleRegisterClientDoc
  */
-OLESTATUS OleRegisterClientDoc(	LPCSTR classname, LPCSTR docname,
-                                LONG reserved, LHCLIENTDOC *hRet )
+OLESTATUS WINAPI OleRegisterClientDoc(	LPCSTR classname, LPCSTR docname,
+                                        LONG reserved, LHCLIENTDOC *hRet )
 {
     dprintf_ole(stdnimp,"OleRegisterClientDoc:%s %s\n",classname,docname);
     *hRet=++OLE_current_handle;
@@ -29,7 +29,7 @@
 /***********************************************************************
  *           OleRenameClientDoc
  */
-OLESTATUS OleRenameClientDoc(LHCLIENTDOC hDoc, LPCSTR newName)
+OLESTATUS WINAPI OleRenameClientDoc(LHCLIENTDOC hDoc, LPCSTR newName)
 {
     dprintf_ole(stdnimp,"OleRenameClientDoc: %ld %s\n",hDoc, newName);
     return OLE_OK;
@@ -38,7 +38,7 @@
 /***********************************************************************
  *           OleRevokeClientDoc
  */
-OLESTATUS OleRevokeClientDoc(LHCLIENTDOC hServerDoc)
+OLESTATUS WINAPI OleRevokeClientDoc(LHCLIENTDOC hServerDoc)
 {
     dprintf_ole(stdnimp,"OleRevokeClientDoc:%ld\n",hServerDoc);
     return OLE_OK;
@@ -47,7 +47,7 @@
 /***********************************************************************
  *           OleIsDcMeta
  */
-BOOL16 OleIsDcMeta(HDC16 hdc)
+BOOL16 WINAPI OleIsDcMeta(HDC16 hdc)
 {
 	dprintf_ole(stddeb,"OleIsDCMeta(%04x)\n",hdc);
 	return GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ) != 0;
diff --git a/misc/olesvr.c b/misc/olesvr.c
index b9e41ff..0ebc3e2 100644
--- a/misc/olesvr.c
+++ b/misc/olesvr.c
@@ -17,9 +17,9 @@
 /***********************************************************************
  *           OleRegisterServer
  */
-OLESTATUS OleRegisterServer( LPCSTR name, LPOLESERVER serverStruct,
-                             LHSERVER *hRet, HINSTANCE16 hServer,
-                             OLE_SERVER_USE use )
+OLESTATUS WINAPI OleRegisterServer( LPCSTR name, LPOLESERVER serverStruct,
+                                    LHSERVER *hRet, HINSTANCE16 hServer,
+                                    OLE_SERVER_USE use )
 {
     dprintf_ole(stdnimp,"OleRegisterServer:%s\n",name);
     *hRet=++OLE_current_handle;
@@ -30,7 +30,7 @@
 /***********************************************************************
  *           OleBlockServer
  */
-OLESTATUS OleBlockServer(LHSERVER hServer)
+OLESTATUS WINAPI OleBlockServer(LHSERVER hServer)
 {
     fprintf(stdnimp,"OleBlockServer:%ld\n",hServer);
     return OLE_OK;
@@ -39,7 +39,7 @@
 /***********************************************************************
  *           OleUnblockServer
  */
-OLESTATUS OleUnblockServer(LHSERVER hServer, BOOL16 *block)
+OLESTATUS WINAPI OleUnblockServer(LHSERVER hServer, BOOL16 *block)
 {
     fprintf(stdnimp,"OleUnblockServer:%ld\n",hServer);
     /* no more blocked messages :) */
@@ -50,8 +50,9 @@
 /***********************************************************************
  *           OleRegisterServerDoc
  */
-OLESTATUS OleRegisterServerDoc( LHSERVER hServer, LPCSTR docname,
-                                LPOLESERVERDOC document, LHSERVERDOC *hRet)
+OLESTATUS WINAPI OleRegisterServerDoc( LHSERVER hServer, LPCSTR docname,
+                                       LPOLESERVERDOC document,
+                                       LHSERVERDOC *hRet)
 {
     dprintf_ole(stdnimp,"OleRegisterServerDoc:%ld,%s\n", hServer, docname);
     *hRet=++OLE_current_handle;
@@ -61,7 +62,7 @@
 /***********************************************************************
  *           OleRevokeServerDoc
  */
-OLESTATUS OleRevokeServerDoc(LHSERVERDOC hServerDoc)
+OLESTATUS WINAPI OleRevokeServerDoc(LHSERVERDOC hServerDoc)
 {
     dprintf_ole(stdnimp,"OleRevokeServerDoc:%ld\n",hServerDoc);
     return OLE_OK;
@@ -70,7 +71,7 @@
 /***********************************************************************
  *           OleRevokeServer
  */
-OLESTATUS OleRevokeServer(LHSERVER hServer)
+OLESTATUS WINAPI OleRevokeServer(LHSERVER hServer)
 {
     dprintf_ole(stdnimp,"OleRevokeServer:%ld\n",hServer);
     return OLE_OK;
diff --git a/misc/printdrv.c b/misc/printdrv.c
index df0bb96..2a6cc30 100644
--- a/misc/printdrv.c
+++ b/misc/printdrv.c
@@ -13,7 +13,7 @@
 #include "winerror.h"
 
 
-INT16 StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
+INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
 {
   INT16 retVal;
   printf("In startdoc16(%p)\n", lpdoc );
@@ -28,17 +28,16 @@
   return retVal;
 }
 
-INT16
-EndDoc16(HDC16 hdc)
+INT16 WINAPI EndDoc16(HDC16 hdc)
 {
   return  Escape16(hdc, ENDDOC, 0, 0, 0);
 }
 
 
 
-DWORD
-DrvGetPrinterData(LPSTR lpPrinter, LPSTR lpProfile, LPDWORD lpType,
-                  LPBYTE lpPrinterData, int cbData, LPDWORD lpNeeded)
+DWORD WINAPI DrvGetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
+                               LPDWORD lpType, LPBYTE lpPrinterData,
+                               int cbData, LPDWORD lpNeeded)
 {
     fprintf(stderr,"In DrvGetPrinterData ");
     if (HIWORD(lpPrinter))
@@ -55,9 +54,9 @@
 
 
 
-DWORD
-DrvSetPrinterData(LPSTR lpPrinter, LPSTR lpProfile, LPDWORD lpType,
-                  LPBYTE lpPrinterData, DWORD dwSize)
+DWORD WINAPI DrvSetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
+                               LPDWORD lpType, LPBYTE lpPrinterData,
+                               DWORD dwSize)
 {
     fprintf(stderr,"In DrvSetPrinterData ");
     if (HIWORD(lpPrinter))
@@ -73,4 +72,20 @@
 }
 
 
+INT32 WINAPI DeviceCapabilities32A(LPCSTR printer,LPCSTR target,WORD z,
+                                   LPSTR a,LPDEVMODE32A b)
+{
+    fprintf(stderr,"DeviceCapabilitiesA(%s,%s,%d,%p,%p)\n",printer,target,z,a,b);
+    return 1;   	
+}
+
+LONG WINAPI DocumentProperties32A(HWND32 hWnd,HANDLE32 hPrinter,
+                                LPSTR pDeviceName, LPDEVMODE32A pDevModeOutput,
+                                  LPDEVMODE32A pDevModeInput,DWORD fMode )
+{
+    fprintf(stderr,"DocumentPropertiesA(%d,%d,%s,%p,%p,%d)\n",
+	hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
+    );
+    return 1;
+}
 
diff --git a/misc/registry.c b/misc/registry.c
index 791e5db..56dea7d 100644
--- a/misc/registry.c
+++ b/misc/registry.c
@@ -543,7 +543,7 @@
 	lplpkey= &(lpkey->nextsub);
 	lpxkey	= *lplpkey;
 	while (lpxkey) {
-		if (!lstrcmp32W(lpxkey->keyname,keyname))
+		if (!lstrcmpi32W(lpxkey->keyname,keyname))
 			break;
 		lplpkey	= &(lpxkey->next);
 		lpxkey	= *lplpkey;
@@ -573,7 +573,7 @@
 				break;
 		} else {
 			if (	val->name!=NULL && 
-				!lstrcmp32W(val->name,name)
+				!lstrcmpi32W(val->name,name)
 			)
 				break;
 		}
@@ -1625,7 +1625,7 @@
  */
 
 /* RegOpenKeyExW		[ADVAPI32.150] */
-DWORD RegOpenKeyEx32W(
+DWORD WINAPI RegOpenKeyEx32W(
 	HKEY	hkey,
 	LPCWSTR	lpszSubKey,
 	DWORD	dwReserved,
@@ -1654,7 +1654,7 @@
 	while (wps[i]) {
 		lpxkey=lpNextKey->nextsub;
 		while (lpxkey) {
-			if (!lstrcmp32W(wps[i],lpxkey->keyname))
+			if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 				break;
 			lpxkey=lpxkey->next;
 		}
@@ -1672,7 +1672,7 @@
 }
 
 /* RegOpenKeyW			[ADVAPI32.151] */
-DWORD RegOpenKey32W(
+DWORD WINAPI RegOpenKey32W(
 	HKEY	hkey,
 	LPCWSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1685,7 +1685,7 @@
 
 
 /* RegOpenKeyExA		[ADVAPI32.149] */
-DWORD RegOpenKeyEx32A(
+DWORD WINAPI RegOpenKeyEx32A(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	DWORD	dwReserved,
@@ -1709,7 +1709,7 @@
 }
 
 /* RegOpenKeyA			[ADVAPI32.148] */
-DWORD RegOpenKey32A(
+DWORD WINAPI RegOpenKey32A(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1721,7 +1721,7 @@
 }
 
 /* RegOpenKey			[SHELL.1] [KERNEL.217] */
-DWORD RegOpenKey16(
+DWORD WINAPI RegOpenKey16(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1746,7 +1746,7 @@
  */
 
 /* RegCreateKeyExW		[ADVAPI32.131] */
-DWORD RegCreateKeyEx32W(
+DWORD WINAPI RegCreateKeyEx32W(
 	HKEY	hkey,
 	LPCWSTR	lpszSubKey,
 	DWORD	dwReserved,
@@ -1790,7 +1790,7 @@
 	while (wps[i]) {
 		lpxkey=lpNextKey->nextsub;
 		while (lpxkey) {
-			if (!lstrcmp32W(wps[i],lpxkey->keyname))
+			if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 				break;
 			lpxkey=lpxkey->next;
 		}
@@ -1851,7 +1851,7 @@
 }
 
 /* RegCreateKeyW		[ADVAPI32.132] */
-DWORD RegCreateKey32W(
+DWORD WINAPI RegCreateKey32W(
 	HKEY	hkey,
 	LPCWSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1876,7 +1876,7 @@
 }
 
 /* RegCreateKeyExA		[ADVAPI32.130] */
-DWORD RegCreateKeyEx32A(
+DWORD WINAPI RegCreateKeyEx32A(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	DWORD	dwReserved,
@@ -1928,7 +1928,7 @@
 }
 
 /* RegCreateKeyA		[ADVAPI32.129] */
-DWORD RegCreateKey32A(
+DWORD WINAPI RegCreateKey32A(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1952,7 +1952,7 @@
 }
 
 /* RegCreateKey			[SHELL.2] [KERNEL.218] */
-DWORD RegCreateKey16(
+DWORD WINAPI RegCreateKey16(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	LPHKEY	retkey
@@ -1976,7 +1976,7 @@
  */
 
 /* RegQueryValueExW		[ADVAPI32.158] */
-DWORD RegQueryValueEx32W(
+DWORD WINAPI RegQueryValueEx32W(
 	HKEY	hkey,
 	LPWSTR	lpszValueName,
 	LPDWORD	lpdwReserved,
@@ -2002,7 +2002,7 @@
 	} else {
 		for (i=0;i<lpkey->nrofvalues;i++)
 			if (	lpkey->values[i].name &&
-				!lstrcmp32W(lpszValueName,lpkey->values[i].name)
+				!lstrcmpi32W(lpszValueName,lpkey->values[i].name)
 			)
 				break;
 	}
@@ -2038,7 +2038,7 @@
 }
 
 /* RegQueryValueW		[ADVAPI32.159] */
-DWORD RegQueryValue32W(
+DWORD WINAPI RegQueryValue32W(
 	HKEY	hkey,
 	LPWSTR	lpszSubKey,
 	LPWSTR	lpszData,
@@ -2075,7 +2075,7 @@
 }
 
 /* RegQueryValueExA		[ADVAPI32.157] */
-DWORD RegQueryValueEx32A(
+DWORD WINAPI RegQueryValueEx32A(
 	HKEY	hkey,
 	LPSTR	lpszValueName,
 	LPDWORD	lpdwReserved,
@@ -2151,7 +2151,7 @@
 }
 
 /* RegQueryValueEx		[KERNEL.225] */
-DWORD RegQueryValueEx16(
+DWORD WINAPI RegQueryValueEx16(
 	HKEY	hkey,
 	LPSTR	lpszValueName,
 	LPDWORD	lpdwReserved,
@@ -2174,7 +2174,7 @@
 }
 
 /* RegQueryValueA		[ADVAPI32.156] */
-DWORD RegQueryValue32A(
+DWORD WINAPI RegQueryValue32A(
 	HKEY	hkey,
 	LPSTR	lpszSubKey,
 	LPSTR	lpszData,
@@ -2211,7 +2211,7 @@
 }
 
 /* RegQueryValue		[SHELL.6] [KERNEL.224] */
-DWORD RegQueryValue16(
+DWORD WINAPI RegQueryValue16(
 	HKEY	hkey,
 	LPSTR	lpszSubKey,
 	LPSTR	lpszData,
@@ -2238,7 +2238,7 @@
  */
 
 /* RegSetValueExW		[ADVAPI32.170] */
-DWORD RegSetValueEx32W(
+DWORD WINAPI RegSetValueEx32W(
 	HKEY	hkey,
 	LPWSTR	lpszValueName,
 	DWORD	dwReserved,
@@ -2266,7 +2266,7 @@
 	} else {
 		for (i=0;i<lpkey->nrofvalues;i++)
 			if (	lpkey->values[i].name &&
-				!lstrcmp32W(lpszValueName,lpkey->values[i].name)
+				!lstrcmpi32W(lpszValueName,lpkey->values[i].name)
 			)
 				break;
 	}
@@ -2294,7 +2294,7 @@
 }
 
 /* RegSetValueExA		[ADVAPI32.169] */
-DWORD RegSetValueEx32A(
+DWORD WINAPI RegSetValueEx32A(
 	HKEY	hkey,
 	LPSTR	lpszValueName,
 	DWORD	dwReserved,
@@ -2327,7 +2327,7 @@
 }
 
 /* RegSetValueEx		[KERNEL.226] */
-DWORD RegSetValueEx16(
+DWORD WINAPI RegSetValueEx16(
 	HKEY	hkey,
 	LPSTR	lpszValueName,
 	DWORD	dwReserved,
@@ -2342,7 +2342,7 @@
 }
 
 /* RegSetValueW			[ADVAPI32.171] */
-DWORD RegSetValue32W(
+DWORD WINAPI RegSetValue32W(
 	HKEY	hkey,
 	LPCWSTR	lpszSubKey,
 	DWORD	dwType,
@@ -2378,7 +2378,7 @@
 
 }
 /* RegSetValueA			[ADVAPI32.168] */
-DWORD RegSetValue32A(
+DWORD WINAPI RegSetValue32A(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	DWORD	dwType,
@@ -2411,7 +2411,7 @@
 }
 
 /* RegSetValue			[KERNEL.221] [SHELL.5] */
-DWORD RegSetValue16(
+DWORD WINAPI RegSetValue16(
 	HKEY	hkey,
 	LPCSTR	lpszSubKey,
 	DWORD	dwType,
@@ -2435,7 +2435,7 @@
  */
 
 /* RegEnumKeyExW		[ADVAPI32.139] */
-DWORD RegEnumKeyEx32W(
+DWORD WINAPI RegEnumKeyEx32W(
 	HKEY	hkey,
 	DWORD	iSubkey,
 	LPWSTR	lpszName,
@@ -2475,7 +2475,7 @@
 }
 
 /* RegEnumKeyW			[ADVAPI32.140] */
-DWORD RegEnumKey32W(
+DWORD WINAPI RegEnumKey32W(
 	HKEY	hkey,
 	DWORD	iSubkey,
 	LPWSTR	lpszName,
@@ -2489,7 +2489,7 @@
 	return RegEnumKeyEx32W(hkey,iSubkey,lpszName,&lpcchName,NULL,NULL,NULL,&ft);
 }
 /* RegEnumKeyExA		[ADVAPI32.138] */
-DWORD RegEnumKeyEx32A(
+DWORD WINAPI RegEnumKeyEx32A(
 	HKEY	hkey,
 	DWORD	iSubkey,
 	LPSTR	lpszName,
@@ -2546,7 +2546,7 @@
 }
 
 /* RegEnumKeyA			[ADVAPI32.137] */
-DWORD RegEnumKey32A(
+DWORD WINAPI RegEnumKey32A(
 	HKEY	hkey,
 	DWORD	iSubkey,
 	LPSTR	lpszName,
@@ -2570,7 +2570,7 @@
 }
 
 /* RegEnumKey			[SHELL.7] [KERNEL.216] */
-DWORD RegEnumKey16(
+DWORD WINAPI RegEnumKey16(
 	HKEY	hkey,
 	DWORD	iSubkey,
 	LPSTR	lpszName,
@@ -2590,7 +2590,7 @@
  */
 
 /* RegEnumValueW		[ADVAPI32.142] */
-DWORD RegEnumValue32W(
+DWORD WINAPI RegEnumValue32W(
 	HKEY	hkey,
 	DWORD	iValue,
 	LPWSTR	lpszValue,
@@ -2636,7 +2636,7 @@
 }
 
 /* RegEnumValueA		[ADVAPI32.141] */
-DWORD RegEnumValue32A(
+DWORD WINAPI RegEnumValue32A(
 	HKEY	hkey,
 	DWORD	iValue,
 	LPSTR	lpszValue,
@@ -2693,7 +2693,7 @@
 }
 
 /* RegEnumValue			[KERNEL.223] */
-DWORD RegEnumValue16(
+DWORD WINAPI RegEnumValue16(
 	HKEY	hkey,
 	DWORD	iValue,
 	LPSTR	lpszValue,
@@ -2722,7 +2722,7 @@
  *  Close registry key
  */
 /* RegCloseKey			[SHELL.3] [KERNEL.220] [ADVAPI32.126] */
-DWORD RegCloseKey(HKEY hkey) {
+DWORD WINAPI RegCloseKey(HKEY hkey) {
 	dprintf_reg(stddeb,"RegCloseKey(%x)\n",hkey);
 	remove_handle(hkey);
 	return ERROR_SUCCESS;
@@ -2734,7 +2734,7 @@
  * RegDeleteKey16 -> RegDeleteKey32A -> RegDeleteKey32W
  */
 /* RegDeleteKeyW		[ADVAPI32.134] */
-DWORD RegDeleteKey32W(HKEY hkey,LPWSTR lpszSubKey) {
+DWORD WINAPI RegDeleteKey32W(HKEY hkey,LPWSTR lpszSubKey) {
 	LPKEYSTRUCT	*lplpPrevKey,lpNextKey,lpxkey;
 	LPWSTR		*wps;
 	int		wpc,i;
@@ -2754,7 +2754,7 @@
 	while (i<wpc-1) {
 		lpxkey=lpNextKey->nextsub;
 		while (lpxkey) {
-			if (!lstrcmp32W(wps[i],lpxkey->keyname))
+			if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 				break;
 			lpxkey=lpxkey->next;
 		}
@@ -2769,7 +2769,7 @@
 	lpxkey	= lpNextKey->nextsub;
 	lplpPrevKey = &(lpNextKey->nextsub);
 	while (lpxkey) {
-		if (!lstrcmp32W(wps[i],lpxkey->keyname))
+		if (!lstrcmpi32W(wps[i],lpxkey->keyname))
 			break;
 		lplpPrevKey	= &(lpxkey->next);
 		lpxkey		= lpxkey->next;
@@ -2790,7 +2790,7 @@
 }
 
 /* RegDeleteKeyA		[ADVAPI32.133] */
-DWORD RegDeleteKey32A(HKEY hkey,LPCSTR lpszSubKey) {
+DWORD WINAPI RegDeleteKey32A(HKEY hkey,LPCSTR lpszSubKey) {
 	LPWSTR	lpszSubKeyW;
 	DWORD	ret;
 
@@ -2804,7 +2804,7 @@
 }
 
 /* RegDeleteKey			[SHELL.4] [KERNEL.219] */
-DWORD RegDeleteKey16(HKEY hkey,LPCSTR lpszSubKey) {
+DWORD WINAPI RegDeleteKey16(HKEY hkey,LPCSTR lpszSubKey) {
 	dprintf_reg(stddeb,"RegDeleteKey16(%x,%s)\n",
 		hkey,lpszSubKey
 	);
@@ -2818,7 +2818,8 @@
  * RegDeleteValue16 -> RegDeleteValue32A -> RegDeleteValue32W
  */
 /* RegDeleteValueW		[ADVAPI32.136] */
-DWORD RegDeleteValue32W(HKEY hkey,LPWSTR lpszValue) {
+DWORD WINAPI RegDeleteValue32W(HKEY hkey,LPWSTR lpszValue)
+{
 	DWORD		i;
 	LPKEYSTRUCT	lpkey;
 	LPKEYVALUE	val;
@@ -2832,7 +2833,7 @@
 	if (lpszValue) {
 		for (i=0;i<lpkey->nrofvalues;i++)
 			if (	lpkey->values[i].name &&
-				!lstrcmp32W(lpkey->values[i].name,lpszValue)
+				!lstrcmpi32W(lpkey->values[i].name,lpszValue)
 			)
 				break;
 	} else {
@@ -2859,7 +2860,8 @@
 }
 
 /* RegDeleteValueA		[ADVAPI32.135] */
-DWORD RegDeleteValue32A(HKEY hkey,LPSTR lpszValue) {
+DWORD WINAPI RegDeleteValue32A(HKEY hkey,LPSTR lpszValue)
+{
 	LPWSTR	lpszValueW;
 	DWORD	ret;
 
@@ -2871,13 +2873,15 @@
 }
 
 /* RegDeleteValue		[KERNEL.222] */
-DWORD RegDeleteValue16(HKEY hkey,LPSTR lpszValue) {
+DWORD WINAPI RegDeleteValue16(HKEY hkey,LPSTR lpszValue)
+{
 	dprintf_reg( stddeb,"RegDeleteValue16(%x,%s)\n", hkey,lpszValue );
 	return RegDeleteValue32A(hkey,lpszValue);
 }
 
 /* RegFlushKey			[ADVAPI32.143] [KERNEL.227] */
-DWORD RegFlushKey(HKEY hkey) {
+DWORD WINAPI RegFlushKey(HKEY hkey)
+{
 	dprintf_reg(stddeb,"RegFlushKey(%x), STUB.\n",hkey);
 	return SHELL_ERROR_SUCCESS;
 }
@@ -2885,7 +2889,7 @@
 /* FIXME: lpcchXXXX ... is this counting in WCHARS or in BYTEs ?? */
 
 /* RegQueryInfoKeyW		[ADVAPI32.153] */
-DWORD RegQueryInfoKey32W(
+DWORD WINAPI RegQueryInfoKey32W(
 	HKEY	hkey,
 	LPWSTR	lpszClass,
 	LPDWORD	lpcchClass,
@@ -2961,7 +2965,7 @@
 }
 
 /* RegQueryInfoKeyA		[ADVAPI32.152] */
-DWORD RegQueryInfoKey32A(
+DWORD WINAPI RegQueryInfoKey32A(
 	HKEY	hkey,
 	LPSTR	lpszClass,
 	LPDWORD	lpcchClass,
@@ -3014,7 +3018,8 @@
 	return ret;
 }
 /* RegConnectRegistryA		[ADVAPI32.127] */
-DWORD RegConnectRegistry32A(LPCSTR machine,HKEY hkey,LPHKEY reskey) {
+DWORD WINAPI RegConnectRegistry32A(LPCSTR machine,HKEY hkey,LPHKEY reskey)
+{
 	fprintf(stderr,"RegConnectRegistry32A(%s,%08x,%p), STUB.\n",
 		machine,hkey,reskey
 	);
diff --git a/misc/shell.c b/misc/shell.c
index 041fc8b..b3a9ffe 100644
--- a/misc/shell.c
+++ b/misc/shell.c
@@ -62,7 +62,7 @@
 /*************************************************************************
  *				DragAcceptFiles		[SHELL.9]
  */
-void DragAcceptFiles(HWND16 hWnd, BOOL16 b)
+void WINAPI DragAcceptFiles(HWND16 hWnd, BOOL16 b)
 {
     WND* wnd = WIN_FindWndPtr(hWnd);
 
@@ -75,7 +75,8 @@
 /*************************************************************************
  *				DragQueryFile		[SHELL.11]
  */
-UINT16 DragQueryFile(HDROP16 hDrop, WORD wFile, LPSTR lpszFile, WORD wLength)
+UINT16 WINAPI DragQueryFile(HDROP16 hDrop, WORD wFile, LPSTR lpszFile,
+                            WORD wLength)
 {
     /* hDrop is a global memory block allocated with GMEM_SHARE 
      * with DROPFILESTRUCT as a header and filenames following
@@ -116,7 +117,7 @@
 /*************************************************************************
  *				DragFinish		[SHELL.12]
  */
-void DragFinish(HDROP16 h)
+void WINAPI DragFinish(HDROP16 h)
 {
     GlobalFree16((HGLOBAL16)h);
 }
@@ -125,7 +126,7 @@
 /*************************************************************************
  *				DragQueryPoint		[SHELL.13]
  */
-BOOL16 DragQueryPoint(HDROP16 hDrop, POINT16 *p)
+BOOL16 WINAPI DragQueryPoint(HDROP16 hDrop, POINT16 *p)
 {
     LPDROPFILESTRUCT lpDropFileStruct;  
     BOOL16           bRet;
@@ -143,8 +144,7 @@
  *				SHELL_FindExecutable
  * Utility for code sharing between FindExecutable and ShellExecute
  */
-static HINSTANCE16 SHELL_FindExecutable( LPCSTR lpFile, 
-                                         LPCSTR lpDirectory,
+static HINSTANCE32 SHELL_FindExecutable( LPCSTR lpFile, 
                                          LPCSTR lpOperation,
                                          LPSTR lpResult)
 {
@@ -155,15 +155,13 @@
     char command[256];      /* command from registry */
     LONG commandlen=256;    /* This is the most DOS can handle :) */
     char buffer[256];       /* Used to GetProfileString */
-    HINSTANCE16 retval=31;  /* default - 'No association was found' */
+    HINSTANCE32 retval=31;  /* default - 'No association was found' */
     char *tok;              /* token pointer */
     int i;                  /* random counter */
     char xlpFile[256];      /* result of SearchPath */
 
-    dprintf_exec(stddeb, "SHELL_FindExecutable: File %s, Dir %s\n", 
-		 (lpFile != NULL?lpFile:"-"), 
-		 (lpDirectory != NULL?lpDirectory:"-"));
-
+    dprintf_exec(stddeb, "SHELL_FindExecutable: %s\n",
+                 (lpFile != NULL?lpFile:"-") );
     lpResult[0]='\0'; /* Start off with an empty return string */
 
     /* trap NULL parameters on entry */
@@ -172,7 +170,8 @@
 	/* FIXME - should throw a warning, perhaps! */
 	return 2; /* File not found. Close enough, I guess. */
     }
-    if (SearchPath32A(lpDirectory,lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
+
+    if (SearchPath32A( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
         lpFile = xlpFile;
 
     /* First thing we need is the file's extension */
@@ -215,7 +214,7 @@
 				 * attached */
 				dprintf_exec(stddeb, "SHELL_FindExecutable: found %s\n",
 							 lpResult);
-	    return 33;
+                                return 33;
 
 		/* Greater than 32 to indicate success FIXME According to the
 		 * docs, I should be returning a handle for the
@@ -292,11 +291,12 @@
 /*************************************************************************
  *				ShellExecute16		[SHELL.20]
  */
-HINSTANCE16 ShellExecute16( HWND16 hWnd, LPCSTR lpOperation, LPCSTR lpFile,
-                            LPCSTR lpParameters, LPCSTR lpDirectory,
-                            INT16 iShowCmd )
+HINSTANCE16 WINAPI ShellExecute16( HWND16 hWnd, LPCSTR lpOperation,
+                                   LPCSTR lpFile, LPCSTR lpParameters,
+                                   LPCSTR lpDirectory, INT16 iShowCmd )
 {
     HINSTANCE16 retval=31;
+    char old_dir[1024];
     char cmd[256];
 
     dprintf_exec(stddeb, "ShellExecute(%04x,'%s','%s','%s','%s',%x)\n",
@@ -308,30 +308,36 @@
     if (lpOperation==NULL) /* default is open */
       lpOperation="open";
 
-    retval = SHELL_FindExecutable( lpFile, lpDirectory, lpOperation, cmd );
-
-    if ( retval <= 32 )
+    if (lpDirectory)
     {
-	return retval;
+        GetCurrentDirectory32A( sizeof(old_dir), old_dir );
+        SetCurrentDirectory32A( lpDirectory );
     }
 
-    if (lpParameters)
-    {
-	strcat(cmd," ");
-	strcat(cmd,lpParameters);
-    }
+    retval = SHELL_FindExecutable( lpFile, lpOperation, cmd );
 
-    dprintf_exec(stddeb,"ShellExecute:starting %s\n",cmd);
-    return WinExec32(cmd,iShowCmd);
+    if (retval > 32)  /* Found */
+    {
+        if (lpParameters)
+        {
+            strcat(cmd," ");
+            strcat(cmd,lpParameters);
+        }
+
+        dprintf_exec(stddeb,"ShellExecute:starting %s\n",cmd);
+        retval = WinExec32( cmd, iShowCmd );
+    }
+    if (lpDirectory) SetCurrentDirectory32A( old_dir );
+    return retval;
 }
 
 
 /*************************************************************************
  *             ShellExecute32A   (SHELL32.84)
  */
-HINSTANCE32 ShellExecute32A( HWND32 hWnd, LPCSTR lpOperation, LPCSTR lpFile,
-                             LPCSTR lpParameters, LPCSTR lpDirectory,
-                             INT32 iShowCmd )
+HINSTANCE32 WINAPI ShellExecute32A( HWND32 hWnd, LPCSTR lpOperation,
+                                    LPCSTR lpFile, LPCSTR lpParameters,
+                                    LPCSTR lpDirectory, INT32 iShowCmd )
 {
     return ShellExecute16( hWnd, lpOperation, lpFile, lpParameters,
                            lpDirectory, iShowCmd );
@@ -341,10 +347,20 @@
 /*************************************************************************
  *             FindExecutable16   (SHELL.21)
  */
-HINSTANCE16 FindExecutable16( LPCSTR lpFile, LPCSTR lpDirectory,
-                              LPSTR lpResult )
+HINSTANCE16 WINAPI FindExecutable16( LPCSTR lpFile, LPCSTR lpDirectory,
+                                     LPSTR lpResult )
 {
-    HINSTANCE16 retval=31;    /* default - 'No association was found' */
+    return (HINSTANCE16)FindExecutable32A( lpFile, lpDirectory, lpResult );
+}
+
+/*************************************************************************
+ *             FindExecutable32A   (SHELL32.184)
+ */
+HINSTANCE32 WINAPI FindExecutable32A( LPCSTR lpFile, LPCSTR lpDirectory,
+                                      LPSTR lpResult )
+{
+    HINSTANCE32 retval=31;    /* default - 'No association was found' */
+    char old_dir[1024];
 
     dprintf_exec(stddeb, "FindExecutable: File %s, Dir %s\n", 
 		 (lpFile != NULL?lpFile:"-"), 
@@ -359,10 +375,16 @@
 	return 2; /* File not found. Close enough, I guess. */
     }
 
-    retval = SHELL_FindExecutable( lpFile, lpDirectory, "open",
-				  lpResult );
+    if (lpDirectory)
+    {
+        GetCurrentDirectory32A( sizeof(old_dir), old_dir );
+        SetCurrentDirectory32A( lpDirectory );
+    }
+
+    retval = SHELL_FindExecutable( lpFile, "open", lpResult );
 
     dprintf_exec(stddeb, "FindExecutable: returning %s\n", lpResult);
+    if (lpDirectory) SetCurrentDirectory32A( old_dir );
     return retval;
 }
 
@@ -377,8 +399,8 @@
 /*************************************************************************
  *             AboutDlgProc32  (not an exported API function)
  */
-LRESULT AboutDlgProc32( HWND32 hWnd, UINT32 msg, WPARAM32 wParam,
-                        LPARAM lParam )
+LRESULT WINAPI AboutDlgProc32( HWND32 hWnd, UINT32 msg, WPARAM32 wParam,
+                               LPARAM lParam )
 {
     char Template[512], AppTitle[512];
 
@@ -413,8 +435,8 @@
 /*************************************************************************
  *             AboutDlgProc16   (SHELL.33)
  */
-LRESULT AboutDlgProc16( HWND16 hWnd, UINT16 msg, WPARAM16 wParam,
-                        LPARAM lParam )
+LRESULT WINAPI AboutDlgProc16( HWND16 hWnd, UINT16 msg, WPARAM16 wParam,
+                               LPARAM lParam )
 {
     return AboutDlgProc32( hWnd, msg, wParam, lParam );
 }
@@ -423,8 +445,8 @@
 /*************************************************************************
  *             ShellAbout16   (SHELL.22)
  */
-BOOL16 ShellAbout16( HWND16 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
-                     HICON16 hIcon )
+BOOL16 WINAPI ShellAbout16( HWND16 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
+                            HICON16 hIcon )
 {
     return ShellAbout32A( hWnd, szApp, szOtherStuff, hIcon );
 }
@@ -432,8 +454,8 @@
 /*************************************************************************
  *             ShellAbout32A   (SHELL32.82)
  */
-BOOL32 ShellAbout32A( HWND32 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
-                      HICON32 hIcon )
+BOOL32 WINAPI ShellAbout32A( HWND32 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
+                             HICON32 hIcon )
 {
     ABOUT_INFO info;
     info.szApp        = szApp;
@@ -449,8 +471,8 @@
 /*************************************************************************
  *             ShellAbout32W   (SHELL32.83)
  */
-BOOL32 ShellAbout32W( HWND32 hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
-                      HICON32 hIcon )
+BOOL32 WINAPI ShellAbout32W( HWND32 hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
+                             HICON32 hIcon )
 {
     BOOL32 ret;
     ABOUT_INFO info;
@@ -604,7 +626,9 @@
  *
  * This abortion is called directly by Progman
  */
-HGLOBAL16 InternalExtractIcon(HINSTANCE16 hInstance, LPCSTR lpszExeFileName, UINT16 nIconIndex, WORD n )
+HGLOBAL16 WINAPI InternalExtractIcon(HINSTANCE16 hInstance,
+                                     LPCSTR lpszExeFileName, UINT16 nIconIndex,
+                                     WORD n )
 {
   HGLOBAL16 	hRet = 0;
   HGLOBAL16*	RetPtr = NULL;
@@ -706,8 +730,8 @@
 /*************************************************************************
  *             ExtractIcon16   (SHELL.34)
  */
-HICON16 ExtractIcon16( HINSTANCE16 hInstance, LPCSTR lpszExeFileName,
-                       UINT16 nIconIndex )
+HICON16 WINAPI ExtractIcon16( HINSTANCE16 hInstance, LPCSTR lpszExeFileName,
+                              UINT16 nIconIndex )
 {
   HGLOBAL16 handle = InternalExtractIcon(hInstance,lpszExeFileName,nIconIndex, 1);
 
@@ -726,8 +750,8 @@
 /*************************************************************************
  *             ExtractIcon32A   (SHELL32.20)
  */
-HICON32 ExtractIcon32A( HINSTANCE32 hInstance, LPCSTR lpszExeFileName,
-                        UINT32 nIconIndex )
+HICON32 WINAPI ExtractIcon32A( HINSTANCE32 hInstance, LPCSTR lpszExeFileName,
+                               UINT32 nIconIndex )
 {
     /* FIXME */
     return ExtractIcon16( hInstance, lpszExeFileName, nIconIndex );
@@ -740,7 +764,8 @@
  * Return icon for given file (either from file itself or from associated
  * executable) and patch parameters if needed.
  */
-HICON16 ExtractAssociatedIcon(HINSTANCE16 hInst,LPSTR lpIconPath,LPWORD lpiIcon)
+HICON16 WINAPI ExtractAssociatedIcon(HINSTANCE16 hInst,LPSTR lpIconPath,
+                                     LPWORD lpiIcon)
 {
     HICON16 hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon);
 
@@ -794,7 +819,7 @@
   return NULL;
 }
 
-SEGPTR FindEnvironmentString(LPSTR str)
+SEGPTR WINAPI FindEnvironmentString(LPSTR str)
 {
  SEGPTR  spEnv = GetDOSEnvironment();
  LPSTR  lpEnv = (LPSTR)PTR_SEG_TO_LIN(spEnv);
@@ -813,7 +838,7 @@
  * Replace %KEYWORD% in the str with the value of variable KEYWORD
  * from "DOS" environment.
  */
-DWORD DoEnvironmentSubst(LPSTR str,WORD length)
+DWORD WINAPI DoEnvironmentSubst(LPSTR str,WORD length)
 {
   LPSTR   lpEnv = (LPSTR)PTR_SEG_TO_LIN(GetDOSEnvironment());
   LPSTR   lpBuffer = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length);
@@ -886,7 +911,7 @@
  *				ShellHookProc		[SHELL.103]
  * System-wide WH_SHELL hook.
  */
-LRESULT ShellHookProc(INT16 code, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI ShellHookProc(INT16 code, WPARAM16 wParam, LPARAM lParam)
 {
     dprintf_reg(stddeb,"ShellHookProc: %i, %04x, %08x\n", code, wParam, 
 						      (unsigned)lParam );
@@ -907,7 +932,7 @@
 /*************************************************************************
  *				RegisterShellHook	[SHELL.102]
  */
-BOOL32 RegisterShellHook(HWND16 hWnd, UINT16 uAction)
+BOOL32 WINAPI RegisterShellHook(HWND16 hWnd, UINT16 uAction)
 {
     dprintf_reg(stddeb,"RegisterShellHook: %04x [%u]\n", hWnd, uAction );
 
@@ -948,10 +973,10 @@
 /*************************************************************************
  *				SHGetFileInfoA		[SHELL32.54]
  */
-DWORD
-SHGetFileInfo32A(LPCSTR path,DWORD dwFileAttributes,SHFILEINFO32A *psfi,
-	UINT32 sizeofpsfi,UINT32 flags
-) {
+DWORD WINAPI SHGetFileInfo32A(LPCSTR path,DWORD dwFileAttributes,
+                              SHFILEINFO32A *psfi, UINT32 sizeofpsfi,
+                              UINT32 flags )
+{
 	fprintf(stdnimp,"SHGetFileInfo32A(%s,0x%08lx,%p,%d,0x%08x)\n",
 		path,dwFileAttributes,psfi,sizeofpsfi,flags
 	);
@@ -961,8 +986,8 @@
 /*************************************************************************
  *				CommandLineToArgvW	[SHELL32.2]
  */
-LPWSTR*
-CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs) {
+LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
+{
 	LPWSTR	*argv,s,t;
 	int	i;
 
diff --git a/misc/sound.c b/misc/sound.c
index 7c06aea..452a6f7 100644
--- a/misc/sound.c
+++ b/misc/sound.c
@@ -7,181 +7,183 @@
 #include <stdio.h>
 #include "windows.h"
 
-INT16 OpenSound16(void)
+INT16 WINAPI OpenSound16(void)
 {
   printf("OpenSound16()\n");
   return -1;
 }
 
-void OpenSound32(void)
+void WINAPI OpenSound32(void)
 {
   printf("OpenSound32()\n");
 }
 
-void CloseSound(void)
+void WINAPI CloseSound(void)
 {
   printf("CloseSound()\n");
 }
 
-INT16 SetVoiceQueueSize16(INT16 nVoice, INT16 nBytes)
+INT16 WINAPI SetVoiceQueueSize16(INT16 nVoice, INT16 nBytes)
 {
   printf("SetVoiceQueueSize16 (%d,%d)\n",nVoice,nBytes);
   return 0;
 }
 
-DWORD SetVoiceQueueSize32(DWORD nVoice, DWORD nBytes)
+DWORD WINAPI SetVoiceQueueSize32(DWORD nVoice, DWORD nBytes)
 {
   printf("SetVoiceQueueSize32 (%ld,%ld)\n",nVoice,nBytes);
   return 0;
 }
 
-INT16 SetVoiceNote16(INT16 nVoice, INT16 nValue, INT16 nLength, INT16 nCdots)
+INT16 WINAPI SetVoiceNote16(INT16 nVoice, INT16 nValue, INT16 nLength,
+                            INT16 nCdots)
 {
   printf("SetVoiceNote16 (%d,%d,%d,%d)\n",nVoice,nValue,nLength,nCdots);
   return 0;
 }
 
-DWORD SetVoiceNote32(DWORD nVoice, DWORD nValue, DWORD nLength, DWORD nCdots)
+DWORD WINAPI SetVoiceNote32(DWORD nVoice, DWORD nValue, DWORD nLength,
+                            DWORD nCdots)
 {
   printf("SetVoiceNote32 (%ld,%ld,%ld,%ld)\n",nVoice,nValue,nLength,nCdots);
   return 0;
 }
 
-INT16 SetVoiceAccent16(INT16 nVoice, INT16 nTempo, INT16 nVolume,
-                       INT16 nMode, INT16 nPitch)
+INT16 WINAPI SetVoiceAccent16(INT16 nVoice, INT16 nTempo, INT16 nVolume,
+                              INT16 nMode, INT16 nPitch)
 {
   printf("SetVoiceAccent16(%d,%d,%d,%d,%d)\n", nVoice, nTempo, 
 	 nVolume, nMode, nPitch);
   return 0;
 }
 
-DWORD SetVoiceAccent32(DWORD nVoice, DWORD nTempo, DWORD nVolume,
-                       DWORD nMode, DWORD nPitch)
+DWORD WINAPI SetVoiceAccent32(DWORD nVoice, DWORD nTempo, DWORD nVolume,
+                              DWORD nMode, DWORD nPitch)
 {
   printf("SetVoiceAccent32(%ld,%ld,%ld,%ld,%ld)\n", nVoice, nTempo, 
 	 nVolume, nMode, nPitch);
   return 0;
 }
 
-INT16 SetVoiceEnvelope16(INT16 nVoice, INT16 nShape, INT16 nRepeat)
+INT16 WINAPI SetVoiceEnvelope16(INT16 nVoice, INT16 nShape, INT16 nRepeat)
 {
   printf("SetVoiceEnvelope16(%d,%d,%d)\n",nVoice,nShape,nRepeat);
   return 0;
 }
 
-DWORD SetVoiceEnvelope32(DWORD nVoice, DWORD nShape, DWORD nRepeat)
+DWORD WINAPI SetVoiceEnvelope32(DWORD nVoice, DWORD nShape, DWORD nRepeat)
 {
   printf("SetVoiceEnvelope32(%ld,%ld,%ld)\n",nVoice,nShape,nRepeat);
   return 0;
 }
 
-INT16 SetSoundNoise16(INT16 nSource, INT16 nDuration)
+INT16 WINAPI SetSoundNoise16(INT16 nSource, INT16 nDuration)
 {
   printf("SetSoundNoise16(%d,%d)\n",nSource,nDuration);
   return 0;
 }
 
-DWORD SetSoundNoise32(DWORD nSource, DWORD nDuration)
+DWORD WINAPI SetSoundNoise32(DWORD nSource, DWORD nDuration)
 {
   printf("SetSoundNoise32(%ld,%ld)\n",nSource,nDuration);
   return 0;
 }
 
-INT16 SetVoiceSound16(INT16 nVoice, DWORD lFrequency, INT16 nDuration)
+INT16 WINAPI SetVoiceSound16(INT16 nVoice, DWORD lFrequency, INT16 nDuration)
 {
   printf("SetVoiceSound16(%d, %ld, %d)\n",nVoice,lFrequency, nDuration);
   return 0;
 }
 
-DWORD SetVoiceSound32(DWORD nVoice, DWORD lFrequency, DWORD nDuration)
+DWORD WINAPI SetVoiceSound32(DWORD nVoice, DWORD lFrequency, DWORD nDuration)
 {
   printf("SetVoiceSound32(%ld, %ld, %ld)\n",nVoice,lFrequency, nDuration);
   return 0;
 }
 
-INT16 StartSound16(void)
+INT16 WINAPI StartSound16(void)
 {
   return 0;
 }
 
-INT16 StopSound16(void)
+INT16 WINAPI StopSound16(void)
 {
   return 0;
 }
 
-INT16 WaitSoundState16(INT16 x)
+INT16 WINAPI WaitSoundState16(INT16 x)
 {
     fprintf(stderr, "WaitSoundState16(%d)\n", x);
     return 0;
 }
 
-DWORD WaitSoundState32(DWORD x)
+DWORD WINAPI WaitSoundState32(DWORD x)
 {
     fprintf(stderr, "WaitSoundState32(%ld)\n", x);
     return 0;
 }
 
-INT16 SyncAllVoices16(void)
+INT16 WINAPI SyncAllVoices16(void)
 {
     fprintf(stderr, "SyncAllVoices16()\n");
     return 0;
 }
 
-DWORD SyncAllVoices32(void)
+DWORD WINAPI SyncAllVoices32(void)
 {
     fprintf(stderr, "SyncAllVoices32()\n");
     return 0;
 }
 
-INT16 CountVoiceNotes16(INT16 x)
+INT16 WINAPI CountVoiceNotes16(INT16 x)
 {
     fprintf(stderr, "CountVoiceNotes16(%d)\n", x);
     return 0;
 }
 
-DWORD CountVoiceNotes32(DWORD x)
+DWORD WINAPI CountVoiceNotes32(DWORD x)
 {
     fprintf(stderr, "CountVoiceNotes32(%ld)\n", x);
     return 0;
 }
 
-LPINT16 GetThresholdEvent16(void)
+LPINT16 WINAPI GetThresholdEvent16(void)
 {
     fprintf(stderr, "GetThresholdEvent16()\n");
     return NULL;
 }
 
-LPDWORD GetThresholdEvent32(void)
+LPDWORD WINAPI GetThresholdEvent32(void)
 {
     fprintf(stderr, "GetThresholdEvent32()\n");
     return NULL;
 }
 
-INT16 GetThresholdStatus16(void)
+INT16 WINAPI GetThresholdStatus16(void)
 {
     fprintf(stderr, "GetThresholdStatus16()\n");
     return 0;
 }
 
-DWORD GetThresholdStatus32(void)
+DWORD WINAPI GetThresholdStatus32(void)
 {
     fprintf(stderr, "GetThresholdStatus32()\n");
     return 0;
 }
 
-INT16 SetVoiceThreshold16(INT16 a, INT16 b)
+INT16 WINAPI SetVoiceThreshold16(INT16 a, INT16 b)
 {
 	fprintf(stderr, "SetVoiceThreshold16(%d,%d)\n", a, b);
         return 0;
 }
 
-DWORD SetVoiceThreshold32(DWORD a, DWORD b)
+DWORD WINAPI SetVoiceThreshold32(DWORD a, DWORD b)
 {
     fprintf(stderr, "SetVoiceThreshold32(%ld,%ld)\n", a, b);
     return 0;
 }
 
-void DoBeep(void)
+void WINAPI DoBeep(void)
 {
 	fprintf(stderr, "BEEP!\n");
 }
diff --git a/misc/stress.c b/misc/stress.c
index d800323..6b4e2fe 100644
--- a/misc/stress.c
+++ b/misc/stress.c
@@ -8,14 +8,14 @@
 #include "debug.h"
 
 
-int AllocDiskSpace(long lLeft, UINT16 uDrive)
+int WINAPI AllocDiskSpace(long lLeft, UINT16 uDrive)
 {
 	dprintf_stress(stdnimp, "stress.dll: AllocDiskSpace %d, %ld\n", uDrive, lLeft);
 
 	return 1;
 }
 
-int AllocFileHandles(int Left)
+int WINAPI AllocFileHandles(int Left)
 {
 	dprintf_stress(stddeb, "stress.dll: AllocFileHandles %d\n", Left);
 
@@ -25,48 +25,48 @@
 		return 1;
 }
 
-BOOL16 AllocGDIMem(UINT16 uLeft)
+BOOL16 WINAPI AllocGDIMem(UINT16 uLeft)
 {
 	dprintf_stress(stddeb, "stress.dll: AllocGDIMem %d\n", uLeft);
 
 	return 1;
 }
 
-BOOL16 AllocMem(DWORD dwLeft)
+BOOL16 WINAPI AllocMem(DWORD dwLeft)
 {
 	dprintf_stress(stdnimp, "stress.dll: AllocMem %ld\n", dwLeft);
 
 	return 1;
 }
 
-BOOL16 AllocUserMem(UINT16 uContig)
+BOOL16 WINAPI AllocUserMem(UINT16 uContig)
 {
 	dprintf_stress(stddeb, "stress.dll: AllocUserMem %d\n", uContig);
 
 	return 1;
 }
 
-void FreeAllMem(void)
+void WINAPI FreeAllMem(void)
 {
 	dprintf_stress(stddeb, "stress.dll: FreeAllMem\n");
 }
 
-void FreeAllGDIMem(void)
+void WINAPI FreeAllGDIMem(void)
 {
 	dprintf_stress(stddeb, "stress.dll: FreeAllGDIMem\n");
 }
 
-void FreeAllUserMem(void)
+void WINAPI FreeAllUserMem(void)
 {
 	dprintf_stress(stddeb, "stress.dll: FreeAllUserMem\n");
 }
 
-void GetFreeAllUserMem(void)
+void WINAPI GetFreeAllUserMem(void)
 {
        dprintf_stress(stddeb, "stress.dll: GetFreeAllUserMem\n");
 }
 
-int GetFreeFileHandles(void)
+int WINAPI GetFreeFileHandles(void)
 {
 	dprintf_stress(stddeb, "stress.dll: GetFreeFileHandles\n");
 
@@ -77,12 +77,12 @@
 #endif
 }
 
-void UnAllocDiskSpace(UINT16 drive)
+void WINAPI UnAllocDiskSpace(UINT16 drive)
 {
 	dprintf_stress(stddeb, "stress.dll: UnAllocDiskSpace %d\n", drive);
 }
 
-void UnAllocFileHandles(void)
+void WINAPI UnAllocFileHandles(void)
 {
 	dprintf_stress(stddeb, "stress.dll: GetFreeAllUserMem\n");
 }
diff --git a/misc/system.c b/misc/system.c
index dee79bd..1c34729 100644
--- a/misc/system.c
+++ b/misc/system.c
@@ -100,7 +100,7 @@
  * Note: the function always takes 2 WORD arguments, contrary to what
  *       "Undocumented Windows" says.
   */
-DWORD InquireSystem( WORD code, WORD arg )
+DWORD WINAPI InquireSystem( WORD code, WORD arg )
 {
     WORD drivetype;
 
@@ -125,7 +125,7 @@
 /***********************************************************************
  *           CreateSystemTimer   (SYSTEM.2)
  */
-WORD CreateSystemTimer( WORD rate, FARPROC16 callback )
+WORD WINAPI CreateSystemTimer( WORD rate, FARPROC16 callback )
 {
     int i;
 
@@ -150,7 +150,7 @@
  *
  * Note: do not confuse this function with USER.182
  */
-WORD SYSTEM_KillSystemTimer( WORD timer )
+WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
 {
     if (!timer || (timer > NB_SYS_TIMERS)) return timer;  /* Error */
     SYS_Timers[timer-1].callback = NULL;
@@ -162,7 +162,7 @@
 /***********************************************************************
  *           EnableSystemTimers   (SYSTEM.4)
  */
-void EnableSystemTimers(void)
+void WINAPI EnableSystemTimers(void)
 {
     SYS_TimersDisabled = FALSE;
     if (SYS_NbTimers) SYSTEM_StartTicks();
@@ -172,7 +172,7 @@
 /***********************************************************************
  *           DisableSystemTimers   (SYSTEM.5)
  */
-void DisableSystemTimers(void)
+void WINAPI DisableSystemTimers(void)
 {
     SYS_TimersDisabled = TRUE;
     if (SYS_NbTimers) SYSTEM_StopTicks();
diff --git a/misc/toolhelp.c b/misc/toolhelp.c
index f5f73db..cba7996 100644
--- a/misc/toolhelp.c
+++ b/misc/toolhelp.c
@@ -29,7 +29,8 @@
 
 static int nrofnotifys = 0;
 
-BOOL16 NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback, WORD wFlags )
+BOOL16 WINAPI NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback,
+                              WORD wFlags )
 {
     int	i;
 
@@ -51,7 +52,7 @@
     return TRUE;
 }
 
-BOOL16 NotifyUnregister( HTASK16 htask )
+BOOL16 WINAPI NotifyUnregister( HTASK16 htask )
 {
     int	i;
     
diff --git a/misc/tweak.c b/misc/tweak.c
index e8f0095..0d88d0b 100644
--- a/misc/tweak.c
+++ b/misc/tweak.c
@@ -241,80 +241,6 @@
 
 /******************************************************************************
  *
- *   int  TWEAK_CheckOldFonts()
- *
- *   Examines wine.conf for old/invalid font entries and recommend changes to
- *   the user.
- *
- *   Revision history
- *        05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
- *             Original implementation.
- *
- *****************************************************************************/
-
-static void  TWEAK_CheckOldFontsCallback(char const *, char const *, void *);
-
-static char const  *fontmsgprologue = 
-"Wine warning:\n"
-"   The following entries in the [fonts] section of the wine.conf file are\n"
-"   obsolete or invalid:\n";
-
-static char const  *fontmsgepilogue =
-"   These entries should be eliminated or updated.\n"
-"   See the documentation/fonts file for more information.\n";
-
-static int  TWEAK_CheckOldFonts()
-{
-    int  found = 0;
-
-    PROFILE_EnumerateWineIniSection("Fonts", &TWEAK_CheckOldFontsCallback,
-				    (void *)&found);
-    if(found)
-	fprintf(stderr, fontmsgepilogue);
-
-    return 1;
-}
-
-static void  TWEAK_CheckOldFontsCallback(
-    char const  *key,
-    char const  *value,
-    void  *found)
-{
-    /* Ignore any keys that start with potential comment characters "'", '#',
-       or ';'. */
-    if(key[0] == '\'' || key[0] == '#' || key[0] == ';' || key[0] == '\0')
-	return;
-
-    /* Make sure this is a valid key */
-    if(strncasecmp(key, "Alias", 5) == 0 ||
-       strcasecmp(key, "Default") == 0) {
-
-	/* Valid key; make sure the value doesn't contain a wildcard */
-	if(strchr(value, '*')) {
-	    if(*(int *)found == 0) {
-		fprintf(stderr, fontmsgprologue);
-		++*(int *)found;
-	    }
-	    
-	    fprintf(stderr, "     %s=%s [no wildcards allowed]\n", key, value);
-	}
-    }
-    else {
-	/* Not a valid key */
-	if(*(int *)found == 0) {
-	    fprintf(stderr, fontmsgprologue);
-	    ++*(int *)found;
-	}
-
-	fprintf(stderr, "     %s=%s [obsolete]\n", key, value);
-    }
-
-    return;
-}
-
-
-/******************************************************************************
- *
  *   int  TWEAK_CheckConfiguration()
  *
  *   Examines wine.conf for old/bad entries and recommends changes to the user.
@@ -327,12 +253,10 @@
 
 int  TWEAK_CheckConfiguration()
 {
-    TWEAK_CheckOldFonts();
     return 1;
 }
 
 
-
 /******************************************************************************
  *
  *     Tweak graphic subsystem.
diff --git a/misc/ver.c b/misc/ver.c
index 0a747bf..89426ca 100644
--- a/misc/ver.c
+++ b/misc/ver.c
@@ -303,8 +303,9 @@
 }
 
 /* GetFileResourceSize				[VER.2] */
-DWORD
-GetFileResourceSize(LPCSTR filename,SEGPTR restype,SEGPTR resid,LPDWORD off) {
+DWORD WINAPI GetFileResourceSize(LPCSTR filename,SEGPTR restype,SEGPTR resid,
+                                 LPDWORD off)
+{
 	HFILE32			lzfd;
 	OFSTRUCT		ofs;
 	BYTE			*resdata;
@@ -331,10 +332,9 @@
 }
 
 /* GetFileResource				[VER.3] */
-DWORD
-GetFileResource(LPCSTR filename,SEGPTR restype,SEGPTR resid,
-		DWORD off,DWORD datalen,LPVOID data
-) {
+DWORD WINAPI GetFileResource(LPCSTR filename,SEGPTR restype,SEGPTR resid,
+                             DWORD off,DWORD datalen,LPVOID data )
+{
 	HFILE32			lzfd;
 	OFSTRUCT		ofs;
 	BYTE			*resdata;
@@ -367,8 +367,8 @@
 }
 
 /* GetFileVersionInfoSize			[VER.6] */
-DWORD
-GetFileVersionInfoSize16(LPCSTR filename,LPDWORD handle) {
+DWORD WINAPI GetFileVersionInfoSize16(LPCSTR filename,LPDWORD handle)
+{
 	DWORD	len,ret;
 	BYTE	buf[72];
 	VS_FIXEDFILEINFO *vffi;
@@ -479,14 +479,14 @@
 }
 
 /* GetFileVersionInfoSize32A			[VERSION.1] */
-DWORD
-GetFileVersionInfoSize32A(LPCSTR filename,LPDWORD handle) {
+DWORD WINAPI GetFileVersionInfoSize32A(LPCSTR filename,LPDWORD handle)
+{
 	dprintf_ver(stddeb,"GetFileVersionInfoSize32A(%s,%p)\n",filename,handle);
 	return GetFileVersionInfoSize16(filename,handle);
 }
 
 /* GetFileVersionInfoSize32W			[VERSION.2] */
-DWORD GetFileVersionInfoSize32W( LPCWSTR filename, LPDWORD handle )
+DWORD WINAPI GetFileVersionInfoSize32W( LPCWSTR filename, LPDWORD handle )
 {
     LPSTR xfn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
     DWORD ret = GetFileVersionInfoSize16( xfn, handle );
@@ -495,8 +495,9 @@
 }
 
 /* GetFileVersionInfo				[VER.7] */
-DWORD 
-GetFileVersionInfo16(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data) {
+DWORD  WINAPI GetFileVersionInfo16(LPCSTR filename,DWORD handle,DWORD datasize,
+                                   LPVOID data)
+{
 	dprintf_ver(stddeb,"GetFileVersionInfo16(%s,%ld,%ld,%p)\n->",
 		filename,handle,datasize,data
 	);
@@ -506,14 +507,15 @@
 }
 
 /* GetFileVersionInfoA				[VERSION.0] */
-DWORD 
-GetFileVersionInfo32A(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data) {
+DWORD  WINAPI GetFileVersionInfo32A(LPCSTR filename,DWORD handle,
+                                    DWORD datasize,LPVOID data)
+{
 	return GetFileVersionInfo16(filename,handle,datasize,data);
 }
 
 /* GetFileVersionInfoW				[VERSION.3] */
-DWORD GetFileVersionInfo32W( LPCWSTR filename, DWORD handle, DWORD datasize,
-                             LPVOID data)
+DWORD WINAPI GetFileVersionInfo32W( LPCWSTR filename, DWORD handle,
+                                    DWORD datasize, LPVOID data)
 {
     LPSTR fn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
     DWORD ret = GetFileVersionInfo16( fn, handle, datasize, data );
@@ -534,7 +536,7 @@
  *
  ****************************************************************************/
 
-DWORD VerFindFile16(
+DWORD WINAPI VerFindFile16(
     UINT16 flags,
     LPCSTR lpszFilename,
     LPCSTR lpszWinDir,
@@ -693,8 +695,7 @@
 }
 
 /* VerFindFileA						[VERSION.5] */
-DWORD
-VerFindFile32A(
+DWORD WINAPI VerFindFile32A(
 	UINT32 flags,LPCSTR filename,LPCSTR windir,LPCSTR appdir,
 	LPSTR curdir,UINT32 *pcurdirlen,LPSTR destdir,UINT32 *pdestdirlen )
 {
@@ -707,8 +708,7 @@
 }
 
 /* VerFindFileW						[VERSION.6] */
-DWORD
-VerFindFile32W(
+DWORD WINAPI VerFindFile32W(
 	UINT32 flags,LPCWSTR filename,LPCWSTR windir,LPCWSTR appdir,
 	LPWSTR curdir,UINT32 *pcurdirlen,LPWSTR destdir,UINT32 *pdestdirlen )
 {
@@ -735,8 +735,7 @@
 }
 
 /* VerInstallFile					[VER.9] */
-DWORD
-VerInstallFile16(
+DWORD WINAPI VerInstallFile16(
 	UINT16 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
  	LPCSTR destdir,LPCSTR curdir,LPSTR tmpfile,UINT16 *tmpfilelen )
 {
@@ -784,8 +783,7 @@
     }
 }
 
-DWORD
-VerInstallFile32A(
+DWORD WINAPI VerInstallFile32A(
 	UINT32 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
  	LPCSTR destdir,LPCSTR curdir,LPSTR tmpfile,UINT32 *tmpfilelen )
 {
@@ -948,8 +946,7 @@
 }
 
 /* VerInstallFileW				[VERSION.8] */
-DWORD
-VerInstallFile32W(
+DWORD WINAPI VerInstallFile32W(
 	UINT32 flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
 	LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,UINT32 *tmpfilelen )
 {
@@ -1035,8 +1032,8 @@
 
 /* VerQueryValue 			[VER.11] */
 /* take care, 'buffer' is NOT a SEGPTR, it just points to one */
-DWORD
-VerQueryValue16(SEGPTR segblock,LPCSTR subblock,SEGPTR *buffer,UINT16 *buflen)
+DWORD WINAPI VerQueryValue16(SEGPTR segblock,LPCSTR subblock,SEGPTR *buffer,
+                             UINT16 *buflen)
 {
 	BYTE	*block=PTR_SEG_TO_LIN(segblock),*b;
 	struct	db	*db;
@@ -1062,8 +1059,8 @@
 	return 1;
 }
 
-DWORD
-VerQueryValue32A(LPVOID vblock,LPCSTR subblock,LPVOID *vbuffer,UINT32 *buflen)
+DWORD WINAPI VerQueryValue32A(LPVOID vblock,LPCSTR subblock,
+                              LPVOID *vbuffer,UINT32 *buflen)
 {
 	BYTE	*b,*block=(LPBYTE)vblock,**buffer=(LPBYTE*)vbuffer;
 	struct	db	*db;
@@ -1088,8 +1085,8 @@
 	return 1;
 }
 
-DWORD
-VerQueryValue32W(LPVOID vblock,LPCWSTR subblock,LPVOID *vbuffer,UINT32 *buflen)
+DWORD WINAPI VerQueryValue32W(LPVOID vblock,LPCWSTR subblock,LPVOID *vbuffer,
+                              UINT32 *buflen)
 {
 	/* FIXME: hmm, we not only need to convert subblock, but also 
 	 *        the content...or?
diff --git a/misc/w32sys.c b/misc/w32sys.c
index 8fae50d..427b47e 100644
--- a/misc/w32sys.c
+++ b/misc/w32sys.c
@@ -12,7 +12,7 @@
 /***********************************************************************
  *           GetWin32sInfo   (W32SYS.12)
  */
-WORD GetWin32sInfo( LPWIN32SINFO lpInfo)
+WORD WINAPI GetWin32sInfo( LPWIN32SINFO lpInfo)
 {
     lpInfo->bMajor = 1;
     lpInfo->bMinor = 3;
diff --git a/misc/winsock.c b/misc/winsock.c
index 159ed1c..3246b41 100644
--- a/misc/winsock.c
+++ b/misc/winsock.c
@@ -2,14 +2,9 @@
  * based on Windows Sockets 1.1 specs
  * (ftp.microsoft.com:/Advsys/winsock/spec11/WINSOCK.TXT)
  * 
- * (C) 1993,1994,1996 John Brezak, Erik Bos, Alex Korobka.
+ * (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
  *
- * TODO: Merge Async...() handling with X event loop by adding 
- *	 thread/task fdset to select(2) in windows/event.c.
- *       Also fork dns lookup helper during the startup (with a pipe 
- *	 for communication) and make it fork for a database request
- *	 instead of forking the main process (i.e. something like 
- *	 Netscape 4.0).
+ * TODO: 32-bit asynchronous services.
  */
  
 #include <stdio.h>
@@ -41,6 +36,8 @@
 #include "winnt.h"
 #include "heap.h"
 #include "ldt.h"
+#include "task.h"
+#include "message.h"
 #include "winsock.h"
 #include "miscemu.h"
 #include "stddebug.h"
@@ -57,10 +54,6 @@
 /* ----------------------------------- internal data */
 
 extern int h_errno;
-extern void __sigio(int);
-
-ws_async_ctl            async_ctl;
-int                     async_qid = -1;
 
 static HANDLE32 	_WSHeap = 0;
 static unsigned char*	_ws_stub = NULL;
@@ -74,13 +67,13 @@
 #define WS_PTR2HANDLE(ptr) \
         ((short)((int)(ptr) - (int)_ws_stub))
 #define WS_HANDLE2PTR(handle) \
-        ((unsigned)((int)_ws_stub + (int)handle))
+        ((unsigned)((int)_ws_stub + (int)(handle)))
 
 #define WSI_CHECK_RANGE(pwsi, pws) \
 	( ((unsigned)(pws) > (unsigned)(pwsi)) && \
 	  ((unsigned)(pws) < ((unsigned)(pwsi) + sizeof(WSINFO))) )
 
-static INT16         _ws_sock_ops[] =
+static INT32         _ws_sock_ops[] =
        { WS_SO_DEBUG, WS_SO_REUSEADDR, WS_SO_KEEPALIVE, WS_SO_DONTROUTE,
          WS_SO_BROADCAST, WS_SO_LINGER, WS_SO_OOBINLINE, WS_SO_SNDBUF,
          WS_SO_RCVBUF, WS_SO_ERROR, WS_SO_TYPE, WS_SO_DONTLINGER, 0 };
@@ -89,28 +82,27 @@
          SO_LINGER, SO_OOBINLINE, SO_SNDBUF, SO_RCVBUF, SO_ERROR, SO_TYPE,
 	 SO_LINGER };
 
-static INT16 init_async_select(ws_socket* pws, HWND16 hWnd, UINT16 uMsg, UINT32 lEvent);
-static int notify_client(ws_socket* pws, unsigned flag);
-
 static int _check_ws(LPWSINFO pwsi, ws_socket* pws);
 static int _check_buffer(LPWSINFO pwsi, int size);
 
-static void fixup_wshe(struct ws_hostent* p_wshe, SEGPTR base);
-static void fixup_wspe(struct ws_protoent* p_wspe, SEGPTR base);
-static void fixup_wsse(struct ws_servent* p_wsse, SEGPTR base);
+extern void EVENT_AddIO( int fd, unsigned flag );
+extern void EVENT_DeleteIO( int fd, unsigned flag );
 
-static int cancel_async_select(ws_socket*);
-
-static void convert_sockopt(INT16 *level, INT16 *optname)
+/***********************************************************************
+ *          convert_sockopt()
+ *
+ * Converts socket flags from Windows format.
+ */
+static void convert_sockopt(INT32 *level, INT32 *optname)
 {
-  int           i;
+  int i;
   switch (*level)
   {
      case WS_SOL_SOCKET:
         *level = SOL_SOCKET;
         for(i=0; _ws_sock_ops[i]; i++)
             if( _ws_sock_ops[i] == *optname ) break;
-        if( _ws_sock_ops[i] ) *optname = (INT16)_px_sock_ops[i];
+        if( _ws_sock_ops[i] ) *optname = _px_sock_ops[i];
         else fprintf(stderr, "convert_sockopt() unknown optname %d\n", *optname);
         break;
      case WS_IPPROTO_TCP:
@@ -118,71 +110,63 @@
   }
 }
 
-static void _ws_global_init()
-{
-   if( !_ws_stub )
-   {
-     _WSHeap = HeapCreate(HEAP_ZERO_MEMORY, 8120, 32768);
-     if( !(_ws_stub = WS_ALLOC(0x10)) )
-       fprintf(stderr,"Fatal: failed to create WinSock heap\n");
-   }
-   if( async_qid == -1 ) 
-     if( (async_qid = msgget(IPC_PRIVATE, IPC_CREAT | 0x1FF)) == -1 )
-       fprintf(stderr,"Fatal: failed to create WinSock resource\n");
-}
-
-/* ----------------------------------- Per-thread info */
-
-static void wsi_link(LPWSINFO pwsi)
-{ if( _wsi_list ) _wsi_list->prev = pwsi;
-  pwsi->next = _wsi_list; _wsi_list = pwsi; 
-}
-
-static void wsi_unlink(LPWSINFO pwsi)
-{
-  if( pwsi == _wsi_list ) _wsi_list = pwsi->next;
-  else 
-  { pwsi->prev->next = pwsi->next;
-    if( pwsi->next ) pwsi->next->prev = pwsi->prev; } 
-}
+/* ----------------------------------- Per-thread info (or per-process?) */
 
 static LPWSINFO wsi_find(HTASK16 hTask)
-{ LPWSINFO pwsi = _wsi_list;
-  while( pwsi && pwsi->tid != hTask ) pwsi = pwsi->next;
-  return pwsi; 
+{ 
+    TDB*	   pTask = (TDB*)GlobalLock16(hTask);
+    if( pTask )
+    {
+	if( pTask->pwsi ) return pTask->pwsi;
+	else
+	{
+	    LPWSINFO pwsi = _wsi_list;
+	    while( pwsi && pwsi->tid != hTask ) pwsi = pwsi->next;
+	    if( pwsi )
+		fprintf(stderr,"loose wsi struct! pwsi=0x%08x, task=0x%04x\n", 
+					(unsigned)pwsi, hTask );
+	    return pwsi; 
+	}
+    }
+    return NULL;
 }
 
 static ws_socket* wsi_alloc_socket(LPWSINFO pwsi, int fd)
 {
-  if( pwsi->last_free >= 0 )
-  {
-    int i = pwsi->last_free;
+    /* Initialize a new entry in the socket table */
 
-    pwsi->last_free = pwsi->sock[i].flags;
-    pwsi->sock[i].fd = fd;
-    pwsi->sock[i].flags = 0;
-    return &pwsi->sock[i];
-  }
-  return NULL;
+    if( pwsi->last_free >= 0 )
+    {
+	int i = pwsi->last_free;
+
+	pwsi->last_free = pwsi->sock[i].flags;	/* free list */
+	pwsi->sock[i].fd = fd;
+	pwsi->sock[i].flags = 0;
+	return &pwsi->sock[i];
+    }
+    return NULL;
 }
 
 static void fd_set_normalize(fd_set* fds, LPWSINFO pwsi, ws_fd_set* ws, int* highfd)
 {
-  FD_ZERO(fds);
-  if(ws) 
-  { 
-    int 	i;
-    ws_socket*  pws;
-    for(i=0;i<(ws->fd_count);i++) 
-    {
-      pws = (ws_socket*)WS_HANDLE2PTR(ws->fd_array[i]);
-      if( _check_ws(pwsi, pws) ) 
-      { 
-        if( pws->fd > *highfd ) *highfd = pws->fd; 
-        FD_SET(pws->fd, fds); 
-      }
+    /* translate Winsock fd set into the normal fd set */
+
+    FD_ZERO(fds);
+    if( ws ) 
+    { 
+	int 	i;
+	ws_socket*  pws;
+
+	for( i = 0; i < (ws->fd_count) ; i++ ) 
+	{
+	    pws = (ws_socket*)WS_HANDLE2PTR(ws->fd_array[i]);
+	    if( _check_ws(pwsi, pws) ) 
+	    {
+		if( pws->fd > *highfd ) *highfd = pws->fd; 
+		FD_SET(pws->fd, fds); 
+	    }
+	}
     }
-  }
 }
 
 /*
@@ -229,24 +213,19 @@
     return;
 }
 
-static void fd_set_update_except(LPWSINFO pwsi, fd_set *fds, ws_fd_set *ws,
-				 fd_set *errorfds)
+HANDLE16 __ws_gethandle( void* ptr )
 {
-    if (ws)
-    {
-	int i, j, count = ws->fd_count;
+    return (HANDLE16)WS_PTR2HANDLE(ptr);
+}
 
-	for (i=j=0; i < count; i++)
-	{
-	    ws_socket *pws = (ws_socket *)WS_HANDLE2PTR(ws->fd_array[i]);
+void* __ws_memalloc( int size )
+{
+    return WS_ALLOC(size);
+}
 
-	    if (_check_ws(pwsi, pws) && (FD_ISSET(pws->fd, fds)
-                                         || FD_ISSET(pws->fd, errorfds)))
-	    ws->fd_array[j++] = ws->fd_array[i];
-	}
-	ws->fd_count = j;
-    }
-    return;
+void __ws_memfree(void* ptr)
+{
+    WS_FREE(ptr);
 }
 
 /* ----------------------------------- API ----- 
@@ -254,9 +233,15 @@
  * Init / cleanup / error checking.
  */
 
-INT16 WSAStartup(UINT16 wVersionRequested, LPWSADATA lpWSAData)
+/***********************************************************************
+ *      WSAStartup16()			(WINSOCK.115)
+ *
+ * Create socket control struct, attach it to the global list and
+ * update a pointer in the task struct.
+ */
+INT16 WINAPI WSAStartup16(UINT16 wVersionRequested, LPWSADATA lpWSAData)
 {
-  WSADATA WINSOCK_data = { 0x0101, 0x0101,
+    WSADATA WINSOCK_data = { 0x0101, 0x0101,
                           "WINE Sockets 1.1",
                         #ifdef linux
                                 "Linux/i386",
@@ -272,191 +257,288 @@
                                 "Unknown",
                         #endif
 			   WS_MAX_SOCKETS_PER_THREAD,
-			   WS_MAX_UDP_DATAGRAM, NULL };
-  HTASK16               tid = GetCurrentTask();
-  LPWSINFO              pwsi;
+			   WS_MAX_UDP_DATAGRAM, (SEGPTR)NULL };
+    HTASK16             tid = GetCurrentTask();
+    LPWSINFO            pwsi;
 
-  dprintf_winsock(stddeb, "WSAStartup: verReq=%x\n", wVersionRequested);
+    dprintf_winsock(stddeb, "WSAStartup: verReq=%x\n", wVersionRequested);
 
-  if (LOBYTE(wVersionRequested) < 1 || (LOBYTE(wVersionRequested) == 1 &&
-      HIBYTE(wVersionRequested) < 1)) return WSAVERNOTSUPPORTED;
+    if (LOBYTE(wVersionRequested) < 1 || (LOBYTE(wVersionRequested) == 1 &&
+        HIBYTE(wVersionRequested) < 1)) return WSAVERNOTSUPPORTED;
 
-  if (!lpWSAData) return WSAEINVAL;
+    if (!lpWSAData) return WSAEINVAL;
 
-  _ws_global_init();
-  if( _WSHeap == 0 ) return WSASYSNOTREADY;
-  
-  pwsi = wsi_find(GetCurrentTask());
-  if( pwsi == NULL )
-  {
-    if( (pwsi = (LPWSINFO)WS_ALLOC( sizeof(WSINFO))) )
+    /* initialize socket heap */
+
+    if( !_ws_stub )
     {
-      int i = 0;
-      pwsi->tid = tid;
-      for( i = 0; i < WS_MAX_SOCKETS_PER_THREAD; i++ )
-      { 
-	pwsi->sock[i].fd = -1; 
-	pwsi->sock[i].flags = i + 1; 
-      }
-      pwsi->sock[WS_MAX_SOCKETS_PER_THREAD - 1].flags = -1;
-    } 
-    else return WSASYSNOTREADY;
-    wsi_link(pwsi);
-  } else pwsi->num_startup++;
+	_WSHeap = HeapCreate(HEAP_ZERO_MEMORY, 8120, 32768);
+	if( !(_ws_stub = WS_ALLOC(0x10)) )
+	{
+	    fprintf(stderr,"Fatal: failed to create WinSock heap\n");
+	    return 0;
+	}
+    }
+    if( _WSHeap == 0 ) return WSASYSNOTREADY;
 
-  /* return winsock information */
-  memcpy(lpWSAData, &WINSOCK_data, sizeof(WINSOCK_data));
+    /* create socket array for this task */
+  
+    pwsi = wsi_find(GetCurrentTask());
+    if( pwsi == NULL )
+    {
+	TDB* pTask = (TDB*)GlobalLock16( tid );
 
-  dprintf_winsock(stddeb, "WSAStartup: succeeded\n");
-  return(0);
+	if( (pwsi = (LPWSINFO)WS_ALLOC( sizeof(WSINFO))) )
+	{
+	    int i = 0;
+	    pwsi->tid = tid;
+	    for( i = 0; i < WS_MAX_SOCKETS_PER_THREAD; i++ )
+	    {
+		pwsi->sock[i].fd = -1; 
+		pwsi->sock[i].flags = i + 1; 
+	    }
+	    pwsi->sock[WS_MAX_SOCKETS_PER_THREAD - 1].flags = -1;
+	}
+	else return WSASYSNOTREADY;
+
+        /* add this control struct to the global list */
+
+	pwsi->prev = NULL;
+	if( _wsi_list ) 
+	    _wsi_list->prev = pwsi;
+	pwsi->next = _wsi_list; 
+	_wsi_list = pwsi;
+	pTask->pwsi = pwsi;
+    }
+    else pwsi->num_startup++;
+
+    /* return winsock information */
+
+    memcpy(lpWSAData, &WINSOCK_data, sizeof(WINSOCK_data));
+
+    dprintf_winsock(stddeb, "WSAStartup: succeeded\n");
+    return 0;
 }
 
+/***********************************************************************
+ *      WSAStartup32()			(WSOCK32.115)
+ */
+INT32 WINAPI WSAStartup32(UINT32 wVersionRequested, LPWSADATA lpWSAData)
+{
+    return WSAStartup16( wVersionRequested, lpWSAData );
+}
+
+/***********************************************************************
+ *      WSACleanup()			(WINSOCK.116)
+ *
+ * Cleanup functions of varying impact.
+ */
 void WINSOCK_Shutdown()
 {
-  if( async_qid != -1 )
-    if( msgctl(async_qid, IPC_RMID, NULL) == -1 )
-          fprintf(stderr,"failed to delete WS message queue.\n");
-    else async_qid = -1;
+    /* Called on exit(), has to remove all outstanding async DNS processes.  */
+
+    WINSOCK_cancel_task_aops( 0, __ws_memfree );
 }
 
-INT16 WSACleanup(void)
+INT32 WINSOCK_DeleteTaskWSI( TDB* pTask, LPWSINFO pwsi )
 {
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    /* WSACleanup() backend, called on task termination as well. */
 
-  /* FIXME: do global cleanup if no current task */
+    int	i, j, n;
 
-  dprintf_winsock(stddeb, "WSACleanup(%08x)\n", (unsigned)pwsi);
-  if( pwsi )
-  {
-      int	i, j, n;
+    if( --pwsi->num_startup > 0 ) return 0;
 
-      if( pwsi->num_startup-- ) return 0;
+    SIGNAL_MaskAsyncEvents( TRUE );
+    if( pTask ) 
+	pTask->pwsi = NULL;
+    WINSOCK_cancel_task_aops( pTask->hSelf, __ws_memfree );
+    SIGNAL_MaskAsyncEvents( FALSE );
 
-      SIGNAL_MaskAsyncEvents( TRUE );
-      WINSOCK_cancel_async_op(GetCurrentTask());
-      SIGNAL_MaskAsyncEvents( FALSE );
+    /* unlink socket control struct */
 
-      wsi_unlink(pwsi);
-      if( _wsi_list == NULL ) WINSOCK_Shutdown();
+    if( pwsi == _wsi_list ) 
+	_wsi_list = pwsi->next;
+    else
+	pwsi->prev->next = pwsi->next;
+    if( pwsi->next ) pwsi->next->prev = pwsi->prev; 
 
-      if( pwsi->flags & WSI_BLOCKINGCALL )
-	  dprintf_winsock(stddeb,"\tinside blocking call!\n");
-      if( pwsi->num_async_rq )
-	  dprintf_winsock(stddeb,"\thave %i outstanding async ops!\n", pwsi->num_async_rq );
+    if( _wsi_list == NULL ) 
+	WINSOCK_Shutdown();	/* just in case */
 
-      for(i = 0, j = 0, n = 0; i < WS_MAX_SOCKETS_PER_THREAD; i++)
+    if( pwsi->flags & WSI_BLOCKINGCALL )
+	dprintf_winsock(stddeb,"\tinside blocking call!\n");
+
+/* FIXME: aop_control() doesn't decrement pwsi->num_async_rq
+ *
+ *    if( pwsi->num_async_rq )
+ *	  dprintf_winsock(stddeb,"\thave %i outstanding async ops!\n", pwsi->num_async_rq );
+ */
+
+    for(i = 0, j = 0, n = 0; i < WS_MAX_SOCKETS_PER_THREAD; i++)
 	if( pwsi->sock[i].fd != -1 )
-	{ 
-	  n += cancel_async_select(&pwsi->sock[i]);
-          close(pwsi->sock[i].fd); j++; 
+	{
+	    if( pwsi->sock[i].psop )
+	    {
+		n++;
+		WSAAsyncSelect( (SOCKET16)WS_PTR2HANDLE(pwsi->sock + i), 0, 0, 0 );
+	    }
+            close(pwsi->sock[i].fd); j++; 
         }
-      if( j ) 
+    if( j ) 
 	  dprintf_winsock(stddeb,"\tclosed %i sockets, killed %i async selects!\n", j, n);
 
-      if( pwsi->buffer ) SEGPTR_FREE(pwsi->buffer);
-      if( pwsi->dbuffer ) SEGPTR_FREE(pwsi->dbuffer);
-      WS_FREE(pwsi);
-      return 0;
-  }
-  return SOCKET_ERROR;
+    /* delete scratch buffers */
+
+    if( pwsi->buffer ) SEGPTR_FREE(pwsi->buffer);
+    if( pwsi->dbuffer ) SEGPTR_FREE(pwsi->dbuffer);
+	
+    memset( pwsi, 0, sizeof(WSINFO) );
+    WS_FREE(pwsi);
+    return 0;
 }
 
-INT16 WSAGetLastError(void)
+INT32 WINAPI WSACleanup(void)
 {
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-  INT16		ret;
+    HTASK16	hTask = GetCurrentTask();
 
-  dprintf_winsock(stddeb, "WSAGetLastError(%08x)", (unsigned)pwsi);
-
-  ret = (pwsi) ? pwsi->err : WSANOTINITIALISED;
-
-  dprintf_winsock(stddeb, " = %i\n", (int)ret);
-  return ret;
+    dprintf_winsock(stddeb, "WSACleanup(%04x)\n", hTask );
+    if( hTask )
+    {
+	LPWSINFO pwsi = wsi_find(hTask);
+	if( pwsi )
+	    return WINSOCK_DeleteTaskWSI( (TDB*)GlobalLock16(hTask), pwsi );
+	return SOCKET_ERROR;
+    }
+    else
+	WINSOCK_Shutdown(); /* remove all outstanding DNS requests */
+    return 0;
 }
 
-void WSASetLastError(INT16 iError)
+
+/***********************************************************************
+ *      WSAGetLastError()		(WSOCK32.111)(WINSOCK.111)
+ */
+INT32 WINAPI WSAGetLastError(void)
 {
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    INT16		ret;
 
-  dprintf_winsock(stddeb, "WSASetLastError(%08x): %d\n", (unsigned)pwsi, (int)iError);
+    dprintf_winsock(stddeb, "WSAGetLastError(%08x)", (unsigned)pwsi);
 
-  if( pwsi ) pwsi->err = iError;
+    ret = (pwsi) ? pwsi->err : WSANOTINITIALISED;
+
+    dprintf_winsock(stddeb, " = %i\n", (int)ret);
+    return ret;
+}
+
+/***********************************************************************
+ *      WSASetLastError32()		(WSOCK32.112)
+ */
+void WINAPI WSASetLastError32(INT32 iError)
+{
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WSASetLastError(%08x): %d\n", (unsigned)pwsi, (int)iError);
+    if( pwsi ) pwsi->err = iError;
+}
+
+/***********************************************************************
+ *      WSASetLastError16()		(WINSOCK.112)
+ */
+void WINAPI WSASetLastError16(INT16 iError)
+{
+    WSASetLastError32(iError);
 }
 
 int _check_ws(LPWSINFO pwsi, ws_socket* pws)
 {
-  if( pwsi )
-    if( pwsi->flags & WSI_BLOCKINGCALL ) pwsi->err = WSAEINPROGRESS;
-    else if( WSI_CHECK_RANGE(pwsi, pws) ) return 1;
-    else pwsi->err = WSAENOTSOCK;
-  return 0;
+    if( pwsi )
+	if( pwsi->flags & WSI_BLOCKINGCALL ) pwsi->err = WSAEINPROGRESS;
+	else if( WSI_CHECK_RANGE(pwsi, pws) ) return 1;
+		 else pwsi->err = WSAENOTSOCK;
+    return 0;
 }
 
 int _check_buffer(LPWSINFO pwsi, int size)
 {
-  if( pwsi->buffer && pwsi->buflen >= size ) return 1;
-  else SEGPTR_FREE(pwsi->buffer);
-  pwsi->buffer = (char*)SEGPTR_ALLOC((pwsi->buflen = size)); 
-  return (pwsi->buffer != NULL);
+    if( pwsi->buffer && pwsi->buflen >= size ) return 1;
+    else SEGPTR_FREE(pwsi->buffer);
+
+    pwsi->buffer = (char*)SEGPTR_ALLOC((pwsi->buflen = size)); 
+    return (pwsi->buffer != NULL);
 }
 
-/* ----- socket operations */
+/* ----------------------------------- i/o APIs */
 
-SOCKET16 WINSOCK_accept(SOCKET16 s, struct sockaddr *addr, INT16 *addrlen16)
+/***********************************************************************
+ *		accept()		(WSOCK32.1)
+ */
+SOCKET32 WINAPI WINSOCK_accept32(SOCKET32 s, struct sockaddr *addr,
+                                 INT32 *addrlen32)
 {
-  ws_socket*	pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO	pwsi = wsi_find(GetCurrentTask());
+    ws_socket*	pws  = (ws_socket*)WS_HANDLE2PTR((SOCKET16)s);
+    LPWSINFO	pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_ACCEPT(%08x): socket %04x\n", 
-				   (unsigned)pwsi, (UINT16)s); 
-  if( _check_ws(pwsi, pws) )
-  {
-     int 	sock, fd_flags, addrlen32 = *addrlen16;
+    dprintf_winsock(stddeb, "WS_ACCEPT(%08x): socket %04x\n", 
+				  (unsigned)pwsi, (UINT16)s ); 
+    if( _check_ws(pwsi, pws) )
+    {
+	int 	sock, fd_flags;
 
-     /* this is how block info is supposed to be used -
-      * WSAIsBlocking() would then check WSI_BLOCKINGCALL bit.
-      */
+	fd_flags = fcntl(pws->fd, F_GETFL, 0);
 
-     fd_flags = fcntl(pws->fd, F_GETFL, 0);
-     if( !(fd_flags & O_NONBLOCK) ) pwsi->flags |= WSI_BLOCKINGCALL; 
+	if( (sock = accept(pws->fd, addr, addrlen32)) >= 0 )
+	{
+	    ws_socket*	pnew = wsi_alloc_socket(pwsi, sock); 
+	    if( pnew )
+	    {
+		s = (SOCKET32)WS_PTR2HANDLE(pnew);
+		if( pws->psop && pws->flags & WS_FD_ACCEPT )
+		{
+		    EVENT_AddIO( pws->fd, EVENT_IO_READ );	/* reenabler */
 
-     if( (sock = accept(pws->fd, addr, &addrlen32)) >= 0 )
-     {
-        ws_socket*	pnew = wsi_alloc_socket(pwsi, sock); 
-	notify_client(pws, WS_FD_ACCEPT);
-        if( pnew )
-        {
-	  if( pws->p_aop )
-	      init_async_select(pnew, pws->p_aop->hWnd,
-				      pws->p_aop->uMsg,
-				      pws->p_aop->flags & ~WS_FD_ACCEPT );
-
-	  pwsi->flags &= ~WSI_BLOCKINGCALL; 
-	  return (SOCKET16)WS_PTR2HANDLE(pnew);
-        } 
-	else pwsi->err = WSAENOBUFS;
-     } 
-     else pwsi->err = wsaErrno();
-
-     pwsi->flags &= ~WSI_BLOCKINGCALL;
-  }
-  return INVALID_SOCKET;
+		    /* async select the accept()'ed socket */
+		    WSAAsyncSelect( s, pws->psop->hWnd, pws->psop->uMsg,
+				    pws->flags & ~WS_FD_ACCEPT );
+		}
+		return s;
+            } 
+	    else pwsi->err = WSAENOBUFS;
+	} 
+	else pwsi->err = wsaErrno();
+    }
+    return INVALID_SOCKET32;
 }
 
-INT16 WINSOCK_bind(SOCKET16 s, struct sockaddr *name, INT16 namelen)
+/***********************************************************************
+ *              accept()		(WINSOCK.1)
+ */
+SOCKET16 WINAPI WINSOCK_accept16(SOCKET16 s, struct sockaddr* addr,
+                                 INT16* addrlen16 )
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    INT32 addrlen32 = *addrlen16;
+    SOCKET32 retSocket = WINSOCK_accept32( s, addr, &addrlen32 );
+   *addrlen16 = (INT16)addrlen32;
+    return (SOCKET16)retSocket;
+}
 
-  dprintf_winsock(stddeb, "WS_BIND(%08x): socket %04x, ptr %8x, length %d\n", 
+/***********************************************************************
+ *		bind()			(WSOCK32.2)
+ */
+INT32 WINAPI WINSOCK_bind32(SOCKET32 s, struct sockaddr *name, INT32 namelen)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_BIND(%08x): socket %04x, ptr %8x, length %d\n", 
 			   (unsigned)pwsi, s, (int) name, namelen);
 #if 0
-  dump_sockaddr(name);
+    dump_sockaddr(name);
 #endif
 
-  if ( _check_ws(pwsi, pws) )
-    if (namelen >= sizeof(*name)) 
-       if ( ((struct sockaddr_in *)name)->sin_family == AF_INET )
+    if ( _check_ws(pwsi, pws) )
+      if ( namelen >= sizeof(*name) ) 
+	if ( ((struct sockaddr_in *)name)->sin_family == AF_INET )
 	  if ( bind(pws->fd, name, namelen) < 0 ) 
 	  {
 	     int	loc_errno = errno;
@@ -469,34 +551,59 @@
 		default: pwsi->err = wsaErrno();
 	     }
 	  }
-	  else return 0;
-       else pwsi->err = WSAEAFNOSUPPORT;
-    else pwsi->err = WSAEFAULT;
-  return SOCKET_ERROR;
+	  else return 0; /* success */
+	else pwsi->err = WSAEAFNOSUPPORT;
+      else pwsi->err = WSAEFAULT;
+    return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_closesocket(SOCKET16 s)
+/***********************************************************************
+ *              bind()			(WINSOCK.2)
+ */
+INT16 WINAPI WINSOCK_bind16(SOCKET16 s, struct sockaddr *name, INT16 namelen)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_CLOSE(%08x): socket %08x\n", (unsigned)pwsi, s);
-
-  if( _check_ws(pwsi, pws) )
-  { 
-    int		fd = pws->fd;
-
-    cancel_async_select(pws);
-    pws->fd = -1;
-    pws->flags = (unsigned)pwsi->last_free;
-    pwsi->last_free = pws - &pwsi->sock[0];
-    if (close(fd) == 0) return 0;
-    pwsi->err = (errno == EBADF) ? WSAENOTSOCK : wsaErrno();
-  }
-  return SOCKET_ERROR;
+  return (INT16)WINSOCK_bind32( s, name, namelen );
 }
 
-INT16 WINSOCK_connect(SOCKET16 s, struct sockaddr *name, INT16 namelen)
+/***********************************************************************
+ *		closesocket()		(WSOCK32.3)
+ */
+INT32 WINAPI WINSOCK_closesocket32(SOCKET32 s)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_CLOSE(%08x): socket %08x\n", (unsigned)pwsi, s);
+
+    if( _check_ws(pwsi, pws) )
+    { 
+	int	fd = pws->fd;
+
+	if( pws->psop ) WSAAsyncSelect( s, 0, 0, 0 );
+
+	pws->fd = -1;
+	pws->flags = (unsigned)pwsi->last_free;
+	pwsi->last_free = pws - &pwsi->sock[0]; /* add to free list */
+
+	if( close(fd) == 0 ) 
+	    return 0;
+	pwsi->err = (errno == EBADF) ? WSAENOTSOCK : wsaErrno();
+    }
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              closesocket()           (WINSOCK.3)
+ */
+INT16 WINAPI WINSOCK_closesocket16(SOCKET16 s)
+{
+    return (INT16)WINSOCK_closesocket32(s);
+}
+
+/***********************************************************************
+ *		connect()		(WSOCK32.4)
+ */
+INT32 WINAPI WINSOCK_connect32(SOCKET32 s, struct sockaddr *name, INT32 namelen)
 {
   ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
   LPWSINFO      pwsi = wsi_find(GetCurrentTask());
@@ -511,13 +618,22 @@
   {
     if (connect(pws->fd, name, namelen) == 0) 
     { 
-	if( pws->p_aop )
-	    /* we need to notify handler process if
-	     * connect() succeeded NOT in response to winsock message
-	     */
-	    notify_client(pws, WS_FD_CONNECTED);
-
-        pws->flags &= ~(WS_FD_INACTIVE | WS_FD_CONNECT); 
+	pws->flags &= ~(WS_FD_INACTIVE | WS_FD_CONNECT);
+	if( pws->psop && pws->flags & WS_FD_CONNECT )
+	{
+	    if( !(pws->flags & WS_FD_CONNECTED) )
+	    {
+		if( pws->flags & (WS_FD_READ | WS_FD_CLOSE) )
+		    EVENT_AddIO( pws->fd, EVENT_IO_READ );
+		else
+		    EVENT_DeleteIO( pws->fd, EVENT_IO_READ );
+		if( pws->flags & WS_FD_WRITE )
+		    EVENT_AddIO( pws->fd, EVENT_IO_WRITE );
+		else
+		    EVENT_DeleteIO( pws->fd, EVENT_IO_WRITE );
+		pws->flags |= WS_FD_CONNECTED;
+	    }
+	}
         return 0; 
     }
     pwsi->err = (errno == EINPROGRESS) ? WSAEWOULDBLOCK : wsaErrno();
@@ -525,77 +641,142 @@
   return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_getpeername(SOCKET16 s, struct sockaddr *name, INT16 *namelen)
+/***********************************************************************
+ *              connect()               (WINSOCK.4)
+ */
+INT16 WINAPI WINSOCK_connect16(SOCKET16 s, struct sockaddr *name, INT16 namelen)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+  return (INT16)WINSOCK_connect32( s, name, namelen );
+}
 
-  dprintf_winsock(stddeb, "WS_GETPEERNAME(%08x): socket: %04x, ptr %8x, ptr %8x\n", 
+/***********************************************************************
+ *		getpeername()		(WSOCK32.5)
+ */
+INT32 WINAPI WINSOCK_getpeername32(SOCKET32 s, struct sockaddr *name,
+                                   INT32 *namelen)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GETPEERNAME(%08x): socket: %04x, ptr %8x, ptr %8x\n", 
 			   (unsigned)pwsi, s, (int) name, *namelen);
-  if( _check_ws(pwsi, pws) )
-  {
-    int	namelen32 = *namelen;
-    if (getpeername(pws->fd, name, &namelen32) == 0) 
-    { 
+    if( _check_ws(pwsi, pws) )
+    {
+	if (getpeername(pws->fd, name, namelen) == 0) 
+	    return 0; 
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              getpeername()		(WINSOCK.5)
+ */
+INT16 WINAPI WINSOCK_getpeername16(SOCKET16 s, struct sockaddr *name,
+                                   INT16 *namelen16)
+{
+    INT32 namelen32 = *namelen16;
+    INT32 retVal = WINSOCK_getpeername32( s, name, &namelen32 );
+
 #if 0
-	dump_sockaddr(name);
+    dump_sockaddr(name);
 #endif
-       *namelen = (INT16)namelen32; 
-        return 0; 
-    }
-    pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return SOCKET_ERROR;
+
+   *namelen16 = namelen32;
+    return (INT16)retVal;
 }
 
-INT16 WINSOCK_getsockname(SOCKET16 s, struct sockaddr *name, INT16 *namelen)
+/***********************************************************************
+ *		getsockname()		(WSOCK32.6)
+ */
+INT32 WINAPI WINSOCK_getsockname32(SOCKET32 s, struct sockaddr *name,
+                                   INT32 *namelen)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_GETSOCKNAME(%08x): socket: %04x, ptr %8x, ptr %8x\n", 
+    dprintf_winsock(stddeb, "WS_GETSOCKNAME(%08x): socket: %04x, ptr %8x, ptr %8x\n", 
 			  (unsigned)pwsi, s, (int) name, (int) *namelen);
-  if( _check_ws(pwsi, pws) )
-  {
-    int namelen32 = *namelen;
-    if (getsockname(pws->fd, name, &namelen32) == 0)
-    { 
-	*namelen = (INT16)namelen32; 
-	 return 0; 
+    if( _check_ws(pwsi, pws) )
+    {
+	if (getsockname(pws->fd, name, namelen) == 0)
+	    return 0; 
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
     }
-    pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return SOCKET_ERROR;
+    return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_getsockopt(SOCKET16 s, INT16 level, 
-			 INT16 optname, char *optval, INT16 *optlen)
+/***********************************************************************
+ *              getsockname()		(WINSOCK.6)
+ */
+INT16 WINAPI WINSOCK_getsockname16(SOCKET16 s, struct sockaddr *name,
+                                   INT16 *namelen16)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GETSOCKOPT(%08x): socket: %04x, opt %d, ptr %8x, ptr %8x\n", 
-			   (unsigned)pwsi, s, level, (int) optval, (int) *optlen);
-
-  if( _check_ws(pwsi, pws) )
-  {
-     int	optlen32 = *optlen;
-
-     convert_sockopt(&level, &optname);
-     if (getsockopt(pws->fd, (int) level, optname, optval, &optlen32) == 0 )
-     { *optlen = (INT16)optlen32; return 0; }
-     pwsi->err = (errno == EBADF) ? WSAENOTSOCK : wsaErrno();
-  }
-  return SOCKET_ERROR;
+    INT32 namelen32 = *namelen16;
+    INT32 retVal = WINSOCK_getsockname32( s, name, &namelen32 );
+   *namelen16 = namelen32;
+    return (INT16)retVal;
 }
 
-u_long  WINSOCK_htonl(u_long hostlong)   { return( htonl(hostlong) ); }
-u_short WINSOCK_htons(u_short hostshort) { return( htons(hostshort) ); }
-u_long  WINSOCK_inet_addr(char *cp)      { return( inet_addr(cp) ); }
-u_long  WINSOCK_ntohl(u_long netlong)    { return( ntohl(netlong) ); }
-u_short WINSOCK_ntohs(u_short netshort)  { return( ntohs(netshort) ); }
 
-SEGPTR WINSOCK_inet_ntoa(struct in_addr in)
+/***********************************************************************
+ *		getsockopt()		(WSOCK32.7)
+ */
+INT32 WINAPI WINSOCK_getsockopt32(SOCKET32 s, INT32 level, 
+                                  INT32 optname, char *optval, INT32 *optlen)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GETSOCKOPT(%08x): socket: %04x, opt %d, ptr %8x, ptr %8x\n", 
+			   (unsigned)pwsi, s, level, (int) optval, (int) *optlen);
+    if( _check_ws(pwsi, pws) )
+    {
+	convert_sockopt(&level, &optname);
+	if (getsockopt(pws->fd, (int) level, optname, optval, optlen) == 0 )
+	    return 0;
+	pwsi->err = (errno == EBADF) ? WSAENOTSOCK : wsaErrno();
+    }
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              getsockopt()		(WINSOCK.7)
+ */
+INT16 WINAPI WINSOCK_getsockopt16(SOCKET16 s, INT16 level,
+                                  INT16 optname, char *optval, INT16 *optlen)
+{
+    INT32 optlen32 = *optlen;
+    INT32 retVal = WINSOCK_getsockopt32( s, level, optname, optval, &optlen32 );
+   *optlen = optlen32;
+    return (INT16)retVal;
+}
+
+/***********************************************************************
+ *		htonl()			(WINSOCK.8)(WSOCK32.8)
+ */
+u_long WINAPI WINSOCK_htonl(u_long hostlong)   { return( htonl(hostlong) ); }
+/***********************************************************************
+ *		htons()			(WINSOCK.9)(WSOCK32.9)
+ */
+u_short WINAPI WINSOCK_htons(u_short hostshort) { return( htons(hostshort) ); }
+/***********************************************************************
+ *		inet_addr()		(WINSOCK.10)
+ */
+u_long WINAPI WINSOCK_inet_addr(char *cp)      { return( inet_addr(cp) ); }
+/***********************************************************************
+ *		htohl()			(WINSOCK.14)(WSOCK32.14)
+ */
+u_long WINAPI WINSOCK_ntohl(u_long netlong)    { return( ntohl(netlong) ); }
+/***********************************************************************
+ *		ntohs()			(WINSOCK.15)(WSOCK32.15)
+ */
+u_short WINAPI WINSOCK_ntohs(u_short netshort)  { return( ntohs(netshort) ); }
+
+/***********************************************************************
+ *		inet_ntoa()		(WINSOCK.11)
+ */
+SEGPTR WINAPI WINSOCK_inet_ntoa(struct in_addr in)
 {
   /* use "buffer for dummies" here because some applications have 
    * propensity to decode addresses in ws_hostent structure without 
@@ -623,7 +804,10 @@
   return (SEGPTR)NULL;
 }
 
-INT16 WINSOCK_ioctlsocket(SOCKET16 s, UINT32 cmd, UINT32 *argp)
+/***********************************************************************
+ *		ioctlsocket()		(WSOCK32.12)
+ */
+INT32 WINAPI WINSOCK_ioctlsocket32(SOCKET32 s, UINT32 cmd, UINT32 *argp)
 {
   ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
   LPWSINFO      pwsi = wsi_find(GetCurrentTask());
@@ -642,8 +826,9 @@
 
 	case WS_FIONBIO:    
 		newcmd=FIONBIO;  
-		if( pws->p_aop && *argp == 0 ) 
+		if( pws->psop && *argp == 0 ) 
 		{
+		    /* AsyncSelect()'ed sockets are always nonblocking */
 		    pwsi->err = WSAEINVAL; 
 		    return SOCKET_ERROR; 
 		}
@@ -668,81 +853,141 @@
   return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_listen(SOCKET16 s, INT16 backlog)
+/***********************************************************************
+ *              ioctlsocket()           (WINSOCK.12)
+ */
+INT16 WINAPI WINSOCK_ioctlsocket16(SOCKET16 s, UINT32 cmd, UINT32 *argp)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    return (INT16)WINSOCK_ioctlsocket32( s, cmd, argp );
+}
 
-  dprintf_winsock(stddeb, "WS_LISTEN(%08x): socket %04x, backlog %d\n", 
-			  (unsigned)pwsi, s, backlog);
-  if( _check_ws(pwsi, pws) )
-  {
-    if( !pws->p_aop )
+
+/***********************************************************************
+ *		listen()		(WSOCK32.13)
+ */
+INT32 WINAPI WINSOCK_listen32(SOCKET32 s, INT32 backlog)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_LISTEN(%08x): socket %04x, backlog %d\n", 
+			    (unsigned)pwsi, s, backlog);
+    if( _check_ws(pwsi, pws) )
     {
-      int  fd_flags = fcntl(pws->fd, F_GETFL, 0);
-      if( !(fd_flags & O_NONBLOCK) ) pws->flags |= WS_FD_ACCEPT;
-    }
-    else notify_client(pws, WS_FD_ACCEPT);
+	if( !pws->psop )
+	{
+	    int  fd_flags = fcntl(pws->fd, F_GETFL, 0);
+	    if( !(fd_flags & O_NONBLOCK) ) pws->flags |= WS_FD_ACCEPT;
+	}
 
-    if (listen(pws->fd, backlog) == 0) return 0;
-    pwsi->err = wsaErrno();
-  }
-  return SOCKET_ERROR;
+	if (listen(pws->fd, backlog) == 0) return 0;
+	pwsi->err = wsaErrno();
+    }
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_recv(SOCKET16 s, char *buf, INT16 len, INT16 flags)
+/***********************************************************************
+ *              listen()		(WINSOCK.13)
+ */
+INT16 WINAPI WINSOCK_listen16(SOCKET16 s, INT16 backlog)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_RECV(%08x): socket %04x, buf %8x, len %d, flags %d",
-                          (unsigned)pwsi, s, (unsigned)buf, len, flags);
-  if( _check_ws(pwsi, pws) )
-  {
-    int length;
-    if ((length = recv(pws->fd, buf, len, flags)) >= 0) 
-    { 
-	dprintf_winsock(stddeb, " -> %i bytes\n", length);
-	notify_client(pws, WS_FD_READ);
-	return (INT16)length;
-    }
-    pwsi->err = wsaErrno();
-  }
-  dprintf_winsock(stddeb, " -> ERROR\n");
-  return SOCKET_ERROR;
+    return (INT16)WINSOCK_listen32( s, backlog );
 }
 
-INT16 WINSOCK_recvfrom(SOCKET16 s, char *buf, INT16 len, INT16 flags, 
-		struct sockaddr *from, INT16 *fromlen16)
+
+/***********************************************************************
+ *		recv()			(WSOCK32.16)
+ */
+INT32 WINAPI WINSOCK_recv32(SOCKET32 s, char *buf, INT32 len, INT32 flags)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_RECVFROM(%08x): socket %04x, ptr %08x, len %d, flags %d\n",
+    dprintf_winsock(stddeb, "WS_RECV(%08x): socket %04x, buf %8x, len %d, flags %d",
                           (unsigned)pwsi, s, (unsigned)buf, len, flags);
-  if( _check_ws(pwsi, pws) )
-  {
-    int length, fromlen32 = *fromlen16;
+    if( _check_ws(pwsi, pws) )
+    {
+	INT32 length;
+	if ((length = recv(pws->fd, buf, len, flags)) >= 0) 
+	{ 
+	    dprintf_winsock(stddeb, " -> %i bytes\n", length);
 
-    if ((length = recvfrom(pws->fd, buf, len, flags, from, &fromlen32)) >= 0)
-    {   
-      *fromlen16 = fromlen32; 
-       notify_client(pws, WS_FD_READ);
-       return (INT16)length;
+	    if( pws->psop && (pws->flags & (WS_FD_READ | WS_FD_CLOSE)) )
+		EVENT_AddIO( pws->fd, EVENT_IO_READ );	/* reenabler */
+
+	    return length;
+	}
+	pwsi->err = wsaErrno();
     }
-    pwsi->err = wsaErrno();
-  }
-  return SOCKET_ERROR;
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    dprintf_winsock(stddeb, " -> ERROR\n");
+    return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_select(INT16 nfds, ws_fd_set *ws_readfds,
-				 ws_fd_set *ws_writefds,
-				 ws_fd_set *ws_exceptfds, struct timeval *timeout)
+/***********************************************************************
+ *              recv()			(WINSOCK.16)
+ */
+INT16 WINAPI WINSOCK_recv16(SOCKET16 s, char *buf, INT16 len, INT16 flags)
+{
+    return (INT16)WINSOCK_recv32( s, buf, len, flags );
+}
+
+
+/***********************************************************************
+ *		recvfrom()		(WSOCK32.17)
+ */
+INT32 WINAPI WINSOCK_recvfrom32(SOCKET32 s, char *buf, INT32 len, INT32 flags, 
+                                struct sockaddr *from, INT32 *fromlen32)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_RECVFROM(%08x): socket %04x, ptr %08x, len %d, flags %d",
+                          (unsigned)pwsi, s, (unsigned)buf, len, flags);
+    if( _check_ws(pwsi, pws) )
+    {
+	int length;
+
+	if ((length = recvfrom(pws->fd, buf, len, flags, from, fromlen32)) >= 0)
+	{
+	    dprintf_winsock(stddeb, " -> %i bytes\n", length);
+
+	    if( pws->psop && (pws->flags & (WS_FD_READ | WS_FD_CLOSE)) )
+		EVENT_AddIO( pws->fd, EVENT_IO_READ );  /* reenabler */
+
+	    return (INT16)length;
+	}
+	pwsi->err = wsaErrno();
+    }
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    dprintf_winsock(stddeb, " -> ERROR\n");
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              recvfrom()		(WINSOCK.17)
+ */
+INT16 WINAPI WINSOCK_recvfrom16(SOCKET16 s, char *buf, INT16 len, INT16 flags,
+                                struct sockaddr *from, INT16 *fromlen16)
+{
+    INT32 fromlen32 = *fromlen16;
+    INT32 retVal = WINSOCK_recvfrom32( s, buf, len, flags, from, &fromlen32 );
+   *fromlen16 = fromlen32;
+    return (INT16)retVal;
+}
+
+/***********************************************************************
+ *		select()		(WINSOCK.18)
+ */
+INT16 WINAPI WINSOCK_select16(INT16 nfds, ws_fd_set *ws_readfds,
+                              ws_fd_set *ws_writefds, ws_fd_set *ws_exceptfds,
+                              struct timeval *timeout)
 {
   LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 	
   dprintf_winsock(stddeb, "WS_SELECT(%08x): nfds %d (ignored), read %8x, write %8x, excp %8x\n", 
-	  (unsigned) pwsi, nfds, (unsigned) ws_readfds, (unsigned) ws_writefds, (unsigned) ws_exceptfds);
+  (unsigned) pwsi, nfds, (unsigned) ws_readfds, (unsigned) ws_writefds, (unsigned) ws_exceptfds);
 
   if( pwsi )
   {
@@ -760,7 +1005,23 @@
 	  {
 	    fd_set_update(pwsi, &readfds, ws_readfds, &errorfds);
 	    fd_set_update(pwsi, &writefds, ws_writefds, &errorfds);
-	    fd_set_update_except(pwsi, &exceptfds, ws_exceptfds, &errorfds);
+
+	    /* update exception set (see "weirdness" comment in the
+	     * beginning of the file). */
+
+	    if (ws_exceptfds)
+	    {
+		int i, j, count = ws_exceptfds->fd_count;
+
+		for (i = j = 0; i < count; i++)
+		{
+		    ws_socket *pws = (ws_socket *)WS_HANDLE2PTR(ws_exceptfds->fd_array[i]);
+		    if( _check_ws(pwsi, pws) && 
+			(FD_ISSET(pws->fd, &exceptfds) || FD_ISSET(pws->fd, &errorfds)) )
+			ws_exceptfds->fd_array[j++] = ws_exceptfds->fd_array[i];
+		}
+		ws_exceptfds->fd_count = j;
+	    }
 	  }
 	  return highfd; 
      }
@@ -769,95 +1030,191 @@
   return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_send(SOCKET16 s, char *buf, INT16 len, INT16 flags)
+/***********************************************************************
+ *              select()		(WSOCK32.18)
+ */
+INT32 WINAPI WINSOCK_select32(INT32 nfds, ws_fd_set *ws_readfds,
+                              ws_fd_set *ws_writefds, ws_fd_set *ws_exceptfds,
+                              struct timeval *timeout)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    /* struct timeval is the same for both 32- and 16-bit code */
+    return WINSOCK_select16( (INT16)nfds, ws_readfds, ws_writefds, ws_exceptfds, timeout );
+}
 
-  dprintf_winsock(stddeb, "WS_SEND(%08x): socket %04x, ptr %08x, length %d, flags %d\n", 
+
+/***********************************************************************
+ *		send()			(WSOCK32.19)
+ */
+INT32 WINAPI WINSOCK_send32(SOCKET32 s, char *buf, INT32 len, INT32 flags)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_SEND(%08x): socket %04x, ptr %08x, length %d, flags %d\n", 
 			  (unsigned)pwsi, s, (unsigned) buf, len, flags);
-  if( _check_ws(pwsi, pws) )
-  {
-    int		length;
-    if ((length = send(pws->fd, buf, len, flags)) < 0 ) 
-    {  
-	length = SOCKET_ERROR;
+    if( _check_ws(pwsi, pws) )
+    {
+	int	length;
+
+	if ((length = send(pws->fd, buf, len, flags)) < 0 ) 
+	{
+	    pwsi->err = wsaErrno();
+	    if( pwsi->err == WSAEWOULDBLOCK && 
+		pws->psop && pws->flags & WS_FD_WRITE )
+		EVENT_AddIO( pws->fd, EVENT_IO_WRITE );	/* reenabler */
+	}
+	else return (INT16)length;
+    }
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              send()			(WINSOCK.19)
+ */
+INT16 WINAPI WINSOCK_send16(SOCKET16 s, char *buf, INT16 len, INT16 flags)
+{
+    return WINSOCK_send32( s, buf, len, flags );
+}
+
+/***********************************************************************
+ *		sendto()		(WSOCK32.20)
+ */
+INT32 WINAPI WINSOCK_sendto32(SOCKET32 s, char *buf, INT32 len, INT32 flags,
+                              struct sockaddr *to, INT32 tolen)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_SENDTO(%08x): socket %04x, ptr %08x, length %d, flags %d\n",
+                          (unsigned)pwsi, s, (unsigned) buf, len, flags);
+    if( _check_ws(pwsi, pws) )
+    {
+	INT32	length;
+
+	if ((length = sendto(pws->fd, buf, len, flags, to, tolen)) < 0 )
+	{
+	    pwsi->err = wsaErrno();
+	    if( pwsi->err == WSAEWOULDBLOCK &&
+		pws->psop && pws->flags & WS_FD_WRITE )
+		EVENT_AddIO( pws->fd, EVENT_IO_WRITE ); /* reenabler */
+	} 
+	else return length;
+    }
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              sendto()		(WINSOCK.20)
+ */
+INT16 WINAPI WINSOCK_sendto16(SOCKET16 s, char *buf, INT16 len, INT16 flags,
+                              struct sockaddr *to, INT16 tolen)
+{
+    return (INT16)WINSOCK_sendto32( s, buf, len, flags, to, tolen );
+}
+
+/***********************************************************************
+ *		setsockopt()		(WSOCK32.21)
+ */
+INT32 WINAPI WINSOCK_setsockopt32(SOCKET16 s, INT32 level, INT32 optname, 
+                                  char *optval, INT32 optlen)
+{
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_SETSOCKOPT(%08x): socket %04x, lev %d, opt %d, ptr %08x, len %d\n",
+			  (unsigned)pwsi, s, level, optname, (int) optval, optlen);
+    if( _check_ws(pwsi, pws) )
+    {
+	convert_sockopt(&level, &optname);
+	if (setsockopt(pws->fd, level, optname, optval, optlen) == 0) return 0;
 	pwsi->err = wsaErrno();
     }
-    notify_client(pws, WS_FD_WRITE);
-    return (INT16)length;
-  }
-  return SOCKET_ERROR;
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    return SOCKET_ERROR;
 }
 
-INT16 WINSOCK_sendto(SOCKET16 s, char *buf, INT16 len, INT16 flags,
-		     struct sockaddr *to, INT16 tolen)
+/***********************************************************************
+ *              setsockopt()		(WINSOCK.21)
+ */
+INT16 WINAPI WINSOCK_setsockopt16(SOCKET16 s, INT16 level, INT16 optname,
+                                  char *optval, INT16 optlen)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_SENDTO(%08x): socket %04x, ptr %08x, length %d, flags %d\n",
-                          (unsigned)pwsi, s, (unsigned) buf, len, flags);
-  if( _check_ws(pwsi, pws) )
-  {
-    int		length;
-
-    if ((length = sendto(pws->fd, buf, len, flags, to, tolen)) < 0 )
-    {
-	length = SOCKET_ERROR;
-        pwsi->err = wsaErrno();
-    }
-    notify_client(pws, WS_FD_WRITE);
-    return (INT16)length;
-  }
-  return SOCKET_ERROR;
-}
-
-INT16 WINSOCK_setsockopt(SOCKET16 s, INT16 level, INT16 optname, 
-			 char *optval, INT16 optlen)
-{
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_SETSOCKOPT(%08x): socket %04x, level %d, opt %d, ptr %08x, len %d\n",
-			  (unsigned)pwsi, s, level, optname, (int) optval, optlen);
-  if( _check_ws(pwsi, pws) )
-  {
-    int		linger32[2];
-    convert_sockopt(&level, &optname);
+    INT32 linger32[2];
     if( optname == SO_LINGER )
     {
-	INT16*	   ptr = (INT16*)optval;
-        linger32[0] = ptr[0];
-	linger32[1] = ptr[1]; 
+	INT16* ptr = (INT16*)optval;
+	linger32[0] = ptr[0];
+	linger32[1] = ptr[1];
 	optval = (char*)&linger32;
 	optlen = sizeof(linger32);
     }
-    if (setsockopt(pws->fd, level, optname, optval, optlen) == 0) return 0;
-    pwsi->err = wsaErrno();
-  }
-  return SOCKET_ERROR;
+    return (INT16)WINSOCK_setsockopt32( s, level, optname, optval, optlen );
 }
 
-INT16 WINSOCK_shutdown(SOCKET16 s, INT16 how)
+
+/***********************************************************************
+ *		shutdown()		(WSOCK32.22)
+ */
+INT32 WINAPI WINSOCK_shutdown32(SOCKET32 s, INT32 how)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_SHUTDOWN(%08x): socket %04x, how %i\n",
-			   (unsigned)pwsi, s, how );
-  if( _check_ws(pwsi, pws) )
-  {
-    pws->flags |= WS_FD_INACTIVE;
-    cancel_async_select(pws);
+    dprintf_winsock(stddeb, "WS_SHUTDOWN(%08x): socket %04x, how %i\n",
+			    (unsigned)pwsi, s, how );
+    if( _check_ws(pwsi, pws) )
+    {
+	if( pws->psop )
+	    switch( how )
+	    {
+		case 0: /* drop receives */
+			if( pws->flags & (WS_FD_READ | WS_FD_CLOSE) )
+			    EVENT_DeleteIO( pws->fd, EVENT_IO_READ );
+			pws->flags &= ~(WS_FD_READ | WS_FD_CLOSE);
+			break;
 
-    if (shutdown(pws->fd, how) == 0) return 0;
-    pwsi->err = wsaErrno();
-  }
-  return SOCKET_ERROR;
+		case 1: /* drop sends */
+			if( pws->flags & WS_FD_WRITE )
+			    EVENT_DeleteIO( pws->fd, EVENT_IO_WRITE );
+			pws->flags &= ~WS_FD_WRITE;
+			break;
+
+		case 2: /* drop all */
+		default:
+			WSAAsyncSelect( s, 0, 0, 0 );
+			break;
+	    }
+
+	if (shutdown(pws->fd, how) == 0) 
+	{
+	    if( how > 1 ) 
+	    {
+		pws->flags &= ~WS_FD_CONNECTED;
+		pws->flags |= WS_FD_INACTIVE;
+	    }
+	    return 0;
+	}
+	pwsi->err = wsaErrno();
+    } 
+    else if( pwsi ) pwsi->err = WSAENOTSOCK;
+    return SOCKET_ERROR;
 }
 
-SOCKET16 WINSOCK_socket(INT16 af, INT16 type, INT16 protocol)
+/***********************************************************************
+ *              shutdown()		(WINSOCK.22)
+ */
+INT16 WINAPI WINSOCK_shutdown16(SOCKET16 s, INT16 how)
+{
+    return (INT16)WINSOCK_shutdown32( s, how );
+}
+
+
+/***********************************************************************
+ *		socket()		(WSOCK32.23)
+ */
+SOCKET32 WINAPI WINSOCK_socket32(INT32 af, INT32 type, INT32 protocol)
 {
   LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 
@@ -873,7 +1230,8 @@
     {
 	case AF_INET:
 	case AF_UNSPEC: break;
-	default:        pwsi->err = WSAEAFNOSUPPORT; return INVALID_SOCKET;
+	default:        pwsi->err = WSAEAFNOSUPPORT; 
+			return INVALID_SOCKET32;
     }
 
     /* check the socket type */
@@ -881,13 +1239,14 @@
     {
 	case SOCK_STREAM:
 	case SOCK_DGRAM:
-	case SOCK_RAW: break;
-	default:       pwsi->err = WSAESOCKTNOSUPPORT; return INVALID_SOCKET;
+	case SOCK_RAW:  break;
+	default:        pwsi->err = WSAESOCKTNOSUPPORT; 
+			return INVALID_SOCKET32;
     }
 
     /* check the protocol type */
     if ( protocol < 0 )  /* don't support negative values */
-    { pwsi->err = WSAEPROTONOSUPPORT; return INVALID_SOCKET; }
+    { pwsi->err = WSAEPROTONOSUPPORT; return INVALID_SOCKET32; }
 
     if ( af == AF_UNSPEC)  /* did they not specify the address family? */
         switch(protocol) 
@@ -896,7 +1255,7 @@
              if (type == SOCK_STREAM) { af = AF_INET; break; }
           case IPPROTO_UDP:
              if (type == SOCK_DGRAM)  { af = AF_INET; break; }
-          default: pwsi->err = WSAEPROTOTYPE; return INVALID_SOCKET;
+          default: pwsi->err = WSAEPROTOTYPE; return INVALID_SOCKET32;
         }
 
     if ((sock = socket(af, type, protocol)) >= 0) 
@@ -906,11 +1265,10 @@
 	dprintf_winsock(stddeb,"\tcreated %04x (handle %i)\n", sock, (UINT16)WS_PTR2HANDLE(pnew));
 
         if( pnew ) return (SOCKET16)WS_PTR2HANDLE(pnew);
-	{
-          close(sock);
-          pwsi->err = WSAENOBUFS;
-          return INVALID_SOCKET;
-	}
+	
+        close(sock);
+        pwsi->err = WSAENOBUFS;
+        return INVALID_SOCKET32;
     }
 
     if (errno == EPERM) /* raw socket denied */
@@ -921,265 +1279,337 @@
   }
  
   dprintf_winsock(stddeb, "\t\tfailed!\n");
-  return INVALID_SOCKET;
+  return INVALID_SOCKET32;
+}
+
+/***********************************************************************
+ *              socket()		(WINSOCK.23)
+ */
+SOCKET16 WINAPI WINSOCK_socket16(INT16 af, INT16 type, INT16 protocol)
+{
+    return (SOCKET16)WINSOCK_socket32( af, type, protocol );
 }
     
 
-/* ----- database functions 
+/* ----------------------------------- DNS services
  *
- * Note that ws_...ent structures we return have SEGPTR pointers inside them.
+ * IMPORTANT: 16-bit API structures have SEGPTR pointers inside them.
+ * Also, we have to use wsock32 stubs to convert error codes from Unix
+ * to WSA, hence no direct mapping in if1632/wsock32.spec.
+ *
+ * FIXME: Win32 may need "short" h_addrtype and h_length in
+ * ...ent structures. If so, use WS_dup_...(pwsi, ..., 0) to
+ * convert.
  */
 
 static char*	NULL_STRING = "NULL";
 
-/*
-struct WIN_hostent *
-*/
-SEGPTR WINSOCK_gethostbyaddr(const char *addr, INT16 len, INT16 type)
-{
-  LPWSINFO      	pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_GetHostByAddr(%08x): ptr %8x, len %d, type %d\n", 
+/***********************************************************************
+ *		gethostbyaddr()		(WINSOCK.51)
+ *
+ *
+struct WIN_hostent *
+ */
+SEGPTR WINAPI WINSOCK_gethostbyaddr16(const char *addr, INT16 len, INT16 type)
+{
+    LPWSINFO      	pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetHostByAddr16(%08x): ptr %8x, len %d, type %d\n", 
 			  (unsigned)pwsi, (unsigned) addr, len, type);
-  if( pwsi )
-  {
-    struct hostent* 	host;
-    if( (host = gethostbyaddr(addr, len, type)) != NULL )
-      if( WS_dup_he(pwsi, host, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  } 
-  return NULL;
-}
-
-/*
-struct WIN_hostent *
-*/
-SEGPTR WINSOCK_gethostbyname(const char *name)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetHostByName(%08x): %s\n",
-                          (unsigned)pwsi, (name)?name:"NULL");
-  if( pwsi )
-  {
-    struct hostent*     host;
-    if( (host = gethostbyname(name)) != NULL )
-      if( WS_dup_he(pwsi, host, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return NULL;
-}
-
-INT16 WINSOCK_gethostname(char *name, INT16 namelen)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetHostName(%08x): name %s, len %d\n", 
-			  (unsigned)pwsi, (name)?name:NULL_STRING, namelen);
-  if( pwsi )
-  {
-    if (gethostname(name, namelen) == 0) return 0;
-    pwsi->err = (errno == EINVAL) ? WSAEFAULT : wsaErrno();
-  }
-  return SOCKET_ERROR;
-}
-
-/*
-struct WIN_protoent *
-*/
-SEGPTR WINSOCK_getprotobyname(char *name)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetProtoByName(%08x): %s\n",
-                          (unsigned)pwsi, (name)?name:NULL_STRING);
-  if( pwsi )
-  {
-    struct protoent*     proto;
-    if( (proto = getprotobyname(name)) != NULL )
-      if( WS_dup_pe(pwsi, proto, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return NULL;
-}
-
-/*
-struct WIN_protoent *
-*/
-SEGPTR WINSOCK_getprotobynumber(INT16 number)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetProtoByNumber(%08x): %i\n", (unsigned)pwsi, number);
-
-  if( pwsi )
-  {
-    struct protoent*     proto;
-    if( (proto = getprotobynumber(number)) != NULL )
-      if( WS_dup_pe(pwsi, proto, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = WSANO_DATA;
-  }
-  return NULL;
-}
-
-/*
-struct WIN_servent *
-*/
-SEGPTR WINSOCK_getservbyname(const char *name, const char *proto)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetServByName(%08x): '%s', '%s'\n", 
-			  (unsigned)pwsi, (name)?name:NULL_STRING, (proto)?proto:NULL_STRING);
-
-  if( pwsi )
-  {
-    struct servent*     serv;
-    if( (serv = getservbyname(name, proto)) != NULL )
-      if( WS_dup_se(pwsi, serv, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return NULL;
-}
-
-/*
-struct WIN_servent *
-*/
-SEGPTR WINSOCK_getservbyport(INT16 port, const char *proto)
-{
-  LPWSINFO              pwsi = wsi_find(GetCurrentTask());
-
-  dprintf_winsock(stddeb, "WS_GetServByPort(%08x): %i, '%s'\n",
-                          (unsigned)pwsi, (int)port, (proto)?proto:NULL_STRING);
-  if( pwsi )
-  {
-    struct servent*     serv;
-    if( (serv = getservbyport(port, proto)) != NULL )
-      if( WS_dup_se(pwsi, serv, WS_DUP_SEGPTR) )
-          return SEGPTR_GET(pwsi->buffer);
-      else pwsi->err = WSAENOBUFS;
-    else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
-  }
-  return NULL;
-}
-
-
-/* ----------------------------------- Windows sockets extensions -- *
- *								     *
- * ----------------------------------------------------------------- */
-
-static int aop_control(ws_async_op* p_aop, int flag )
-{
-  unsigned	lLength;
-
-  read(p_aop->fd[0], &lLength, sizeof(unsigned));
-  if( LOWORD(lLength) )
-    if( (int)LOWORD(lLength) <= p_aop->buflen )
+    if( pwsi )
     {
-      char* buffer = (char*)PTR_SEG_TO_LIN(p_aop->buffer_base);
-      read(p_aop->fd[0], buffer, LOWORD(lLength));
-      switch( p_aop->flags )
-      {
-	case WSMSG_ASYNC_HOSTBYNAME:
-	case WSMSG_ASYNC_HOSTBYADDR: 
-	     fixup_wshe((struct ws_hostent*)buffer, p_aop->buffer_base); break;
-	case WSMSG_ASYNC_PROTOBYNAME:
-	case WSMSG_ASYNC_PROTOBYNUM:
-	     fixup_wspe((struct ws_protoent*)buffer, p_aop->buffer_base); break;
-	case WSMSG_ASYNC_SERVBYNAME:
-	case WSMSG_ASYNC_SERVBYPORT:
-	     fixup_wsse((struct ws_servent*)buffer, p_aop->buffer_base); break;
-	default:
-	     if( p_aop->flags ) fprintf(stderr,"Received unknown async request!\n"); 
-	     return AOP_CONTROL_REMOVE;
-      }
+	struct hostent*	host = gethostbyaddr(addr, len, type);
+	if( host )
+	    if( WS_dup_he(pwsi, host, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else 
+		pwsi->err = WSAENOBUFS;
+	else 
+	    pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
     }
-    else lLength =  ((UINT32)LOWORD(lLength)) | ((unsigned)WSAENOBUFS << 16);
-
-#if 0
-  printf("async op completed: hWnd [%04x], uMsg [%04x], aop [%04x], event [%08x]\n",
-	 p_aop->hWnd, p_aop->uMsg, (HANDLE16)WS_PTR2HANDLE(p_aop), (LPARAM)lLength);
-#endif
-
-  PostMessage16(p_aop->hWnd, p_aop->uMsg, (HANDLE16)WS_PTR2HANDLE(p_aop), (LPARAM)lLength);
-  return AOP_CONTROL_REMOVE;
+    return (SEGPTR)NULL;
 }
 
-
-static HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND16 hWnd, UINT16 uMsg, LPCSTR init,
-				 INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen, UINT32 flag)
+/***********************************************************************
+ *              gethostbyaddr()		(WSOCK32.51)
+ */
+struct hostent*  WINAPI WINSOCK_gethostbyaddr32(const char *addr, INT32 len,
+                                                INT32 type)
 {
-  /* queue 'flag' request and fork off its handler */
+    LPWSINFO		pwsi = wsi_find(GetCurrentTask());
 
-  async_ctl.ws_aop = (ws_async_op*)WS_ALLOC(sizeof(ws_async_op));
-
-  if( async_ctl.ws_aop )
-  {
-      HANDLE16        handle = (HANDLE16)WS_PTR2HANDLE(async_ctl.ws_aop);
-
-      if( pipe(async_ctl.ws_aop->fd) == 0 )
-      {
-	async_ctl.init = (char*)init;
-	async_ctl.lLength = len;
-	async_ctl.lEvent = type;
-
-        async_ctl.ws_aop->hWnd = hWnd;
-        async_ctl.ws_aop->uMsg = uMsg;
-
-	async_ctl.ws_aop->buffer_base = sbuf; async_ctl.ws_aop->buflen = buflen;
-	async_ctl.ws_aop->flags = flag;
-	async_ctl.ws_aop->aop_control = &aop_control;
-	WINSOCK_link_async_op( async_ctl.ws_aop );
-
-        async_ctl.ws_aop->pid = fork();
-        if( async_ctl.ws_aop->pid )
-        {
-            close(async_ctl.ws_aop->fd[1]);        /* write endpoint */
-
-           /* Damn, BSD'ish SIGIO doesn't work on pipes/streams
-            *
-            * async_io(async_ctl.ws_aop->fd[0], 1);
-            */
-
-            dprintf_winsock(stddeb, "\tasync_op = %04x (child %i)\n",
-                                    handle, async_ctl.ws_aop->pid);
-            return handle;
-        } else
-                /* child process */
-                 {
-                   close(async_ctl.ws_aop->fd[0]); /* read endpoint */
-		   switch(flag)
-		   {
-		     case WSMSG_ASYNC_HOSTBYADDR:
-		     case WSMSG_ASYNC_HOSTBYNAME:
- 			WS_do_async_gethost(pwsi,flag);
-		     case WSMSG_ASYNC_PROTOBYNUM:
-		     case WSMSG_ASYNC_PROTOBYNAME:
-			WS_do_async_getproto(pwsi,flag);
-		     case WSMSG_ASYNC_SERVBYPORT:
-		     case WSMSG_ASYNC_SERVBYNAME:
-			WS_do_async_getserv(pwsi,flag);
-		   }
-		   _exit(0); /* skip atexit()'ed cleanup */
-                 }
-      }
-      WS_FREE(async_ctl.ws_aop);
-      pwsi->err = wsaErrno();
-  } else pwsi->err = WSAEWOULDBLOCK;
-  return 0;
+    dprintf_winsock(stddeb, "WS_GetHostByAddr32(%08x): ptr %8x, len %d, type %d\n",
+                            (unsigned)pwsi, (unsigned) addr, len, type);
+    if( pwsi )
+    {
+	struct hostent* host = gethostbyaddr( addr, len, type );
+	if( host ) 
+	    return host;
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return NULL;
 }
 
-HANDLE16 WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
+/***********************************************************************
+ *		gethostbyname()		(WINSOCK.52) 
+ *
+ *
+struct WIN_hostent *
+ */
+SEGPTR WINAPI WINSOCK_gethostbyname16(const char *name)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetHostByName16(%08x): %s\n",
+                          (unsigned)pwsi, (name)?name:"NULL");
+    if( pwsi )
+    {
+	struct hostent*     host;
+	if( (host = gethostbyname(name)) != NULL )
+	    if( WS_dup_he(pwsi, host, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else pwsi->err = WSAENOBUFS;
+	else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+  }
+  return (SEGPTR)NULL;
+}
+
+/***********************************************************************
+ *              gethostbyname()		(WSOCK32,52)
+ */
+struct hostent*  WINAPI WINSOCK_gethostbyname32(const char* name)
+{
+    LPWSINFO            pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetHostByName32(%08x): %s\n",
+                            (unsigned)pwsi, (name)?name:"NULL");
+    if( pwsi )
+    {
+	struct hostent* host = gethostbyname( name );
+	if( host )
+	    return host;
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return NULL;
+}
+
+/***********************************************************************
+ *		gethostname()		(WSOCK32.57)
+ */
+INT32 WINAPI WINSOCK_gethostname32(char *name, INT32 namelen)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetHostName(%08x): name %s, len %d\n", 
+			  (unsigned)pwsi, (name)?name:NULL_STRING, namelen);
+    if( pwsi )
+    {
+	if (gethostname(name, namelen) == 0) return 0;
+	pwsi->err = (errno == EINVAL) ? WSAEFAULT : wsaErrno();
+    }
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *              gethostname()		(WINSOCK.57)
+ */
+INT16 WINAPI WINSOCK_gethostname16(char *name, INT16 namelen)
+{
+    return (INT16)WINSOCK_gethostname32(name, namelen);
+}
+
+/***********************************************************************
+ *		getprotobyname()	(WINSOCK.53)
+ *
+ *
+struct WIN_protoent *
+ */
+SEGPTR WINAPI WINSOCK_getprotobyname16(char *name)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetProtoByName16(%08x): %s\n",
+                          (unsigned)pwsi, (name)?name:NULL_STRING);
+    if( pwsi )
+    {
+	struct protoent*     proto;
+	if( (proto = getprotobyname(name)) != NULL )
+	    if( WS_dup_pe(pwsi, proto, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else pwsi->err = WSAENOBUFS;
+	else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return (SEGPTR)NULL;
+}
+
+/***********************************************************************
+ *              getprotobyname()	(WSOCK32.53)
+ */
+struct protoent* WINAPI WINSOCK_getprotobyname32(char* name)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetProtoByName32(%08x): %s\n",
+                          (unsigned)pwsi, (name)?name:NULL_STRING);
+    if( pwsi )
+    {
+	struct protoent* proto;
+	if( (proto = getprotobyname(name)) != NULL )
+                return proto;
+        pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return NULL;
+}
+
+
+/***********************************************************************
+ *		getprotobynumber()	(WINSOCK.54)
+ *
+ *
+struct WIN_protoent *
+ */
+SEGPTR WINAPI WINSOCK_getprotobynumber16(INT16 number)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetProtoByNumber16(%08x): %i\n", (unsigned)pwsi, number);
+
+    if( pwsi )
+    {
+	struct protoent*     proto;
+	if( (proto = getprotobynumber(number)) != NULL )
+	    if( WS_dup_pe(pwsi, proto, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else pwsi->err = WSAENOBUFS;
+	else pwsi->err = WSANO_DATA;
+    }
+    return (SEGPTR)NULL;
+}
+
+/***********************************************************************
+ *              getprotobynumber()	(WSOCK32.54)
+ */
+struct protoent* WINAPI WINSOCK_getprotobynumber32(INT32 number)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetProtoByNumber32(%08x): %i\n", (unsigned)pwsi, number);
+
+    if( pwsi )
+    {
+	struct protoent* proto;
+	if( (proto = getprotobynumber(number)) != NULL )
+	    return proto;
+	pwsi->err = WSANO_DATA;
+    }
+    return NULL;
+}
+
+/***********************************************************************
+ *		getservbyname()		(WINSOCK.55)
+ *
+ *
+struct WIN_servent *
+ */
+SEGPTR WINAPI WINSOCK_getservbyname16(const char *name, const char *proto)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetServByName16(%08x): '%s', '%s'\n", 
+			  (unsigned)pwsi, (name)?name:NULL_STRING, (proto)?proto:NULL_STRING);
+    if( pwsi )
+    {
+	struct servent*     serv;
+	if( (serv = getservbyname(name, proto)) != NULL )
+	    if( WS_dup_se(pwsi, serv, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else pwsi->err = WSAENOBUFS;
+	else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return (SEGPTR)NULL;
+}
+
+/***********************************************************************
+ *              getservbyname()		(WSOCK32.55)
+ */
+struct servent* WINAPI WINSOCK_getservbyname32(const char *name, const char *proto)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetServByName32(%08x): '%s', '%s'\n",
+                          (unsigned)pwsi, (name)?name:NULL_STRING, (proto)?proto:NULL_STRING);
+    if( pwsi )
+    {
+	struct servent* serv;
+	if( (serv = getservbyname(name, proto)) != NULL )
+	    return serv;
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return NULL;
+}
+
+/***********************************************************************
+ *		getservbyport()		(WINSOCK.56)
+ *
+ *
+struct WIN_servent *
+ */
+SEGPTR WINAPI WINSOCK_getservbyport16(INT16 port, const char *proto)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetServByPort16(%08x): %i, '%s'\n",
+                          (unsigned)pwsi, (int)port, (proto)?proto:NULL_STRING);
+    if( pwsi )
+    {
+	struct servent*     serv;
+	if( (serv = getservbyport(port, proto)) != NULL )
+	    if( WS_dup_se(pwsi, serv, WS_DUP_SEGPTR) )
+		return SEGPTR_GET(pwsi->buffer);
+	    else pwsi->err = WSAENOBUFS;
+	else pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return (SEGPTR)NULL;
+}
+
+/***********************************************************************
+ *              getservbyport()		(WSOCK32.56)
+ */
+struct servent* WINAPI WINSOCK_getservbyport32(INT32 port, const char *proto)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_GetServByPort32(%08x): %i, '%s'\n",
+                          (unsigned)pwsi, (int)port, (proto)?proto:NULL_STRING);
+    if( pwsi )
+    {
+	struct servent* serv;
+	if( (serv = getservbyport(port, proto)) != NULL )
+	    return serv;
+	pwsi->err = (h_errno < 0) ? wsaErrno() : wsaHerrno();
+    }
+    return NULL;
+}
+
+
+/* ------------------------------------- Windows sockets extensions -- *
+ *								       *
+ * ------------------------------------------------------------------- */
+
+
+/***********************************************************************
+ *          Asynchronous DNS services
+ */
+
+/* winsock_dns.c */
+extern HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND16 hWnd, UINT16 uMsg, INT16 type, LPCSTR init,
+				 INT16 len, LPCSTR proto, SEGPTR sbuf, INT16 buflen, UINT32 flag);
+
+/***********************************************************************
+ *       WSAAsyncGetHostByAddr()	(WINSOCK.102)
+ */
+HANDLE16 WINAPI WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
                                INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
@@ -1188,14 +1618,17 @@
                           (unsigned)pwsi, hWnd, uMsg, (unsigned)addr , len );
 
   if( pwsi ) 
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, addr, len,
-			    type, sbuf, buflen, WSMSG_ASYNC_HOSTBYADDR );
+    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, type, addr, len,
+			    NULL, sbuf, buflen, WSMSG_ASYNC_HOSTBYADDR );
   return 0;
 }
 
 
-HANDLE16 WSAAsyncGetHostByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
-                               SEGPTR sbuf, INT16 buflen)
+/***********************************************************************
+ *       WSAAsyncGetHostByName()	(WINSOCK.103)
+ */
+HANDLE16 WINAPI WSAAsyncGetHostByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
+                                      SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1203,14 +1636,17 @@
                           (unsigned)pwsi, hWnd, uMsg, (name)?name:NULL_STRING, (int)buflen );
 
   if( pwsi )
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, name, 0,
-                            0, sbuf, buflen, WSMSG_ASYNC_HOSTBYNAME );
+    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
+                            NULL, sbuf, buflen, WSMSG_ASYNC_HOSTBYNAME );
   return 0;
 }                     
 
 
-HANDLE16 WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
-                                SEGPTR sbuf, INT16 buflen)
+/***********************************************************************
+ *       WSAAsyncGetProtoByName()	(WINSOCK.105)
+ */
+HANDLE16 WINAPI WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
+                                       SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1218,14 +1654,17 @@
                           (unsigned)pwsi, hWnd, uMsg, (name)?name:NULL_STRING );
 
   if( pwsi )
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, name, 0,
-                            0, sbuf, buflen, WSMSG_ASYNC_PROTOBYNAME );
+    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
+                            NULL, sbuf, buflen, WSMSG_ASYNC_PROTOBYNAME );
   return 0;
 }
 
 
-HANDLE16 WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 uMsg, INT16 number, 
-                                  SEGPTR sbuf, INT16 buflen)
+/***********************************************************************
+ *       WSAAsyncGetProtoByNumber()	(WINSOCK.104)
+ */
+HANDLE16 WINAPI WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 uMsg, INT16 number, 
+                                         SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1233,14 +1672,17 @@
                           (unsigned)pwsi, hWnd, uMsg, number );
 
   if( pwsi )
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, NULL, 0,
-                            number, sbuf, buflen, WSMSG_ASYNC_PROTOBYNUM );
+    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, number, NULL, 0,
+                            NULL, sbuf, buflen, WSMSG_ASYNC_PROTOBYNUM );
   return 0;
 }
 
 
-HANDLE16 WSAAsyncGetServByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
-                               LPCSTR proto, SEGPTR sbuf, INT16 buflen)
+/***********************************************************************
+ *       WSAAsyncGetServByName()	(WINSOCK.107)
+ */
+HANDLE16 WINAPI WSAAsyncGetServByName(HWND16 hWnd, UINT16 uMsg, LPCSTR name, 
+                                      LPCSTR proto, SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1248,17 +1690,16 @@
                    (unsigned)pwsi, hWnd, uMsg, (name)?name:NULL_STRING, (proto)?proto:NULL_STRING );
 
   if( pwsi )
-  { 
-    async_ctl.buffer = (char*)proto;
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, name, 0,
-                            0, sbuf, buflen, WSMSG_ASYNC_SERVBYNAME );
-  }
+    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
+                            proto, sbuf, buflen, WSMSG_ASYNC_SERVBYNAME );
   return 0;
 }
 
-
-HANDLE16 WSAAsyncGetServByPort(HWND16 hWnd, UINT16 uMsg, INT16 port, 
-			       LPCSTR proto, SEGPTR sbuf, INT16 buflen)
+/***********************************************************************
+ *       WSAAsyncGetServByPort()	(WINSOCK.106)
+ */
+HANDLE16 WINAPI WSAAsyncGetServByPort(HWND16 hWnd, UINT16 uMsg, INT16 port, 
+                                      LPCSTR proto, SEGPTR sbuf, INT16 buflen)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1266,170 +1707,315 @@
                            (unsigned)pwsi, hWnd, uMsg, port, (proto)?proto:NULL_STRING );
 
   if( pwsi )
-    return __WSAsyncDBQuery(pwsi, hWnd, uMsg, proto, 0,
-                            port, sbuf, buflen, WSMSG_ASYNC_SERVBYPORT );
+      return __WSAsyncDBQuery(pwsi, hWnd, uMsg, port, proto, 0,
+                              NULL, sbuf, buflen, WSMSG_ASYNC_SERVBYPORT );
   return 0;
 }
 
-INT16 WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle)
+/***********************************************************************
+ *       WSACancelAsyncRequest()	(WINSOCK.108)
+ */
+INT16 WINAPI WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle)
 {
+  INT16			retVal = SOCKET_ERROR;
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
   ws_async_op*		p_aop = (ws_async_op*)WS_HANDLE2PTR(hAsyncTaskHandle);
 
   dprintf_winsock(stddeb, "WS_CancelAsyncRequest(%08x): handle %04x\n", 
 			   (unsigned)pwsi, hAsyncTaskHandle);
   if( pwsi )
-    if( WINSOCK_check_async_op(p_aop) )
-    {
-  	kill(p_aop->pid, SIGKILL); 
-	waitpid(p_aop->pid, NULL, 0); /* just in case */
-	close(p_aop->fd[0]);
-	WINSOCK_unlink_async_op(p_aop);
-	WS_FREE(p_aop);
-	return 0;
-    }
-    else pwsi->err = WSAEINVAL;
-  return SOCKET_ERROR;
-}
-
-/* ----- asynchronous select() */
-
-int cancel_async_select(ws_socket* pws)
-{
-  if( pws->p_aop )
   {
-    kill(pws->p_aop->pid, SIGKILL);
-    waitpid(pws->p_aop->pid, NULL, 0);
-    WS_FREE(pws->p_aop); 
-    pws->p_aop = NULL;
-    return 1;
-  }
-  return 0;
-}
-
-void _sigusr1_handler_parent(int sig)
-{
-  /* child process puts MTYPE_CLIENT data packet into the
-   * 'async_qid' message queue and signals us with SIGUSR1.
-   * This handler reads the queue and posts 'uMsg' notification
-   * message.
-   */
-
-  ipc_packet		ipack;
-
-  signal( SIGUSR1, _sigusr1_handler_parent);
-  while( msgrcv(async_qid, (struct msgbuf*)&ipack,
-          MTYPE_CLIENT_SIZE, MTYPE_CLIENT, IPC_NOWAIT) != -1 )
-  {
-    if( ipack.wParam && abs((short)ipack.wParam) < 32768 )
-    {
-      ws_socket*        pws = (ws_socket*)WS_HANDLE2PTR(ipack.wParam);
-      if( pws->p_aop && abs((char*)_ws_stub - (char*)pws->p_aop) < 32768 )
+      SIGNAL_MaskAsyncEvents( TRUE );	/* block SIGIO */
+      if( WINSOCK_cancel_async_op(p_aop) )
       {
-	  pws->flags &= ~(ipack.lParam);
-#if 0
-          printf("async event - hWnd %04x, uMsg %04x [%08x]\n",
-                  pws->p_aop->hWnd, pws->p_aop->uMsg, ipack.lParam );
-#endif
-	  PostMessage16(pws->p_aop->hWnd, pws->p_aop->uMsg, 
-                        (WPARAM16)ipack.wParam, (LPARAM)ipack.lParam );
+	  WS_FREE(p_aop);
+	  pwsi->num_async_rq--;
+	  retVal = 0;
       }
-      else fprintf(stderr,"AsyncSelect:stray async_op in socket %04x!\n", ipack.wParam);
-    }
-    else fprintf(stderr,"AsyncSelect:stray socket at %04x!\n", ipack.wParam);
+      else pwsi->err = WSAEINVAL;
+      SIGNAL_MaskAsyncEvents( FALSE );
   }
+  return retVal;
 }
 
-int notify_client( ws_socket* pws, unsigned flag )
+/***********************************************************************
+ *      WSAAsyncSelect()		(WINSOCK.101)
+ */
+
+static ws_select_op* __ws_select_list = NULL;
+
+BOOL32 WINSOCK_HandleIO( int* max_fd, int num_pending, fd_set io_set[3] )
 {
-  if( pws->p_aop && ((pws->p_aop->flags & flag) ||
-		     (flag == WS_FD_CONNECTED && pws->flags & WS_FD_CONNECT)) )
-  {
-     async_ctl.ip.mtype = MTYPE_PARENT;
-     async_ctl.ip.lParam = flag;
-     while( msgsnd(async_qid, (struct msgbuf*)&(async_ctl.ip),
-                               MTYPE_PARENT_SIZE, 0) == -1 )
-     { 
-	if( errno == EINTR ) continue;
-	else
-	{
-	    perror("AsyncSelect(parent)"); 
-	    cancel_async_select(pws);
-	    pws->flags &= WS_FD_INTERNAL;
-	    return 0;
-	}
-     }
-     kill(pws->p_aop->pid, SIGUSR1);
-     return 1;
-  }
-  return 0;
-}
+    /* This function is called by the event dispatcher
+     * with io_set containing the result of select() */
 
-INT16 init_async_select(ws_socket* pws, HWND16 hWnd, UINT16 uMsg, UINT32 lEvent)
-{
-    ws_async_op*        p_aop;
+    ws_select_op*	psop = __ws_select_list;
+    BOOL32		bPost = FALSE;
+    DWORD		dwEvent, dwErrBytes;
+    int			num_posted;
 
-    if( cancel_async_select(pws) )  /* delete old async handler if any */
-      pws->flags &= WS_FD_INTERNAL;
+    dprintf_winsock(stddeb,"WINSOCK_HandleIO: %i pending descriptors\n", num_pending );
 
-    if( lEvent == 0 ) return 0;
-
-    /* setup async handler - some data may be redundant */
-
-    WINSOCK_unblock_io(pws->fd, 1);
-    if( (p_aop = (ws_async_op*)WS_ALLOC(sizeof(ws_async_op))) )
+    for( num_posted = dwEvent = 0 ; psop; psop = psop->next )
     {
-      p_aop->hWnd = hWnd;
-      p_aop->uMsg = uMsg;
-      pws->p_aop = p_aop;
+	unsigned	flags = psop->pws->flags;
+	int		fd = psop->pws->fd;
+	int		r, w, e;
 
-      async_ctl.lEvent = p_aop->flags = lEvent;
-      async_ctl.ws_sock = pws;
-      async_ctl.ip.wParam = (UINT16)WS_PTR2HANDLE(pws);
-      async_ctl.ip.lParam = 0;
+	w = 0;
+	if( (r = FD_ISSET( fd, &io_set[EVENT_IO_READ] )) ||
+	    (w = FD_ISSET( fd, &io_set[EVENT_IO_WRITE] )) ||
+	    (e = FD_ISSET( fd, &io_set[EVENT_IO_EXCEPT] )) )
+	{
+	    /* This code removes WS_FD flags on one-shot events (WS_FD_CLOSE, 
+	     * WS_FD_CONNECT), otherwise it clears descriptors in the io_set.
+	     * Reenabling calls turn them back on.
+	     */
 
-      p_aop->pid = fork();
-      if( p_aop->pid != -1 )
-        if( p_aop->pid == 0 ) WINSOCK_do_async_select(); /* child process */
-	else pws->flags |= lEvent;
+	    dprintf_winsock(stddeb,"\tchecking psop = 0x%08x\n", (unsigned) psop );
 
-      signal( SIGUSR1, _sigusr1_handler_parent );
-      return 0;                                  /* Wine process */
+	    num_pending--;
+
+	    if( flags & WS_FD_ACCEPT )
+	    {
+		/* listening socket */
+
+		FD_CLR( fd, &io_set[EVENT_IO_WRITE] );
+		if( r )
+		{
+		    FD_CLR( fd, &io_set[EVENT_IO_READ] ); /* reenabled by the next accept() */
+		    dwEvent = WSAMAKESELECTREPLY( WS_FD_ACCEPT, 0 );
+		    bPost = TRUE;
+		} 
+		else continue;
+	    }
+	    else if( flags & WS_FD_CONNECT )
+	    {
+		/* connecting socket */
+
+		if( w || (w = FD_ISSET( fd, &io_set[EVENT_IO_WRITE] )) )
+		{
+		    /* ready to write means that socket is connected */
+
+		    psop->pws->flags |= WS_FD_CONNECTED;
+		    psop->pws->flags &= ~(WS_FD_CONNECT | WS_FD_INACTIVE);
+		    dwEvent = WSAMAKESELECTREPLY( WS_FD_CONNECT, 0 );
+
+		    if( flags & (WS_FD_READ | WS_FD_CLOSE))
+			FD_SET( fd, &io_set[EVENT_IO_READ] );
+		    if( flags & WS_FD_WRITE ) FD_SET( fd, &io_set[EVENT_IO_WRITE] );
+		    else FD_CLR( fd, &io_set[EVENT_IO_WRITE] );
+		    bPost = TRUE;
+		}
+		else if( r )
+		{
+		    /* failure - do read() to get correct errno */
+
+		    if( read( fd, &dwErrBytes, sizeof(dwErrBytes) ) == -1 )
+		    {
+			dwEvent = WSAMAKESELECTREPLY( WS_FD_CONNECT, wsaErrno() );
+			bPost = TRUE;
+		    }
+		}
+		/* otherwise bPost stays FALSE */
+	    }
+	    else 
+	    {
+		/* connected socket --
+		 * removed WS_FD_OOB code for now.
+		 */
+
+		if( flags & WS_FD_WRITE &&
+		   (w || (w = FD_ISSET( fd, &io_set[EVENT_IO_WRITE] ))) )
+		{
+		    /* this will be reenabled when send() or sendto() fail with
+		     * WSAEWOULDBLOCK */
+
+		    if( PostMessage16( psop->hWnd, psop->uMsg, (WPARAM16)WS_PTR2HANDLE(psop->pws), 
+			              (LPARAM)WSAMAKESELECTREPLY( WS_FD_WRITE, 0 ) ) )
+		    {
+			FD_CLR( fd, &io_set[EVENT_IO_WRITE] );
+			num_posted++;
+		    }
+		}
+
+		if( r && (flags & (WS_FD_READ | WS_FD_CLOSE)) )
+		{
+		    int val = (flags & WS_FD_RAW);
+
+		     /* WS_FD_RAW is set by the WSAAsyncSelect() init */
+
+		    bPost = TRUE;
+		    if( !val && ioctl( fd, FIONREAD, (char*)&dwErrBytes) == -1 )
+		    {
+			/* weirdness */
+
+			dwEvent = WSAMAKESELECTREPLY( WS_FD_READ, wsaErrno() );
+		    }
+		    else if( val || dwErrBytes )
+		    {
+			/* got pending data, will be reenabled by recv() or recvfrom() */
+
+			FD_CLR( fd, &io_set[EVENT_IO_READ] );
+			dwEvent = WSAMAKESELECTREPLY( WS_FD_READ, 0 );
+		    }
+		    else
+		    {
+			/* 0 bytes to read - connection reset by peer? */
+
+			do
+			    val = read( fd, (char*)&dwErrBytes, sizeof(dwErrBytes));
+			while( errno == EINTR );
+			if( errno != EWOULDBLOCK )
+			{
+			    switch( val )
+			    {
+				case  0: errno = ENETDOWN;	/* soft reset, fall through */
+				case -1: 			/* hard reset */
+					 dwEvent = WSAMAKESELECTREPLY( WS_FD_CLOSE, wsaErrno() );
+					 break;
+
+				default: bPost = FALSE;
+					 continue;		/* FIXME: this is real bad */
+			    }
+			}
+			else { bPost = FALSE; continue; }	/* more weirdness */
+
+			/* this is it, this socket is closed */
+
+			psop->pws->flags &= ~(WS_FD_READ | WS_FD_CLOSE | WS_FD_WRITE);
+			FD_CLR( fd, &io_set[EVENT_IO_READ] );
+			FD_CLR( fd, &io_set[EVENT_IO_WRITE] );
+
+			if( *max_fd == (fd + 1) ) (*max_fd)--;
+		    }
+		}
+	    }
+
+	    if( bPost )
+	    {
+		PostMessage16( psop->hWnd, psop->uMsg, 
+			      (WPARAM16)WS_PTR2HANDLE(psop->pws), (LPARAM)dwEvent );
+		bPost = FALSE;
+		num_posted++;
+	    }
+	}
+	if( num_pending <= 0 ) break;
     }
-    return SOCKET_ERROR;
+
+    dprintf_winsock(stddeb, "\tdone, %i posted events\n", num_posted );
+    return ( num_posted ) ? TRUE : FALSE;
 }
 
-INT16 WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 uMsg, UINT32 lEvent)
+
+INT16 WINAPI WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 uMsg, UINT32 lEvent)
 {
-  ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
-  LPWSINFO      pwsi = wsi_find(GetCurrentTask());
+    ws_socket*    pws  = (ws_socket*)WS_HANDLE2PTR(s);
+    LPWSINFO      pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_AsyncSelect(%08x): %04x, hWnd %04x, uMsg %04x, event %08x\n",
+    dprintf_winsock(stddeb, "WS_AsyncSelect(%08x): %04x, hWnd %04x, uMsg %04x, event %08x\n",
 			  (unsigned)pwsi, s, hWnd, uMsg, (unsigned)lEvent );
-  if( _check_ws(pwsi, pws) )
-    if( init_async_select(pws, hWnd, uMsg, lEvent) == 0 ) return 0;
-    else pwsi->err = WSAENOBUFS;
-  return SOCKET_ERROR; 
+    if( _check_ws(pwsi, pws) )
+    {
+	ws_select_op* psop;
+
+	if( (psop = pws->psop) )
+	{
+	    /* delete previous control struct */
+
+	    if( psop == __ws_select_list )
+		__ws_select_list = psop->next;
+	    else
+		psop->prev->next = psop->next; 
+	    if( psop->next ) psop->next->prev = psop->prev;
+
+	    if( pws->flags & (WS_FD_ACCEPT | WS_FD_CONNECT | WS_FD_READ | WS_FD_CLOSE) )
+		EVENT_DeleteIO( pws->fd, EVENT_IO_READ );
+	    if( pws->flags & (WS_FD_CONNECT | WS_FD_WRITE) )
+		EVENT_DeleteIO( pws->fd, EVENT_IO_WRITE );
+
+	    dprintf_winsock(stddeb,"\tremoving psop = 0x%08x\n", (unsigned) psop );
+
+	    WS_FREE( pws->psop );
+	    pws->flags &= ~(WS_FD_RAW | WS_FD_ACCEPT | WS_FD_CONNECT | 
+			    WS_FD_READ | WS_FD_WRITE | WS_FD_CLOSE);
+	    pws->psop = NULL;
+	}
+
+	if( lEvent )
+	{
+	    psop = (ws_select_op*)WS_ALLOC(sizeof(ws_select_op));
+	    if( psop )
+	    {
+		int sock_type, bytes = sizeof(int);
+
+		WINSOCK_unblock_io( pws->fd, TRUE );
+
+		psop->prev = NULL;
+		psop->next = __ws_select_list;
+		if( __ws_select_list )
+		    __ws_select_list->prev = psop;
+		__ws_select_list = psop;
+		
+		psop->pws = pws;
+		psop->hWnd = hWnd;
+		psop->uMsg = uMsg;
+
+		pws->psop = psop;
+		pws->flags |= (0x0000FFFF &lEvent);
+		getsockopt(pws->fd, SOL_SOCKET, SO_TYPE, &sock_type, &bytes);
+		if( sock_type == SOCK_RAW ) pws->flags |= WS_FD_RAW;
+
+		if( lEvent & (WS_FD_ACCEPT | WS_FD_CONNECT | WS_FD_READ | WS_FD_CLOSE) )
+		    EVENT_AddIO( pws->fd, EVENT_IO_READ );
+		if( lEvent & (WS_FD_CONNECT | WS_FD_WRITE) )
+		    EVENT_AddIO( pws->fd, EVENT_IO_WRITE );
+
+		/* TODO: handle WS_FD_ACCEPT right away if the socket is readable */
+
+		dprintf_winsock(stddeb,"\tcreating psop = 0x%08x\n", (unsigned)psop );
+
+		return 0; /* success */
+	    }
+	    else pwsi->err = WSAENOBUFS;
+	} 
+	else return 0;
+    } 
+    else if( pwsi ) pwsi->err = WSAEINVAL;
+    return SOCKET_ERROR; 
 }
 
-/* ----- miscellaneous */
 
-INT16 __WSAFDIsSet(SOCKET16 fd, ws_fd_set *set)
+/***********************************************************************
+ *	__WSAFDIsSet()			(WINSOCK.151)
+ */
+INT16 WINAPI __WSAFDIsSet16(SOCKET16 s, ws_fd_set *set)
 {
   int i = set->fd_count;
   
-  dprintf_winsock(stddeb, "__WSAFDIsSet(%d,%8lx)\n",fd,(unsigned long)set);
+  dprintf_winsock(stddeb, "__WSAFDIsSet(%d,%8lx)\n", s,(unsigned long)set);
     
   while (i--)
-      if (set->fd_array[i] == fd) return 1;
+      if (set->fd_array[i] == s) return 1;
   return 0;
 }                                                            
 
-BOOL16 WSAIsBlocking(void)
+/***********************************************************************
+ *      __WSAFDIsSet()			(WSOCK32.151)
+ */
+INT32 WINAPI __WSAFDIsSet32(SOCKET32 s, ws_fd_set *set)
+{
+    return __WSAFDIsSet16( (SOCKET16)s, set );
+}
+
+/***********************************************************************
+ *      WSAIsBlocking()			(WINSOCK.114)(WSOCK32.114)
+ */
+BOOL32 WINAPI WSAIsBlocking(void)
 {
   /* By default WinSock should set all its sockets to non-blocking mode
    * and poll in PeekMessage loop when processing "blocking" ones. This 
-   * function * is supposed to tell if program is in this loop. Our 
+   * function is supposed to tell if program is in this loop. Our 
    * blocking calls are truly blocking so we always return FALSE.
    *
    * Note: It is allowed to call this function without prior WSAStartup().
@@ -1439,7 +2025,10 @@
   return FALSE;
 }
 
-INT16 WSACancelBlockingCall(void)
+/***********************************************************************
+ *      WSACancelBlockingCall()		(WINSOCK.113)(WSOCK32.113)
+ */
+INT32 WINAPI WSACancelBlockingCall(void)
 {
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
@@ -1449,45 +2038,82 @@
   return SOCKET_ERROR;
 }
 
-FARPROC16 WSASetBlockingHook16(FARPROC16 lpBlockFunc)
+
+/***********************************************************************
+ *      WSASetBlockingHook16()		(WINSOCK.109)
+ */
+FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc)
 {
   FARPROC16		prev;
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
   dprintf_winsock(stddeb, "WS_SetBlockingHook16(%08x): hook %08x\n", 
 			  (unsigned)pwsi, (unsigned) lpBlockFunc);
-
   if( pwsi ) { 
-      prev = pwsi->blocking_hook; 
-      pwsi->blocking_hook = lpBlockFunc; 
+      prev = (FARPROC16)pwsi->blocking_hook; 
+      pwsi->blocking_hook = (DWORD)lpBlockFunc; 
+      pwsi->flags &= ~WSI_BLOCKINGHOOK32;
       return prev; 
   }
   return 0;
 }
 
-FARPROC32 WSASetBlockingHook32(FARPROC32 lpBlockFunc)
-{
-  fprintf( stderr, "WSASetBlockingHook32(%p): empty stub\n", lpBlockFunc );
-  return NULL;
-}
 
-INT16 WSAUnhookBlockingHook16(void)
+/***********************************************************************
+ *      WSASetBlockingHook32()
+ */
+FARPROC32 WINAPI WSASetBlockingHook32(FARPROC32 lpBlockFunc)
 {
+  FARPROC32             prev;
   LPWSINFO              pwsi = wsi_find(GetCurrentTask());
 
-  dprintf_winsock(stddeb, "WS_UnhookBlockingHook(%08x)\n", (unsigned)pwsi);
-  if( pwsi ) return (INT16)(INT32)(pwsi->blocking_hook = (FARPROC16)NULL);
-  return SOCKET_ERROR;
-}
-
-INT32 WSAUnhookBlockingHook32(void)
-{
-  fprintf( stderr, "WSAUnhookBlockingHook32(): empty stub\n");
+  dprintf_winsock(stddeb, "WS_SetBlockingHook32(%08x): hook %08x\n",
+                          (unsigned)pwsi, (unsigned) lpBlockFunc);
+  if( pwsi ) {
+      prev = (FARPROC32)pwsi->blocking_hook;
+      pwsi->blocking_hook = (DWORD)lpBlockFunc;
+      pwsi->flags |= WSI_BLOCKINGHOOK32;
+      return prev;
+  }
   return NULL;
 }
 
-VOID
-WsControl(DWORD x1,DWORD x2,LPDWORD x3,LPDWORD x4,LPDWORD x5,LPDWORD x6) 
+
+/***********************************************************************
+ *      WSAUnhookBlockingHook16()	(WINSOCK.110)
+ */
+INT16 WINAPI WSAUnhookBlockingHook16(void)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_UnhookBlockingHook16(%08x)\n", (unsigned)pwsi);
+    if( pwsi ) return (INT16)(pwsi->blocking_hook = 0);
+    return SOCKET_ERROR;
+}
+
+
+/***********************************************************************
+ *      WSAUnhookBlockingHook32()
+ */
+INT32 WINAPI WSAUnhookBlockingHook32(void)
+{
+    LPWSINFO              pwsi = wsi_find(GetCurrentTask());
+
+    dprintf_winsock(stddeb, "WS_UnhookBlockingHook32(%08x)\n", (unsigned)pwsi);
+    if( pwsi )
+    {
+	pwsi->blocking_hook = 0;
+	pwsi->flags &= ~WSI_BLOCKINGHOOK32;
+	return 0;
+    }
+    return SOCKET_ERROR;
+}
+
+/***********************************************************************
+ *      WsControl()
+ */
+VOID WINAPI WsControl(DWORD x1,DWORD x2,LPDWORD x3,LPDWORD x4,
+                      LPDWORD x5,LPDWORD x6) 
 {
 	fprintf(stdnimp,"WsControl(%lx,%lx,%p,%p,%p,%p)\n",
 		x1,x2,x3,x4,x5,x6
@@ -1548,8 +2174,8 @@
 {
    /* Duplicate hostent structure and flatten data (with its pointers)
     * into pwsi->buffer. Internal pointers can be linear, SEGPTR, or 
-    * relative to 0 depending on "flag" value. Return data size (also 
-    * in the pwsi->buflen).
+    * relative to pwsi->buffer depending on "flag" value. Returns size
+    * of the data copied (also in the pwsi->buflen).
     */
 
    int size = hostent_size(p_he);
@@ -1561,14 +2187,14 @@
      p = pwsi->buffer;
      p_base = (flag & WS_DUP_OFFSET) ? NULL
 				     : ((flag & WS_DUP_SEGPTR) ? (char*)SEGPTR_GET(p) : p);
-     p += (flag & WS_DUP_SEGPTR) ? sizeof(struct ws_hostent) : sizeof(struct hostent);
+     p += (flag & WS_DUP_NATIVE) ? sizeof(struct hostent) : sizeof(struct ws_hostent);
      p_name = p;
      strcpy(p, p_he->h_name); p += strlen(p) + 1;
      p_aliases = p;
      p += list_dup(p_he->h_aliases, p, p_base + (p - pwsi->buffer), 0);
      p_addr = p;
      list_dup(p_he->h_addr_list, p, p_base + (p - pwsi->buffer), p_he->h_length);
-     if( !(flag & WS_DUP_SEGPTR) )
+     if( flag & WS_DUP_NATIVE )
      { struct hostent* p_to = (struct hostent*)pwsi->buffer;
        p_to->h_addrtype = p_he->h_addrtype; p_to->h_length = p_he->h_length;
        p_to->h_name = p_base + (p_name - pwsi->buffer);
@@ -1587,22 +2213,6 @@
    return size;
 }
 
-void fixup_wshe(struct ws_hostent* p_wshe, SEGPTR base)
-{
-   /* add 'base' to ws_hostent pointers to convert them from offsets */ 
-
-   int i;
-   unsigned*	p_aliases,*p_addr;
-
-   p_aliases = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_aliases); 
-   p_addr = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_addr_list);
-   ((unsigned)(p_wshe->h_name)) += (unsigned)base;
-   ((unsigned)(p_wshe->h_aliases)) += (unsigned)base;
-   ((unsigned)(p_wshe->h_addr_list)) += (unsigned)base;
-   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
-   for(i=0;p_addr[i];i++) p_addr[i] += (unsigned)base;
-}
-
 /* ----- protoent */
 
 static int protoent_size(struct protoent* p_pe)
@@ -1626,12 +2236,12 @@
      p = pwsi->buffer; 
      p_base = (flag & WS_DUP_OFFSET) ? NULL
 				     : ((flag & WS_DUP_SEGPTR) ? (char*)SEGPTR_GET(p) : p);
-     p += (flag & WS_DUP_SEGPTR)? sizeof(struct ws_protoent) : sizeof(struct protoent);
+     p += (flag & WS_DUP_NATIVE)? sizeof(struct protoent) : sizeof(struct ws_protoent);
      p_name = p;
      strcpy(p, p_pe->p_name); p += strlen(p) + 1;
      p_aliases = p;
      list_dup(p_pe->p_aliases, p, p_base + (p - pwsi->buffer), 0);
-     if( !(flag & WS_DUP_NATIVE) )
+     if( flag & WS_DUP_NATIVE )
      { struct protoent* p_to = (struct protoent*)pwsi->buffer;
        p_to->p_proto = p_pe->p_proto;
        p_to->p_name = p_base + (p_name - pwsi->buffer); 
@@ -1646,15 +2256,6 @@
    return size;
 }
 
-void fixup_wspe(struct ws_protoent* p_wspe, SEGPTR base)
-{
-   int i;
-   unsigned*       p_aliases = (unsigned*)((char*)p_wspe + (unsigned)p_wspe->p_aliases); 
-   ((unsigned)(p_wspe->p_name)) += (unsigned)base;
-   ((unsigned)(p_wspe->p_aliases)) += (unsigned)base;
-   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
-}
-
 /* ----- servent */
 
 static int servent_size(struct servent* p_se)
@@ -1678,7 +2279,7 @@
      p = pwsi->buffer;
      p_base = (flag & WS_DUP_OFFSET) ? NULL 
 				     : ((flag & WS_DUP_SEGPTR) ? (char*)SEGPTR_GET(p) : p);
-     p += (flag & WS_DUP_SEGPTR)? sizeof(struct ws_servent) : sizeof(struct servent);
+     p += (flag & WS_DUP_NATIVE)? sizeof(struct servent) : sizeof(struct ws_servent);
      p_name = p;
      strcpy(p, p_se->s_name); p += strlen(p) + 1;
      p_proto = p;
@@ -1686,7 +2287,7 @@
      p_aliases = p;
      list_dup(p_se->s_aliases, p, p_base + (p - pwsi->buffer), 0);
 
-     if( !(flag & WS_DUP_SEGPTR) )
+     if( flag & WS_DUP_NATIVE )
      { struct servent* p_to = (struct servent*)pwsi->buffer;
        p_to->s_port = p_se->s_port;
        p_to->s_name = p_base + (p_name - pwsi->buffer); 
@@ -1703,16 +2304,6 @@
    return size;
 }
 
-void fixup_wsse(struct ws_servent* p_wsse, SEGPTR base)
-{
-   int i;
-   unsigned*       p_aliases = (unsigned*)((char*)p_wsse + (unsigned)p_wsse->s_aliases);
-   ((unsigned)(p_wsse->s_name)) += (unsigned)base;
-   ((p_wsse->s_proto)) += (unsigned)base;
-   ((p_wsse->s_aliases)) += (unsigned)base;
-   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
-}
-
 /* ----------------------------------- error handling */
 
 UINT16 wsaErrno(void)
diff --git a/misc/winsock_async.c b/misc/winsock_async.c
deleted file mode 100644
index 5cd0382..0000000
--- a/misc/winsock_async.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * asynchronous winsock services
- * 
- * (C) 1996 Alex Korobka.
- *
- * FIXME: telftp16 (ftp part) stalls on AsyncSelect with FD_ACCEPT.
- */
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <sys/wait.h>
-#include <errno.h>
-#ifdef __EMX__
-#include <sys/so_ioctl.h>
-#include <sys/param.h>
-#endif
-#ifdef __svr4__
-#include <sys/file.h>
-#include <sys/filio.h>
-#endif
-
-extern int h_errno;
-
-#include "windows.h"
-#include "winsock.h"
-#include "debug.h"
-
-#ifndef FASYNC
-#define FASYNC FIOASYNC
-#endif
-
-#define __WS_ASYNC_DEBUG	0
-
-static int		__async_io_max_fd = 0;
-static fd_set		__async_io_fdset;
-static ws_async_op*	__async_op_list = NULL;
-
-extern ws_async_ctl	async_ctl;
-extern int		async_qid;
-
-fd_set		 fd_read, fd_write, fd_excp;
-
-/* ----------------------------------- async/non-blocking I/O */
-
-int WINSOCK_async_io(int fd, int async)
-{
-    int fd_flags;
-
-#ifndef __EMX__
-    fcntl(fd, F_SETOWN, getpid());
-#endif
-
-    fd_flags = fcntl(fd, F_GETFL, 0);
-    if (fcntl(fd, F_SETFL, (async)? fd_flags | FASYNC
-                                  : fd_flags & ~FASYNC ) != -1) return 0;
-    return -1;
-}
-
-int WINSOCK_unblock_io(int fd, int noblock)
-{
-    int fd_flags;
-
-    fd_flags = fcntl(fd, F_GETFL, 0);
-    if (fcntl(fd, F_SETFL, (noblock)? fd_flags |  O_NONBLOCK
-                                    : fd_flags & ~O_NONBLOCK ) != -1) return 0;
-    return -1;
-}
-
-int WINSOCK_check_async_op(ws_async_op* p_aop)
-{
-  ws_async_op*   p = __async_op_list;
-  while( p ) if( p == p_aop ) return 1;
-	     else p = p->next;
-  return 0;
-}
-
-void WINSOCK_cancel_async_op(HTASK16 hTask)
-{
-  ws_async_op*   p = __async_op_list;
-  while( p ) 
-     if(hTask == GetWindowTask16(p->hWnd)) 
-        p->flags = 0;
-}
-
-void WINSOCK_link_async_op(ws_async_op* p_aop)
-{
-  if( __async_op_list ) __async_op_list->prev = p_aop;
-  else FD_ZERO(&__async_io_fdset);
-
-  p_aop->next = __async_op_list; 
-  p_aop->prev = NULL;
-  __async_op_list = p_aop;
-
-  FD_SET(p_aop->fd[0], &__async_io_fdset);
-  if( p_aop->fd[0] > __async_io_max_fd ) 
-		     __async_io_max_fd = p_aop->fd[0];
-}
-
-void WINSOCK_unlink_async_op(ws_async_op* p_aop)
-{
-  if( p_aop == __async_op_list ) __async_op_list = p_aop->next;
-  else
-  { p_aop->prev->next = p_aop->next;
-    if( p_aop->next ) p_aop->next->prev = p_aop->prev; }
-  FD_CLR(p_aop->fd[0], &__async_io_fdset); 
-  if( p_aop->fd[0] == __async_io_max_fd )
-		      __async_io_max_fd--;
-}
-
-/* ----------------------------------- SIGIO handler -
- *
- * link_async_op/unlink_async_op allow to install generic
- * async IO handlers (provided that aop_control function is defined).
- *
- * Note: AsyncGetXbyY expilicitly raise it.
- */
-
-void WINSOCK_sigio(int signal)
-{
- struct timeval         timeout;
- fd_set                 check_set;
- ws_async_op*		p_aop;
-
- check_set = __async_io_fdset;
- memset(&timeout, 0, sizeof(timeout));
-
- while( select(__async_io_max_fd + 1,
-              &check_set, NULL, NULL, &timeout) > 0)
- {
-   for( p_aop = __async_op_list;
-	p_aop ; p_aop = p_aop->next )
-      if( FD_ISSET(p_aop->fd[0], &check_set) )
-          if( p_aop->aop_control(p_aop, AOP_IO) == AOP_CONTROL_REMOVE )
-	  {
-	      if( p_aop->pid ) 
-	      { 
-		kill(p_aop->pid, SIGKILL);
-		waitpid(p_aop->pid, NULL, WNOHANG);
-	      }
-	      WINSOCK_unlink_async_op( p_aop );
-	  }
-   check_set = __async_io_fdset;
-  }
-}
-
-/* ----------------------------------- child process IPC */
-
-static void _sigusr1_handler_child(int sig)
-{
-   /* read message queue to decide which
-    * async_ctl parameters to update 
-    *
-    * Note: we don't want to have SA_RESTART on this signal
-    * handler, otherwise select() won't notice changed fd sets.
-    */
-
-   signal( SIGUSR1, _sigusr1_handler_child );
-   while( msgrcv(async_qid, (struct msgbuf*)&async_ctl.ip,
-          MTYPE_PARENT_SIZE, MTYPE_PARENT, IPC_NOWAIT) != -1 )
-   {
-       /* only ip.lParam is updated */
-#if __WS_ASYNC_DEBUG
-       printf("handler - event %08x\n", async_ctl.ip.lParam );
-#endif
-
-       switch( async_ctl.ip.lParam )
-       {
-	  /* These are events we are notified of.
-	   */
-
-          case   WS_FD_CONNECTED: async_ctl.lEvent &= ~WS_FD_CONNECT;
-				  FD_SET(async_ctl.ws_sock->fd, &fd_read);
-				  FD_SET(async_ctl.ws_sock->fd, &fd_write);
-			  	  break;
-
-          case   WS_FD_ACCEPT:  async_ctl.ws_sock->flags |= WS_FD_ACCEPT;
-				FD_SET(async_ctl.ws_sock->fd, &fd_read);
-                                FD_SET(async_ctl.ws_sock->fd, &fd_write);
-                                break;
-          case   WS_FD_OOB:     async_ctl.lEvent |= WS_FD_OOB;
-				FD_SET(async_ctl.ws_sock->fd, &fd_excp);
-                                break;
-          case   WS_FD_READ:    async_ctl.lEvent |= WS_FD_READ;
-				FD_SET(async_ctl.ws_sock->fd, &fd_read);
-                                break;
-          case   WS_FD_WRITE:   async_ctl.lEvent |= WS_FD_WRITE;
-				FD_SET(async_ctl.ws_sock->fd, &fd_write);
-                                break;
-          default:
-       }
-   }
-}
-
-static int notify_parent( unsigned flag )
-{
-  if( flag & WSMSG_ASYNC_SELECT )
-  {
-     async_ctl.ip.mtype = MTYPE_CLIENT;
-     while( msgsnd(async_qid, (struct msgbuf*)&(async_ctl.ip),
-                               MTYPE_CLIENT_SIZE, 0) == -1 )
-     {
-       if( errno == EINTR ) continue;
-#ifdef EIDRM
-       else if( errno == EIDRM ) _exit(0);
-#endif
-       else 
-       { 
-	 perror("AsyncSelect(child)"); 
-	 return 0; 
-       }
-     }
-     kill(getppid(), SIGUSR1); 
-
-#if __WS_ASYNC_DEBUG
-  printf("handler - notify [%08x]\n", async_ctl.ip.lParam);
-#endif
-  }
-  else /* use half-duplex pipe to handle variable length packets */
-  {
-     write(async_ctl.ws_aop->fd[1], &async_ctl.lLength, sizeof(unsigned) );
-     write(async_ctl.ws_aop->fd[1], async_ctl.buffer, async_ctl.lLength );
-#ifndef __EMX__
-     kill(getppid(), SIGIO);    /* simulate async I/O */
-#endif
-#if __WS_ASYNC_DEBUG
-  printf("handler - notify aop [%d, buf %d]\n", async_ctl.lLength, async_ctl.ws_aop->buflen);
-#endif
-     pause();
-  }
-  return 1;
-}
-
-/* ----------------------------------- async select */
-
-static void setup_fd_sets()
-{
-   FD_ZERO(&fd_read); FD_ZERO(&fd_write); FD_ZERO(&fd_excp);
-
-   if( async_ctl.lEvent & WS_FD_OOB) 
-       FD_SET(async_ctl.ws_sock->fd, &fd_excp);
-   if( async_ctl.lEvent & (WS_FD_ACCEPT | WS_FD_READ |
-			   WS_FD_CONNECT | WS_FD_CLOSE) ) 
-       FD_SET(async_ctl.ws_sock->fd, &fd_read);
-   if( async_ctl.lEvent & (WS_FD_WRITE | WS_FD_CONNECT) ) 
-       FD_SET(async_ctl.ws_sock->fd, &fd_write);
-}
-
-static void setup_sig_sets(sigset_t* sig_block)
-{
-   sigemptyset(sig_block);
-   sigaddset(sig_block, SIGUSR1);
-   sigprocmask( SIG_BLOCK, sig_block, NULL);
-   signal( SIGUSR1, _sigusr1_handler_child );
-}
-
-void WINSOCK_do_async_select()
-{
-  sigset_t    sig_block;
-  int	      sock_type, bytes;
-
-  getsockopt(async_ctl.ws_sock->fd, SOL_SOCKET, SO_TYPE, &sock_type, &bytes);
-  setup_sig_sets(&sig_block);
-  setup_fd_sets();
-
-  while(1)
-  {
-    int		val;
-
-    if( sock_type != SOCK_STREAM )
-        async_ctl.lEvent &= ~(WS_FD_ACCEPT | WS_FD_CONNECT);
-    sigprocmask( SIG_UNBLOCK, &sig_block, NULL); 
-
-#if __WS_ASYNC_DEBUG
-    printf("select(2)[%i,%i,%i]... ", 
-	     FD_ISSET(async_ctl.ws_sock->fd, &fd_read),
-	     FD_ISSET(async_ctl.ws_sock->fd, &fd_write),
-	     FD_ISSET(async_ctl.ws_sock->fd, &fd_excp));
-#endif
-    if( (val = select(async_ctl.ws_sock->fd + 1, 
-		     &fd_read, &fd_write, &fd_excp, NULL)) == -1 )
-      if( errno == EINTR ) continue;
-#if __WS_ASYNC_DEBUG
-    printf("got %i events\n", val);
-#endif
-
-#if __WS_ASYNC_DEBUG
-    if( FD_ISSET(async_ctl.ws_sock->fd, &fd_read) )
-	printf("handler - read is READY! [%08x]\n", async_ctl.lEvent & (WS_FD_READ | WS_FD_CLOSE));
-#endif
-
-    sigprocmask( SIG_BLOCK, &sig_block, NULL);
-    async_ctl.ip.lParam = 0;
-    if( async_ctl.ws_sock->flags & WS_FD_ACCEPT )
-    {
-	/* listening socket */
-	
-	FD_CLR(async_ctl.ws_sock->fd, &fd_read);
-	FD_CLR(async_ctl.ws_sock->fd, &fd_write);
-
-	async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_ACCEPT, 0 );
-        notify_parent( WSMSG_ASYNC_SELECT );
-	continue;
-    }
-    else /* I/O socket */
-    {
-	if( async_ctl.lEvent & WS_FD_CONNECT )
-	{
-	  if( FD_ISSET(async_ctl.ws_sock->fd, &fd_write) ) 
-	  {
-	      /* success - reinit fd sets to start I/O */
-
-	      if( async_ctl.lEvent & (WS_FD_READ | WS_FD_CLOSE))
-		   FD_SET(async_ctl.ws_sock->fd, &fd_read);
-	      else FD_CLR(async_ctl.ws_sock->fd, &fd_read);
-	      if( async_ctl.lEvent & WS_FD_WRITE )
-		   FD_SET(async_ctl.ws_sock->fd, &fd_write);
-	      else FD_CLR(async_ctl.ws_sock->fd, &fd_write);
-
-	      async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_CONNECT, 0 );
-	      async_ctl.lEvent &= ~WS_FD_CONNECT; /* one-shot */
-	  }
-	  else if( FD_ISSET(async_ctl.ws_sock->fd, &fd_read) )
-	  {
-              /* failure - do read() to get correct errno */
-
-              if( read(async_ctl.ws_sock->fd, &bytes, 4) == -1 )
-                  async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_CONNECT, wsaErrno() );
-              else continue;
-	  } else continue; /* OOB?? */
-
-          notify_parent( WSMSG_ASYNC_SELECT );
-	}
-	else /* connected socket */
-	{
-
-	  if( async_ctl.lEvent & WS_FD_OOB )
-	    if( FD_ISSET(async_ctl.ws_sock->fd, &fd_excp) )
-	    {
-	      async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_OOB, 0 );
-	      async_ctl.lEvent &= ~WS_FD_OOB;
-	      FD_CLR(async_ctl.ws_sock->fd, &fd_excp);
-	      notify_parent( WSMSG_ASYNC_SELECT );
-	    }
-	    else FD_SET(async_ctl.ws_sock->fd, &fd_excp);
-
-          if( async_ctl.lEvent & WS_FD_WRITE )
-            if( FD_ISSET( async_ctl.ws_sock->fd, &fd_write ) )
-            {
-              async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_WRITE, 0 );
-              async_ctl.lEvent &= ~WS_FD_WRITE;
-              FD_CLR(async_ctl.ws_sock->fd, &fd_write);
-              notify_parent( WSMSG_ASYNC_SELECT );
-            }
-            else FD_SET(async_ctl.ws_sock->fd, &fd_write);
-
-	  if( async_ctl.lEvent & (WS_FD_READ | WS_FD_CLOSE) )
-	    if( FD_ISSET(async_ctl.ws_sock->fd, &fd_read) )
-	    {
-	      int 	ok = 0;
-
-	      if( sock_type == SOCK_RAW ) ok = 1;
-	      else if( ioctl( async_ctl.ws_sock->fd, FIONREAD, (char*)&bytes) == -1 )
-	      {
-		  async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_READ, wsaErrno() );
-		  FD_CLR( async_ctl.ws_sock->fd, &fd_read );
-		  bytes = 0;
-	      }
-
-	      if( bytes || ok )	/* got data */
-	      {
-#if __WS_ASYNC_DEBUG
-		  if( ok ) printf("\traw/datagram read pending\n");
-		  else printf("\t%i bytes pending\n", bytes );
-#endif
-		  if( async_ctl.lEvent & WS_FD_READ )
-		  {
-		     async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_READ, 0 );
-		     async_ctl.lEvent &= ~WS_FD_READ;
-		     if( !(async_ctl.lEvent & WS_FD_CLOSE) ) 
-			   FD_CLR( async_ctl.ws_sock->fd, &fd_read );
-		  }
-		  else if( !(async_ctl.lEvent & (WS_FD_WRITE | WS_FD_OOB)) ) 
-		       {
-			  sigprocmask( SIG_UNBLOCK, &sig_block, NULL);
-			  pause();
-			  sigprocmask( SIG_BLOCK, &sig_block, NULL);
-		       }
-		       else continue;
-	      }
-	      else		/* 0 bytes to read */
-	      {
-		  val = read( async_ctl.ws_sock->fd, (char*)&bytes, 4);
-	          if( errno == EWOULDBLOCK || errno == EINTR ) 
-		  { 
-#if __WS_ASYNC_DEBUG
-		    printf("\twould block..\n");
-#endif
-		    continue;
-		  }
-		  switch( val )
-		  {
-		    case  0: errno = ENETDOWN;	/* ENETDOWN */
-		    case -1: 			/* ECONNRESET */
-			     async_ctl.ip.lParam = WSAMAKESELECTREPLY( WS_FD_CLOSE, wsaErrno() );
-			     break;
-		    default: continue;
-		  }
-		  async_ctl.lEvent &= ~(WS_FD_CLOSE | WS_FD_READ); /* one-shot */
-		  FD_ZERO(&fd_read); FD_ZERO(&fd_write); 
-	      }
-
-	      notify_parent( WSMSG_ASYNC_SELECT );
-	  }
-	  else FD_SET(async_ctl.ws_sock->fd, &fd_read);
-
-	} /* connected socket */
-    } /* I/O socket */
-  } /* while */
-}
-
-
-/* ----------------------------------- getXbyY requests */
-
-static void _async_fail()
-{
-     async_ctl.lLength =
-        (h_errno < 0) ? (unsigned)WSAMAKEASYNCREPLY( 0, wsaErrno() )
-                      : (unsigned)WSAMAKEASYNCREPLY( 0, wsaHerrno() );
-     write(async_ctl.ws_aop->fd[1], &async_ctl.lLength, sizeof(unsigned) );
-#ifndef __EMX__
-     kill(getppid(), SIGIO);    /* simulate async I/O */
-#endif
-     pause();
-}
-
-void dump_ws_hostent_offset(struct ws_hostent* wshe)
-{
-  int		i;
-  char*		base = (char*)wshe;
-  unsigned*	ptr;
-
-  printf("h_name = %08x\t[%s]\n", (unsigned)wshe->h_name, base + (unsigned)wshe->h_name);
-  printf("h_aliases = %08x\t[%08x]\n", (unsigned)wshe->h_aliases, 
-				       (unsigned)(base + (unsigned)wshe->h_aliases));
-  ptr = (unsigned*)(base + (unsigned)wshe->h_aliases);
-  for(i = 0; ptr[i]; i++ )
-  {
-	printf("%i - %08x ", i + 1, ptr[i]);
-	printf(" [%s]\n", ((char*)base) + ptr[i]);
-  }
-  printf("h_length = %i\n", wshe->h_length);
-}
-
-void WS_do_async_gethost(LPWSINFO pwsi, unsigned flag )
-{  
-  int			size = 0;
-  struct hostent* 	p_he;
-
-  close(async_ctl.ws_aop->fd[0]);
-  p_he = (flag & WSMSG_ASYNC_HOSTBYNAME)
-	 ? gethostbyname(async_ctl.init)
-	 : gethostbyaddr(async_ctl.init,
-		 	 async_ctl.lLength, async_ctl.lEvent);
-  if( p_he ) size = WS_dup_he(pwsi, p_he, WS_DUP_SEGPTR | WS_DUP_OFFSET );
-  if( size )
-  {
-     async_ctl.buffer = pwsi->buffer;
-     async_ctl.lLength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
-     notify_parent( flag );
-  }
-  else _async_fail();
-}
-
-void WS_do_async_getproto(LPWSINFO pwsi, unsigned flag )
-{
-  int			size = 0;
-  struct protoent*	p_pe;
-
-  close(async_ctl.ws_aop->fd[0]);
-  p_pe = (flag & WSMSG_ASYNC_PROTOBYNAME)
-	 ? getprotobyname(async_ctl.init)
-	 : getprotobynumber(async_ctl.lEvent);
-  if( p_pe ) size = WS_dup_pe(pwsi, p_pe, WS_DUP_SEGPTR | WS_DUP_OFFSET );
-  if( size )
-  {
-     async_ctl.buffer = pwsi->buffer;
-     async_ctl.lLength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
-     notify_parent( flag );
-  } 
-  else _async_fail();
-}
-
-void WS_do_async_getserv(LPWSINFO pwsi, unsigned flag )
-{
-  int			size = 0;
-  struct servent* 	p_se;
-
-  close(async_ctl.ws_aop->fd[0]);
-  p_se = (flag & WSMSG_ASYNC_SERVBYNAME)
-	 ? getservbyname(async_ctl.init, async_ctl.buffer)
-	 : getservbyport(async_ctl.lEvent, async_ctl.init);
-  if( p_se ) size = WS_dup_se(pwsi, p_se, WS_DUP_SEGPTR | WS_DUP_OFFSET );
-  if( size )
-  {
-     async_ctl.buffer = pwsi->buffer;
-     async_ctl.lLength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
-     notify_parent( flag );
-  }
-  else _async_fail();
-}
-
diff --git a/misc/winsock_dns.c b/misc/winsock_dns.c
new file mode 100644
index 0000000..8042489
--- /dev/null
+++ b/misc/winsock_dns.c
@@ -0,0 +1,530 @@
+/*
+ * asynchronous DNS services
+ * 
+ * (C) 1996,1997 Alex Korobka.
+ *
+ * TODO: Fork dns lookup helper during the startup (with a pipe
+ *       for communication) and make it fork for a database request
+ *       instead of forking the main process (i.e. something like
+ *       Netscape 4.0).
+ */
+
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/wait.h>
+#include <errno.h>
+#ifdef __EMX__
+#include <sys/so_ioctl.h>
+#include <sys/param.h>
+#endif
+#ifdef __svr4__
+#include <sys/file.h>
+#include <sys/filio.h>
+#endif
+
+extern int h_errno;
+
+#include "windows.h"
+#include "heap.h"
+#include "ldt.h"
+#include "message.h"
+#include "miscemu.h"
+#include "winsock.h"
+#include "debug.h"
+
+#ifndef FASYNC
+#define FASYNC FIOASYNC
+#endif
+
+#define __WS_ASYNC_DEBUG	0
+
+typedef struct          /* async DNS op control struct */
+{
+  ws_async_op*  ws_aop;
+  char*         buffer;
+  int           type;
+  union
+  {
+    char*       init;
+    char*       name;
+    char*       addr;
+  } rq;
+  unsigned      ilength;
+} ws_async_ctl;
+
+extern HANDLE16	__ws_gethandle( void* ptr );
+extern void*	__ws_memalloc( int size );
+extern void	__ws_memfree( void* ptr );
+
+/* NOTE: ws_async_op list is traversed inside the SIGIO handler! */
+
+static int		__async_io_max_fd = 0;
+static fd_set		__async_io_fdset;
+static ws_async_op*	__async_op_list = NULL;
+
+static void fixup_wshe(struct ws_hostent* p_wshe, SEGPTR base);
+static void fixup_wspe(struct ws_protoent* p_wspe, SEGPTR base);
+static void fixup_wsse(struct ws_servent* p_wsse, SEGPTR base);
+
+extern void EVENT_AddIO( int fd, unsigned flag );
+extern void EVENT_DeleteIO( int fd, unsigned flag );
+
+/* ----------------------------------- async/non-blocking I/O */
+
+int WINSOCK_async_io(int fd, int async)
+{
+    int fd_flags;
+
+#ifndef __EMX__
+    fcntl(fd, F_SETOWN, getpid());
+#endif
+
+    fd_flags = fcntl(fd, F_GETFL, 0);
+    if (fcntl(fd, F_SETFL, (async)? fd_flags | FASYNC
+                                  : fd_flags & ~FASYNC ) != -1) return 0;
+    return -1;
+}
+
+int WINSOCK_unblock_io(int fd, int noblock)
+{
+    int fd_flags;
+
+    fd_flags = fcntl(fd, F_GETFL, 0);
+    if (fcntl(fd, F_SETFL, (noblock)? fd_flags |  O_NONBLOCK
+                                    : fd_flags & ~O_NONBLOCK ) != -1) return 0;
+    return -1;
+}
+
+int WINSOCK_check_async_op(ws_async_op* p_aop)
+{
+  ws_async_op*   p = __async_op_list;
+  while( p ) if( p == p_aop ) return 1;
+	     else p = p->next;
+  return 0;
+}
+
+int WINSOCK_cancel_async_op(ws_async_op* p_aop)
+{
+    /* SIGIO unsafe! */
+
+    if( WINSOCK_check_async_op(p_aop) )
+    {
+	if( !(p_aop->flags & WSMSG_DEAD_AOP) )
+	{
+            kill(p_aop->pid, SIGKILL);
+            waitpid(p_aop->pid, NULL, 0); /* just in case */
+            close(p_aop->fd[0]);
+	}
+        WINSOCK_unlink_async_op(p_aop);
+	EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
+        p_aop->flags = 0;
+	p_aop->hWnd = p_aop->uMsg = 0;
+        return 1;
+    }
+    return 0;
+}
+
+void WINSOCK_cancel_task_aops(HTASK16 hTask, void (*__opfree)(void*))
+{
+    /* SIGIO safe, hTask == 0 cancels all outstanding async ops */
+
+    int num = 0;
+    ws_async_op*   p, *next;
+
+    dprintf_winsock(stddeb,"\tcancelling async DNS requests... ");
+
+    SIGNAL_MaskAsyncEvents( TRUE );
+    next = __async_op_list;
+    while( (p = next) ) 
+    {
+	HTASK16 hWndTask = GetWindowTask16(p->hWnd);
+
+	next = p->next;
+	if(!hTask || !hWndTask || (hTask == hWndTask))
+	{
+	    WINSOCK_cancel_async_op(p);
+	    if( __opfree ) __opfree(p);
+	    num++;
+	}
+    }
+    SIGNAL_MaskAsyncEvents( FALSE );
+    dprintf_winsock(stddeb,"%i total\n", num );
+}
+
+void WINSOCK_link_async_op(ws_async_op* p_aop)
+{
+  /* SIGIO safe */
+
+  p_aop->prev = NULL;
+  SIGNAL_MaskAsyncEvents( TRUE );
+  if( __async_op_list )
+  {
+      ws_async_op*	p = __async_op_list;
+      __async_op_list->prev = p_aop;
+
+      /* traverse the list and reap dead ops */
+      while( p )
+      {
+	  if( p->flags & WSMSG_DEAD_AOP )
+	  {
+	      ws_async_op* dead = p;
+
+	      dprintf_winsock(stddeb,"\treaping dead aop [%08x]\n", (unsigned)p );
+
+	      p = p->next;
+	      WINSOCK_unlink_async_op( dead );
+	      __ws_memfree( dead );
+	      continue;
+	  }
+	  p = p->next;
+      }
+  }
+  else FD_ZERO(&__async_io_fdset);
+  p_aop->next = __async_op_list;
+  __async_op_list = p_aop;
+  SIGNAL_MaskAsyncEvents( FALSE );
+
+  FD_SET(p_aop->fd[0], &__async_io_fdset);
+  if( p_aop->fd[0] > __async_io_max_fd ) 
+		     __async_io_max_fd = p_aop->fd[0];
+}
+
+void WINSOCK_unlink_async_op(ws_async_op* p_aop)
+{
+  /* SIGIO unsafe! */
+
+  if( p_aop == __async_op_list ) __async_op_list = p_aop->next;
+  else
+      p_aop->prev->next = p_aop->next;
+  if( p_aop->next ) p_aop->next->prev = p_aop->prev;
+
+  FD_CLR(p_aop->fd[0], &__async_io_fdset); 
+  if( p_aop->fd[0] == __async_io_max_fd )
+		      __async_io_max_fd--;
+}
+
+/* ----------------------------------- SIGIO handler -
+ *
+ * link_async_op/unlink_async_op allow to install generic
+ * async IO handlers (provided that aop_control function is defined).
+ *
+ * Note: AsyncGetXbyY expilicitly raise it.
+ */
+
+void WINSOCK_sigio(int signal)
+{
+ struct timeval         timeout;
+ fd_set                 check_set;
+ ws_async_op*		p_aop;
+
+ check_set = __async_io_fdset;
+ memset(&timeout, 0, sizeof(timeout));
+
+ while( select(__async_io_max_fd + 1,
+              &check_set, NULL, NULL, &timeout) > 0)
+ {
+   for( p_aop = __async_op_list;
+	p_aop ; p_aop = p_aop->next )
+      if( FD_ISSET(p_aop->fd[0], &check_set) )
+          if( p_aop->aop_control(p_aop, AOP_IO) == AOP_CONTROL_REMOVE )
+	  {
+	      p_aop->flags = WSMSG_DEAD_AOP;  /* can't free inside the signal */
+	      close(p_aop->fd[0]);
+	      FD_CLR(p_aop->fd[0],&__async_io_fdset);
+	      if( p_aop->fd[0] == __async_io_max_fd )
+				 __async_io_max_fd = p_aop->fd[0];
+	      if( p_aop->pid ) 
+	      { 
+		  kill(p_aop->pid, SIGKILL); 
+		  waitpid(p_aop->pid, NULL, WNOHANG);
+		  p_aop->pid = 0;
+	      }
+	  }
+   check_set = __async_io_fdset;
+  }
+}
+
+/* ----------------------------------- getXbyY requests */
+
+static	 ws_async_ctl	async_ctl; /* child process control struct */
+
+static int aop_control(ws_async_op* p_aop, int flag )
+{
+    unsigned    lLength;
+
+  /* success:   LOWORD(lLength) has the length of the struct
+   *            to read.
+   * failure:   LOWORD(lLength) is zero, HIWORD(lLength) contains
+   *            the error code.
+   */
+
+    read(p_aop->fd[0], &lLength, sizeof(unsigned));
+    if( LOWORD(lLength) )
+    {
+	if( (int)LOWORD(lLength) <= p_aop->buflen )
+	{
+            char* buffer = (char*)PTR_SEG_TO_LIN(p_aop->buffer_base);
+            read(p_aop->fd[0], buffer, LOWORD(lLength));
+            switch( p_aop->flags )
+            {
+		case WSMSG_ASYNC_HOSTBYNAME:
+		case WSMSG_ASYNC_HOSTBYADDR:
+		     fixup_wshe((struct ws_hostent*)buffer, p_aop->buffer_base); break;
+		case WSMSG_ASYNC_PROTOBYNAME:
+		case WSMSG_ASYNC_PROTOBYNUM:
+		     fixup_wspe((struct ws_protoent*)buffer, p_aop->buffer_base); break;
+		case WSMSG_ASYNC_SERVBYNAME:
+		case WSMSG_ASYNC_SERVBYPORT:
+		     fixup_wsse((struct ws_servent*)buffer, p_aop->buffer_base); break;
+		default:
+                     if( p_aop->flags ) fprintf(stderr,"Received unknown async request!\n");
+                     return AOP_CONTROL_REMOVE;
+            }
+	}
+        else lLength =  ((UINT32)LOWORD(lLength)) | ((unsigned)WSAENOBUFS << 16);
+    } /* failure */
+
+#if __WS_ASYNC_DEBUG
+    printf("DNS aop completed: hWnd [%04x], uMsg [%04x], aop [%04x], event [%08x]\n",
+         p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength);
+#endif
+
+    /* FIXME: update num_async_rq */
+    EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
+    PostMessage16( p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength );
+    
+    return AOP_CONTROL_REMOVE;  /* one-shot request */
+}
+
+
+HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND16 hWnd, UINT16 uMsg, INT16 type, LPSTR init,
+		  	  INT16 len, LPSTR proto, SEGPTR sbuf, INT16 buflen, UINT32 flag)
+{
+    /* queue 'flag' request and fork off its handler */
+
+    async_ctl.ws_aop = (ws_async_op*)__ws_memalloc(sizeof(ws_async_op));
+
+    if( async_ctl.ws_aop )
+    {
+	HANDLE16        handle = __ws_gethandle(async_ctl.ws_aop);
+
+	if( pipe(async_ctl.ws_aop->fd) == 0 )
+	{
+	    async_ctl.rq.init = (char*)init;
+	    async_ctl.ilength = len;
+	    async_ctl.buffer = proto;
+	    async_ctl.type = type;
+
+	    async_ctl.ws_aop->hWnd = hWnd;
+	    async_ctl.ws_aop->uMsg = uMsg;
+	    async_ctl.ws_aop->buffer_base = sbuf; async_ctl.ws_aop->buflen = buflen;
+	    async_ctl.ws_aop->flags = flag;
+	    async_ctl.ws_aop->aop_control = &aop_control;
+
+	    WINSOCK_link_async_op( async_ctl.ws_aop );
+
+	    async_ctl.ws_aop->pid = fork();
+	    if( async_ctl.ws_aop->pid )
+	    {
+		close(async_ctl.ws_aop->fd[1]);  /* write endpoint */
+		dprintf_winsock(stddeb, "\tasync_op = %04x (child %i)\n",
+					handle, async_ctl.ws_aop->pid);
+		if( async_ctl.ws_aop->pid > 0 )
+		{
+		    EVENT_AddIO( async_ctl.ws_aop->fd[0], EVENT_IO_READ );
+		    pwsi->num_async_rq++;
+		    return __ws_gethandle(async_ctl.ws_aop);
+		}
+
+		/* fork() failed */
+		close(async_ctl.ws_aop->fd[0]);
+		pwsi->err = WSAEWOULDBLOCK;
+	    }
+	    else
+	    {
+		/* child process */
+
+		close(async_ctl.ws_aop->fd[0]);  /* read endpoint */
+		switch( flag )
+		{
+		    case WSMSG_ASYNC_HOSTBYADDR:
+		    case WSMSG_ASYNC_HOSTBYNAME:
+			WS_do_async_gethost(pwsi, flag);
+			break;
+		    case WSMSG_ASYNC_PROTOBYNUM:
+		    case WSMSG_ASYNC_PROTOBYNAME:
+			WS_do_async_getproto(pwsi, flag);
+			break;
+		    case WSMSG_ASYNC_SERVBYPORT:
+		    case WSMSG_ASYNC_SERVBYNAME:
+			WS_do_async_getserv(pwsi, flag);
+			break;
+		}
+		_exit(0); 	/* skip  atexit()'ed cleanup */
+	    }
+	}
+	else pwsi->err = wsaErrno(); /* failed to create pipe */
+
+	__ws_memfree((void*)async_ctl.ws_aop);
+    } else pwsi->err = WSAEWOULDBLOCK;
+    return 0;
+}
+
+static int _async_notify()
+{
+    /* use half-duplex pipe to send variable length packets 
+     * to the parent process */
+     
+    write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned));
+    write(async_ctl.ws_aop->fd[1], async_ctl.buffer, async_ctl.ilength );
+
+#ifndef __EMX__
+    kill(getppid(), SIGIO);    /* simulate async I/O */
+#endif
+
+#if __WS_ASYNC_DEBUG
+    printf("handler - notify aop [%d, buf %d]\n", async_ctl.ilength, async_ctl.ws_aop->buflen);
+#endif
+    return 1;
+}
+
+static void _async_fail()
+{
+     /* write a DWORD with error code (low word is zero) */
+
+     async_ctl.ilength =
+        (h_errno < 0) ? (unsigned)WSAMAKEASYNCREPLY( 0, wsaErrno() )
+                      : (unsigned)WSAMAKEASYNCREPLY( 0, wsaHerrno() );
+     write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned) );
+#ifndef __EMX__
+     kill(getppid(), SIGIO);    /* simulate async I/O */
+#endif
+
+#if __WS_ASYNC_DEBUG
+    printf("handler - failed aop [%d, buf %d]\n", async_ctl.ilength, async_ctl.ws_aop->buflen);
+#endif
+}
+
+void dump_ws_hostent_offset(struct ws_hostent* wshe)
+{
+  int		i;
+  char*		base = (char*)wshe;
+  unsigned*	ptr;
+
+  printf("h_name = %08x\t[%s]\n", (unsigned)wshe->h_name, base + (unsigned)wshe->h_name);
+  printf("h_aliases = %08x\t[%08x]\n", (unsigned)wshe->h_aliases, 
+				       (unsigned)(base + (unsigned)wshe->h_aliases));
+  ptr = (unsigned*)(base + (unsigned)wshe->h_aliases);
+  for(i = 0; ptr[i]; i++ )
+  {
+	printf("%i - %08x ", i + 1, ptr[i]);
+	printf(" [%s]\n", ((char*)base) + ptr[i]);
+  }
+  printf("h_length = %i\n", wshe->h_length);
+}
+
+void WS_do_async_gethost(LPWSINFO pwsi, unsigned flag )
+{  
+  int			size = 0;
+  struct hostent* 	p_he;
+
+  close(async_ctl.ws_aop->fd[0]);
+
+  dprintf_winsock(stddeb,"DNS: getting hostent for [%s]\n", async_ctl.rq.name );
+
+  p_he = (flag & WSMSG_ASYNC_HOSTBYNAME)
+	 ? gethostbyname(async_ctl.rq.name)
+	 : gethostbyaddr(async_ctl.rq.name,
+		 	 async_ctl.ilength, async_ctl.type);
+  dprintf_winsock(stddeb,"DNS: done!\n");
+
+  if( p_he ) size = WS_dup_he(pwsi, p_he, WS_DUP_SEGPTR | WS_DUP_OFFSET );
+  if( size )
+  {
+     async_ctl.buffer = pwsi->buffer;
+     async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
+     _async_notify( flag );
+  }
+  else _async_fail();
+}
+
+void WS_do_async_getproto(LPWSINFO pwsi, unsigned flag )
+{
+  int			size = 0;
+  struct protoent*	p_pe;
+
+  close(async_ctl.ws_aop->fd[0]);
+  p_pe = (flag & WSMSG_ASYNC_PROTOBYNAME)
+	 ? getprotobyname(async_ctl.rq.name)
+	 : getprotobynumber(async_ctl.type);
+  if( p_pe ) size = WS_dup_pe(pwsi, p_pe, WS_DUP_SEGPTR | WS_DUP_OFFSET );
+  if( size )
+  {
+     async_ctl.buffer = pwsi->buffer;
+     async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
+     _async_notify( flag );
+  } 
+  else _async_fail();
+}
+
+void WS_do_async_getserv(LPWSINFO pwsi, unsigned flag )
+{
+  int			size = 0;
+  struct servent* 	p_se;
+
+  close(async_ctl.ws_aop->fd[0]);
+  p_se = (flag & WSMSG_ASYNC_SERVBYNAME)
+	 ? getservbyname(async_ctl.rq.name, async_ctl.buffer)
+	 : getservbyport(async_ctl.type, async_ctl.buffer);
+  if( p_se ) size = WS_dup_se(pwsi, p_se, WS_DUP_SEGPTR | WS_DUP_OFFSET );
+  if( size )
+  {
+     async_ctl.buffer = pwsi->buffer;
+     async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
+     _async_notify( flag );
+  }
+  else _async_fail();
+}
+
+/* ----------------------------------- helper functions */
+
+void fixup_wshe(struct ws_hostent* p_wshe, SEGPTR base)
+{
+   /* add 'base' to ws_hostent pointers to convert them from offsets */
+
+   int i;
+   unsigned*    p_aliases,*p_addr;
+
+   p_aliases = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_aliases);
+   p_addr = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_addr_list);
+   ((unsigned)(p_wshe->h_name)) += (unsigned)base;
+   ((unsigned)(p_wshe->h_aliases)) += (unsigned)base;
+   ((unsigned)(p_wshe->h_addr_list)) += (unsigned)base;
+   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
+   for(i=0;p_addr[i];i++) p_addr[i] += (unsigned)base;
+}
+
+void fixup_wspe(struct ws_protoent* p_wspe, SEGPTR base)
+{
+   int i;
+   unsigned*       p_aliases = (unsigned*)((char*)p_wspe + (unsigned)p_wspe->p_aliases);
+   ((unsigned)(p_wspe->p_name)) += (unsigned)base;
+   ((unsigned)(p_wspe->p_aliases)) += (unsigned)base;
+   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
+}
+
+void fixup_wsse(struct ws_servent* p_wsse, SEGPTR base)
+{
+   int i;
+   unsigned*       p_aliases = (unsigned*)((char*)p_wsse + (unsigned)p_wsse->s_aliases);
+   ((unsigned)(p_wsse->s_name)) += (unsigned)base;
+   ((p_wsse->s_proto)) += (unsigned)base;
+   ((p_wsse->s_aliases)) += (unsigned)base;
+   for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
+}
+
diff --git a/misc/wsprintf.c b/misc/wsprintf.c
index 9cfbc57..f347fd5 100644
--- a/misc/wsprintf.c
+++ b/misc/wsprintf.c
@@ -230,7 +230,8 @@
 /***********************************************************************
  *           wvsnprintf16   (Not a Windows API)
  */
-INT16 wvsnprintf16( LPSTR buffer, UINT16 maxlen, LPCSTR spec, LPCVOID args )
+INT16 WINAPI wvsnprintf16( LPSTR buffer, UINT16 maxlen, LPCSTR spec,
+                           LPCVOID args )
 {
     WPRINTF_FORMAT format;
     LPSTR p = buffer;
@@ -329,7 +330,8 @@
 /***********************************************************************
  *           wvsnprintf32A   (Not a Windows API)
  */
-INT32 wvsnprintf32A( LPSTR buffer, UINT32 maxlen, LPCSTR spec, LPCVOID args )
+INT32 WINAPI wvsnprintf32A( LPSTR buffer, UINT32 maxlen, LPCSTR spec,
+                            LPCVOID args )
 {
     WPRINTF_FORMAT format;
     LPSTR p = buffer;
@@ -397,7 +399,8 @@
 /***********************************************************************
  *           wvsnprintf32W   (Not a Windows API)
  */
-INT32 wvsnprintf32W( LPWSTR buffer, UINT32 maxlen, LPCWSTR spec, LPCVOID args )
+INT32 WINAPI wvsnprintf32W( LPWSTR buffer, UINT32 maxlen, LPCWSTR spec,
+                            LPCVOID args )
 {
     WPRINTF_FORMAT format;
     LPWSTR p = buffer;
@@ -464,7 +467,7 @@
 /***********************************************************************
  *           wvsprintf16   (USER.421)
  */
-INT16 wvsprintf16( LPSTR buffer, LPCSTR spec, LPCVOID args )
+INT16 WINAPI wvsprintf16( LPSTR buffer, LPCSTR spec, LPCVOID args )
 {
     return wvsnprintf16( buffer, 0xffff, spec, args );
 }
@@ -473,7 +476,7 @@
 /***********************************************************************
  *           wvsprintf32A   (USER32.586)
  */
-INT32 wvsprintf32A( LPSTR buffer, LPCSTR spec, LPCVOID args )
+INT32 WINAPI wvsprintf32A( LPSTR buffer, LPCSTR spec, LPCVOID args )
 {
     return wvsnprintf32A( buffer, 0xffffffff, spec, args );
 }
@@ -482,7 +485,7 @@
 /***********************************************************************
  *           wvsprintf32W   (USER32.587)
  */
-INT32 wvsprintf32W( LPWSTR buffer, LPCWSTR spec, LPCVOID args )
+INT32 WINAPI wvsprintf32W( LPWSTR buffer, LPCWSTR spec, LPCVOID args )
 {
     return wvsnprintf32W( buffer, 0xffffffff, spec, args );
 }
@@ -492,7 +495,7 @@
  *           wsprintf16   (USER.420)
  */
 /* Winelib version */
-INT16 wsprintf16( LPSTR buffer, LPCSTR spec, ... )
+INT16 WINAPIV wsprintf16( LPSTR buffer, LPCSTR spec, ... )
 {
     va_list valist;
     INT16 res;
@@ -505,7 +508,7 @@
 }
 
 /* Emulator version */
-INT16 WIN16_wsprintf16(void)
+INT16 WINAPIV WIN16_wsprintf16(void)
 {
     SEGPTR *win_stack = (SEGPTR *)CURRENT_STACK16->args;
     LPSTR buffer = (LPSTR)PTR_SEG_TO_LIN(win_stack[0]);
@@ -519,7 +522,7 @@
  *           wsprintf32A   (USER32.584)
  */
 /* Winelib version */
-INT32 wsprintf32A( LPSTR buffer, LPCSTR spec, ... )
+INT32 WINAPIV wsprintf32A( LPSTR buffer, LPCSTR spec, ... )
 {
     va_list valist;
     INT32 res;
@@ -531,7 +534,7 @@
 }
 
 /* Emulator version */
-INT32 WIN32_wsprintf32A( DWORD *args )
+INT32 WINAPIV WIN32_wsprintf32A( DWORD *args )
 {
     return wvsprintf32A( (LPSTR)args[0], (LPCSTR)args[1], (LPCVOID)&args[2] );
 }
@@ -541,7 +544,7 @@
  *           wsprintf32W   (USER32.585)
  */
 /* Winelib version */
-INT32 wsprintf32W( LPWSTR buffer, LPCWSTR spec, ... )
+INT32 WINAPIV wsprintf32W( LPWSTR buffer, LPCWSTR spec, ... )
 {
     va_list valist;
     INT32 res;
@@ -553,7 +556,7 @@
 }
 
 /* Emulator version */
-INT32 WIN32_wsprintf32W( DWORD *args )
+INT32 WINAPIV WIN32_wsprintf32W( DWORD *args )
 {
     return wvsprintf32W( (LPWSTR)args[0], (LPCWSTR)args[1], (LPCVOID)&args[2]);
 }
diff --git a/miscemu/emulate.c b/miscemu/emulate.c
index eee31e0..6e5ec58 100644
--- a/miscemu/emulate.c
+++ b/miscemu/emulate.c
@@ -28,7 +28,7 @@
  */
 /* FIXME: Only skeletal implementation for now */
 
-void WIN87_fpmath( CONTEXT *context )
+void WINAPI WIN87_fpmath( CONTEXT *context )
 {
     dprintf_int(stddeb, "_fpmath: (cs:eip=%x:%lx es=%x bx=%04x ax=%04x dx==%04x)\n",
                  (WORD)CS_reg(context), EIP_reg(context),
@@ -107,21 +107,20 @@
 }
 
 
-void
-WIN87_WinEm87Info(struct Win87EmInfoStruct *pWIS, int cbWin87EmInfoStruct)
+void WINAPI WIN87_WinEm87Info(struct Win87EmInfoStruct *pWIS,
+                              int cbWin87EmInfoStruct)
 {
   dprintf_int(stddeb, "__WinEm87Info(%p,%d)\n",pWIS,cbWin87EmInfoStruct);
 }
 
-void
-WIN87_WinEm87Restore(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
+void WINAPI WIN87_WinEm87Restore(void *pWin87EmSaveArea,
+                                 int cbWin87EmSaveArea)
 {
   dprintf_int(stddeb, "__WinEm87Restore(%p,%d)\n",
 	pWin87EmSaveArea,cbWin87EmSaveArea);
 }
 
-void
-WIN87_WinEm87Save(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
+void WINAPI WIN87_WinEm87Save(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
 {
   dprintf_int(stddeb, "__WinEm87Save(%p,%d)\n",
 	pWin87EmSaveArea,cbWin87EmSaveArea);
diff --git a/miscemu/instr.c b/miscemu/instr.c
index 931cfe8..9e414c4 100644
--- a/miscemu/instr.c
+++ b/miscemu/instr.c
@@ -8,7 +8,7 @@
 #include "windows.h"
 #include "ldt.h"
 #include "miscemu.h"
-#include "sigcontext.h"
+#include "sig_context.h"
 
 
 #define STACK_sig(context) \
diff --git a/msdos/dpmi.c b/msdos/dpmi.c
index 05404ce..ae7a852 100644
--- a/msdos/dpmi.c
+++ b/msdos/dpmi.c
@@ -52,7 +52,7 @@
  *
  * Handler for int 31h (DPMI).
  */
-void INT_Int31Handler( CONTEXT *context )
+void WINAPI INT_Int31Handler( CONTEXT *context )
 {
     DWORD dw;
     BYTE *ptr;
diff --git a/msdos/int10.c b/msdos/int10.c
index bb99f8e..e73d5bd 100644
--- a/msdos/int10.c
+++ b/msdos/int10.c
@@ -15,7 +15,7 @@
  *
  * Handler for int 10h (video).
  */
-void INT_Int10Handler( CONTEXT *context )
+void WINAPI INT_Int10Handler( CONTEXT *context )
 {
     switch(AH_reg(context))
     {
diff --git a/msdos/int11.c b/msdos/int11.c
index 88b3041..c66f20c 100644
--- a/msdos/int11.c
+++ b/msdos/int11.c
@@ -15,7 +15,7 @@
  *
  * Handler for int 11h (get equipment list).
  */
-void INT_Int11Handler( CONTEXT *context )
+void WINAPI INT_Int11Handler( CONTEXT *context )
 {
     int diskdrives = 0;
     int parallelports = 0;
diff --git a/msdos/int12.c b/msdos/int12.c
index cff7f52..79429bd 100644
--- a/msdos/int12.c
+++ b/msdos/int12.c
@@ -9,7 +9,7 @@
  *
  * Handler for int 12h (get memory size).
  */
-void INT_Int12Handler( CONTEXT *context )
+void WINAPI INT_Int12Handler( CONTEXT *context )
 {
     AX_reg(context) = 640;
 }
diff --git a/msdos/int13.c b/msdos/int13.c
index 9213897..eb9560c 100644
--- a/msdos/int13.c
+++ b/msdos/int13.c
@@ -15,7 +15,7 @@
  *
  * Handler for int 13h (disk I/O).
  */
-void INT_Int13Handler( CONTEXT *context )
+void WINAPI INT_Int13Handler( CONTEXT *context )
 {
     switch(AH_reg(context))
     {
diff --git a/msdos/int1a.c b/msdos/int1a.c
index ddc52ef..1e8157a 100644
--- a/msdos/int1a.c
+++ b/msdos/int1a.c
@@ -44,7 +44,7 @@
  *
  * Handler for int 1ah (date and time).
  */
-void INT_Int1aHandler( CONTEXT *context )
+void WINAPI INT_Int1aHandler( CONTEXT *context )
 {
     time_t ltime;
     DWORD ticks;
diff --git a/msdos/int21.c b/msdos/int21.c
index 46b0004..d01e61f 100644
--- a/msdos/int21.c
+++ b/msdos/int21.c
@@ -95,14 +95,14 @@
     return TRUE;
 }
 
-BYTE *GetCurrentDTA(void)
+static BYTE *GetCurrentDTA(void)
 {
     TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
     return (BYTE *)PTR_SEG_TO_LIN( pTask->dta );
 }
 
 
-void ChopOffWhiteSpace(char *string)
+static void ChopOffWhiteSpace(char *string)
 {
 	int length;
 
@@ -324,7 +324,7 @@
 }
 
 
-void OpenExistingFile( CONTEXT *context )
+static void OpenExistingFile( CONTEXT *context )
 {
     AX_reg(context) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
                               AL_reg(context) );
@@ -880,7 +880,7 @@
 /***********************************************************************
  *           DOS3Call  (KERNEL.102)
  */
-void DOS3Call( CONTEXT *context )
+void WINAPI DOS3Call( CONTEXT *context )
 {
     BOOL32	bSetDOSExtendedError = FALSE;
 
@@ -1044,7 +1044,7 @@
         break;
             
     case 0x30: /* GET DOS VERSION */
-        AX_reg(context) = DOSVERSION;
+        AX_reg(context) = HIWORD(GetVersion16());
         BX_reg(context) = 0x0012;     /* 0x123456 is Wine's serial # */
         CX_reg(context) = 0x3456;
         break;
@@ -1077,7 +1077,7 @@
 		break;
 				
 	      case 0x06: /* GET TRUE VERSION NUMBER */
-		BX_reg(context) = DOSVERSION;
+		BX_reg(context) = HIWORD(GetVersion16());
 		DX_reg(context) = 0x00;
 		break;
 
diff --git a/msdos/int25.c b/msdos/int25.c
index 7073bd8..8e99609 100644
--- a/msdos/int25.c
+++ b/msdos/int25.c
@@ -18,7 +18,7 @@
  *
  * Handler for int 25h (absolute disk read).
  */
-void INT_Int25Handler( CONTEXT *context )
+void WINAPI INT_Int25Handler( CONTEXT *context )
 {
     BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(context), BX_reg(context) );
     DWORD begin, length;
diff --git a/msdos/int26.c b/msdos/int26.c
index 09ee526..4a58a5c 100644
--- a/msdos/int26.c
+++ b/msdos/int26.c
@@ -17,7 +17,7 @@
  *
  * Handler for int 26h (absolute disk read).
  */
-void INT_Int26Handler( CONTEXT *context )
+void WINAPI INT_Int26Handler( CONTEXT *context )
 {
     BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(context), BX_reg(context) );
     DWORD begin, length;
diff --git a/msdos/int2a.c b/msdos/int2a.c
index 02e37d8..35b6c22 100644
--- a/msdos/int2a.c
+++ b/msdos/int2a.c
@@ -15,7 +15,7 @@
  *
  * Handler for int 2ah (network).
  */
-void INT_Int2aHandler( CONTEXT *context )
+void WINAPI INT_Int2aHandler( CONTEXT *context )
 {
     switch(AH_reg(context))
     {
diff --git a/msdos/int2f.c b/msdos/int2f.c
index d8dbae1..b43e3b2 100644
--- a/msdos/int2f.c
+++ b/msdos/int2f.c
@@ -11,7 +11,6 @@
 #include "msdos.h"
 #include "miscemu.h"
 #include "module.h"
-#include "options.h"
 #include "stddebug.h"
 /* #define DEBUG_INT */
 #include "debug.h"
@@ -27,7 +26,7 @@
  *
  * Handler for int 2fh (multiplex).
  */
-void INT_Int2fHandler( CONTEXT *context )
+void WINAPI INT_Int2fHandler( CONTEXT *context )
 {
     switch(AH_reg(context))
     {
@@ -76,13 +75,15 @@
     switch(AL_reg(context))
     {
     case 0x00:  /* Windows enhanced mode installation check */
-        AX_reg(context) = (Options.mode == MODE_ENHANCED) ? WINVERSION : 0;
+        AX_reg(context) = (GetWinFlags() & WF_ENHANCED) ?
+                                                  LOWORD(GetVersion16()) : 0;
         break;
 	
     case 0x0a:  /* Get Windows version and type */
         AX_reg(context) = 0;
-        BX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
-        CX_reg(context) = (Options.mode == MODE_ENHANCED) ? 3 : 2;
+        BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
+                          (LOWORD(GetVersion16()) >> 8);
+        CX_reg(context) = (GetWinFlags() & WF_ENHANCED) ? 3 : 2;
         break;
 
     case 0x80:  /* Release time-slice */
diff --git a/msdos/int4b.c b/msdos/int4b.c
index 4f4e8c5..6157547 100644
--- a/msdos/int4b.c
+++ b/msdos/int4b.c
@@ -8,7 +8,7 @@
  *           INT_Int4bHandler
  *
  */
-void INT_Int4bHandler( CONTEXT *context )
+void WINAPI INT_Int4bHandler( CONTEXT *context )
 {
     switch(AH_reg(context))
     {
diff --git a/msdos/int5c.c b/msdos/int5c.c
index ab22059..6a17e8a 100644
--- a/msdos/int5c.c
+++ b/msdos/int5c.c
@@ -15,7 +15,7 @@
  *
  * Also handler for interrupt 5c. 
  */
-void NetBIOSCall( CONTEXT *context )
+void WINAPI NetBIOSCall( CONTEXT *context )
 {
     BYTE* ptr;
     ptr = (BYTE*) PTR_SEG_OFF_TO_LIN(ES_reg(context),BX_reg(context));
diff --git a/msdos/vxd.c b/msdos/vxd.c
index a56c1e5..dc51e79 100644
--- a/msdos/vxd.c
+++ b/msdos/vxd.c
@@ -21,20 +21,29 @@
              CX_reg(context), DX_reg(context), SI_reg(context), \
              DI_reg(context), (WORD)DS_reg(context), (WORD)ES_reg(context) )
 
+
+static WORD VXD_WinVersion(void)
+{
+    WORD version = GetVersion16();
+    return (version >> 8) | (version << 8);
+}
+
 /***********************************************************************
  *           VXD_PageFile
  */
-void VXD_PageFile( CONTEXT *context )
+void WINAPI VXD_PageFile( CONTEXT *context )
 {
+    unsigned	service = AX_reg(context);
+
     /* taken from Ralf Brown's Interrupt List */
 
-    dprintf_vxd(stddeb,"VxD PageFile called ...\n");
+    dprintf_vxd(stddeb,"VxD: [%04x] PageFile\n", (UINT16)service );
 
-    switch(AX_reg(context)) 
+    switch(service)
     {
     case 0x00: /* get version, is this windows version? */
 	dprintf_vxd(stddeb,"VxD PageFile: returning version\n");
-        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+        AX_reg(context) = VXD_WinVersion();
 	RESET_CFLAG(context);
 	break;
 
@@ -69,15 +78,17 @@
 /***********************************************************************
  *           VXD_Shell
  */
-void VXD_Shell( CONTEXT *context )
+void WINAPI VXD_Shell( CONTEXT *context )
 {
-    dprintf_vxd(stddeb,"VxD Shell called ...\n");
+    unsigned	service = DX_reg(context);
 
-    switch (DX_reg(context)) /* Ralf Brown says EDX, but I use DX instead */
+    dprintf_vxd(stddeb,"VxD: [%04x] Shell\n", (UINT16)service);
+
+    switch (service) /* Ralf Brown says EDX, but I use DX instead */
     {
     case 0x0000:
 	dprintf_vxd(stddeb,"VxD Shell: returning version\n");
-        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+        AX_reg(context) = VXD_WinVersion();
 	EBX_reg(context) = 1; /* system VM Handle */
 	break;
 
@@ -127,15 +138,17 @@
 /***********************************************************************
  *           VXD_Comm
  */
-void VXD_Comm( CONTEXT *context )
+void WINAPI VXD_Comm( CONTEXT *context )
 {
-    dprintf_vxd(stddeb,"VxD Comm called ...\n");
+    unsigned	service = AX_reg(context);
 
-    switch (AX_reg(context))
+    dprintf_vxd(stddeb,"VxD: [%04x] Comm\n", (UINT16)service);
+
+    switch (service)
     {
     case 0x0000: /* get version */
 	dprintf_vxd(stddeb,"VxD Comm: returning version\n");
-        AX_reg(context) = (WINVERSION >> 8) | ((WINVERSION << 8) & 0xff00);
+        AX_reg(context) = VXD_WinVersion();
 	RESET_CFLAG(context);
 	break;
 
@@ -146,3 +159,37 @@
         VXD_BARF( context, "comm" );
     }
 }
+
+/***********************************************************************
+ *           VXD_Timer
+ */
+void VXD_Timer( CONTEXT *context )
+{
+    unsigned service = AX_reg(context);
+
+    dprintf_vxd(stddeb,"VxD: [%04x] Virtual Timer\n", (UINT16)service);
+
+    switch(service)
+    {
+    case 0x0000: /* version */
+	AX_reg(context) = VXD_WinVersion();
+	RESET_CFLAG(context);
+	break;
+
+    case 0x0100: /* clock tick time, in 840nsecs */
+	EAX_reg(context) = GetTickCount();
+
+	EDX_reg(context) = EAX_reg(context) >> 22;
+	EAX_reg(context) <<= 10; /* not very precise */
+	break;
+
+    case 0x0101: /* current Windows time, msecs */
+    case 0x0102: /* current VM time, msecs */
+	EAX_reg(context) = GetTickCount();
+	break;
+
+    default:
+	VXD_BARF( context, "VTD" );
+    }
+}
+
diff --git a/multimedia/joystick.c b/multimedia/joystick.c
index 4e643e2..cdd65ab 100644
--- a/multimedia/joystick.c
+++ b/multimedia/joystick.c
@@ -111,7 +111,7 @@
 /**************************************************************************
  * 				JoyGetNumDevs		[MMSYSTEM.101]
  */
-WORD JoyGetNumDevs(void)
+WORD WINAPI JoyGetNumDevs(void)
 {
 int joy;
 WORD joy_cnt = 0;
@@ -130,7 +130,7 @@
 /**************************************************************************
  * 				JoyGetDevCaps		[MMSYSTEM.102]
  */
-WORD JoyGetDevCaps(WORD wID, LPJOYCAPS lpCaps, WORD wSize)
+WORD WINAPI JoyGetDevCaps(WORD wID, LPJOYCAPS lpCaps, WORD wSize)
 {
     dprintf_mmsys(stderr, "JoyGetDevCaps(%04X, %p, %d);\n",
             wID, lpCaps, wSize);
@@ -138,7 +138,7 @@
     if (JoyOpenDriver(wID) == TRUE) {
         lpCaps->wMid = MM_MICROSOFT;
         lpCaps->wPid = MM_PC_JOYSTICK;
-        strcpy(lpCaps->szPname, "WineJoy\0"); /* joystick product name */
+        strcpy(lpCaps->szPname, "WineJoy"); /* joystick product name */
         lpCaps->wXmin = 0; /* FIXME */
         lpCaps->wXmax = 0xffff;
         lpCaps->wYmin = 0;
@@ -159,7 +159,7 @@
 /**************************************************************************
  * 				JoyGetPos	       	[MMSYSTEM.103]
  */
-WORD JoyGetPos(WORD wID, LPJOYINFO lpInfo)
+WORD WINAPI JoyGetPos(WORD wID, LPJOYINFO lpInfo)
 {
         struct js_status js;
 
@@ -184,7 +184,7 @@
 /**************************************************************************
  * 				JoyGetThreshold		[MMSYSTEM.104]
  */
-WORD JoyGetThreshold(WORD wID, LPWORD lpThreshold)
+WORD WINAPI JoyGetThreshold(WORD wID, LPWORD lpThreshold)
 {
     dprintf_mmsys(stderr, "JoyGetThreshold(%04X, %p);\n", wID, lpThreshold);
     if (wID > 3) return JOYERR_PARMS;
@@ -195,7 +195,7 @@
 /**************************************************************************
  * 				JoyReleaseCapture	[MMSYSTEM.105]
  */
-WORD JoyReleaseCapture(WORD wID)
+WORD WINAPI JoyReleaseCapture(WORD wID)
 {
     dprintf_mmsys(stderr, "JoyReleaseCapture(%04X);\n", wID);
     JoyCaptured = FALSE;
@@ -208,7 +208,7 @@
 /**************************************************************************
  * 				JoySetCapture		[MMSYSTEM.106]
  */
-WORD JoySetCapture(HWND16 hWnd, WORD wID, WORD wPeriod, BOOL16 bChanged)
+WORD WINAPI JoySetCapture(HWND16 hWnd, WORD wID, WORD wPeriod, BOOL16 bChanged)
 {
 
     dprintf_mmsys(stderr, "JoySetCapture(%04X, %04X, %d, %d);\n",
@@ -227,7 +227,7 @@
 /**************************************************************************
  * 				JoySetThreshold		[MMSYSTEM.107]
  */
-WORD JoySetThreshold(WORD wID, WORD wThreshold)
+WORD WINAPI JoySetThreshold(WORD wID, WORD wThreshold)
 {
     dprintf_mmsys(stderr, "JoySetThreshold(%04X, %d);\n", wID, wThreshold);
 
@@ -239,7 +239,7 @@
 /**************************************************************************
  * 				JoySetCalibration	[MMSYSTEM.109]
  */
-WORD JoySetCalibration(WORD wID)
+WORD WINAPI JoySetCalibration(WORD wID)
 {
     fprintf(stderr, "EMPTY STUB !!! JoySetCalibration(%04X);\n", wID);
     return JOYERR_NOCANDO;
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index 1624ee3..f97ca49 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -42,8 +42,8 @@
 extern UINT16 MMSYSTEM_NextDevID(UINT16 wDevID);
 extern BOOL32 MMSYSTEM_DevIDValid(UINT16 wDevID);
 
-LONG DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
-		      DWORD dwParam1, DWORD dwParam2);
+LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
+                             DWORD dwParam1, DWORD dwParam2);
 
 LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
@@ -2107,8 +2107,8 @@
 /* FIXME: "all" is a valid devicetype and we should access all devices if
  * it is used. (imagine "close all"). Not implemented yet.
  */
-DWORD mciSendString (LPCSTR lpstrCommand, LPSTR lpstrReturnString, 
-	UINT16 uReturnLength, HWND16 hwndCallback)
+DWORD WINAPI mciSendString (LPCSTR lpstrCommand, LPSTR lpstrReturnString, 
+                            UINT16 uReturnLength, HWND16 hwndCallback)
 {
 	char	*cmd,*dev,*args,**keywords,*filename;
 	WORD	uDevTyp=0,wDevID=0;
diff --git a/multimedia/midi.c b/multimedia/midi.c
index 7384f8d..9392819 100644
--- a/multimedia/midi.c
+++ b/multimedia/midi.c
@@ -1089,7 +1089,7 @@
 	lpCaps->wMid = 0x00FF; 	/* Manufac ID */
 	lpCaps->wPid = 0x0001; 	/* Product ID */
 	lpCaps->vDriverVersion = 0x001; /* Product Version */
-	strcpy(lpCaps->szPname, "Linux MIDIOUT Driver version 0.01");
+	strcpy(lpCaps->szPname, "Linux MIDIOUT Driver v0.01");
 /* FIXME
    Values are the same as I get with Borland TC 4.5
 */
diff --git a/multimedia/mmsystem.c b/multimedia/mmsystem.c
index b4f6cf9..b13221f 100644
--- a/multimedia/mmsystem.c
+++ b/multimedia/mmsystem.c
@@ -39,8 +39,8 @@
 
 UINT16 midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
 UINT16 waveGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize);
-LONG DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
-		      DWORD dwParam1, DWORD dwParam2);
+LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
+                             DWORD dwParam1, DWORD dwParam2);
 
 LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 		     DWORD dwParam1, DWORD dwParam2);
@@ -98,8 +98,8 @@
 /**************************************************************************
 * 				MMSYSTEM_WEP		[MMSYSTEM.1]
 */
-int MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
-		 WORD cbHeapSize, LPSTR lpCmdLine)
+int WINAPI MMSYSTEM_WEP(HINSTANCE16 hInstance, WORD wDataSeg,
+                        WORD cbHeapSize, LPSTR lpCmdLine)
 {
 	fprintf(stderr, "STUB: Unloading MMSystem DLL ... hInst=%04X \n", hInstance);
 	return(TRUE);
@@ -108,7 +108,7 @@
 /**************************************************************************
 * 				sndPlaySound		[MMSYSTEM.2]
 */
-BOOL16 sndPlaySound(LPCSTR lpszSoundName, UINT16 uFlags)
+BOOL16 WINAPI sndPlaySound(LPCSTR lpszSoundName, UINT16 uFlags)
 {
 	BOOL16			bRet = FALSE;
 	HMMIO16			hmmio;
@@ -251,7 +251,7 @@
 /**************************************************************************
 * 				mmsystemGetVersion	[MMSYSTEM.5]
 */
-WORD mmsystemGetVersion()
+WORD WINAPI mmsystemGetVersion()
 {
 	dprintf_mmsys(stddeb, "mmsystemGetVersion // 0.4.0 ...?... :-) !\n");
 	return 0x0040;
@@ -260,8 +260,8 @@
 /**************************************************************************
 * 				DriverProc	[MMSYSTEM.6]
 */
-LRESULT DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
-						DWORD dwParam1, DWORD dwParam2)
+LRESULT WINAPI DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
+                          DWORD dwParam1, DWORD dwParam2)
 {
 	return DrvDefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
 }
@@ -269,8 +269,8 @@
 /**************************************************************************
 * 				DriverCallback	[MMSYSTEM.31]
 */
-BOOL16 DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, 
-		WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
+BOOL16 WINAPI DriverCallback(DWORD dwCallBack, UINT16 uFlags, HANDLE16 hDev, 
+                             WORD wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -303,7 +303,7 @@
 /**************************************************************************
 * 				auxGetNumDevs		[MMSYSTEM.350]
 */
-UINT16 auxGetNumDevs()
+UINT16 WINAPI auxGetNumDevs()
 {
 	UINT16	count = 0;
 	dprintf_mmsys(stddeb, "auxGetNumDevs !\n");
@@ -315,7 +315,7 @@
 /**************************************************************************
 * 				auxGetDevCaps		[MMSYSTEM.351]
 */
-UINT16 auxGetDevCaps(UINT16 uDeviceID, AUXCAPS * lpCaps, UINT16 uSize)
+UINT16 WINAPI auxGetDevCaps(UINT16 uDeviceID, AUXCAPS * lpCaps, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "auxGetDevCaps(%04X, %p, %d) !\n", 
 					uDeviceID, lpCaps, uSize);
@@ -326,7 +326,7 @@
 /**************************************************************************
 * 				auxGetVolume		[MMSYSTEM.352]
 */
-UINT16 auxGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
+UINT16 WINAPI auxGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
 {
 	dprintf_mmsys(stddeb, "auxGetVolume(%04X, %p) !\n", uDeviceID, lpdwVolume);
 	return auxMessage(uDeviceID, AUXDM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
@@ -335,7 +335,7 @@
 /**************************************************************************
 * 				auxSetVolume		[MMSYSTEM.353]
 */
-UINT16 auxSetVolume(UINT16 uDeviceID, DWORD dwVolume)
+UINT16 WINAPI auxSetVolume(UINT16 uDeviceID, DWORD dwVolume)
 {
 	dprintf_mmsys(stddeb, "auxSetVolume(%04X, %08lX) !\n", uDeviceID, dwVolume);
 	return auxMessage(uDeviceID, AUXDM_SETVOLUME, 0L, dwVolume, 0L);
@@ -344,7 +344,7 @@
 /**************************************************************************
 * 				auxOutMessage		[MMSYSTEM.354]
 */
-DWORD auxOutMessage(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
+DWORD WINAPI auxOutMessage(UINT16 uDeviceID, UINT16 uMessage, DWORD dw1, DWORD dw2)
 {
 	dprintf_mmsys(stddeb, "auxOutMessage(%04X, %04X, %08lX, %08lX)\n", 
 				uDeviceID, uMessage, dw1, dw2);
@@ -354,7 +354,7 @@
 /**************************************************************************
 * 				mciGetErrorString		[MMSYSTEM.706]
 */
-BOOL16 mciGetErrorString (DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
+BOOL16 WINAPI mciGetErrorString (DWORD wError, LPSTR lpstrBuffer, UINT16 uLength)
 {
 	LPSTR	msgptr;
 	dprintf_mmsys(stddeb, "mciGetErrorString(%08lX, %p, %d);\n", wError, lpstrBuffer, uLength);
@@ -630,7 +630,7 @@
 /**************************************************************************
 * 				mciDriverNotify			[MMSYSTEM.711]
 */
-BOOL16 mciDriverNotify(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
+BOOL16 WINAPI mciDriverNotify(HWND16 hWndCallBack, UINT16 wDevID, UINT16 wStatus)
 {
 	dprintf_mmsys(stddeb, "mciDriverNotify(%04X, %u, %04X)\n", hWndCallBack, wDevID, wStatus);
 	if (!IsWindow32(hWndCallBack)) return FALSE;
@@ -935,7 +935,8 @@
 /**************************************************************************
 * 				mciSendCommand			[MMSYSTEM.701]
 */
-DWORD mciSendCommand(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1, DWORD dwParam2)
+DWORD WINAPI mciSendCommand(UINT16 wDevID, UINT16 wMsg, DWORD dwParam1,
+                            DWORD dwParam2)
 {
     HDRVR16 hDrv = 0;
     dprintf_mci(stddeb, "mciSendCommand(%04X, %s, %08lX, %08lX)\n", 
@@ -977,7 +978,7 @@
 /**************************************************************************
 * 				mciGetDeviceID	       	[MMSYSTEM.703]
 */
-UINT16 mciGetDeviceID (LPCSTR lpstrName)
+UINT16 WINAPI mciGetDeviceID (LPCSTR lpstrName)
 {
     UINT16 wDevID;
 
@@ -1007,8 +1008,8 @@
 /**************************************************************************
 * 				mciSetYieldProc		[MMSYSTEM.714]
 */
-BOOL16 mciSetYieldProc (UINT16 uDeviceID, 
-		YIELDPROC fpYieldProc, DWORD dwYieldData)
+BOOL16 WINAPI mciSetYieldProc (UINT16 uDeviceID, 
+                               YIELDPROC fpYieldProc, DWORD dwYieldData)
 {
     return FALSE;
 }
@@ -1016,7 +1017,7 @@
 /**************************************************************************
 * 				mciGetDeviceIDFromElementID	[MMSYSTEM.715]
 */
-UINT16 mciGetDeviceIDFromElementID(DWORD dwElementID, LPCSTR lpstrType)
+UINT16 WINAPI mciGetDeviceIDFromElementID(DWORD dwElementID, LPCSTR lpstrType)
 {
     return 0;
 }
@@ -1024,7 +1025,7 @@
 /**************************************************************************
 * 				mciGetYieldProc		[MMSYSTEM.716]
 */
-YIELDPROC mciGetYieldProc(UINT16 uDeviceID, DWORD * lpdwYieldData)
+YIELDPROC WINAPI mciGetYieldProc(UINT16 uDeviceID, DWORD * lpdwYieldData)
 {
     return NULL;
 }
@@ -1032,7 +1033,7 @@
 /**************************************************************************
 * 				mciGetCreatorTask	[MMSYSTEM.717]
 */
-HTASK16 mciGetCreatorTask(UINT16 uDeviceID)
+HTASK16 WINAPI mciGetCreatorTask(UINT16 uDeviceID)
 {
     return 0;
 }
@@ -1040,7 +1041,7 @@
 /**************************************************************************
 * 				midiOutGetNumDevs	[MMSYSTEM.201]
 */
-UINT16 midiOutGetNumDevs(void)
+UINT16 WINAPI midiOutGetNumDevs(void)
 {
 	UINT16	count = 0;
 	dprintf_mmsys(stddeb, "midiOutGetNumDevs\n");
@@ -1052,7 +1053,7 @@
 /**************************************************************************
 * 				midiOutGetDevCaps	[MMSYSTEM.202]
 */
-UINT16 midiOutGetDevCaps(UINT16 uDeviceID, MIDIOUTCAPS * lpCaps, UINT16 uSize)
+UINT16 WINAPI midiOutGetDevCaps(UINT16 uDeviceID, MIDIOUTCAPS * lpCaps, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "midiOutGetDevCaps\n");
 	return modMessage(uDeviceID,MODM_GETDEVCAPS,0,(DWORD)lpCaps,uSize);
@@ -1061,7 +1062,7 @@
 /**************************************************************************
 * 				midiOutGetErrorText 	[MMSYSTEM.203]
 */
-UINT16 midiOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
+UINT16 WINAPI midiOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "midiOutGetErrorText\n");
 	return midiGetErrorText(uError, lpText, uSize);
@@ -1071,7 +1072,7 @@
 /**************************************************************************
 * 				midiGetErrorText       	[internal]
 */
-UINT16 midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
+UINT16 WINAPI midiGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
 {
 	LPSTR	msgptr;
 	if ((lpText == NULL) || (uSize < 1)) return(FALSE);
@@ -1116,8 +1117,8 @@
 /**************************************************************************
 * 				midiOutOpen    		[MMSYSTEM.204]
 */
-UINT16 midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT16 uDeviceID,
-		 DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
+UINT16 WINAPI midiOutOpen(HMIDIOUT16 * lphMidiOut, UINT16 uDeviceID,
+                          DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HMIDI16	hMidiOut;
 	LPMIDIOPENDESC	lpDesc;
@@ -1154,7 +1155,7 @@
 /**************************************************************************
 * 				midiOutClose		[MMSYSTEM.205]
 */
-UINT16 midiOutClose(HMIDIOUT16 hMidiOut)
+UINT16 WINAPI midiOutClose(HMIDIOUT16 hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutClose(%04X)\n", hMidiOut);
@@ -1166,8 +1167,8 @@
 /**************************************************************************
 * 				midiOutPrepareHeader	[MMSYSTEM.206]
 */
-UINT16 midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
-    MIDIHDR * lpMidiOutHdr, UINT16 uSize)
+UINT16 WINAPI midiOutPrepareHeader(HMIDIOUT16 hMidiOut,
+                                   MIDIHDR * lpMidiOutHdr, UINT16 uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutPrepareHeader(%04X, %p, %d)\n", 
@@ -1181,8 +1182,8 @@
 /**************************************************************************
 * 				midiOutUnprepareHeader	[MMSYSTEM.207]
 */
-UINT16 midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
-    MIDIHDR * lpMidiOutHdr, UINT16 uSize)
+UINT16 WINAPI midiOutUnprepareHeader(HMIDIOUT16 hMidiOut,
+                                     MIDIHDR * lpMidiOutHdr, UINT16 uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutUnprepareHeader(%04X, %p, %d)\n", 
@@ -1196,7 +1197,7 @@
 /**************************************************************************
 * 				midiOutShortMsg		[MMSYSTEM.208]
 */
-UINT16 midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg)
+UINT16 WINAPI midiOutShortMsg(HMIDIOUT16 hMidiOut, DWORD dwMsg)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutShortMsg(%04X, %08lX)\n", hMidiOut, dwMsg);
@@ -1208,8 +1209,8 @@
 /**************************************************************************
 * 				midiOutLongMsg		[MMSYSTEM.209]
 */
-UINT16 midiOutLongMsg(HMIDIOUT16 hMidiOut,
-    MIDIHDR * lpMidiOutHdr, UINT16 uSize)
+UINT16 WINAPI midiOutLongMsg(HMIDIOUT16 hMidiOut,
+                             MIDIHDR * lpMidiOutHdr, UINT16 uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutLongMsg(%04X, %p, %d)\n", 
@@ -1223,7 +1224,7 @@
 /**************************************************************************
 * 				midiOutReset		[MMSYSTEM.210]
 */
-UINT16 midiOutReset(HMIDIOUT16 hMidiOut)
+UINT16 WINAPI midiOutReset(HMIDIOUT16 hMidiOut)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutReset(%04X)\n", hMidiOut);
@@ -1235,7 +1236,7 @@
 /**************************************************************************
 * 				midiOutGetVolume	[MMSYSTEM.211]
 */
-UINT16 midiOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
+UINT16 WINAPI midiOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
 {
 	dprintf_mmsys(stddeb, "midiOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
 	return modMessage(uDeviceID, MODM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
@@ -1245,7 +1246,7 @@
 /**************************************************************************
 * 				midiOutSetVolume	[MMSYSTEM.212]
 */
-UINT16 midiOutSetVolume(UINT16 uDeviceID, DWORD dwVolume)
+UINT16 WINAPI midiOutSetVolume(UINT16 uDeviceID, DWORD dwVolume)
 {
 	dprintf_mmsys(stddeb, "midiOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
 	return modMessage(uDeviceID, MODM_SETVOLUME, 0L, dwVolume, 0L);
@@ -1255,8 +1256,8 @@
 /**************************************************************************
 * 				midiOutCachePatches		[MMSYSTEM.213]
 */
-UINT16 midiOutCachePatches(HMIDIOUT16 hMidiOut,
-    UINT16 uBank, WORD * lpwPatchArray, UINT16 uFlags)
+UINT16 WINAPI midiOutCachePatches(HMIDIOUT16 hMidiOut, UINT16 uBank,
+                                  WORD * lpwPatchArray, UINT16 uFlags)
 {
         /* not really necessary to support this */
 	fprintf(stdnimp, "midiOutCachePatches: not supported yet\n");
@@ -1266,8 +1267,8 @@
 /**************************************************************************
 * 				midiOutCacheDrumPatches	[MMSYSTEM.214]
 */
-UINT16 midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut,
-    UINT16 uPatch, WORD * lpwKeyArray, UINT16 uFlags)
+UINT16 WINAPI midiOutCacheDrumPatches(HMIDIOUT16 hMidiOut, UINT16 uPatch,
+                                      WORD * lpwKeyArray, UINT16 uFlags)
 {
 	fprintf(stdnimp, "midiOutCacheDrumPatchesi: not supported yet\n");
 	return MMSYSERR_NOTSUPPORTED;
@@ -1276,7 +1277,7 @@
 /**************************************************************************
 * 				midiOutGetID		[MMSYSTEM.215]
 */
-UINT16 midiOutGetID(HMIDIOUT16 hMidiOut, UINT16 * lpuDeviceID)
+UINT16 WINAPI midiOutGetID(HMIDIOUT16 hMidiOut, UINT16 * lpuDeviceID)
 {
 	dprintf_mmsys(stddeb, "midiOutGetID\n");
 	return 0;
@@ -1285,8 +1286,8 @@
 /**************************************************************************
 * 				midiOutMessage		[MMSYSTEM.216]
 */
-DWORD midiOutMessage(HMIDIOUT16 hMidiOut, UINT16 uMessage, 
-						DWORD dwParam1, DWORD dwParam2)
+DWORD WINAPI midiOutMessage(HMIDIOUT16 hMidiOut, UINT16 uMessage, 
+                            DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiOutMessage(%04X, %04X, %08lX, %08lX)\n", 
@@ -1300,7 +1301,7 @@
 /**************************************************************************
 * 				midiInGetNumDevs	[MMSYSTEM.301]
 */
-UINT16 midiInGetNumDevs(void)
+UINT16 WINAPI midiInGetNumDevs(void)
 {
 	UINT16	count = 0;
 	dprintf_mmsys(stddeb, "midiInGetNumDevs\n");
@@ -1312,8 +1313,8 @@
 /**************************************************************************
 * 				midiInGetDevCaps	[MMSYSTEM.302]
 */
-UINT16 midiInGetDevCaps(UINT16 uDeviceID,
-    LPMIDIINCAPS lpCaps, UINT16 uSize)
+UINT16 WINAPI midiInGetDevCaps(UINT16 uDeviceID,
+                               LPMIDIINCAPS lpCaps, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "midiInGetDevCaps\n");
 	return midMessage(uDeviceID,MIDM_GETDEVCAPS,0,(DWORD)lpCaps,uSize);;
@@ -1322,7 +1323,7 @@
 /**************************************************************************
 * 				midiInGetErrorText 		[MMSYSTEM.303]
 */
-UINT16 midiInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
+UINT16 WINAPI midiInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "midiInGetErrorText\n");
 	return (midiGetErrorText(uError, lpText, uSize));
@@ -1331,8 +1332,8 @@
 /**************************************************************************
 * 				midiInOpen		[MMSYSTEM.304]
 */
-UINT16 midiInOpen(HMIDIIN16 * lphMidiIn, UINT16 uDeviceID,
-    DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
+UINT16 WINAPI midiInOpen(HMIDIIN16 * lphMidiIn, UINT16 uDeviceID,
+                         DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
 {
 	HMIDI16	hMidiIn;
 	LPMIDIOPENDESC	lpDesc;
@@ -1369,7 +1370,7 @@
 /**************************************************************************
 * 				midiInClose		[MMSYSTEM.305]
 */
-UINT16 midiInClose(HMIDIIN16 hMidiIn)
+UINT16 WINAPI midiInClose(HMIDIIN16 hMidiIn)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiInClose(%04X)\n", hMidiIn);
@@ -1381,8 +1382,8 @@
 /**************************************************************************
 * 				midiInPrepareHeader	[MMSYSTEM.306]
 */
-UINT16 midiInPrepareHeader(HMIDIIN16 hMidiIn,
-    MIDIHDR * lpMidiInHdr, UINT16 uSize)
+UINT16 WINAPI midiInPrepareHeader(HMIDIIN16 hMidiIn,
+                                  MIDIHDR * lpMidiInHdr, UINT16 uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiInPrepareHeader(%04X, %p, %d)\n", 
@@ -1396,8 +1397,8 @@
 /**************************************************************************
 * 				midiInUnprepareHeader	[MMSYSTEM.307]
 */
-UINT16 midiInUnprepareHeader(HMIDIIN16 hMidiIn,
-    MIDIHDR * lpMidiInHdr, UINT16 uSize)
+UINT16 WINAPI midiInUnprepareHeader(HMIDIIN16 hMidiIn,
+                                    MIDIHDR * lpMidiInHdr, UINT16 uSize)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiInUnprepareHeader(%04X, %p, %d)\n", 
@@ -1411,8 +1412,8 @@
 /**************************************************************************
 * 				midiInAddBuffer		[MMSYSTEM.308]
 */
-UINT16 midiInAddBuffer(HMIDIIN16 hMidiIn,
-    MIDIHDR * lpMidiInHdr, UINT16 uSize)
+UINT16 WINAPI midiInAddBuffer(HMIDIIN16 hMidiIn,
+                              MIDIHDR * lpMidiInHdr, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "midiInAddBuffer\n");
 	return 0;
@@ -1421,7 +1422,7 @@
 /**************************************************************************
 * 				midiInStart			[MMSYSTEM.309]
 */
-UINT16 midiInStart(HMIDIIN16 hMidiIn)
+UINT16 WINAPI midiInStart(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInStart\n");
 	return 0;
@@ -1430,7 +1431,7 @@
 /**************************************************************************
 * 				midiInStop			[MMSYSTEM.310]
 */
-UINT16 midiInStop(HMIDIIN16 hMidiIn)
+UINT16 WINAPI midiInStop(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInStop\n");
 	return 0;
@@ -1439,7 +1440,7 @@
 /**************************************************************************
 * 				midiInReset			[MMSYSTEM.311]
 */
-UINT16 midiInReset(HMIDIIN16 hMidiIn)
+UINT16 WINAPI midiInReset(HMIDIIN16 hMidiIn)
 {
 	dprintf_mmsys(stddeb, "midiInReset\n");
 	return 0;
@@ -1448,7 +1449,7 @@
 /**************************************************************************
 * 				midiInGetID			[MMSYSTEM.312]
 */
-UINT16 midiInGetID(HMIDIIN16 hMidiIn, UINT16 * lpuDeviceID)
+UINT16 WINAPI midiInGetID(HMIDIIN16 hMidiIn, UINT16 * lpuDeviceID)
 {
 	dprintf_mmsys(stddeb, "midiInGetID\n");
 	return 0;
@@ -1457,8 +1458,8 @@
 /**************************************************************************
 * 				midiInMessage		[MMSYSTEM.313]
 */
-DWORD midiInMessage(HMIDIIN16 hMidiIn, UINT16 uMessage, 
-							DWORD dwParam1, DWORD dwParam2)
+DWORD WINAPI midiInMessage(HMIDIIN16 hMidiIn, UINT16 uMessage, 
+                           DWORD dwParam1, DWORD dwParam2)
 {
 	LPMIDIOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "midiInMessage(%04X, %04X, %08lX, %08lX)\n", 
@@ -1472,7 +1473,7 @@
 /**************************************************************************
 * 				waveOutGetNumDevs		[MMSYSTEM.401]
 */
-UINT16 waveOutGetNumDevs()
+UINT16 WINAPI waveOutGetNumDevs()
 {
 	UINT16	count = 0;
 	dprintf_mmsys(stddeb, "waveOutGetNumDevs\n");
@@ -1484,7 +1485,8 @@
 /**************************************************************************
 * 				waveOutGetDevCaps		[MMSYSTEM.402]
 */
-UINT16 waveOutGetDevCaps(UINT16 uDeviceID, WAVEOUTCAPS * lpCaps, UINT16 uSize)
+UINT16 WINAPI waveOutGetDevCaps(UINT16 uDeviceID, WAVEOUTCAPS * lpCaps,
+                                UINT16 uSize)
 {
 	if (uDeviceID > waveOutGetNumDevs() - 1) return MMSYSERR_BADDEVICEID;
 	if (uDeviceID == (UINT16)WAVE_MAPPER) return MMSYSERR_BADDEVICEID; /* FIXME: do we have a wave mapper ? */
@@ -1495,7 +1497,7 @@
 /**************************************************************************
 * 				waveOutGetErrorText 	[MMSYSTEM.403]
 */
-UINT16 waveOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
+UINT16 WINAPI waveOutGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
 {
    dprintf_mmsys(stddeb, "waveOutGetErrorText\n");
    return(waveGetErrorText(uError, lpText, uSize));
@@ -1571,8 +1573,9 @@
 /**************************************************************************
 * 				waveOutOpen			[MMSYSTEM.404]
 */
-UINT16 waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT16 uDeviceID,
-    const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
+UINT16 WINAPI waveOutOpen(HWAVEOUT16 * lphWaveOut, UINT16 uDeviceID,
+                          const LPWAVEFORMAT lpFormat, DWORD dwCallback,
+                          DWORD dwInstance, DWORD dwFlags)
 {
 	HWAVEOUT16 hWaveOut;
 	LPWAVEOPENDESC	lpDesc;
@@ -1621,7 +1624,7 @@
 /**************************************************************************
 * 				waveOutClose		[MMSYSTEM.405]
 */
-UINT16 waveOutClose(HWAVEOUT16 hWaveOut)
+UINT16 WINAPI waveOutClose(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1634,8 +1637,8 @@
 /**************************************************************************
 * 				waveOutPrepareHeader	[MMSYSTEM.406]
 */
-UINT16 waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
-     WAVEHDR * lpWaveOutHdr, UINT16 uSize)
+UINT16 WINAPI waveOutPrepareHeader(HWAVEOUT16 hWaveOut,
+                                   WAVEHDR * lpWaveOutHdr, UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1650,8 +1653,8 @@
 /**************************************************************************
 * 				waveOutUnprepareHeader	[MMSYSTEM.407]
 */
-UINT16 waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
-    WAVEHDR * lpWaveOutHdr, UINT16 uSize)
+UINT16 WINAPI waveOutUnprepareHeader(HWAVEOUT16 hWaveOut,
+                                     WAVEHDR * lpWaveOutHdr, UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1666,7 +1669,8 @@
 /**************************************************************************
 * 				waveOutWrite		[MMSYSTEM.408]
 */
-UINT16 waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,  UINT16 uSize)
+UINT16 WINAPI waveOutWrite(HWAVEOUT16 hWaveOut, WAVEHDR * lpWaveOutHdr,
+                           UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1680,7 +1684,7 @@
 /**************************************************************************
 * 				waveOutPause		[MMSYSTEM.409]
 */
-UINT16 waveOutPause(HWAVEOUT16 hWaveOut)
+UINT16 WINAPI waveOutPause(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1693,7 +1697,7 @@
 /**************************************************************************
 * 				waveOutRestart		[MMSYSTEM.410]
 */
-UINT16 waveOutRestart(HWAVEOUT16 hWaveOut)
+UINT16 WINAPI waveOutRestart(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1706,7 +1710,7 @@
 /**************************************************************************
 * 				waveOutReset		[MMSYSTEM.411]
 */
-UINT16 waveOutReset(HWAVEOUT16 hWaveOut)
+UINT16 WINAPI waveOutReset(HWAVEOUT16 hWaveOut)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutReset(%04X)\n", hWaveOut);
@@ -1718,7 +1722,8 @@
 /**************************************************************************
 * 				waveOutGetPosition	[MMSYSTEM.412]
 */
-UINT16 waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpTime, UINT16 uSize)
+UINT16 WINAPI waveOutGetPosition(HWAVEOUT16 hWaveOut, MMTIME * lpTime,
+                                 UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPosition(%04X, %p, %u);\n", hWaveOut, lpTime, uSize);
@@ -1731,7 +1736,7 @@
 /**************************************************************************
 * 				waveOutGetPitch		[MMSYSTEM.413]
 */
-UINT16 waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch)
+UINT16 WINAPI waveOutGetPitch(HWAVEOUT16 hWaveOut, DWORD * lpdwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPitch(%04X, %p);\n", hWaveOut, lpdwPitch);
@@ -1744,7 +1749,7 @@
 /**************************************************************************
 * 				waveOutSetPitch		[MMSYSTEM.414]
 */
-UINT16 waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch)
+UINT16 WINAPI waveOutSetPitch(HWAVEOUT16 hWaveOut, DWORD dwPitch)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutSetPitch(%04X, %08lX);\n", hWaveOut, dwPitch);
@@ -1756,7 +1761,7 @@
 /**************************************************************************
 * 				waveOutGetVolume	[MMSYSTEM.415]
 */
-UINT16 waveOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
+UINT16 WINAPI waveOutGetVolume(UINT16 uDeviceID, DWORD * lpdwVolume)
 {
 	dprintf_mmsys(stddeb, "waveOutGetVolume(%04X, %p);\n", uDeviceID, lpdwVolume);
 	return wodMessage(uDeviceID, WODM_GETVOLUME, 0L, (DWORD)lpdwVolume, 0L);
@@ -1765,7 +1770,7 @@
 /**************************************************************************
 * 				waveOutSetVolume	[MMSYSTEM.416]
 */
-UINT16 waveOutSetVolume(UINT16 uDeviceID, DWORD dwVolume)
+UINT16 WINAPI waveOutSetVolume(UINT16 uDeviceID, DWORD dwVolume)
 {
 	dprintf_mmsys(stddeb, "waveOutSetVolume(%04X, %08lX);\n", uDeviceID, dwVolume);
 	return wodMessage(uDeviceID, WODM_SETVOLUME, 0L, dwVolume, 0L);
@@ -1774,7 +1779,7 @@
 /**************************************************************************
 * 				waveOutGetPlaybackRate	[MMSYSTEM.417]
 */
-UINT16 waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate)
+UINT16 WINAPI waveOutGetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD * lpdwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetPlaybackRate(%04X, %p);\n", hWaveOut, lpdwRate);
@@ -1787,7 +1792,7 @@
 /**************************************************************************
 * 				waveOutSetPlaybackRate	[MMSYSTEM.418]
 */
-UINT16 waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate)
+UINT16 WINAPI waveOutSetPlaybackRate(HWAVEOUT16 hWaveOut, DWORD dwRate)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutSetPlaybackRate(%04X, %08lX);\n", hWaveOut, dwRate);
@@ -1800,7 +1805,7 @@
 /**************************************************************************
 * 				waveOutBreakLoop 	[MMSYSTEM.419]
 */
-UINT16 waveOutBreakLoop(HWAVEOUT16 hWaveOut)
+UINT16 WINAPI waveOutBreakLoop(HWAVEOUT16 hWaveOut)
 {
 	dprintf_mmsys(stddeb, "waveOutBreakLoop(%04X)\n", hWaveOut);
 	return MMSYSERR_INVALHANDLE;
@@ -1809,7 +1814,7 @@
 /**************************************************************************
 * 				waveOutGetID	 	[MMSYSTEM.420]
 */
-UINT16 waveOutGetID(HWAVEOUT16 hWaveOut, UINT16 * lpuDeviceID)
+UINT16 WINAPI waveOutGetID(HWAVEOUT16 hWaveOut, UINT16 * lpuDeviceID)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutGetID(%04X, %p);\n", hWaveOut, lpuDeviceID);
@@ -1823,8 +1828,8 @@
 /**************************************************************************
 * 				waveOutMessage 		[MMSYSTEM.421]
 */
-DWORD waveOutMessage(HWAVEOUT16 hWaveOut, UINT16 uMessage, 
-							DWORD dwParam1, DWORD dwParam2)
+DWORD WINAPI waveOutMessage(HWAVEOUT16 hWaveOut, UINT16 uMessage, 
+                            DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
 	dprintf_mmsys(stddeb, "waveOutMessage(%04X, %04X, %08lX, %08lX)\n", 
@@ -1837,7 +1842,7 @@
 /**************************************************************************
 * 				waveInGetNumDevs 		[MMSYSTEM.501]
 */
-UINT16 waveInGetNumDevs()
+UINT16 WINAPI waveInGetNumDevs()
 {
 	UINT16	count = 0;
 	dprintf_mmsys(stddeb, "waveInGetNumDevs\n");
@@ -1850,7 +1855,7 @@
 /**************************************************************************
 * 				waveInGetDevCaps 		[MMSYSTEM.502]
 */
-UINT16 waveInGetDevCaps(UINT16 uDeviceID, WAVEINCAPS * lpCaps, UINT16 uSize)
+UINT16 WINAPI waveInGetDevCaps(UINT16 uDeviceID, WAVEINCAPS * lpCaps, UINT16 uSize)
 {
 	dprintf_mmsys(stddeb, "waveInGetDevCaps\n");
 	return widMessage(uDeviceID, WIDM_GETDEVCAPS, 0L, (DWORD)lpCaps, uSize);
@@ -1860,7 +1865,7 @@
 /**************************************************************************
 * 				waveInGetErrorText 	[MMSYSTEM.503]
 */
-UINT16 waveInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
+UINT16 WINAPI waveInGetErrorText(UINT16 uError, LPSTR lpText, UINT16 uSize)
 {
    dprintf_mmsys(stddeb, "waveInGetErrorText\n");
    return(waveGetErrorText(uError, lpText, uSize));
@@ -1870,8 +1875,9 @@
 /**************************************************************************
 * 				waveInOpen			[MMSYSTEM.504]
 */
-UINT16 waveInOpen(HWAVEIN16 * lphWaveIn, UINT16 uDeviceID,
-    const LPWAVEFORMAT lpFormat, DWORD dwCallback, DWORD dwInstance, DWORD dwFlags)
+UINT16 WINAPI waveInOpen(HWAVEIN16 * lphWaveIn, UINT16 uDeviceID,
+                         const LPWAVEFORMAT lpFormat, DWORD dwCallback,
+                         DWORD dwInstance, DWORD dwFlags)
 {
 	HWAVEIN16 hWaveIn;
 	LPWAVEOPENDESC	lpDesc;
@@ -1918,7 +1924,7 @@
 /**************************************************************************
 * 				waveInClose			[MMSYSTEM.505]
 */
-UINT16 waveInClose(HWAVEIN16 hWaveIn)
+UINT16 WINAPI waveInClose(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -1932,8 +1938,8 @@
 /**************************************************************************
 * 				waveInPrepareHeader		[MMSYSTEM.506]
 */
-UINT16 waveInPrepareHeader(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize)
+UINT16 WINAPI waveInPrepareHeader(HWAVEIN16 hWaveIn,
+                                  WAVEHDR * lpWaveInHdr, UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
@@ -1956,8 +1962,8 @@
 /**************************************************************************
 * 				waveInUnprepareHeader	[MMSYSTEM.507]
 */
-UINT16 waveInUnprepareHeader(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize)
+UINT16 WINAPI waveInUnprepareHeader(HWAVEIN16 hWaveIn,
+                                    WAVEHDR * lpWaveInHdr, UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
@@ -1979,8 +1985,8 @@
 /**************************************************************************
 * 				waveInAddBuffer		[MMSYSTEM.508]
 */
-UINT16 waveInAddBuffer(HWAVEIN16 hWaveIn,
-    WAVEHDR * lpWaveInHdr, UINT16 uSize)
+UINT16 WINAPI waveInAddBuffer(HWAVEIN16 hWaveIn,
+                              WAVEHDR * lpWaveInHdr, UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 	LPWAVEHDR 		lp32WaveInHdr;
@@ -2002,7 +2008,7 @@
 /**************************************************************************
 * 				waveInStart			[MMSYSTEM.509]
 */
-UINT16 waveInStart(HWAVEIN16 hWaveIn)
+UINT16 WINAPI waveInStart(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2016,7 +2022,7 @@
 /**************************************************************************
 * 				waveInStop			[MMSYSTEM.510]
 */
-UINT16 waveInStop(HWAVEIN16 hWaveIn)
+UINT16 WINAPI waveInStop(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2030,7 +2036,7 @@
 /**************************************************************************
 * 				waveInReset			[MMSYSTEM.511]
 */
-UINT16 waveInReset(HWAVEIN16 hWaveIn)
+UINT16 WINAPI waveInReset(HWAVEIN16 hWaveIn)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2044,7 +2050,8 @@
 /**************************************************************************
 * 				waveInGetPosition	[MMSYSTEM.512]
 */
-UINT16 waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpTime, UINT16 uSize)
+UINT16 WINAPI waveInGetPosition(HWAVEIN16 hWaveIn, MMTIME * lpTime,
+                                UINT16 uSize)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2059,7 +2066,7 @@
 /**************************************************************************
 * 				waveInGetID			[MMSYSTEM.513]
 */
-UINT16 waveInGetID(HWAVEIN16 hWaveIn, UINT16 * lpuDeviceID)
+UINT16 WINAPI waveInGetID(HWAVEIN16 hWaveIn, UINT16 * lpuDeviceID)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2075,8 +2082,8 @@
 /**************************************************************************
 * 				waveInMessage 		[MMSYSTEM.514]
 */
-DWORD waveInMessage(HWAVEIN16 hWaveIn, UINT16 uMessage,
-		    DWORD dwParam1, DWORD dwParam2)
+DWORD WINAPI waveInMessage(HWAVEIN16 hWaveIn, UINT16 uMessage,
+                           DWORD dwParam1, DWORD dwParam2)
 {
 	LPWAVEOPENDESC	lpDesc;
 
@@ -2091,7 +2098,8 @@
 /**************************************************************************
 * 				mmioOpen       		[MMSYSTEM.1210]
 */
-HMMIO16 mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo, DWORD dwOpenFlags)
+HMMIO16 WINAPI mmioOpen(LPSTR szFileName, MMIOINFO * lpmmioinfo,
+                        DWORD dwOpenFlags)
 {
         HFILE32 hFile;
 	HMMIO16		hmmio;
@@ -2121,7 +2129,7 @@
 /**************************************************************************
 * 				mmioClose      		[MMSYSTEM.1211]
 */
-UINT16 mmioClose(HMMIO16 hmmio, UINT16 uFlags)
+UINT16 WINAPI mmioClose(HMMIO16 hmmio, UINT16 uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmio(stddeb, "mmioClose(%04X, %04X);\n", hmmio, uFlags);
@@ -2138,7 +2146,7 @@
 /**************************************************************************
 * 				mmioRead	       	[MMSYSTEM.1212]
 */
-LONG mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch)
+LONG WINAPI mmioRead(HMMIO16 hmmio, HPSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
@@ -2156,7 +2164,7 @@
 /**************************************************************************
 * 				mmioWrite      		[MMSYSTEM.1213]
 */
-LONG mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch)
+LONG WINAPI mmioWrite(HMMIO16 hmmio, HPCSTR pch, LONG cch)
 {
 	LONG		count;
 	LPMMIOINFO	lpmminfo;
@@ -2171,7 +2179,7 @@
 /**************************************************************************
 * 				mmioSeek       		[MMSYSTEM.1214]
 */
-LONG mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin)
+LONG WINAPI mmioSeek(HMMIO16 hmmio, LONG lOffset, int iOrigin)
 {
 	int		count;
 	LPMMIOINFO	lpmminfo;
@@ -2189,7 +2197,7 @@
 /**************************************************************************
 * 				mmioGetInfo	       	[MMSYSTEM.1215]
 */
-UINT16 mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags)
+UINT16 WINAPI mmioGetInfo(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmio(stddeb, "mmioGetInfo\n");
@@ -2203,7 +2211,7 @@
 /**************************************************************************
 * 				mmioSetInfo    		[MMSYSTEM.1216]
 */
-UINT16 mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT16 uFlags)
+UINT16 WINAPI mmioSetInfo(HMMIO16 hmmio, const MMIOINFO * lpmmioinfo, UINT16 uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmio(stddeb, "mmioSetInfo\n");
@@ -2216,8 +2224,8 @@
 /**************************************************************************
 * 				mmioSetBuffer		[MMSYSTEM.1217]
 */
-UINT16 mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, 
-						LONG cchBuffer, UINT16 uFlags)
+UINT16 WINAPI mmioSetBuffer(HMMIO16 hmmio, LPSTR pchBuffer, 
+                            LONG cchBuffer, UINT16 uFlags)
 {
 	dprintf_mmio(stddeb, "mmioSetBuffer // empty stub \n");
 	return 0;
@@ -2226,7 +2234,7 @@
 /**************************************************************************
 * 				mmioFlush      		[MMSYSTEM.1218]
 */
-UINT16 mmioFlush(HMMIO16 hmmio, UINT16 uFlags)
+UINT16 WINAPI mmioFlush(HMMIO16 hmmio, UINT16 uFlags)
 {
 	LPMMIOINFO	lpmminfo;
 	dprintf_mmio(stddeb, "mmioFlush(%04X, %04X)\n", hmmio, uFlags);
@@ -2239,7 +2247,7 @@
 /**************************************************************************
 * 				mmioAdvance    		[MMSYSTEM.1219]
 */
-UINT16 mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags)
+UINT16 WINAPI mmioAdvance(HMMIO16 hmmio, MMIOINFO * lpmmioinfo, UINT16 uFlags)
 {
 	int		count = 0;
 	LPMMIOINFO	lpmminfo;
@@ -2263,7 +2271,7 @@
 /**************************************************************************
 * 				mmioStringToFOURCC	[MMSYSTEM.1220]
 */
-FOURCC mmioStringToFOURCC(LPCSTR sz, UINT16 uFlags)
+FOURCC WINAPI mmioStringToFOURCC(LPCSTR sz, UINT16 uFlags)
 {
 	dprintf_mmio(stddeb, "mmioStringToFOURCC // empty stub \n");
 	return 0;
@@ -2272,8 +2280,8 @@
 /**************************************************************************
 * 				mmioInstallIOProc	[MMSYSTEM.1221]
 */
-LPMMIOPROC mmioInstallIOProc(FOURCC fccIOProc, 
-				LPMMIOPROC pIOProc, DWORD dwFlags)
+LPMMIOPROC WINAPI mmioInstallIOProc(FOURCC fccIOProc, 
+                                    LPMMIOPROC pIOProc, DWORD dwFlags)
 {
 	dprintf_mmio(stddeb, "mmioInstallIOProc // empty stub \n");
 	return 0;
@@ -2282,8 +2290,8 @@
 /**************************************************************************
 * 				mmioSendMessage		[MMSYSTEM.1222]
 */
-LRESULT mmioSendMessage(HMMIO16 hmmio, UINT16 uMessage,
-					    LPARAM lParam1, LPARAM lParam2)
+LRESULT WINAPI mmioSendMessage(HMMIO16 hmmio, UINT16 uMessage,
+                               LPARAM lParam1, LPARAM lParam2)
 {
 	dprintf_mmio(stddeb, "mmioSendMessage // empty stub \n");
 	return 0;
@@ -2292,8 +2300,8 @@
 /**************************************************************************
 * 				mmioDescend	       	[MMSYSTEM.1223]
 */
-UINT16 mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
-		    const MMCKINFO * lpckParent, UINT16 uFlags)
+UINT16 WINAPI mmioDescend(HMMIO16 hmmio, MMCKINFO * lpck,
+                          const MMCKINFO * lpckParent, UINT16 uFlags)
 {
 	DWORD	dwfcc, dwOldPos;
 	LPMMIOINFO	lpmminfo;
@@ -2367,7 +2375,7 @@
 /**************************************************************************
 * 				mmioAscend     		[MMSYSTEM.1224]
 */
-UINT16 mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
+UINT16 WINAPI mmioAscend(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
 {
 	dprintf_mmio(stddeb, "mmioAscend // empty stub !\n");
 	return 0;
@@ -2376,7 +2384,7 @@
 /**************************************************************************
 * 				mmioCreateChunk		[MMSYSTEM.1225]
 */
-UINT16 mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
+UINT16 WINAPI mmioCreateChunk(HMMIO16 hmmio, MMCKINFO * lpck, UINT16 uFlags)
 {
 	dprintf_mmio(stddeb, "mmioCreateChunk // empty stub \n");
 	return 0;
@@ -2386,8 +2394,8 @@
 /**************************************************************************
 * 				mmioRename     		[MMSYSTEM.1226]
 */
-UINT16 mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
-     MMIOINFO * lpmmioinfo, DWORD dwRenameFlags)
+UINT16 WINAPI mmioRename(LPCSTR szFileName, LPCSTR szNewFileName,
+                         MMIOINFO * lpmmioinfo, DWORD dwRenameFlags)
 {
 	dprintf_mmio(stddeb, "mmioRename('%s', '%s', %p, %08lX); // empty stub \n",
 			szFileName, szNewFileName, lpmmioinfo, dwRenameFlags);
@@ -2397,7 +2405,7 @@
 /**************************************************************************
 * 				DrvOpen	       		[MMSYSTEM.1100]
 */
-HDRVR16 DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
+HDRVR16 WINAPI DrvOpen(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
 {
 	dprintf_mmsys(stddeb, "DrvOpen('%s', '%s', %08lX);\n",
 		lpDriverName, lpSectionName, lParam);
@@ -2408,7 +2416,7 @@
 /**************************************************************************
 * 				DrvClose       		[MMSYSTEM.1101]
 */
-LRESULT DrvClose(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
+LRESULT WINAPI DrvClose(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
 {
 	dprintf_mmsys(stddeb, "DrvClose(%04X, %08lX, %08lX);\n", hDrvr, lParam1, lParam2);
 	return CloseDriver(hDrvr, lParam1, lParam2);
@@ -2418,7 +2426,8 @@
 /**************************************************************************
 * 				DrvSendMessage		[MMSYSTEM.1102]
 */
-LRESULT DrvSendMessage(HDRVR16 hDriver, WORD msg, LPARAM lParam1, LPARAM lParam2)
+LRESULT WINAPI DrvSendMessage(HDRVR16 hDriver, WORD msg, LPARAM lParam1,
+                              LPARAM lParam2)
 {
 	DWORD 	dwDriverID = 0;
 	dprintf_mmsys(stddeb, "DrvSendMessage(%04X, %04X, %08lX, %08lX);\n",
@@ -2429,7 +2438,7 @@
 /**************************************************************************
 * 				DrvGetModuleHandle	[MMSYSTEM.1103]
 */
-HANDLE16 DrvGetModuleHandle(HDRVR16 hDrvr)
+HANDLE16 WINAPI DrvGetModuleHandle(HDRVR16 hDrvr)
 {
 	dprintf_mmsys(stddeb, "DrvGetModuleHandle(%04X);\n", hDrvr);
         return 0;
@@ -2439,8 +2448,8 @@
 /**************************************************************************
 * 				DrvDefDriverProc	[MMSYSTEM.1104]
 */
-LRESULT DrvDefDriverProc(DWORD dwDriverID, HDRVR16 hDriv, WORD wMsg, 
-						DWORD dwParam1, DWORD dwParam2)
+LRESULT WINAPI DrvDefDriverProc(DWORD dwDriverID, HDRVR16 hDriv, WORD wMsg, 
+                                DWORD dwParam1, DWORD dwParam2)
 {
 	return DefDriverProc(dwDriverID, hDriv, wMsg, dwParam1, dwParam2);
 }
diff --git a/multimedia/time.c b/multimedia/time.c
index d8c5917..6242f85 100644
--- a/multimedia/time.c
+++ b/multimedia/time.c
@@ -114,7 +114,7 @@
 /**************************************************************************
  * 				timeGetSystemTime	[MMSYSTEM.601]
  */
-WORD timeGetSystemTime(LPMMTIME lpTime, WORD wSize)
+WORD WINAPI timeGetSystemTime(LPMMTIME lpTime, WORD wSize)
 {
     dprintf_mmsys(stddeb, "timeGetSystemTime(%p, %u);\n", lpTime, wSize);
     if (!mmTimeStarted)
@@ -127,8 +127,8 @@
 /**************************************************************************
  * 				timeSetEvent		[MMSYSTEM.602]
  */
-WORD timeSetEvent(WORD wDelay, WORD wResol, LPTIMECALLBACK lpFunc,
-		  DWORD dwUser, WORD wFlags)
+WORD WINAPI timeSetEvent(WORD wDelay, WORD wResol, LPTIMECALLBACK lpFunc,
+                         DWORD dwUser, WORD wFlags)
 {
     WORD wNewID = 0;
     LPTIMERENTRY lpNewTimer;
@@ -171,7 +171,7 @@
 /**************************************************************************
  * 				timeKillEvent		[MMSYSTEM.603]
  */
-WORD timeKillEvent(WORD wID)
+WORD WINAPI timeKillEvent(WORD wID)
 {
     LPTIMERENTRY lpTimer = lpTimerList;
     while (lpTimer != NULL) {
@@ -193,7 +193,7 @@
 /**************************************************************************
  * 				timeGetDevCaps		[MMSYSTEM.604]
  */
-WORD timeGetDevCaps(LPTIMECAPS lpCaps, WORD wSize)
+WORD WINAPI timeGetDevCaps(LPTIMECAPS lpCaps, WORD wSize)
 {
     dprintf_mmtime(stddeb, "timeGetDevCaps(%p, %u) !\n", lpCaps, wSize);
     if (!mmTimeStarted)
@@ -206,7 +206,7 @@
 /**************************************************************************
  * 				timeBeginPeriod		[MMSYSTEM.605]
  */
-WORD timeBeginPeriod(WORD wPeriod)
+WORD WINAPI timeBeginPeriod(WORD wPeriod)
 {
     dprintf_mmtime(stddeb, "timeBeginPeriod(%u) !\n", wPeriod);
     if (!mmTimeStarted)
@@ -219,7 +219,7 @@
 /**************************************************************************
  * 				timeEndPeriod		[MMSYSTEM.606]
  */
-WORD timeEndPeriod(WORD wPeriod)
+WORD WINAPI timeEndPeriod(WORD wPeriod)
 {
     dprintf_mmtime(stddeb, "timeEndPeriod(%u) !\n", wPeriod);
     if (wPeriod < MMSYSTIME_MININTERVAL || wPeriod > MMSYSTIME_MAXINTERVAL) 
@@ -230,7 +230,7 @@
 /**************************************************************************
  * 				timeGetTime    		[MMSYSTEM.607]
  */
-DWORD timeGetTime()
+DWORD WINAPI timeGetTime()
 {
     dprintf_mmtime(stddeb, "timeGetTime(); !\n");
     if (!mmTimeStarted)
diff --git a/objects/bitmap.c b/objects/bitmap.c
index fdb59d2..6fe7a98 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -30,10 +30,31 @@
 
 
 /***********************************************************************
+ *           XPutImage_wrapper
+ *
+ * Wrapper to call XPutImage with CALL_LARGE_STACK.
+ */
+
+struct XPutImage_descr
+{
+    BITMAPOBJ *bmp;
+    XImage    *image;
+    INT32      width;
+    INT32      height;
+};
+
+static int XPutImage_wrapper( const struct XPutImage_descr *descr )
+{
+    return XPutImage( display, descr->bmp->pixmap, BITMAP_GC(descr->bmp),
+                      descr->image, 0, 0, 0, 0, descr->width, descr->height );
+}
+
+
+/***********************************************************************
  *           CreateBitmap16    (GDI.48)
  */
-HBITMAP16 CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
-                          UINT16 bpp, LPCVOID bits )
+HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
+                                 UINT16 bpp, LPCVOID bits )
 {
     return CreateBitmap32( width, height, planes, bpp, bits );
 }
@@ -42,8 +63,8 @@
 /***********************************************************************
  *           CreateBitmap32    (GDI32.25)
  */
-HBITMAP32 CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
-                          UINT32 bpp, LPCVOID bits )
+HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
+                                 UINT32 bpp, LPCVOID bits )
 {
     BITMAPOBJ * bmpObjPtr;
     HBITMAP32 hbitmap;
@@ -63,7 +84,7 @@
       /* Create the BITMAPOBJ */
     hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
     if (!hbitmap) return 0;
-    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
+    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
 
     bmpObjPtr->size.cx = 0;
     bmpObjPtr->size.cy = 0;
@@ -85,6 +106,7 @@
     else if (bits)  /* Set bitmap bits */
 	SetBitmapBits32( hbitmap, height * bmpObjPtr->bitmap.bmWidthBytes,
                          bits );
+    GDI_HEAP_UNLOCK( hbitmap );
     return hbitmap;
 }
 
@@ -92,7 +114,7 @@
 /***********************************************************************
  *           CreateCompatibleBitmap16    (GDI.51)
  */
-HBITMAP16 CreateCompatibleBitmap16( HDC16 hdc, INT16 width, INT16 height )
+HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
 {
     return CreateCompatibleBitmap32( hdc, width, height );
 }
@@ -101,7 +123,7 @@
 /***********************************************************************
  *           CreateCompatibleBitmap32    (GDI32.30)
  */
-HBITMAP32 CreateCompatibleBitmap32( HDC32 hdc, INT32 width, INT32 height )
+HBITMAP32 WINAPI CreateCompatibleBitmap32(HDC32 hdc, INT32 width, INT32 height)
 {
     HBITMAP32 hbmpRet = 0;
     DC *dc;
@@ -118,7 +140,7 @@
 /***********************************************************************
  *           CreateBitmapIndirect16    (GDI.49)
  */
-HBITMAP16 CreateBitmapIndirect16( const BITMAP16 * bmp )
+HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
 {
     return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
                            bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
@@ -128,7 +150,7 @@
 /***********************************************************************
  *           CreateBitmapIndirect32    (GDI32.26)
  */
-HBITMAP32 CreateBitmapIndirect32( const BITMAP32 * bmp )
+HBITMAP32 WINAPI CreateBitmapIndirect32( const BITMAP32 * bmp )
 {
     return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
                            bmp->bmBitsPixel, bmp->bmBits );
@@ -136,9 +158,21 @@
 
 
 /***********************************************************************
+ *           BITMAP_GetXImage
+ *
+ * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
+ */
+XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp )
+{
+    return XGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
+                      bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
+}
+
+
+/***********************************************************************
  *           GetBitmapBits16    (GDI.74)
  */
-LONG GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
+LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
 {
     return GetBitmapBits32( hbitmap, count, buffer );
 }
@@ -147,12 +181,12 @@
 /***********************************************************************
  *           GetBitmapBits32    (GDI32.143)
  */
-LONG GetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPVOID buffer )
+LONG WINAPI GetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPVOID buffer )
 {
     BITMAPOBJ * bmp;
-    LONG height,widthbytes;
+    LONG height, old_height;
     XImage * image;
-    LPBYTE tmpbuffer,tbuf;
+    LPBYTE tbuf;
     int	h,w,pad;
     
     /* KLUDGE! */
@@ -169,7 +203,11 @@
     dprintf_bitmap(stddeb, "GetBitmapBits: %dx%d %d colors %p fetched height: %ld\n",
 	    bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
 	    1 << bmp->bitmap.bmBitsPixel, buffer, height );
-    if (!height) return 0;
+    if (!height) 
+    {
+      GDI_HEAP_UNLOCK( hbitmap );
+      return 0;
+    }
 
     switch (bmp->bitmap.bmBitsPixel) {
     case 1:
@@ -198,19 +236,16 @@
 	fprintf(stderr,"GetBitMapBits32: unknown depth %d, please report.\n",
 		bmp->bitmap.bmBitsPixel
 	);
+	GDI_HEAP_UNLOCK( hbitmap );
 	return 0;
     }
 
-    widthbytes	= DIB_GetXImageWidthBytes(bmp->bitmap.bmWidth,bmp->bitmap.bmBitsPixel);
-    tmpbuffer	= (LPBYTE)xmalloc(widthbytes*height);
-    image = XCreateImage( display, DefaultVisualOfScreen(screen),
-		  bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
-		  bmp->bitmap.bmWidth,height,32,widthbytes
-    );
-    
-    CallTo32_LargeStack( (int(*)())XGetSubImage, 11,
-                         display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
-                         height, AllPlanes, ZPixmap, image, 0, 0 );
+    /* Hack: change the bitmap height temporarily to avoid */
+    /*       getting unnecessary bitmap rows. */
+    old_height = bmp->bitmap.bmHeight;
+    bmp->bitmap.bmHeight = height;
+    image = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
+    bmp->bitmap.bmHeight = old_height;
 
     /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
 
@@ -277,7 +312,8 @@
             tbuf += pad;
 	}
     }
-    XDestroyImage( image ); /* frees tbuffer too */
+    XDestroyImage( image );
+    GDI_HEAP_UNLOCK( hbitmap );
     return height * bmp->bitmap.bmWidthBytes;
 }
 
@@ -285,7 +321,7 @@
 /***********************************************************************
  *           SetBitmapBits16    (GDI.106)
  */
-LONG SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
+LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
 {
     return SetBitmapBits32( hbitmap, count, buffer );
 }
@@ -294,8 +330,9 @@
 /***********************************************************************
  *           SetBitmapBits32    (GDI32.303)
  */
-LONG SetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPCVOID buffer )
+LONG WINAPI SetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPCVOID buffer )
 {
+    struct XPutImage_descr descr;
     BITMAPOBJ * bmp;
     LONG height;
     XImage * image;
@@ -317,8 +354,12 @@
       /* Only set entire lines */
     height = count / bmp->bitmap.bmWidthBytes;
     if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
-    if (!height) return 0;
-    	
+    if (!height) 
+    {
+      GDI_HEAP_UNLOCK( hbitmap );
+      return 0;
+    }
+	
     switch (bmp->bitmap.bmBitsPixel) {
     case 1:
 	if (!(bmp->bitmap.bmWidth & 15))
@@ -416,10 +457,14 @@
         break;
     }
 
-    CallTo32_LargeStack( XPutImage, 10,
-                         display, bmp->pixmap, BITMAP_GC(bmp), image, 0, 0,
-                         0, 0, bmp->bitmap.bmWidth, height );
+    descr.bmp    = bmp;
+    descr.image  = image;
+    descr.width  = bmp->bitmap.bmWidth;
+    descr.height = height;
+    CALL_LARGE_STACK( XPutImage_wrapper, &descr );
+
     XDestroyImage( image ); /* frees tmpbuffer too */
+    GDI_HEAP_UNLOCK( hbitmap );
     return height * bmp->bitmap.bmWidthBytes;
 }
 
@@ -429,10 +474,9 @@
  * defines in windows.h
  */
 
-HANDLE32 LoadImage32A(
-	HINSTANCE32 hinst,LPCSTR name,UINT32 type,INT32 desiredx,
-	INT32 desiredy,UINT32 loadflags
-) {
+HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
+                              INT32 desiredx, INT32 desiredy, UINT32 loadflags)
+{
 	if (HIWORD(name)) {
 		dprintf_resource(stddeb,"LoadImage32A(0x%04x,%s,%d,%d,%d,0x%08x)\n",
 			hinst,name,type,desiredx,desiredy,loadflags
@@ -459,8 +503,8 @@
  * FIXME: implementation still lacks nearly all features, see LR_*
  * defines in windows.h
  */
-HANDLE32 CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
-                      INT32 desiredy, UINT32 flags )
+HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
+                             INT32 desiredy, UINT32 flags )
 {
     switch (type)
     {
@@ -478,7 +522,7 @@
 /**********************************************************************
  *	    LoadBitmap16    (USER.175)
  */
-HBITMAP16 LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
+HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
 {
     HBITMAP32 hbitmap = 0;
     HDC32 hdc;
@@ -520,7 +564,7 @@
 /**********************************************************************
  *	    LoadBitmap32W   (USER32.357)
  */
-HBITMAP32 LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
+HBITMAP32 WINAPI LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
 {
     HBITMAP32 hbitmap = 0;
     HDC32 hdc;
@@ -553,7 +597,7 @@
 /**********************************************************************
  *	    LoadBitmap32A   (USER32.356)
  */
-HBITMAP32 LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
+HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
 {
     HBITMAP32 res;
     if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
@@ -629,7 +673,8 @@
 /***********************************************************************
  *           CreateDiscardableBitmap16    (GDI.156)
  */
-HBITMAP16 CreateDiscardableBitmap16( HDC16 hdc, INT16 width, INT16 height )
+HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
+                                            INT16 height )
 {
     return CreateCompatibleBitmap16( hdc, width, height );
 }
@@ -638,7 +683,8 @@
 /***********************************************************************
  *           CreateDiscardableBitmap32    (GDI32.38)
  */
-HBITMAP32 CreateDiscardableBitmap32( HDC32 hdc, INT32 width, INT32 height )
+HBITMAP32 WINAPI CreateDiscardableBitmap32( HDC32 hdc, INT32 width,
+                                            INT32 height )
 {
     return CreateCompatibleBitmap32( hdc, width, height );
 }
@@ -647,11 +693,12 @@
 /***********************************************************************
  *           GetBitmapDimensionEx16    (GDI.468)
  */
-BOOL16 GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
+BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
 {
     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     if (!bmp) return FALSE;
     *size = bmp->size;
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
@@ -659,12 +706,13 @@
 /***********************************************************************
  *           GetBitmapDimensionEx32    (GDI32.144)
  */
-BOOL32 GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
+BOOL32 WINAPI GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
 {
     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     if (!bmp) return FALSE;
     size->cx = (INT32)bmp->size.cx;
     size->cy = (INT32)bmp->size.cy;
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
@@ -672,7 +720,7 @@
 /***********************************************************************
  *           GetBitmapDimension    (GDI.162)
  */
-DWORD GetBitmapDimension( HBITMAP16 hbitmap )
+DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
 {
     SIZE16 size;
     if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
@@ -683,14 +731,15 @@
 /***********************************************************************
  *           SetBitmapDimensionEx16    (GDI.478)
  */
-BOOL16 SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
-                               LPSIZE16 prevSize )
+BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
+                                      LPSIZE16 prevSize )
 {
     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     if (!bmp) return FALSE;
     if (prevSize) *prevSize = bmp->size;
     bmp->size.cx = x;
     bmp->size.cy = y;
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
@@ -698,14 +747,15 @@
 /***********************************************************************
  *           SetBitmapDimensionEx32    (GDI32.304)
  */
-BOOL32 SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
-                               LPSIZE32 prevSize )
+BOOL32 WINAPI SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
+                                      LPSIZE32 prevSize )
 {
     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     if (!bmp) return FALSE;
     if (prevSize) CONV_SIZE16TO32( &bmp->size, prevSize );
     bmp->size.cx = (INT16)x;
     bmp->size.cy = (INT16)y;
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
@@ -713,9 +763,10 @@
 /***********************************************************************
  *           SetBitmapDimension    (GDI.163)
  */
-DWORD SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
+DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
 {
     SIZE16 size;
     if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
     return MAKELONG( size.cx, size.cy );
 }
+
diff --git a/objects/brush.c b/objects/brush.c
index 4a06005..5f216f2 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -16,15 +16,16 @@
 /***********************************************************************
  *           CreateBrushIndirect16    (GDI.50)
  */
-HBRUSH16 CreateBrushIndirect16( const LOGBRUSH16 * brush )
+HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
 {
     BRUSHOBJ * brushPtr;
     HBRUSH16 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
     if (!hbrush) return 0;
-    brushPtr = (BRUSHOBJ *) GDI_HEAP_LIN_ADDR( hbrush );
+    brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
     brushPtr->logbrush.lbStyle = brush->lbStyle;
     brushPtr->logbrush.lbColor = brush->lbColor;
     brushPtr->logbrush.lbHatch = brush->lbHatch;
+    GDI_HEAP_UNLOCK( hbrush );
     return hbrush;
 }
 
@@ -32,15 +33,16 @@
 /***********************************************************************
  *           CreateBrushIndirect32    (GDI32.27)
  */
-HBRUSH32 CreateBrushIndirect32( const LOGBRUSH32 * brush )
+HBRUSH32 WINAPI CreateBrushIndirect32( const LOGBRUSH32 * brush )
 {
     BRUSHOBJ * brushPtr;
     HBRUSH32 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
     if (!hbrush) return 0;
-    brushPtr = (BRUSHOBJ *) GDI_HEAP_LIN_ADDR( hbrush );
+    brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
     brushPtr->logbrush.lbStyle = brush->lbStyle;
     brushPtr->logbrush.lbColor = brush->lbColor;
     brushPtr->logbrush.lbHatch = brush->lbHatch;
+    GDI_HEAP_UNLOCK( hbrush );
     return hbrush;
 }
 
@@ -48,7 +50,7 @@
 /***********************************************************************
  *           CreateHatchBrush16    (GDI.58)
  */
-HBRUSH16 CreateHatchBrush16( INT16 style, COLORREF color )
+HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
 {
     LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
     dprintf_gdi(stddeb, "CreateHatchBrush16: %d %06lx\n", style, color );
@@ -60,7 +62,7 @@
 /***********************************************************************
  *           CreateHatchBrush32    (GDI32.48)
  */
-HBRUSH32 CreateHatchBrush32( INT32 style, COLORREF color )
+HBRUSH32 WINAPI CreateHatchBrush32( INT32 style, COLORREF color )
 {
     LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
     dprintf_gdi(stddeb, "CreateHatchBrush32: %d %06lx\n", style, color );
@@ -72,7 +74,7 @@
 /***********************************************************************
  *           CreatePatternBrush16    (GDI.60)
  */
-HBRUSH16 CreatePatternBrush16( HBITMAP16 hbitmap )
+HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
 {
     return (HBRUSH16)CreatePatternBrush32( hbitmap );
 }
@@ -81,7 +83,7 @@
 /***********************************************************************
  *           CreatePatternBrush32    (GDI32.54)
  */
-HBRUSH32 CreatePatternBrush32( HBITMAP32 hbitmap )
+HBRUSH32 WINAPI CreatePatternBrush32( HBITMAP32 hbitmap )
 {
     LOGBRUSH32 logbrush = { BS_PATTERN, 0, 0 };
     BITMAPOBJ *bmp, *newbmp;
@@ -95,9 +97,15 @@
     logbrush.lbHatch = (INT32)CreateBitmapIndirect16( &bmp->bitmap );
     newbmp = (BITMAPOBJ *) GDI_GetObjPtr( (HGDIOBJ32)logbrush.lbHatch,
                                           BITMAP_MAGIC );
-    if (!newbmp) return 0;
+    if (!newbmp) 
+    {
+      GDI_HEAP_UNLOCK( hbitmap );
+      return 0;
+    }
     XCopyArea( display, bmp->pixmap, newbmp->pixmap, BITMAP_GC(bmp),
 	       0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0 );
+    GDI_HEAP_UNLOCK( hbitmap );
+    GDI_HEAP_UNLOCK( logbrush.lbHatch );
     return CreateBrushIndirect32( &logbrush );
 }
 
@@ -105,7 +113,7 @@
 /***********************************************************************
  *           CreateDIBPatternBrush16    (GDI.445)
  */
-HBRUSH16 CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
+HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
 {
     LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
     BITMAPINFO *info, *newInfo;
@@ -140,7 +148,7 @@
 /***********************************************************************
  *           CreateDIBPatternBrush32    (GDI32.34)
  */
-HBRUSH32 CreateDIBPatternBrush32( HGLOBAL32 hbitmap, UINT32 coloruse )
+HBRUSH32 WINAPI CreateDIBPatternBrush32( HGLOBAL32 hbitmap, UINT32 coloruse )
 {
     LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
     BITMAPINFO *info, *newInfo;
@@ -175,7 +183,7 @@
 /***********************************************************************
  *           CreateSolidBrush    (GDI.66)
  */
-HBRUSH16 CreateSolidBrush16( COLORREF color )
+HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
 {
     LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
     dprintf_gdi(stddeb, "CreateSolidBrush16: %06lx\n", color );
@@ -186,7 +194,7 @@
 /***********************************************************************
  *           CreateSolidBrush32    (GDI32.64)
  */
-HBRUSH32 CreateSolidBrush32( COLORREF color )
+HBRUSH32 WINAPI CreateSolidBrush32( COLORREF color )
 {
     LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
     dprintf_gdi(stddeb, "CreateSolidBrush32: %06lx\n", color );
@@ -197,7 +205,7 @@
 /***********************************************************************
  *           SetBrushOrg    (GDI.148)
  */
-DWORD SetBrushOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetBrushOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     DWORD retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -212,7 +220,7 @@
 /***********************************************************************
  *           SetBrushOrgEx    (GDI32.308)
  */
-BOOL32 SetBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
+BOOL32 WINAPI SetBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
 
@@ -231,7 +239,7 @@
 /***********************************************************************
  *           GetSysColorBrush16    (USER.281)
  */
-HBRUSH16 GetSysColorBrush16( INT16 index )
+HBRUSH16 WINAPI GetSysColorBrush16( INT16 index )
 {
     fprintf( stderr, "Unimplemented stub: GetSysColorBrush16(%d)\n", index );
     return GetStockObject32(LTGRAY_BRUSH);
@@ -241,7 +249,7 @@
 /***********************************************************************
  *           GetSysColorBrush32    (USER32.289)
  */
-HBRUSH32 GetSysColorBrush32( INT32 index)
+HBRUSH32 WINAPI GetSysColorBrush32( INT32 index)
 {
     fprintf( stderr, "Unimplemented stub: GetSysColorBrush32(%d)\n", index );
     return GetStockObject32(LTGRAY_BRUSH);
diff --git a/objects/clipping.c b/objects/clipping.c
index e801cb0..d417c71 100644
--- a/objects/clipping.c
+++ b/objects/clipping.c
@@ -51,7 +51,7 @@
 /***********************************************************************
  *           SelectClipRgn16    (GDI.44)
  */
-INT16 SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
+INT16 WINAPI SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
 {
     return (INT16)SelectClipRgn32( hdc, hrgn );
 }
@@ -60,7 +60,7 @@
 /***********************************************************************
  *           SelectClipRgn32    (GDI32.297)
  */
-INT32 SelectClipRgn32( HDC32 hdc, HRGN32 hrgn )
+INT32 WINAPI SelectClipRgn32( HDC32 hdc, HRGN32 hrgn )
 {
     INT32 retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -81,6 +81,7 @@
     }
 
     CLIPPING_UpdateGCRegion( dc );
+    GDI_HEAP_UNLOCK( hdc );
     return retval;
 }
 
@@ -88,7 +89,7 @@
 /***********************************************************************
  *           SelectVisRgn    (GDI.105)
  */
-INT16 SelectVisRgn( HDC16 hdc, HRGN16 hrgn )
+INT16 WINAPI SelectVisRgn( HDC16 hdc, HRGN16 hrgn )
 {
     int retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -100,6 +101,7 @@
 
     retval = CombineRgn16( dc->w.hVisRgn, hrgn, 0, RGN_COPY );
     CLIPPING_UpdateGCRegion( dc );
+    GDI_HEAP_UNLOCK( hdc );
     return retval;
 }
 
@@ -107,7 +109,7 @@
 /***********************************************************************
  *           OffsetClipRgn16    (GDI.32)
  */
-INT16 OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
+INT16 WINAPI OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
 {
     return (INT16)OffsetClipRgn32( hdc, x, y );
 }
@@ -116,7 +118,7 @@
 /***********************************************************************
  *           OffsetClipRgn32    (GDI32.255)
  */
-INT32 OffsetClipRgn32( HDC32 hdc, INT32 x, INT32 y )
+INT32 WINAPI OffsetClipRgn32( HDC32 hdc, INT32 x, INT32 y )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
@@ -124,6 +126,7 @@
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return ERROR;
 	MF_MetaParam2(dc, META_OFFSETCLIPRGN, x, y);
+	GDI_HEAP_UNLOCK( hdc );
 	return NULLREGION;   /* ?? */
     }
 
@@ -133,16 +136,18 @@
     {
 	INT32 ret = OffsetRgn32( dc->w.hClipRgn, XLPTODP(dc,x), YLPTODP(dc,y));
 	CLIPPING_UpdateGCRegion( dc );
+	GDI_HEAP_UNLOCK( hdc );
 	return ret;
     }
-    else return SIMPLEREGION; /* Clip region == client area */
+    GDI_HEAP_UNLOCK( hdc );
+    return SIMPLEREGION; /* Clip region == client area */
 }
 
 
 /***********************************************************************
  *           OffsetVisRgn    (GDI.102)
  */
-INT16 OffsetVisRgn( HDC16 hdc, INT16 x, INT16 y )
+INT16 WINAPI OffsetVisRgn( HDC16 hdc, INT16 x, INT16 y )
 {
     INT16 retval;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -150,6 +155,7 @@
     dprintf_clipping(stddeb, "OffsetVisRgn: %04x %d,%d\n", hdc, x, y );
     retval = OffsetRgn32( dc->w.hVisRgn, x, y );
     CLIPPING_UpdateGCRegion( dc );
+    GDI_HEAP_UNLOCK( hdc );
     return retval;
 }
 
@@ -194,8 +200,8 @@
 /***********************************************************************
  *           ExcludeClipRect16    (GDI.21)
  */
-INT16 ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
-                         INT16 right, INT16 bottom )
+INT16 WINAPI ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
+                                INT16 right, INT16 bottom )
 {
     return (INT16)ExcludeClipRect32( hdc, left, top, right, bottom );
 }
@@ -204,15 +210,17 @@
 /***********************************************************************
  *           ExcludeClipRect32    (GDI32.92)
  */
-INT32 ExcludeClipRect32( HDC32 hdc, INT32 left, INT32 top,
-                         INT32 right, INT32 bottom )
+INT32 WINAPI ExcludeClipRect32( HDC32 hdc, INT32 left, INT32 top,
+                                INT32 right, INT32 bottom )
 {
+    INT32 ret;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
     {
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return ERROR;
 	MF_MetaParam4(dc, META_EXCLUDECLIPRECT, left, top, right, bottom);
+	GDI_HEAP_UNLOCK( hdc );
 	return NULLREGION;   /* ?? */
     }
 
@@ -223,15 +231,17 @@
 
     dprintf_clipping(stddeb, "ExcludeClipRect: %04x %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_EXCLUDE );
+    ret = CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_EXCLUDE );
+    GDI_HEAP_UNLOCK( hdc );
+    return ret;
 }
 
 
 /***********************************************************************
  *           IntersectClipRect16    (GDI.22)
  */
-INT16 IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
-                           INT16 right, INT16 bottom )
+INT16 WINAPI IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
+                                  INT16 right, INT16 bottom )
 {
     return (INT16)IntersectClipRect32( hdc, left, top, right, bottom );
 }
@@ -240,15 +250,17 @@
 /***********************************************************************
  *           IntersectClipRect32    (GDI32.245)
  */
-INT32 IntersectClipRect32( HDC32 hdc, INT32 left, INT32 top,
-                           INT32 right, INT32 bottom )
+INT32 WINAPI IntersectClipRect32( HDC32 hdc, INT32 left, INT32 top,
+                                  INT32 right, INT32 bottom )
 {
+    INT32 ret;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
     {
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return ERROR;
 	MF_MetaParam4(dc, META_INTERSECTCLIPRECT, left, top, right, bottom);
+	GDI_HEAP_UNLOCK( hdc );
 	return NULLREGION;   /* ?? */
     }
 
@@ -259,7 +271,9 @@
 
     dprintf_clipping(stddeb, "IntersectClipRect: %04x %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_INTERSECT );
+    ret = CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_INTERSECT );
+    GDI_HEAP_UNLOCK( hdc );
+    return ret;
 }
 
 
@@ -298,6 +312,7 @@
         DeleteObject32( dc->w.hVisRgn );
         dc->w.hVisRgn = newRgn;    
         CLIPPING_UpdateGCRegion( dc );
+	GDI_HEAP_UNLOCK( newRgn );
     }
     else DeleteObject32( newRgn );
     return ret;
@@ -307,8 +322,8 @@
 /***********************************************************************
  *           ExcludeVisRect    (GDI.73)
  */
-INT16 ExcludeVisRect( HDC16 hdc, INT16 left, INT16 top,
-                      INT16 right, INT16 bottom )
+INT16 WINAPI ExcludeVisRect( HDC16 hdc, INT16 left, INT16 top,
+                             INT16 right, INT16 bottom )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
@@ -322,8 +337,8 @@
 /***********************************************************************
  *           IntersectVisRect    (GDI.98)
  */
-INT16 IntersectVisRect( HDC16 hdc, INT16 left, INT16 top,
-                        INT16 right, INT16 bottom )
+INT16 WINAPI IntersectVisRect( HDC16 hdc, INT16 left, INT16 top,
+                               INT16 right, INT16 bottom )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
@@ -337,7 +352,7 @@
 /***********************************************************************
  *           PtVisible16    (GDI.103)
  */
-BOOL16 PtVisible16( HDC16 hdc, INT16 x, INT16 y )
+BOOL16 WINAPI PtVisible16( HDC16 hdc, INT16 x, INT16 y )
 {
     return PtVisible32( hdc, x, y );
 }
@@ -346,7 +361,7 @@
 /***********************************************************************
  *           PtVisible32    (GDI32.279)
  */
-BOOL32 PtVisible32( HDC32 hdc, INT32 x, INT32 y )
+BOOL32 WINAPI PtVisible32( HDC32 hdc, INT32 x, INT32 y )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return ERROR;    
@@ -364,7 +379,7 @@
 /***********************************************************************
  *           RectVisible16    (GDI.104)
  */
-BOOL16 RectVisible16( HDC16 hdc, LPRECT16 rect )
+BOOL16 WINAPI RectVisible16( HDC16 hdc, LPRECT16 rect )
 {
     RECT16 tmpRect;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -382,7 +397,7 @@
 /***********************************************************************
  *           RectVisible32    (GDI32.282)
  */
-BOOL32 RectVisible32( HDC32 hdc, LPRECT32 rect )
+BOOL32 WINAPI RectVisible32( HDC32 hdc, LPRECT32 rect )
 {
     RECT16 rect16;
     CONV_RECT32TO16( rect, &rect16 );
@@ -393,7 +408,7 @@
 /***********************************************************************
  *           GetClipBox16    (GDI.77)
  */
-INT16 GetClipBox16( HDC16 hdc, LPRECT16 rect )
+INT16 WINAPI GetClipBox16( HDC16 hdc, LPRECT16 rect )
 {
     int ret;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -407,7 +422,7 @@
 /***********************************************************************
  *           GetClipBox32    (GDI32.162)
  */
-INT32 GetClipBox32( HDC32 hdc, LPRECT32 rect )
+INT32 WINAPI GetClipBox32( HDC32 hdc, LPRECT32 rect )
 {
     INT32 ret;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -421,7 +436,7 @@
 /***********************************************************************
  *           GetClipRgn32  (GDI32.163)
  */
-INT32 GetClipRgn32( HDC32 hdc, HRGN32 hRgn )
+INT32 WINAPI GetClipRgn32( HDC32 hdc, HRGN32 hRgn )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if( dc && hRgn )
@@ -440,7 +455,7 @@
 /***********************************************************************
  *           SaveVisRgn    (GDI.129)
  */
-HRGN16 SaveVisRgn( HDC16 hdc )
+HRGN16 WINAPI SaveVisRgn( HDC16 hdc )
 {
     HRGN32 copy;
     RGNOBJ *obj, *copyObj;
@@ -456,13 +471,28 @@
     dc->w.flags &= ~DC_DIRTY;
 
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
+    {
+        GDI_HEAP_UNLOCK( hdc );
 	return 0;
-    if (!(copy = CreateRectRgn32( 0, 0, 0, 0 ))) return 0;
+    }
+    if (!(copy = CreateRectRgn32( 0, 0, 0, 0 )))
+    {
+        GDI_HEAP_UNLOCK( dc->w.hVisRgn );
+        GDI_HEAP_UNLOCK( hdc );
+        return 0;
+    }  
     CombineRgn32( copy, dc->w.hVisRgn, 0, RGN_COPY );
     if (!(copyObj = (RGNOBJ *) GDI_GetObjPtr( copy, REGION_MAGIC )))
+    {
+        GDI_HEAP_UNLOCK( dc->w.hVisRgn );
+        GDI_HEAP_UNLOCK( hdc );
 	return 0;
+    }
     copyObj->header.hNext = obj->header.hNext;
     obj->header.hNext = copy;
+    GDI_HEAP_UNLOCK( dc->w.hVisRgn );
+    GDI_HEAP_UNLOCK( hdc );
+    GDI_HEAP_UNLOCK( copy );
     return copy;
 }
 
@@ -470,20 +500,39 @@
 /***********************************************************************
  *           RestoreVisRgn    (GDI.130)
  */
-INT16 RestoreVisRgn( HDC16 hdc )
+INT16 WINAPI RestoreVisRgn( HDC16 hdc )
 {
     HRGN32 saved;
     RGNOBJ *obj, *savedObj;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
-    if (!dc || !dc->w.hVisRgn) return ERROR;    
+    if (!dc) return ERROR;    
+    if (!dc->w.hVisRgn)
+    {
+        GDI_HEAP_UNLOCK( hdc );
+        return ERROR;    
+    }
     dprintf_clipping(stddeb, "RestoreVisRgn: %04x\n", hdc );
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( dc->w.hVisRgn, REGION_MAGIC )))
+    {
+        GDI_HEAP_UNLOCK( hdc );
 	return ERROR;
-    if (!(saved = obj->header.hNext)) return ERROR;
+    }
+    if (!(saved = obj->header.hNext)) 
+    {
+        GDI_HEAP_UNLOCK( dc->w.hVisRgn );
+        GDI_HEAP_UNLOCK( hdc );
+        return ERROR;
+    }
     if (!(savedObj = (RGNOBJ *) GDI_GetObjPtr( saved, REGION_MAGIC )))
-	return ERROR;
+    {
+        GDI_HEAP_UNLOCK( dc->w.hVisRgn );
+        GDI_HEAP_UNLOCK( hdc );
+        return ERROR;
+    }
     DeleteObject32( dc->w.hVisRgn );
     dc->w.hVisRgn = saved;
     CLIPPING_UpdateGCRegion( dc );
+    GDI_HEAP_UNLOCK( hdc );
+    GDI_HEAP_UNLOCK( saved );
     return savedObj->xrgn ? COMPLEXREGION : NULLREGION;
 }
diff --git a/objects/color.c b/objects/color.c
index 7d5c0bd..b07b790 100644
--- a/objects/color.c
+++ b/objects/color.c
@@ -857,6 +857,7 @@
     WORD 		 index = 0;
     HPALETTE16		 hPal = (dc)? dc->w.hPalette: STOCK_DEFAULT_PALETTE;
     unsigned char	 spec_type = color >> 24;
+    PALETTEOBJ* 	 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
 
     if ( cSpace.flags & COLOR_FIXED )
     {
@@ -866,7 +867,6 @@
 
 	unsigned 	long red, green, blue;
 	unsigned 	idx = 0;
-	PALETTEOBJ * 	palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
 
 	switch(spec_type)
         {
@@ -876,7 +876,11 @@
 					    palPtr->logpalette.palNumEntries,
 					    NULL, color, FALSE);
 
-            if( palPtr->mapping ) return palPtr->mapping[idx];
+            if( palPtr->mapping )
+	    {
+	        GDI_HEAP_UNLOCK( hPal );
+		return palPtr->mapping[idx];
+	    }
 
 	    color = *(COLORREF*)(palPtr->logpalette.palPalEntry + idx);
 	    break;
@@ -886,11 +890,15 @@
             if( (idx = color & 0xffff) >= palPtr->logpalette.palNumEntries)
             {
                 fprintf(stderr, "\tRGB(%lx) : idx %d is out of bounds, assuming black\n", color, idx);
+		GDI_HEAP_UNLOCK( hPal );
                 return 0;
             }
 
-            if( palPtr->mapping ) return palPtr->mapping[idx];
-
+            if( palPtr->mapping ) 
+	    {
+		GDI_HEAP_UNLOCK( hPal );
+		return palPtr->mapping[idx];
+	    }
 	    color = *(COLORREF*)(palPtr->logpalette.palPalEntry + idx);
 	    break;
 
@@ -900,8 +908,12 @@
 
 	  case 0: /* RGB */
 	    if( dc && (dc->w.bitsPerPixel == 1) )
+	    {
+		GDI_HEAP_UNLOCK( hPal );
 		return (((color >> 16) & 0xff) +
 			((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
+	    }
+
 	}
 
         red = GetRValue(color); green = GetGValue(color); blue = GetBValue(color);
@@ -909,6 +921,7 @@
 	if (COLOR_Graymax)
         {
 	    /* grayscale only; return scaled value */
+	    GDI_HEAP_UNLOCK( hPal );
             return ( (red * 30 + green * 69 + blue * 11) * COLOR_Graymax) / 25500;
 	}
 	else
@@ -918,12 +931,12 @@
             if (COLOR_Greenmax != 255) green = (green * COLOR_Greenmax) / 255;
 	    if (COLOR_Bluemax != 255) blue = (blue * COLOR_Bluemax) / 255;
 
+	    GDI_HEAP_UNLOCK( hPal );
 	    return (red << COLOR_Redshift) | (green << COLOR_Greenshift) | (blue << COLOR_Blueshift);
         }
     }
     else 
     {
-	PALETTEOBJ* palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC);
 
 	/* palPtr can be NULL when DC is being destroyed */
 
@@ -939,8 +952,11 @@
 
        	    case 0:  /* RGB */
 		if( dc && (dc->w.bitsPerPixel == 1) )
+		{
+		    GDI_HEAP_UNLOCK( hPal );
 		    return (((color >> 16) & 0xff) +
 			    ((color >> 8) & 0xff) + (color & 0xff) > 255*3/2) ? 1 : 0;
+		}
 
 	    	index = COLOR_PaletteLookupPixel( COLOR_sysPal, 256, 
 						  COLOR_PaletteToPixel, color, FALSE);
@@ -968,6 +984,7 @@
 	}
     }
 
+    GDI_HEAP_UNLOCK( hPal );
     return index;
 }
 
@@ -977,12 +994,11 @@
  * Set the color-mapping table for selected palette. 
  * Return number of entries which mapping has changed.
  */
-int COLOR_SetMapping( PALETTEOBJ* palPtr, BOOL32 mapOnly )
+int COLOR_SetMapping( PALETTEOBJ* palPtr, UINT32 uStart, UINT32 uNum, BOOL32 mapOnly )
 {
-    int  i, index;
     char flag;
     int  prevMapping = (palPtr->mapping) ? 1 : 0;
-    int  iRemapped = 0;
+    int  index, iRemapped = 0;
 
     /* reset dynamic system palette entries */
 
@@ -994,15 +1010,15 @@
     palPtr->mapping = (int*)xrealloc(palPtr->mapping, sizeof(int)*
                                      palPtr->logpalette.palNumEntries);
 
-    for( i = 0; i < palPtr->logpalette.palNumEntries; i++ )
+    for( uNum += uStart; uStart < uNum; uStart++ )
     {
         index = -1;
         flag = PC_SYS_USED;
 
-        switch( palPtr->logpalette.palPalEntry[i].peFlags & 0x07 )
+        switch( palPtr->logpalette.palPalEntry[uStart].peFlags & 0x07 )
         {
 	case PC_EXPLICIT:   /* palette entries are indices into system palette */
-            index = *(WORD*)(palPtr->logpalette.palPalEntry + i);
+            index = *(WORD*)(palPtr->logpalette.palPalEntry + uStart);
             if( index > 255 || (index >= COLOR_gapStart && index <= COLOR_gapEnd) ) 
             {
                 fprintf(stderr,"PC_EXPLICIT: idx %d out of system palette, assuming black.\n", index); 
@@ -1016,7 +1032,7 @@
             /* fall through */
 	default:	    /* try to collapse identical colors */
             index = COLOR_PaletteLookupExactIndex(COLOR_sysPal, 256,  
-                             *(COLORREF*)(palPtr->logpalette.palPalEntry + i));
+                             *(COLORREF*)(palPtr->logpalette.palPalEntry + uStart));
             /* fall through */
 	case PC_NOCOLLAPSE: 
             if( index < 0 )
@@ -1028,13 +1044,13 @@
                     COLOR_firstFree = COLOR_freeList[index];
 
                     color.pixel = (COLOR_PaletteToPixel) ? COLOR_PaletteToPixel[index] : index;
-                    color.red = palPtr->logpalette.palPalEntry[i].peRed << 8;
-                    color.green = palPtr->logpalette.palPalEntry[i].peGreen << 8;
-                    color.blue = palPtr->logpalette.palPalEntry[i].peBlue << 8;
+                    color.red = palPtr->logpalette.palPalEntry[uStart].peRed << 8;
+                    color.green = palPtr->logpalette.palPalEntry[uStart].peGreen << 8;
+                    color.blue = palPtr->logpalette.palPalEntry[uStart].peBlue << 8;
                     color.flags = DoRed | DoGreen | DoBlue;
                     XStoreColor(display, cSpace.colorMap, &color);
 
-                    COLOR_sysPal[index] = palPtr->logpalette.palPalEntry[i];
+                    COLOR_sysPal[index] = palPtr->logpalette.palPalEntry[uStart];
                     COLOR_sysPal[index].peFlags = flag;
 		    COLOR_freeList[index] = 0;
 
@@ -1044,27 +1060,28 @@
                 else if ( cSpace.flags & COLOR_VIRTUAL ) 
                 {
                     index = COLOR_ToPhysical( NULL, 0x00ffffff &
-                             *(COLORREF*)(palPtr->logpalette.palPalEntry + i));
+                             *(COLORREF*)(palPtr->logpalette.palPalEntry + uStart));
                     break;     
                 }
 
                 /* we have to map to existing entry in the system palette */
 
                 index = COLOR_PaletteLookupPixel(COLOR_sysPal, 256, NULL, 
-                       *(COLORREF*)(palPtr->logpalette.palPalEntry + i), TRUE);
+                       *(COLORREF*)(palPtr->logpalette.palPalEntry + uStart), TRUE);
             }
-	    palPtr->logpalette.palPalEntry[i].peFlags |= PC_SYS_USED;
+	    palPtr->logpalette.palPalEntry[uStart].peFlags |= PC_SYS_USED;
 
             if( COLOR_PaletteToPixel ) index = COLOR_PaletteToPixel[index];
             break;
         }
 
-        if( !prevMapping || palPtr->mapping[i] != index ) iRemapped++;
-        palPtr->mapping[i] = index;
+        if( !prevMapping || palPtr->mapping[uStart] != index ) iRemapped++;
+        palPtr->mapping[uStart] = index;
 
-        dprintf_palette(stddeb,"\tentry %i (%lx) -> pixel %i\n", i, 
-				*(COLORREF*)(palPtr->logpalette.palPalEntry + i), index);
+        dprintf_palette(stddeb,"\tentry %i (%lx) -> pixel %i\n", uStart, 
+				*(COLORREF*)(palPtr->logpalette.palPalEntry + uStart), index);
 	
     }
     return iRemapped;
 }
+
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index e8a9537..317f163 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -522,7 +522,7 @@
 /***********************************************************************
  *           LoadCursor16    (USER.173)
  */
-HCURSOR16 LoadCursor16( HINSTANCE16 hInstance, SEGPTR name )
+HCURSOR16 WINAPI LoadCursor16( HINSTANCE16 hInstance, SEGPTR name )
 {
     if (HIWORD(name))
         dprintf_cursor( stddeb, "LoadCursor16: %04x '%s'\n",
@@ -539,7 +539,7 @@
 /***********************************************************************
  *           LoadIcon16    (USER.174)
  */
-HICON16 LoadIcon16( HINSTANCE16 hInstance, SEGPTR name )
+HICON16 WINAPI LoadIcon16( HINSTANCE16 hInstance, SEGPTR name )
 {
     if (HIWORD(name))
         dprintf_icon( stddeb, "LoadIcon: %04x '%s'\n",
@@ -557,9 +557,10 @@
 /***********************************************************************
  *           CreateCursor16    (USER.406)
  */
-HCURSOR16 CreateCursor16(HINSTANCE16 hInstance, INT16 xHotSpot, INT16 yHotSpot,
-                         INT16 nWidth, INT16 nHeight,
-                         LPCVOID lpANDbits, LPCVOID lpXORbits )
+HCURSOR16 WINAPI CreateCursor16( HINSTANCE16 hInstance,
+                                 INT16 xHotSpot, INT16 yHotSpot,
+                                 INT16 nWidth, INT16 nHeight,
+                                 LPCVOID lpANDbits, LPCVOID lpXORbits )
 {
     CURSORICONINFO info = { { xHotSpot, yHotSpot }, nWidth, nHeight, 0, 1, 1 };
 
@@ -572,9 +573,10 @@
 /***********************************************************************
  *           CreateCursor32    (USER32.66)
  */
-HCURSOR32 CreateCursor32(HINSTANCE32 hInstance, INT32 xHotSpot, INT32 yHotSpot,
-                         INT32 nWidth, INT32 nHeight,
-                         LPCVOID lpANDbits, LPCVOID lpXORbits )
+HCURSOR32 WINAPI CreateCursor32( HINSTANCE32 hInstance,
+                                 INT32 xHotSpot, INT32 yHotSpot,
+                                 INT32 nWidth, INT32 nHeight,
+                                 LPCVOID lpANDbits, LPCVOID lpXORbits )
 {
     CURSORICONINFO info = { { xHotSpot, yHotSpot }, nWidth, nHeight, 0, 1, 1 };
 
@@ -587,9 +589,9 @@
 /***********************************************************************
  *           CreateIcon16    (USER.407)
  */
-HICON16 CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth, INT16 nHeight,
-                      BYTE bPlanes, BYTE bBitsPixel,
-                      LPCVOID lpANDbits, LPCVOID lpXORbits )
+HICON16 WINAPI CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth,
+                             INT16 nHeight, BYTE bPlanes, BYTE bBitsPixel,
+                             LPCVOID lpANDbits, LPCVOID lpXORbits )
 {
     CURSORICONINFO info = { { 0, 0 }, nWidth, nHeight, 0, bPlanes, bBitsPixel};
 
@@ -602,9 +604,9 @@
 /***********************************************************************
  *           CreateIcon32    (USER32.74)
  */
-HICON32 CreateIcon32( HINSTANCE32 hInstance, INT32 nWidth, INT32 nHeight,
-                      BYTE bPlanes, BYTE bBitsPixel,
-                      LPCVOID lpANDbits, LPCVOID lpXORbits )
+HICON32 WINAPI CreateIcon32( HINSTANCE32 hInstance, INT32 nWidth,
+                             INT32 nHeight, BYTE bPlanes, BYTE bBitsPixel,
+                             LPCVOID lpANDbits, LPCVOID lpXORbits )
 {
     CURSORICONINFO info = { { 0, 0 }, nWidth, nHeight, 0, bPlanes, bBitsPixel};
 
@@ -617,8 +619,10 @@
 /***********************************************************************
  *           CreateCursorIconIndirect    (USER.408)
  */
-HGLOBAL16 CreateCursorIconIndirect(HINSTANCE16 hInstance, CURSORICONINFO *info,
-                                   LPCVOID lpANDbits, LPCVOID lpXORbits )
+HGLOBAL16 WINAPI CreateCursorIconIndirect( HINSTANCE16 hInstance,
+                                           CURSORICONINFO *info,
+                                           LPCVOID lpANDbits,
+                                           LPCVOID lpXORbits )
 {
     HGLOBAL16 handle;
     char *ptr;
@@ -644,7 +648,7 @@
 /***********************************************************************
  *           CopyIcon16    (USER.368)
  */
-HICON16 CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
+HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
 {
     dprintf_icon( stddeb, "CopyIcon16: %04x %04x\n", hInstance, hIcon );
     return CURSORICON_Copy( hInstance, hIcon );
@@ -654,7 +658,7 @@
 /***********************************************************************
  *           CopyIcon32    (USER32.59)
  */
-HICON32 CopyIcon32( HICON32 hIcon )
+HICON32 WINAPI CopyIcon32( HICON32 hIcon )
 {
     dprintf_icon( stddeb, "CopyIcon32: %04x\n", hIcon );
     return CURSORICON_Copy( 0, hIcon );
@@ -664,7 +668,7 @@
 /***********************************************************************
  *           CopyCursor16    (USER.369)
  */
-HCURSOR16 CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
+HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
 {
     dprintf_cursor( stddeb, "CopyCursor16: %04x %04x\n", hInstance, hCursor );
     return CURSORICON_Copy( hInstance, hCursor );
@@ -674,7 +678,7 @@
 /***********************************************************************
  *           DestroyIcon16    (USER.457)
  */
-BOOL16 DestroyIcon16( HICON16 hIcon )
+BOOL16 WINAPI DestroyIcon16( HICON16 hIcon )
 {
     return DestroyIcon32( hIcon );
 }
@@ -683,7 +687,7 @@
 /***********************************************************************
  *           DestroyIcon32    (USER32.132)
  */
-BOOL32 DestroyIcon32( HICON32 hIcon )
+BOOL32 WINAPI DestroyIcon32( HICON32 hIcon )
 {
     dprintf_icon( stddeb, "DestroyIcon: %04x\n", hIcon );
     /* FIXME: should check for OEM icon here */
@@ -694,7 +698,7 @@
 /***********************************************************************
  *           DestroyCursor16    (USER.458)
  */
-BOOL16 DestroyCursor16( HCURSOR16 hCursor )
+BOOL16 WINAPI DestroyCursor16( HCURSOR16 hCursor )
 {
     return DestroyCursor32( hCursor );
 }
@@ -703,7 +707,7 @@
 /***********************************************************************
  *           DestroyCursor32    (USER32.131)
  */
-BOOL32 DestroyCursor32( HCURSOR32 hCursor )
+BOOL32 WINAPI DestroyCursor32( HCURSOR32 hCursor )
 {
     dprintf_cursor( stddeb, "DestroyCursor: %04x\n", hCursor );
     /* FIXME: should check for OEM cursor here */
@@ -714,7 +718,7 @@
 /***********************************************************************
  *           DrawIcon16    (USER.84)
  */
-BOOL16 DrawIcon16( HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon )
+BOOL16 WINAPI DrawIcon16( HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon )
 {
     return DrawIcon32( hdc, x, y, hIcon );
 }
@@ -723,7 +727,7 @@
 /***********************************************************************
  *           DrawIcon32    (USER32.158)
  */
-BOOL32 DrawIcon32( HDC32 hdc, INT32 x, INT32 y, HICON32 hIcon )
+BOOL32 WINAPI DrawIcon32( HDC32 hdc, INT32 x, INT32 y, HICON32 hIcon )
 {
     CURSORICONINFO *ptr;
     HDC32 hMemDC;
@@ -761,8 +765,8 @@
 /***********************************************************************
  *           DumpIcon    (USER.459)
  */
-DWORD DumpIcon( SEGPTR pInfo, WORD *lpLen,
-                SEGPTR *lpXorBits, SEGPTR *lpAndBits )
+DWORD WINAPI DumpIcon( SEGPTR pInfo, WORD *lpLen,
+                       SEGPTR *lpXorBits, SEGPTR *lpAndBits )
 {
     CURSORICONINFO *info = PTR_SEG_TO_LIN( pInfo );
     int sizeAnd, sizeXor;
@@ -833,9 +837,8 @@
             image->bitmap_unit = 16;
             _XInitImageFuncPtrs(image);
             if (pixmapAll)
-                CallTo32_LargeStack( XPutImage, 10,
-                                     display, pixmapAll, BITMAP_monoGC, image,
-                                     0, 0, 0, 0, ptr->nWidth, ptr->nHeight*2 );
+                XPutImage( display, pixmapAll, BITMAP_monoGC, image,
+                           0, 0, 0, 0, ptr->nWidth, ptr->nHeight * 2 );
             image->data = NULL;
             XDestroyImage( image );
         }
@@ -925,7 +928,7 @@
 /***********************************************************************
  *           SetCursor16    (USER.69)
  */
-HCURSOR16 SetCursor16( HCURSOR16 hCursor )
+HCURSOR16 WINAPI SetCursor16( HCURSOR16 hCursor )
 {
     return (HCURSOR16)SetCursor32( hCursor );
 }
@@ -934,7 +937,7 @@
 /***********************************************************************
  *           SetCursor32    (USER32.471)
  */
-HCURSOR32 SetCursor32( HCURSOR32 hCursor )
+HCURSOR32 WINAPI SetCursor32( HCURSOR32 hCursor )
 {
     HCURSOR32 hOldCursor;
 
@@ -943,7 +946,8 @@
     hOldCursor = hActiveCursor;
     hActiveCursor = hCursor;
     /* Change the cursor shape only if it is visible */
-    if (CURSOR_ShowCount >= 0) CURSORICON_SetCursor( hActiveCursor );
+    if (CURSOR_ShowCount >= 0)
+        CALL_LARGE_STACK( CURSORICON_SetCursor, hActiveCursor );
     return hOldCursor;
 }
 
@@ -951,7 +955,7 @@
 /***********************************************************************
  *           SetCursorPos16    (USER.70)
  */
-void SetCursorPos16( INT16 x, INT16 y )
+void WINAPI SetCursorPos16( INT16 x, INT16 y )
 {
     SetCursorPos32( x, y );
 }
@@ -960,7 +964,7 @@
 /***********************************************************************
  *           SetCursorPos32    (USER32.473)
  */
-BOOL32 SetCursorPos32( INT32 x, INT32 y )
+BOOL32 WINAPI SetCursorPos32( INT32 x, INT32 y )
 {
     dprintf_cursor( stddeb, "SetCursorPos: x=%d y=%d\n", x, y );
     XWarpPointer( display, rootWindow, rootWindow, 0, 0, 0, 0, x, y );
@@ -971,7 +975,7 @@
 /***********************************************************************
  *           ShowCursor16    (USER.71)
  */
-INT16 ShowCursor16( BOOL16 bShow )
+INT16 WINAPI ShowCursor16( BOOL16 bShow )
 {
     return ShowCursor32( bShow );
 }
@@ -980,20 +984,20 @@
 /***********************************************************************
  *           ShowCursor32    (USER32.529)
  */
-INT32 ShowCursor32( BOOL32 bShow )
+INT32 WINAPI ShowCursor32( BOOL32 bShow )
 {
     dprintf_cursor( stddeb, "ShowCursor: %d, count=%d\n",
                     bShow, CURSOR_ShowCount );
 
     if (bShow)
     {
-        if (++CURSOR_ShowCount == 0)
-            CURSORICON_SetCursor( hActiveCursor );  /* Show it */
+        if (++CURSOR_ShowCount == 0)  /* Show it */
+            CALL_LARGE_STACK( CURSORICON_SetCursor, hActiveCursor );
     }
     else
     {
-        if (--CURSOR_ShowCount == -1)
-            CURSORICON_SetCursor( 0 );  /* Hide it */
+        if (--CURSOR_ShowCount == -1)  /* Hide it */
+            CALL_LARGE_STACK( CURSORICON_SetCursor, 0 );
     }
     return CURSOR_ShowCount;
 }
@@ -1002,7 +1006,7 @@
 /***********************************************************************
  *           GetCursor16    (USER.247)
  */
-HCURSOR16 GetCursor16(void)
+HCURSOR16 WINAPI GetCursor16(void)
 {
     return hActiveCursor;
 }
@@ -1011,7 +1015,7 @@
 /***********************************************************************
  *           GetCursor32    (USER32.226)
  */
-HCURSOR32 GetCursor32(void)
+HCURSOR32 WINAPI GetCursor32(void)
 {
     return hActiveCursor;
 }
@@ -1020,7 +1024,7 @@
 /***********************************************************************
  *           ClipCursor16    (USER.16)
  */
-BOOL16 ClipCursor16( const RECT16 *rect )
+BOOL16 WINAPI ClipCursor16( const RECT16 *rect )
 {
     if (!rect) SetRectEmpty32( &CURSOR_ClipRect );
     else CONV_RECT16TO32( rect, &CURSOR_ClipRect );
@@ -1031,7 +1035,7 @@
 /***********************************************************************
  *           ClipCursor32    (USER32.52)
  */
-BOOL32 ClipCursor32( const RECT32 *rect )
+BOOL32 WINAPI ClipCursor32( const RECT32 *rect )
 {
     if (!rect) SetRectEmpty32( &CURSOR_ClipRect );
     else CopyRect32( &CURSOR_ClipRect, rect );
@@ -1042,7 +1046,7 @@
 /***********************************************************************
  *           GetCursorPos16    (USER.17)
  */
-void GetCursorPos16( POINT16 *pt )
+void WINAPI GetCursorPos16( POINT16 *pt )
 {
     Window root, child;
     int rootX, rootY, childX, childY;
@@ -1064,7 +1068,7 @@
 /***********************************************************************
  *           GetCursorPos32    (USER32.228)
  */
-void GetCursorPos32( POINT32 *pt )
+void WINAPI GetCursorPos32( POINT32 *pt )
 {
     POINT16 pt16;
     GetCursorPos16( &pt16 );
@@ -1075,7 +1079,7 @@
 /***********************************************************************
  *           GetClipCursor16    (USER.309)
  */
-void GetClipCursor16( RECT16 *rect )
+void WINAPI GetClipCursor16( RECT16 *rect )
 {
     if (rect) CONV_RECT32TO16( &CURSOR_ClipRect, rect );
 }
@@ -1084,7 +1088,7 @@
 /***********************************************************************
  *           GetClipCursor32    (USER32.220)
  */
-void GetClipCursor32( RECT32 *rect )
+void WINAPI GetClipCursor32( RECT32 *rect )
 {
     if (rect) CopyRect32( rect, &CURSOR_ClipRect );
 }
@@ -1093,7 +1097,7 @@
 /**********************************************************************
  *	    GetIconID    (USER.455)
  */
-WORD GetIconID( HGLOBAL16 hResource, DWORD resType )
+WORD WINAPI GetIconID( HGLOBAL16 hResource, DWORD resType )
 {
     CURSORICONDIR *lpDir = (CURSORICONDIR *)GlobalLock16(hResource);
 /* LockResource16(hResource); */
@@ -1132,7 +1136,7 @@
 /**********************************************************************
  *	    LoadIconHandler    (USER.456)
  */
-HICON16 LoadIconHandler( HGLOBAL16 hResource, BOOL16 bNew )
+HICON16 WINAPI LoadIconHandler( HGLOBAL16 hResource, BOOL16 bNew )
 {
     dprintf_cursor(stddeb,"LoadIconHandler: hRes=%04x\n",hResource);
 
diff --git a/objects/dc.c b/objects/dc.c
index 0210fc3..77d3996 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -141,7 +141,7 @@
     DC *dc;
 
     if (!(hdc = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return NULL;
-    dc = (DC *) GDI_HEAP_LIN_ADDR( hdc );
+    dc = (DC *) GDI_HEAP_LOCK( hdc );
 
     dc->hSelf      = hdc;
     dc->funcs      = funcs;
@@ -163,15 +163,17 @@
 }
 
 
+
 /***********************************************************************
  *           DC_GetDCPtr
  */
 DC *DC_GetDCPtr( HDC32 hdc )
 {
-    GDIOBJHDR *ptr = (GDIOBJHDR *)GDI_HEAP_LIN_ADDR( hdc );
+    GDIOBJHDR *ptr = (GDIOBJHDR *)GDI_HEAP_LOCK( hdc );
     if (!ptr) return NULL;
     if ((ptr->wMagic == DC_MAGIC) || (ptr->wMagic == METAFILE_DC_MAGIC))
         return (DC *)ptr;
+    GDI_HEAP_UNLOCK( hdc );
     return NULL;
 }
 
@@ -380,14 +382,18 @@
 /***********************************************************************
  *           GetDCState    (GDI.179)
  */
-HDC16 GetDCState( HDC16 hdc )
+HDC16 WINAPI GetDCState( HDC16 hdc )
 {
     DC * newdc, * dc;
     HGDIOBJ16 handle;
     
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
-    if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return 0;
-    newdc = (DC *) GDI_HEAP_LIN_ADDR( handle );
+    if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC )))
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      return 0;
+    }
+    newdc = (DC *) GDI_HEAP_LOCK( handle );
 
     dprintf_dc(stddeb, "GetDCState(%04x): returning %04x\n", hdc, handle );
 
@@ -446,6 +452,8 @@
     }
     else
 	newdc->w.hClipRgn = 0;
+    GDI_HEAP_UNLOCK( handle );
+    GDI_HEAP_UNLOCK( hdc );
     return handle;
 }
 
@@ -453,13 +461,22 @@
 /***********************************************************************
  *           SetDCState    (GDI.180)
  */
-void SetDCState( HDC16 hdc, HDC16 hdcs )
+void WINAPI SetDCState( HDC16 hdc, HDC16 hdcs )
 {
     DC *dc, *dcs;
     
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
-    if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
-    if (!dcs->w.flags & DC_SAVED) return;
+    if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      return;
+    }
+    if (!dcs->w.flags & DC_SAVED)
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      GDI_HEAP_UNLOCK( hdcs );
+      return;
+    }
     dprintf_dc(stddeb, "SetDCState: %04x %04x\n", hdc, hdcs );
 
     dc->w.flags           = dcs->w.flags & ~DC_SAVED;
@@ -506,13 +523,15 @@
     SelectObject32( hdc, dcs->w.hFont );
     SelectObject32( hdc, dcs->w.hPen );
     GDISelectPalette( hdc, dcs->w.hPalette, FALSE );
+    GDI_HEAP_UNLOCK( hdc );
+    GDI_HEAP_UNLOCK( hdcs );
 }
 
 
 /***********************************************************************
  *           SaveDC16    (GDI.30)
  */
-INT16 SaveDC16( HDC16 hdc )
+INT16 WINAPI SaveDC16( HDC16 hdc )
 {
     return (INT16)SaveDC32( hdc );
 }
@@ -521,10 +540,11 @@
 /***********************************************************************
  *           SaveDC32    (GDI32.292)
  */
-INT32 SaveDC32( HDC32 hdc )
+INT32 WINAPI SaveDC32( HDC32 hdc )
 {
     HDC32 hdcs;
     DC * dc, * dcs;
+    INT32 ret;
 
     dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
@@ -532,21 +552,29 @@
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return 0;
 	MF_MetaParam0(dc, META_SAVEDC);
+	GDI_HEAP_UNLOCK( hdc );
 	return 1;  /* ?? */
     }
-    if (!(hdcs = GetDCState( hdc ))) return 0;
-    dcs = (DC *) GDI_HEAP_LIN_ADDR( hdcs );
+    if (!(hdcs = GetDCState( hdc )))
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      return 0;
+    }
+    dcs = (DC *) GDI_HEAP_LOCK( hdcs );
     dcs->header.hNext = dc->header.hNext;
     dc->header.hNext = hdcs;
     dprintf_dc(stddeb, "SaveDC(%04x): returning %d\n", hdc, dc->saveLevel+1 );
-    return ++dc->saveLevel;
+    ret = ++dc->saveLevel;
+    GDI_HEAP_UNLOCK( hdcs );
+    GDI_HEAP_UNLOCK( hdc );
+    return ret;
 }
 
 
 /***********************************************************************
  *           RestoreDC16    (GDI.39)
  */
-BOOL16 RestoreDC16( HDC16 hdc, INT16 level )
+BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
 {
     return RestoreDC32( hdc, level );
 }
@@ -555,7 +583,7 @@
 /***********************************************************************
  *           RestoreDC32    (GDI32.290)
  */
-BOOL32 RestoreDC32( HDC32 hdc, INT32 level )
+BOOL32 WINAPI RestoreDC32( HDC32 hdc, INT32 level )
 {
     DC * dc, * dcs;
 
@@ -565,21 +593,35 @@
     {
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return FALSE;
-	if (level != -1) return FALSE;
+	if (level != -1) 
+	{
+	  GDI_HEAP_UNLOCK( hdc );
+	  return FALSE;
+	}
 	MF_MetaParam1(dc, META_RESTOREDC, level);
+	GDI_HEAP_UNLOCK( hdc );
 	return TRUE;
     }
     if (level == -1) level = dc->saveLevel;
-    if ((level < 1) || (level > dc->saveLevel)) return FALSE;
+    if ((level < 1) || (level > dc->saveLevel))
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      return FALSE;
+    }
     
     while (dc->saveLevel >= level)
     {
 	HDC16 hdcs = dc->header.hNext;
-	if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return FALSE;
+	if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
+	{
+	  GDI_HEAP_UNLOCK( hdc );
+	  return FALSE;
+	}	
 	dc->header.hNext = dcs->header.hNext;
 	if (--dc->saveLevel < level) SetDCState( hdc, hdcs );
 	DeleteDC32( hdcs );
     }
+    GDI_HEAP_UNLOCK( hdc );
     return TRUE;
 }
 
@@ -587,8 +629,8 @@
 /***********************************************************************
  *           CreateDC16    (GDI.53)
  */
-HDC16 CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
-                  const DEVMODE16 *initData )
+HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
+                         const DEVMODE16 *initData )
 {
     DC * dc;
     const DC_FUNCTIONS *funcs;
@@ -609,6 +651,7 @@
     }
 
     DC_InitDC( dc );
+    GDI_HEAP_UNLOCK( dc->hSelf );
     return dc->hSelf;
 }
 
@@ -616,8 +659,8 @@
 /***********************************************************************
  *           CreateDC32A    (GDI32.)
  */
-HDC32 CreateDC32A( LPCSTR driver, LPCSTR device, LPCSTR output,
-                   const DEVMODE32A *initData )
+HDC32 WINAPI CreateDC32A( LPCSTR driver, LPCSTR device, LPCSTR output,
+                          const DEVMODE32A *initData )
 {
     return CreateDC16( driver, device, output, (const DEVMODE16 *)initData );
 }
@@ -626,8 +669,8 @@
 /***********************************************************************
  *           CreateDC32W    (GDI32.)
  */
-HDC32 CreateDC32W( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
-                   const DEVMODE32W *initData )
+HDC32 WINAPI CreateDC32W( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
+                          const DEVMODE32W *initData )
 { 
     LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
     LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
@@ -644,8 +687,8 @@
 /***********************************************************************
  *           CreateIC16    (GDI.153)
  */
-HDC16 CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
-                  const DEVMODE16* initData )
+HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
+                         const DEVMODE16* initData )
 {
       /* Nothing special yet for ICs */
     return CreateDC16( driver, device, output, initData );
@@ -655,8 +698,8 @@
 /***********************************************************************
  *           CreateIC32A    (GDI32.49)
  */
-HDC32 CreateIC32A( LPCSTR driver, LPCSTR device, LPCSTR output,
-                   const DEVMODE32A* initData )
+HDC32 WINAPI CreateIC32A( LPCSTR driver, LPCSTR device, LPCSTR output,
+                          const DEVMODE32A* initData )
 {
       /* Nothing special yet for ICs */
     return CreateDC32A( driver, device, output, initData );
@@ -666,8 +709,8 @@
 /***********************************************************************
  *           CreateIC32W    (GDI32.50)
  */
-HDC32 CreateIC32W( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
-                   const DEVMODE32W* initData )
+HDC32 WINAPI CreateIC32W( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
+                          const DEVMODE32W* initData )
 {
       /* Nothing special yet for ICs */
     return CreateDC32W( driver, device, output, initData );
@@ -677,7 +720,7 @@
 /***********************************************************************
  *           CreateCompatibleDC16    (GDI.52)
  */
-HDC16 CreateCompatibleDC16( HDC16 hdc )
+HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
 {
     return (HDC16)CreateCompatibleDC32( hdc );
 }
@@ -686,7 +729,7 @@
 /***********************************************************************
  *           CreateCompatibleDC32   (GDI32.31)
  */
-HDC32 CreateCompatibleDC32( HDC32 hdc )
+HDC32 WINAPI CreateCompatibleDC32( HDC32 hdc )
 {
     DC *dc, *origDC;
     HBITMAP32 hbitmap;
@@ -722,6 +765,7 @@
     }
 
     DC_InitDC( dc );
+    GDI_HEAP_UNLOCK( dc->hSelf );
     return dc->hSelf;
 }
 
@@ -729,7 +773,7 @@
 /***********************************************************************
  *           DeleteDC16    (GDI.68)
  */
-BOOL16 DeleteDC16( HDC16 hdc )
+BOOL16 WINAPI DeleteDC16( HDC16 hdc )
 {
     return DeleteDC32( hdc );
 }
@@ -738,7 +782,7 @@
 /***********************************************************************
  *           DeleteDC32    (GDI32.67)
  */
-BOOL32 DeleteDC32( HDC32 hdc )
+BOOL32 WINAPI DeleteDC32( HDC32 hdc )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return FALSE;
@@ -775,7 +819,7 @@
 /***********************************************************************
  *           ResetDC16    (GDI.376)
  */
-HDC16 ResetDC16( HDC16 hdc, const DEVMODE16 *devmode )
+HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODE16 *devmode )
 {
     fprintf( stderr, "ResetDC16: empty stub!\n" );
     return hdc;
@@ -785,7 +829,7 @@
 /***********************************************************************
  *           ResetDC32A    (GDI32.287)
  */
-HDC32 ResetDC32A( HDC32 hdc, const DEVMODE32A *devmode )
+HDC32 WINAPI ResetDC32A( HDC32 hdc, const DEVMODE32A *devmode )
 {
     fprintf( stderr, "ResetDC32A: empty stub!\n" );
     return hdc;
@@ -795,7 +839,7 @@
 /***********************************************************************
  *           ResetDC32W    (GDI32.288)
  */
-HDC32 ResetDC32W( HDC32 hdc, const DEVMODE32W *devmode )
+HDC32 WINAPI ResetDC32W( HDC32 hdc, const DEVMODE32W *devmode )
 {
     fprintf( stderr, "ResetDC32A: empty stub!\n" );
     return hdc;
@@ -805,7 +849,7 @@
 /***********************************************************************
  *           GetDeviceCaps16    (GDI.80)
  */
-INT16 GetDeviceCaps16( HDC16 hdc, INT16 cap )
+INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
 {
     return GetDeviceCaps32( hdc, cap );
 }
@@ -814,23 +858,31 @@
 /***********************************************************************
  *           GetDeviceCaps32    (GDI32.171)
  */
-INT32 GetDeviceCaps32( HDC32 hdc, INT32 cap )
+INT32 WINAPI GetDeviceCaps32( HDC32 hdc, INT32 cap )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
+    INT32 ret;
+
     if (!dc) return 0;
 
-    if ((cap < 0) || (cap > sizeof(DeviceCaps)-sizeof(WORD))) return 0;
+    if ((cap < 0) || (cap > sizeof(DeviceCaps)-sizeof(WORD)))
+    {
+      GDI_HEAP_UNLOCK( hdc );
+      return 0;
+    }
     
     dprintf_dc(stddeb, "GetDeviceCaps(%04x,%d): returning %d\n",
 	    hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
-    return *(WORD *)(((char *)dc->w.devCaps) + cap);
+    ret = *(WORD *)(((char *)dc->w.devCaps) + cap);
+    GDI_HEAP_UNLOCK( hdc );
+    return ret;
 }
 
 
 /***********************************************************************
  *           SetBkColor16    (GDI.1)
  */
-COLORREF SetBkColor16( HDC16 hdc, COLORREF color )
+COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
 {
     return SetBkColor32( hdc, color );
 }
@@ -839,7 +891,7 @@
 /***********************************************************************
  *           SetBkColor32    (GDI32.305)
  */
-COLORREF SetBkColor32( HDC32 hdc, COLORREF color )
+COLORREF WINAPI SetBkColor32( HDC32 hdc, COLORREF color )
 {
     COLORREF oldColor;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -848,12 +900,14 @@
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return 0x80000000;
 	MF_MetaParam2(dc, META_SETBKCOLOR, HIWORD(color), LOWORD(color));
+	GDI_HEAP_UNLOCK( hdc );
 	return 0;  /* ?? */
     }
 
     oldColor = dc->w.backgroundColor;
     dc->w.backgroundColor = color;
     dc->w.backgroundPixel = COLOR_ToPhysical( dc, color );
+    GDI_HEAP_UNLOCK( hdc );
     return oldColor;
 }
 
@@ -861,7 +915,7 @@
 /***********************************************************************
  *           SetTextColor16    (GDI.9)
  */
-COLORREF SetTextColor16( HDC16 hdc, COLORREF color )
+COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
 {
     return SetTextColor32( hdc, color );
 }
@@ -870,7 +924,7 @@
 /***********************************************************************
  *           SetTextColor32    (GDI32.338)
  */
-COLORREF SetTextColor32( HDC32 hdc, COLORREF color )
+COLORREF WINAPI SetTextColor32( HDC32 hdc, COLORREF color )
 {
     COLORREF oldColor;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -879,12 +933,14 @@
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return 0x80000000;
 	MF_MetaParam2(dc, META_SETTEXTCOLOR, HIWORD(color), LOWORD(color));
+	GDI_HEAP_UNLOCK( hdc );
 	return 0;  /* ?? */
     }
 
     oldColor = dc->w.textColor;
     dc->w.textColor = color;
     dc->w.textPixel = COLOR_ToPhysical( dc, color );
+    GDI_HEAP_UNLOCK( hdc );
     return oldColor;
 }
 
@@ -892,7 +948,7 @@
 /***********************************************************************
  *           SetTextAlign16    (GDI.346)
  */
-UINT16 SetTextAlign16( HDC16 hdc, UINT16 textAlign )
+UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 textAlign )
 {
     return SetTextAlign32( hdc, textAlign );
 }
@@ -901,7 +957,7 @@
 /***********************************************************************
  *           SetTextAlign32    (GDI32.336)
  */
-UINT32 SetTextAlign32( HDC32 hdc, UINT32 textAlign )
+UINT32 WINAPI SetTextAlign32( HDC32 hdc, UINT32 textAlign )
 {
     UINT32 prevAlign;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -909,10 +965,12 @@
     {
 	if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ))) return 0;
 	MF_MetaParam1( dc, META_SETTEXTALIGN, textAlign );
+	GDI_HEAP_UNLOCK( hdc );
 	return 1;
     }
     prevAlign = dc->w.textAlign;
     dc->w.textAlign = textAlign;
+    GDI_HEAP_UNLOCK( hdc );
     return prevAlign;
 }
 
@@ -920,10 +978,11 @@
 /***********************************************************************
  *           GetDCOrgEx  (GDI32.168)
  */
-BOOL32 GetDCOrgEx( HDC32 hDC, LPPOINT32 lpp )
+BOOL32 WINAPI GetDCOrgEx( HDC32 hDC, LPPOINT32 lpp )
 {
-    DC * dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC );
-    if (!dc || !lpp) return FALSE;
+    DC * dc;
+    if (!lpp) return FALSE;
+    if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return FALSE;
 
     if (!(dc->w.flags & DC_MEMORY))
     {
@@ -935,6 +994,7 @@
     }
     else lpp->x = lpp->y = 0;
     lpp->x += dc->w.DCOrgX; lpp->y += dc->w.DCOrgY;
+    GDI_HEAP_UNLOCK( hDC );
     return TRUE;
 }
 
@@ -942,7 +1002,7 @@
 /***********************************************************************
  *           GetDCOrg    (GDI.79)
  */
-DWORD GetDCOrg( HDC16 hdc )
+DWORD WINAPI GetDCOrg( HDC16 hdc )
 {
     POINT32	pt;
     if( GetDCOrgEx( hdc, &pt) )
@@ -954,7 +1014,7 @@
 /***********************************************************************
  *           SetDCOrg    (GDI.117)
  */
-DWORD SetDCOrg( HDC16 hdc, INT16 x, INT16 y )
+DWORD WINAPI SetDCOrg( HDC16 hdc, INT16 x, INT16 y )
 {
     DWORD prevOrg;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -962,6 +1022,7 @@
     prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
     dc->w.DCOrgX = x;
     dc->w.DCOrgY = y;
+    GDI_HEAP_UNLOCK( hdc );
     return prevOrg;
 }
 
@@ -969,7 +1030,7 @@
 /***********************************************************************
  *           SetDCHook   (GDI.190)
  */
-BOOL16 SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
+BOOL16 WINAPI SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
 {
     DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
 
@@ -979,6 +1040,7 @@
     if (!dc) return FALSE;
     dc->hookProc = hookProc;
     dc->dwHookData = dwHookData;
+    GDI_HEAP_UNLOCK( hdc );
     return TRUE;
 }
 
@@ -986,11 +1048,12 @@
 /***********************************************************************
  *           GetDCHook   (GDI.191)
  */
-DWORD GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
+DWORD WINAPI GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
 {
     DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
     *phookProc = dc->hookProc;
+    GDI_HEAP_UNLOCK( hdc );
     return dc->dwHookData;
 }
 
@@ -998,7 +1061,7 @@
 /***********************************************************************
  *           SetHookFlags       (GDI.192)
  */
-WORD SetHookFlags(HDC16 hDC, WORD flags)
+WORD WINAPI SetHookFlags(HDC16 hDC, WORD flags)
 {
   DC* dc = (DC*)GDI_GetObjPtr( hDC, DC_MAGIC );
 
@@ -1016,6 +1079,7 @@
             dc->w.flags |= DC_DIRTY;
         else if( flags & DCHF_VALIDATEVISRGN || !flags )
             dc->w.flags &= ~DC_DIRTY;
+	GDI_HEAP_UNLOCK( hDC );
         return wRet;
     }
   return 0;
diff --git a/objects/dcvalues.c b/objects/dcvalues.c
index 9ea8221..df7de09 100644
--- a/objects/dcvalues.c
+++ b/objects/dcvalues.c
@@ -10,7 +10,7 @@
 
 
 #define DC_GET_VAL_16( func_type, func_name, dc_field ) \
-func_type func_name( HDC16 hdc ) \
+func_type WINAPI func_name( HDC16 hdc ) \
 { \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
     if (!dc) return 0; \
@@ -18,7 +18,7 @@
 }
 
 #define DC_GET_VAL_32( func_type, func_name, dc_field ) \
-func_type func_name( HDC32 hdc ) \
+func_type WINAPI func_name( HDC32 hdc ) \
 { \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
     if (!dc) return 0; \
@@ -26,7 +26,7 @@
 }
 
 #define DC_GET_X_Y( func_type, func_name, ret_x, ret_y ) \
-func_type func_name( HDC16 hdc ) \
+func_type WINAPI func_name( HDC16 hdc ) \
 { \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
     if (!dc) return 0; \
@@ -34,7 +34,7 @@
 }
 
 #define DC_GET_VAL_EX( func_name, ret_x, ret_y ) \
-BOOL16 func_name##16( HDC16 hdc, LPPOINT16 pt ) \
+BOOL16 WINAPI func_name##16( HDC16 hdc, LPPOINT16 pt ) \
 { \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
     if (!dc) return FALSE; \
@@ -43,7 +43,7 @@
     return TRUE; \
 } \
  \
-BOOL32 func_name##32( HDC32 hdc, LPPOINT32 pt ) \
+BOOL32 WINAPI func_name##32( HDC32 hdc, LPPOINT32 pt ) \
 { \
     DC * dc = (DC *) GDI_GetObjPtr( (HDC16)hdc, DC_MAGIC ); \
     if (!dc) return FALSE; \
@@ -53,7 +53,7 @@
 }
 
 #define DC_SET_MODE_16( func_name, dc_field, min_val, max_val, meta_func ) \
-INT16 func_name( HDC16 hdc, INT16 mode ) \
+INT16 WINAPI func_name( HDC16 hdc, INT16 mode ) \
 { \
     INT16 prevMode; \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
@@ -70,7 +70,7 @@
 }
 
 #define DC_SET_MODE_32( func_name, dc_field, min_val, max_val, meta_func ) \
-INT32 func_name( HDC32 hdc, INT32 mode ) \
+INT32 WINAPI func_name( HDC32 hdc, INT32 mode ) \
 { \
     INT32 prevMode; \
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); \
diff --git a/objects/dib.c b/objects/dib.c
index 433cf71..9746225 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -18,8 +18,31 @@
 
 extern void CLIPPING_UpdateGCRegion(DC* );
 
-static int	bitmapDepthTable[] = { 8, 1, 32, 16, 24, 15, 4, 0 };
-static int	ximageDepthTable[] = { 0, 0, 0,  0,  0,  0,  0 };
+static int bitmapDepthTable[] = { 8, 1, 32, 16, 24, 15, 4, 0 };
+static int ximageDepthTable[] = { 0, 0, 0,  0,  0,  0,  0 };
+
+
+/* This structure holds the arguments for DIB_SetImageBits() */
+typedef struct
+{
+    DC               *dc;
+    LPCVOID           bits;
+    DWORD             lines;
+    DWORD             infoWidth;
+    WORD              depth;
+    WORD              infoBpp;
+    const BITMAPINFO *info;
+    WORD              coloruse;
+    Drawable          drawable;
+    GC                gc;
+    int               xSrc;
+    int               ySrc;
+    int               xDest;
+    int               yDest;
+    int               width;
+    int               height;
+} DIB_SETIMAGEBITS_DESCR;
+
 
 /***********************************************************************
  *           DIB_Init
@@ -152,7 +175,7 @@
  * for a 24-bit deep bitmap.
  */
 static int *DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
-                               BITMAPINFO *info )
+                               const BITMAPINFO *info )
 {
     int i, colors;
     BOOL32 isInfo;
@@ -217,18 +240,20 @@
  *
  * SetDIBits for a 1-bit deep DIB.
  */
-static void DIB_SetImageBits_1( DWORD lines, BYTE *bits, DWORD width,
+static void DIB_SetImageBits_1( DWORD lines, const BYTE *srcbits,
+                                DWORD srcwidth, DWORD dstwidth,
                                 int *colors, XImage *bmpImage )
 {
     DWORD i, x;
-    BYTE pad, pix;
+    BYTE pix;
+    const BYTE *bits = srcbits;
 
-    if (!(width & 31)) pad = 0;
-    else pad = ((32 - (width & 31)) + 7) / 8;
+    /* 32 bit aligned */
+    DWORD linebytes = ((srcwidth + 31) & ~31) / 8;
 
     while (lines--)
     {
-	for (i = width/8, x = 0; (i > 0); i--)
+	for (i = dstwidth/8, x = 0; (i > 0); i--)
 	{
 	    pix = *bits++;
 	    XPutPixel( bmpImage, x++, lines, colors[pix >> 7] );
@@ -241,7 +266,7 @@
 	    XPutPixel( bmpImage, x++, lines, colors[pix & 1] );
 	}
 	pix = *bits;
-	switch(width & 7)
+	switch(dstwidth & 7)
 	{
 	case 7: XPutPixel( bmpImage, x++, lines, colors[pix >> 7] ); pix <<= 1;
 	case 6: XPutPixel( bmpImage, x++, lines, colors[pix >> 7] ); pix <<= 1;
@@ -251,7 +276,8 @@
 	case 2: XPutPixel( bmpImage, x++, lines, colors[pix >> 7] ); pix <<= 1;
 	case 1: XPutPixel( bmpImage, x++, lines, colors[pix >> 7] );
 	}
-	bits += pad;
+	srcbits += linebytes;
+	bits	 = srcbits;
     }
 }
 
@@ -261,25 +287,27 @@
  *
  * SetDIBits for a 4-bit deep DIB.
  */
-static void DIB_SetImageBits_4( DWORD lines, BYTE *bits, DWORD width,
+static void DIB_SetImageBits_4( DWORD lines, const BYTE *srcbits,
+                                DWORD srcwidth, DWORD dstwidth,
                                 int *colors, XImage *bmpImage )
 {
     DWORD i, x;
-    BYTE pad;
-
-    if (!(width & 7)) pad = 0;
-    else pad = ((8 - (width & 7)) + 1) / 2;
+    const BYTE *bits = srcbits;
+  
+    /* 32 bit aligned */
+    DWORD linebytes = ((srcwidth+7)&~7)/2;
 
     while (lines--)
     {
-	for (i = width/2, x = 0; i > 0; i--)
+	for (i = srcwidth/2, x = 0; i > 0; i--)
 	{
 	    BYTE pix = *bits++;
 	    XPutPixel( bmpImage, x++, lines, colors[pix >> 4] );
 	    XPutPixel( bmpImage, x++, lines, colors[pix & 0x0f] );
 	}
-	if (width & 1) XPutPixel( bmpImage, x, lines, colors[*bits >> 4] );
-	bits += pad;
+        if (srcwidth & 1) XPutPixel( bmpImage, x, lines, colors[*bits >> 4] );
+        srcbits += linebytes;
+        bits	 = srcbits;
     }
 }
 
@@ -295,11 +323,11 @@
  *
  * SetDIBits for a 4-bit deep compressed DIB.
  */
-static void DIB_SetImageBits_RLE4( DWORD lines, BYTE *bits, DWORD width,
-                                   int *colors, XImage *bmpImage )
+static void DIB_SetImageBits_RLE4( DWORD lines, const BYTE *bits, DWORD width,
+                                DWORD dstwidth, int *colors, XImage *bmpImage )
 {
 	int x = 0, c, length;
-	BYTE *begin = bits;
+	const BYTE *begin = bits;
 
         lines--;
 	while ((int)lines >= 0)
@@ -355,17 +383,22 @@
  *
  * SetDIBits for an 8-bit deep DIB.
  */
-static void DIB_SetImageBits_8( DWORD lines, BYTE *bits, DWORD width,
+static void DIB_SetImageBits_8( DWORD lines, const BYTE *srcbits,
+                                DWORD srcwidth, DWORD dstwidth,
                                 int *colors, XImage *bmpImage )
 {
     DWORD x;
-    BYTE pad = (4 - (width & 3)) & 3;
+    const BYTE *bits = srcbits;
+
+    /* align to 32 bit */
+    DWORD linebytes = (srcwidth + 3) & ~3;
 
     while (lines--)
     {
-	for (x = 0; x < width; x++)
+	for (x = 0; x < dstwidth; x++)
 	    XPutPixel( bmpImage, x, lines, colors[*bits++] );
-	bits += pad;
+        srcbits += linebytes;
+        bits     = srcbits;
     }
 }
 
@@ -400,12 +433,12 @@
   RleDelta	= 2		/* Delta */
 };
   
-static void DIB_SetImageBits_RLE8( DWORD lines, BYTE *bits, DWORD width,
-                                   int *colors, XImage *bmpImage )
+static void DIB_SetImageBits_RLE8( DWORD lines, const BYTE *bits, DWORD width,
+                                DWORD dstwidth, int *colors, XImage *bmpImage )
 {
     int x;			/* X-positon on each line.  Increases. */
     int line;			/* Line #.  Starts at lines-1, decreases */
-    BYTE *pIn = bits;		/* Pointer to current position in bits */
+    const BYTE *pIn = bits;     /* Pointer to current position in bits */
     BYTE length;		/* The length pf a run */
     BYTE color_index;		/* index into colors[] as read from bits */
     BYTE escape_code;		/* See enum Rle8_EscapeCodes.*/
@@ -553,21 +586,25 @@
  *
  * SetDIBits for a 24-bit deep DIB.
  */
-static void DIB_SetImageBits_24( DWORD lines, BYTE *bits, DWORD width,
+static void DIB_SetImageBits_24( DWORD lines, const BYTE *srcbits,
+                                 DWORD srcwidth, DWORD dstwidth,
 				 DC *dc, XImage *bmpImage )
 {
     DWORD x;
-    BYTE pad = (4 - ((width*3) & 3)) & 3;
+    const BYTE *bits = srcbits;
+  
+    /* align to 32 bit */
+    DWORD linebytes = (srcwidth * 3 + 3) & ~3;
 
     /* "bits" order is reversed for some reason */
 
     while (lines--)
     {
-	for (x = 0; x < width; x++, bits += 3)
+	for (x = 0; x < dstwidth; x++, bits += 3)
 	    XPutPixel( bmpImage, x, lines, 
 		       COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])) );
 
-	bits += pad;
+        bits = (srcbits += linebytes);
     }
 }
 
@@ -578,70 +615,68 @@
  * Transfer the bits to an X image.
  * Helper function for SetDIBits() and SetDIBitsToDevice().
  */
-static int DIB_SetImageBits( DC *dc, DWORD lines, WORD depth, LPSTR bits,
-                             DWORD infoWidth, WORD infoBpp,
-                             BITMAPINFO *info, WORD coloruse,
-			     Drawable drawable, GC gc, int xSrc, int ySrc,
-			     int xDest, int yDest, int width, int height )
+static int DIB_SetImageBits( const DIB_SETIMAGEBITS_DESCR *descr )
 {
     int *colorMapping;
     XImage *bmpImage;
     DWORD compression = 0;
 
-    if (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
-        compression = info->bmiHeader.biCompression;
+    if (descr->info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+        compression = descr->info->bmiHeader.biCompression;
 
       /* Build the color mapping table */
 
-    if (infoBpp > 8) {
-	    	colorMapping = NULL;
-    } else {
-        if (!(colorMapping = DIB_BuildColorMap( dc, coloruse, depth, info )))
-            return 0;
-    }
+    if (descr->infoBpp > 8) colorMapping = NULL;
+    else if (!(colorMapping = DIB_BuildColorMap( descr->dc, descr->coloruse,
+                                                 descr->depth, descr->info )))
+        return 0;
 
-    if( dc->w.flags & DC_DIRTY ) CLIPPING_UpdateGCRegion(dc);
+    if( descr->dc->w.flags & DC_DIRTY ) CLIPPING_UpdateGCRegion(descr->dc);
 
       /* Transfer the pixels */
-    XCREATEIMAGE(bmpImage, infoWidth, lines, depth );
+    XCREATEIMAGE(bmpImage, descr->infoWidth, descr->lines, descr->depth );
 
-    switch(infoBpp)
+    switch(descr->infoBpp)
     {
     case 1:
-	DIB_SetImageBits_1( lines, bits, infoWidth,
-			    colorMapping, bmpImage );
+	DIB_SetImageBits_1( descr->lines, descr->bits, descr->infoWidth,
+			    descr->width, colorMapping, bmpImage );
 	break;
     case 4:
-	if (compression) DIB_SetImageBits_RLE4( lines, bits, infoWidth,
+	if (compression) DIB_SetImageBits_RLE4( descr->lines, descr->bits,
+                                                descr->infoWidth, descr->width,
                                                 colorMapping, bmpImage );
-	else DIB_SetImageBits_4( lines, bits, infoWidth,
-                                 colorMapping, bmpImage );
+	else DIB_SetImageBits_4( descr->lines, descr->bits, descr->infoWidth,
+                                 descr->width, colorMapping, bmpImage );
 	break;
     case 8:
-	if (compression) DIB_SetImageBits_RLE8( lines, bits, infoWidth,
+	if (compression) DIB_SetImageBits_RLE8( descr->lines, descr->bits,
+                                                descr->infoWidth, descr->width,
                                                 colorMapping, bmpImage );
-	else DIB_SetImageBits_8( lines, bits, infoWidth,
-                                 colorMapping, bmpImage );
+	else DIB_SetImageBits_8( descr->lines, descr->bits, descr->infoWidth,
+                                 descr->width, colorMapping, bmpImage );
 	break;
     case 24:
-	DIB_SetImageBits_24( lines, bits, infoWidth, dc, bmpImage );
+	DIB_SetImageBits_24( descr->lines, descr->bits, descr->infoWidth,
+                             descr->width, descr->dc, bmpImage );
 	break;
     default:
-        fprintf( stderr, "Invalid depth %d for SetDIBits!\n", infoBpp );
+        fprintf( stderr, "Invalid depth %d for SetDIBits!\n", descr->infoBpp );
         break;
     }
     if (colorMapping) free(colorMapping);
-    XPutImage( display, drawable, gc, bmpImage, xSrc, ySrc,
-	       xDest, yDest, width, height );
+    XPutImage( display, descr->drawable, descr->gc, bmpImage,
+               descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
+               descr->width, descr->height );
     XDestroyImage( bmpImage );
-    return lines;
+    return descr->lines;
 }
 
 
 /***********************************************************************
  *           StretchDIBits16   (GDI.439)
  */
-INT16 StretchDIBits16( HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
+INT16 WINAPI StretchDIBits16(HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
                        INT16 heightDst, INT16 xSrc, INT16 ySrc, INT16 widthSrc,
                        INT16 heightSrc, const VOID *bits,
                        const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop )
@@ -655,7 +690,7 @@
 /***********************************************************************
  *           StretchDIBits32   (GDI32.351)
  */
-INT32 StretchDIBits32( HDC32 hdc, INT32 xDst, INT32 yDst, INT32 widthDst,
+INT32 WINAPI StretchDIBits32(HDC32 hdc, INT32 xDst, INT32 yDst, INT32 widthDst,
                        INT32 heightDst, INT32 xSrc, INT32 ySrc, INT32 widthSrc,
                        INT32 heightSrc, const void *bits,
                        const BITMAPINFO *info, UINT32 wUsage, DWORD dwRop )
@@ -679,9 +714,9 @@
 /***********************************************************************
  *           SetDIBits16    (GDI.440)
  */
-INT16 SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
-                   UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
-                   UINT16 coloruse )
+INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
+                          UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
+                          UINT16 coloruse )
 {
     return SetDIBits32( hdc, hbitmap, startscan, lines, bits, info, coloruse );
 }
@@ -690,43 +725,68 @@
 /***********************************************************************
  *           SetDIBits32   (GDI32.312)
  */
-INT32 SetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
-                   UINT32 lines, LPCVOID bits, const BITMAPINFO *info,
-                   UINT32 coloruse )
+INT32 WINAPI SetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
+                          UINT32 lines, LPCVOID bits, const BITMAPINFO *info,
+                          UINT32 coloruse )
 {
-    DC * dc;
+    DIB_SETIMAGEBITS_DESCR descr;
     BITMAPOBJ * bmp;
-    DWORD width, height;
-    WORD bpp;
+    DWORD height;
+    INT32 result;
 
       /* Check parameters */
 
-    dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
-    if (!dc) 
+    descr.dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
+    if (!descr.dc) 
     {
-	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
-	if (!dc) return 0;
+	descr.dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
+	if (!descr.dc) return 0;
     }
     if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
-	return 0;
-    if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &bpp ) == -1)
+    {
+        GDI_HEAP_UNLOCK( hdc );
         return 0;
-    if (!lines || (startscan >= (WORD)height)) return 0;
+    }
+    if (DIB_GetBitmapInfo( &info->bmiHeader, &descr.infoWidth, &height,
+                           &descr.infoBpp ) == -1)
+    {
+        GDI_HEAP_UNLOCK( hbitmap );
+        GDI_HEAP_UNLOCK( hdc );
+        return 0;
+    }
+    if (!lines || (startscan >= height))
+    {
+        GDI_HEAP_UNLOCK( hbitmap );
+        GDI_HEAP_UNLOCK( hdc );
+        return 0;
+    }
     if (startscan + lines > height) lines = height - startscan;
 
-    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 16,
-                                dc, lines, bmp->bitmap.bmBitsPixel,
-                                bits, width, bpp, info,
-                                coloruse, bmp->pixmap, BITMAP_GC(bmp), 0, 0, 0,
-                                height - startscan - lines,
-                                bmp->bitmap.bmWidth, lines );
+    descr.bits      = bits;
+    descr.lines     = lines;
+    descr.depth     = bmp->bitmap.bmBitsPixel;
+    descr.info      = info;
+    descr.coloruse  = coloruse;
+    descr.drawable  = bmp->pixmap;
+    descr.gc        = BITMAP_GC(bmp);
+    descr.xSrc      = 0;
+    descr.ySrc      = 0;
+    descr.xDest     = 0;
+    descr.yDest     = height - startscan - lines;
+    descr.width     = bmp->bitmap.bmWidth;
+    descr.height    = lines;
+
+    result = CALL_LARGE_STACK( DIB_SetImageBits, &descr );
+    GDI_HEAP_UNLOCK( hdc );
+    GDI_HEAP_UNLOCK( hbitmap );
+    return result;
 }
 
 
 /***********************************************************************
  *           SetDIBitsToDevice16    (GDI.443)
  */
-INT16 SetDIBitsToDevice16( HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx,
+INT16 WINAPI SetDIBitsToDevice16(HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx,
                            INT16 cy, INT16 xSrc, INT16 ySrc, UINT16 startscan,
                            UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
                            UINT16 coloruse )
@@ -739,14 +799,14 @@
 /***********************************************************************
  *           SetDIBitsToDevice32   (GDI32.313)
  */
-INT32 SetDIBitsToDevice32( HDC32 hdc, INT32 xDest, INT32 yDest, DWORD cx,
+INT32 WINAPI SetDIBitsToDevice32(HDC32 hdc, INT32 xDest, INT32 yDest, DWORD cx,
                            DWORD cy, INT32 xSrc, INT32 ySrc, UINT32 startscan,
                            UINT32 lines, LPCVOID bits, const BITMAPINFO *info,
                            UINT32 coloruse )
 {
+    DIB_SETIMAGEBITS_DESCR descr;
     DC * dc;
     DWORD width, height;
-    WORD bpp;
 
       /* Check parameters */
 
@@ -756,7 +816,8 @@
 	dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
 	if (!dc) return 0;
     }
-    if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &bpp ) == -1)
+    if (DIB_GetBitmapInfo( &info->bmiHeader, &width,
+                           &height, &descr.infoBpp ) == -1)
         return 0;
     if (!lines || (startscan >= height)) return 0;
     if (startscan + lines > height) lines = height - startscan;
@@ -769,14 +830,24 @@
 
     DC_SetupGCForText( dc );  /* To have the correct colors */
     XSetFunction( display, dc->u.x.gc, DC_XROPfunction[dc->w.ROPmode-1] );
-    return CallTo32_LargeStack( (int(*)())DIB_SetImageBits, 16,
-                                dc, lines, dc->w.bitsPerPixel, bits, width,
-                                bpp, info, coloruse,
-                                dc->u.x.drawable, dc->u.x.gc,
-                                xSrc, ySrc - startscan,
-                                dc->w.DCOrgX + XLPTODP( dc, xDest ),
-                                dc->w.DCOrgY + YLPTODP( dc, yDest ),
-                                cx, cy );
+
+    descr.dc        = dc;
+    descr.bits      = bits;
+    descr.lines     = lines;
+    descr.infoWidth = width;
+    descr.depth     = dc->w.bitsPerPixel;
+    descr.info      = info;
+    descr.coloruse  = coloruse;
+    descr.drawable  = dc->u.x.drawable;
+    descr.gc        = dc->u.x.gc;
+    descr.xSrc      = xSrc;
+    descr.ySrc      = ySrc - startscan;
+    descr.xDest     = dc->w.DCOrgX + XLPTODP( dc, xDest );
+    descr.yDest     = dc->w.DCOrgY + YLPTODP( dc, yDest );
+    descr.width     = cx;
+    descr.height    = cy;
+
+    return CALL_LARGE_STACK( DIB_SetImageBits, &descr );
 }
 
 
@@ -784,9 +855,9 @@
 /***********************************************************************
  *           GetDIBits16    (GDI.441)
  */
-INT16 GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
-                   UINT16 lines, LPSTR bits, BITMAPINFO * info,
-                   UINT16 coloruse )
+INT16 WINAPI GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
+                          UINT16 lines, LPSTR bits, BITMAPINFO * info,
+                          UINT16 coloruse )
 {
     return GetDIBits32( hdc, hbitmap, startscan, lines, bits, info, coloruse );
 }
@@ -797,9 +868,9 @@
  *
  * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/func/src/f30_14.htm
  */
-INT32 GetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
-                   UINT32 lines, LPSTR bits, BITMAPINFO * info,
-                   UINT32 coloruse )
+INT32 WINAPI GetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
+                          UINT32 lines, LPSTR bits, BITMAPINFO * info,
+                          UINT32 coloruse )
 {
     DC * dc;
     BITMAPOBJ * bmp;
@@ -818,7 +889,10 @@
     if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
 	return 0;
     if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC )))
-	return 0;
+    {
+        GDI_HEAP_UNLOCK( hbitmap );
+        return 0;
+    }
 
       /* Transfer color info */
     
@@ -851,7 +925,11 @@
 	if( lines > info->bmiHeader.biHeight ) lines = info->bmiHeader.biHeight;
 	yend = startscan + lines;
 	if( startscan >= bmp->bitmap.bmHeight ) 
-	    return FALSE;
+        {
+            GDI_HEAP_UNLOCK( hbitmap );
+            GDI_HEAP_UNLOCK( dc->w.hPalette );
+            return FALSE;
+        }
 	if( yend > bmp->bitmap.bmHeight ) yend = bmp->bitmap.bmHeight;
 
 	/* adjust scanline width */
@@ -861,12 +939,11 @@
 	{
 	    /* bitmap is wider than DIB, copy only a part */
 
-	    pad = 0; xend = info->bmiHeader.biWidth;
+	    pad = 0;
+            xend = info->bmiHeader.biWidth;
 	}
 
-	bmpImage = (XImage *)CallTo32_LargeStack( (int (*)())XGetImage, 8, 
-		               display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
-		               bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
+	bmpImage = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
 
 	switch( info->bmiHeader.biBitCount )
 	{
@@ -965,6 +1042,8 @@
 	info->bmiHeader.biCompression = 0;
     }
 
+    GDI_HEAP_UNLOCK( hbitmap );
+    GDI_HEAP_UNLOCK( dc->w.hPalette );
     return lines;
 }
 
@@ -972,7 +1051,7 @@
 /***********************************************************************
  *           CreateDIBitmap16    (GDI.442)
  */
-HBITMAP16 CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header,
+HBITMAP16 WINAPI CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header,
                             DWORD init, LPCVOID bits, const BITMAPINFO * data,
                             UINT16 coloruse )
 {
@@ -983,7 +1062,7 @@
 /***********************************************************************
  *           CreateDIBitmap32    (GDI32.37)
  */
-HBITMAP32 CreateDIBitmap32( HDC32 hdc, const BITMAPINFOHEADER *header,
+HBITMAP32 WINAPI CreateDIBitmap32( HDC32 hdc, const BITMAPINFOHEADER *header,
                             DWORD init, LPCVOID bits, const BITMAPINFO *data,
                             UINT32 coloruse )
 {
diff --git a/objects/font.c b/objects/font.c
index 75dcf63..216962f 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -177,7 +177,7 @@
 /***********************************************************************
  *           CreateFontIndirect16   (GDI.57)
  */
-HFONT16 CreateFontIndirect16( const LOGFONT16 *font )
+HFONT16 WINAPI CreateFontIndirect16( const LOGFONT16 *font )
 {
     HFONT16 hFont = 0;
 
@@ -187,7 +187,7 @@
 	if( hFont )
 	{
 	    FONTOBJ* fontPtr;
-	    fontPtr = (FONTOBJ *) GDI_HEAP_LIN_ADDR( hFont );
+	    fontPtr = (FONTOBJ *) GDI_HEAP_LOCK( hFont );
 	    memcpy( &fontPtr->logfont, font, sizeof(LOGFONT16) );
 
 	    dprintf_font(stddeb,"CreateFontIndirect(%i %i) '%s' %s %s => %04x\n",
@@ -196,6 +196,7 @@
 				 font->lfWeight > 400 ? "Bold" : "",
 				 font->lfItalic ? "Italic" : "",
 				 hFont);
+	    GDI_HEAP_UNLOCK( hFont );
 	}
     }
     else fprintf(stderr,"CreateFontIndirect(NULL) => NULL\n");
@@ -206,7 +207,7 @@
 /***********************************************************************
  *           CreateFontIndirect32A   (GDI32.44)
  */
-HFONT32 CreateFontIndirect32A( const LOGFONT32A *font )
+HFONT32 WINAPI CreateFontIndirect32A( const LOGFONT32A *font )
 {
     LOGFONT16 font16;
 
@@ -217,7 +218,7 @@
 /***********************************************************************
  *           CreateFontIndirect32W   (GDI32.45)
  */
-HFONT32 CreateFontIndirect32W( const LOGFONT32W *font )
+HFONT32 WINAPI CreateFontIndirect32W( const LOGFONT32W *font )
 {
     LOGFONT16 font16;
 
@@ -228,10 +229,11 @@
 /***********************************************************************
  *           CreateFont16    (GDI.56)
  */
-HFONT16 CreateFont16( INT16 height, INT16 width, INT16 esc, INT16 orient,
-                      INT16 weight, BYTE italic, BYTE underline,
-                      BYTE strikeout, BYTE charset, BYTE outpres,
-                      BYTE clippres, BYTE quality, BYTE pitch, LPCSTR name )
+HFONT16 WINAPI CreateFont16(INT16 height, INT16 width, INT16 esc, INT16 orient,
+                            INT16 weight, BYTE italic, BYTE underline,
+                            BYTE strikeout, BYTE charset, BYTE outpres,
+                            BYTE clippres, BYTE quality, BYTE pitch,
+                            LPCSTR name )
 {
     LOGFONT16 logfont = { height, width, esc, orient, weight, italic, underline,
                           strikeout, charset, outpres, clippres, quality, pitch, };
@@ -247,10 +249,11 @@
 /*************************************************************************
  *           CreateFont32A    (GDI32.43)
  */
-HFONT32 CreateFont32A( INT32 height, INT32 width, INT32 esc, INT32 orient,
-                       INT32 weight, DWORD italic, DWORD underline,
-                       DWORD strikeout, DWORD charset, DWORD outpres,
-                       DWORD clippres, DWORD quality, DWORD pitch, LPCSTR name)
+HFONT32 WINAPI CreateFont32A( INT32 height, INT32 width, INT32 esc,
+                              INT32 orient, INT32 weight, DWORD italic,
+                              DWORD underline, DWORD strikeout, DWORD charset,
+                              DWORD outpres, DWORD clippres, DWORD quality,
+                              DWORD pitch, LPCSTR name )
 {
     return (HFONT32)CreateFont16( height, width, esc, orient, weight, italic,
                                   underline, strikeout, charset, outpres,
@@ -260,11 +263,11 @@
 /*************************************************************************
  *           CreateFont32W    (GDI32.46)
  */
-HFONT32 CreateFont32W( INT32 height, INT32 width, INT32 esc, INT32 orient,
-                       INT32 weight, DWORD italic, DWORD underline,
-                       DWORD strikeout, DWORD charset, DWORD outpres,
-                       DWORD clippres, DWORD quality, DWORD pitch,
-                       LPCWSTR name )
+HFONT32 WINAPI CreateFont32W( INT32 height, INT32 width, INT32 esc,
+                              INT32 orient, INT32 weight, DWORD italic,
+                              DWORD underline, DWORD strikeout, DWORD charset,
+                              DWORD outpres, DWORD clippres, DWORD quality,
+                              DWORD pitch, LPCWSTR name )
 {
     LPSTR namea = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     HFONT32 ret = (HFONT32)CreateFont16( height, width, esc, orient, weight,
@@ -358,7 +361,9 @@
 /***********************************************************************
  *              EnumFontFamiliesEx16	(GDI.613)
  */
-INT16 EnumFontFamiliesEx16( HDC16 hDC, LPLOGFONT16 plf, FONTENUMPROCEX16 efproc, LPARAM lParam, DWORD dwFlags)
+INT16 WINAPI EnumFontFamiliesEx16( HDC16 hDC, LPLOGFONT16 plf,
+                                   FONTENUMPROCEX16 efproc, LPARAM lParam,
+                                   DWORD dwFlags)
 {
     INT16	retVal = 0;
     DC* 	dc = (DC*) GDI_GetObjPtr( hDC, DC_MAGIC );
@@ -419,8 +424,9 @@
 /***********************************************************************
  *              EnumFontFamiliesEx32W	(GDI32.82)
  */
-INT32 EnumFontFamiliesEx32W( HDC32 hDC, LPLOGFONT32W plf, FONTENUMPROCEX32W efproc, 
-					LPARAM lParam, DWORD dwFlags )
+INT32 WINAPI EnumFontFamiliesEx32W( HDC32 hDC, LPLOGFONT32W plf,
+                                    FONTENUMPROCEX32W efproc, 
+                                    LPARAM lParam, DWORD dwFlags )
 {
     return  FONT_EnumFontFamiliesEx32( hDC, plf, (FONTENUMPROC32W)efproc, 
 						  lParam, ENUM_UNICODE );
@@ -429,8 +435,9 @@
 /***********************************************************************
  *              EnumFontFamiliesEx32A	(GDI32.81)
  */
-INT32 EnumFontFamiliesEx32A( HDC32 hDC, LPLOGFONT32A plf, FONTENUMPROCEX32A efproc, 
-					LPARAM lParam, DWORD dwFlags)
+INT32 WINAPI EnumFontFamiliesEx32A( HDC32 hDC, LPLOGFONT32A plf,
+                                    FONTENUMPROCEX32A efproc, 
+                                    LPARAM lParam, DWORD dwFlags)
 {
     return  FONT_EnumFontFamiliesEx32( hDC, (LPLOGFONT32W)plf, 
 				      (FONTENUMPROC32W)efproc, lParam, 0);
@@ -439,7 +446,8 @@
 /***********************************************************************
  *              EnumFontFamilies16	(GDI.330)
  */
-INT16 EnumFontFamilies16( HDC16 hDC, LPCSTR lpFamily, FONTENUMPROC16 efproc, LPARAM lpData )
+INT16 WINAPI EnumFontFamilies16( HDC16 hDC, LPCSTR lpFamily,
+                                 FONTENUMPROC16 efproc, LPARAM lpData )
 {
     LOGFONT16	lf;
 
@@ -453,7 +461,8 @@
 /***********************************************************************
  *              EnumFontFamilies32A	(GDI32.80)
  */
-INT32 EnumFontFamilies32A( HDC32 hDC, LPCSTR lpFamily, FONTENUMPROC32A efproc, LPARAM lpData )
+INT32 WINAPI EnumFontFamilies32A( HDC32 hDC, LPCSTR lpFamily,
+                                  FONTENUMPROC32A efproc, LPARAM lpData )
 {
     LOGFONT32A	lf;
 
@@ -468,7 +477,8 @@
 /***********************************************************************
  *              EnumFontFamilies32W	(GDI32.83)
  */
-INT32 EnumFontFamilies32W( HDC32 hDC, LPCWSTR lpFamily, FONTENUMPROC32W efproc, LPARAM lpData )
+INT32 WINAPI EnumFontFamilies32W( HDC32 hDC, LPCWSTR lpFamily,
+                                  FONTENUMPROC32W efproc, LPARAM lpData )
 {
     LOGFONT32W  lf;
 
@@ -482,7 +492,8 @@
 /***********************************************************************
  *              EnumFonts16		(GDI.70)
  */
-INT16 EnumFonts16( HDC16 hDC, LPCSTR lpName, FONTENUMPROC16 efproc, LPARAM lpData )
+INT16 WINAPI EnumFonts16( HDC16 hDC, LPCSTR lpName, FONTENUMPROC16 efproc,
+                          LPARAM lpData )
 {
     return EnumFontFamilies16( hDC, lpName, (FONTENUMPROCEX16)efproc, lpData );
 }
@@ -490,7 +501,8 @@
 /***********************************************************************
  *              EnumFonts32A		(GDI32.84)
  */
-INT32 EnumFonts32A( HDC32 hDC, LPCSTR lpName, FONTENUMPROC32A efproc, LPARAM lpData )
+INT32 WINAPI EnumFonts32A( HDC32 hDC, LPCSTR lpName, FONTENUMPROC32A efproc,
+                           LPARAM lpData )
 {
     return EnumFontFamilies32A( hDC, lpName, efproc, lpData );
 }
@@ -498,7 +510,8 @@
 /***********************************************************************
  *              EnumFonts32W		(GDI32.85)
  */
-INT32 EnumFonts32W( HDC32 hDC, LPCWSTR lpName, FONTENUMPROC32W efproc, LPARAM lpData )
+INT32 WINAPI EnumFonts32W( HDC32 hDC, LPCWSTR lpName, FONTENUMPROC32W efproc,
+                           LPARAM lpData )
 {
     return EnumFontFamilies32W( hDC, lpName, efproc, lpData );
 }
@@ -507,7 +520,7 @@
 /***********************************************************************
  *           GetTextCharacterExtra16    (GDI.89)
  */
-INT16 GetTextCharacterExtra16( HDC16 hdc )
+INT16 WINAPI GetTextCharacterExtra16( HDC16 hdc )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
@@ -519,7 +532,7 @@
 /***********************************************************************
  *           GetTextCharacterExtra32    (GDI32.225)
  */
-INT32 GetTextCharacterExtra32( HDC32 hdc )
+INT32 WINAPI GetTextCharacterExtra32( HDC32 hdc )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
@@ -531,7 +544,7 @@
 /***********************************************************************
  *           SetTextCharacterExtra16    (GDI.8)
  */
-INT16 SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
+INT16 WINAPI SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
 {
     return (INT16)SetTextCharacterExtra32( hdc, extra );
 }
@@ -540,7 +553,7 @@
 /***********************************************************************
  *           SetTextCharacterExtra32    (GDI32.337)
  */
-INT32 SetTextCharacterExtra32( HDC32 hdc, INT32 extra )
+INT32 WINAPI SetTextCharacterExtra32( HDC32 hdc, INT32 extra )
 {
     INT32 prev;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -555,7 +568,7 @@
 /***********************************************************************
  *           SetTextJustification16    (GDI.10)
  */
-INT16 SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
+INT16 WINAPI SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
 {
     return SetTextJustification32( hdc, extra, breaks );
 }
@@ -564,7 +577,7 @@
 /***********************************************************************
  *           SetTextJustification32    (GDI32.339)
  */
-BOOL32 SetTextJustification32( HDC32 hdc, INT32 extra, INT32 breaks )
+BOOL32 WINAPI SetTextJustification32( HDC32 hdc, INT32 extra, INT32 breaks )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return 0;
@@ -590,7 +603,7 @@
 /***********************************************************************
  *           GetTextFace16    (GDI.92)
  */
-INT16 GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
+INT16 WINAPI GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
 {
         return GetTextFace32A(hdc,count,name);
 }
@@ -598,7 +611,7 @@
 /***********************************************************************
  *           GetTextFace32A    (GDI32.234)
  */
-INT32 GetTextFace32A( HDC32 hdc, INT32 count, LPSTR name )
+INT32 WINAPI GetTextFace32A( HDC32 hdc, INT32 count, LPSTR name )
 {
     FONTOBJ *font;
 
@@ -607,13 +620,14 @@
     if (!(font = (FONTOBJ *) GDI_GetObjPtr( dc->w.hFont, FONT_MAGIC )))
         return 0;
     lstrcpyn32A( name, font->logfont.lfFaceName, count );
+    GDI_HEAP_UNLOCK( dc->w.hFont );
     return strlen(name);
 }
 
 /***********************************************************************
  *           GetTextFace32W    (GDI32.235)
  */
-INT32 GetTextFace32W( HDC32 hdc, INT32 count, LPWSTR name )
+INT32 WINAPI GetTextFace32W( HDC32 hdc, INT32 count, LPWSTR name )
 {
     LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, count );
     INT32 res = GetTextFace32A(hdc,count,nameA);
@@ -626,7 +640,7 @@
 /***********************************************************************
  *           GetTextExtent    (GDI.91)
  */
-DWORD GetTextExtent( HDC16 hdc, LPCSTR str, INT16 count )
+DWORD WINAPI GetTextExtent( HDC16 hdc, LPCSTR str, INT16 count )
 {
     SIZE16 size;
     if (!GetTextExtentPoint16( hdc, str, count, &size )) return 0;
@@ -641,7 +655,8 @@
  * Original Windows versions of GetTextExtentPoint{A,W} have documented
  * bugs.
  */
-BOOL16 GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count, LPSIZE16 size)
+BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count,
+                                    LPSIZE16 size )
 {
     SIZE32 size32;
     BOOL32 ret = GetTextExtentPoint32A( hdc, str, count, &size32 );
@@ -653,8 +668,8 @@
 /***********************************************************************
  *           GetTextExtentPoint32A    (GDI32.230)
  */
-BOOL32 GetTextExtentPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
-                              LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
+                                     LPSIZE32 size )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc)
@@ -676,8 +691,8 @@
 /***********************************************************************
  *           GetTextExtentPoint32W    (GDI32.231)
  */
-BOOL32 GetTextExtentPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
-                              LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
+                                     LPSIZE32 size )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
     BOOL32 ret = GetTextExtentPoint32A( hdc, p, count, size );
@@ -689,8 +704,8 @@
 /***********************************************************************
  *           GetTextExtentPoint32ABuggy    (GDI32.232)
  */
-BOOL32 GetTextExtentPoint32ABuggy( HDC32 hdc, LPCSTR str, INT32 count,
-                                   LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentPoint32ABuggy( HDC32 hdc, LPCSTR str, INT32 count,
+                                          LPSIZE32 size )
 {
     dprintf_font( stddeb, "GetTextExtentPoint32ABuggy: not bug compatible.\n");
     return GetTextExtentPoint32A( hdc, str, count, size );
@@ -699,8 +714,8 @@
 /***********************************************************************
  *           GetTextExtentPoint32WBuggy    (GDI32.233)
  */
-BOOL32 GetTextExtentPoint32WBuggy( HDC32 hdc, LPCWSTR str, INT32 count,
-                                   LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentPoint32WBuggy( HDC32 hdc, LPCWSTR str, INT32 count,
+                                          LPSIZE32 size )
 {
     dprintf_font( stddeb, "GetTextExtentPoint32WBuggy: not bug compatible.\n");
     return GetTextExtentPoint32W( hdc, str, count, size );
@@ -710,9 +725,9 @@
 /***********************************************************************
  *           GetTextExtentExPoint32A    (GDI32.228)
  */
-BOOL32 GetTextExtentExPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
-                                INT32 maxExt,LPINT32 lpnFit, LPINT32 alpDx,
-                                LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentExPoint32A( HDC32 hdc, LPCSTR str, INT32 count,
+                                       INT32 maxExt, LPINT32 lpnFit,
+                                       LPINT32 alpDx, LPSIZE32 size )
 {
     int index, nFit, extent;
     SIZE32 tSize;
@@ -752,9 +767,9 @@
  *           GetTextExtentExPoint32W    (GDI32.229)
  */
 
-BOOL32 GetTextExtentExPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
-                                INT32 maxExt, LPINT32 lpnFit, LPINT32 alpDx,
-                                LPSIZE32 size )
+BOOL32 WINAPI GetTextExtentExPoint32W( HDC32 hdc, LPCWSTR str, INT32 count,
+                                       INT32 maxExt, LPINT32 lpnFit,
+                                       LPINT32 alpDx, LPSIZE32 size )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
     BOOL32 ret = GetTextExtentExPoint32A( hdc, p, count, maxExt,
@@ -766,7 +781,7 @@
 /***********************************************************************
  *           GetTextMetrics16    (GDI.93)
  */
-BOOL16 GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *metrics )
+BOOL16 WINAPI GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *metrics )
 {
     TEXTMETRIC32A tm32;
 
@@ -779,7 +794,7 @@
 /***********************************************************************
  *           GetTextMetrics32A    (GDI32.236)
  */
-BOOL32 GetTextMetrics32A( HDC32 hdc, TEXTMETRIC32A *metrics )
+BOOL32 WINAPI GetTextMetrics32A( HDC32 hdc, TEXTMETRIC32A *metrics )
 {
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc)
@@ -791,8 +806,26 @@
     if (!dc->funcs->pGetTextMetrics ||
         !dc->funcs->pGetTextMetrics( dc,metrics ))
         return FALSE;
+    /* map them from device to logic coordinatesystem before returning.
+     * FIXME: should this be in the device driver?
+     */
+#define WDPTOLP(x) ((x<0)?					\
+		(-abs((x)*dc->wndExtX/dc->vportExtX)):		\
+		(abs((x)*dc->wndExtX/dc->vportExtX)))
+#define HDPTOLP(y) ((y<0)?					\
+		(-abs((y)*dc->wndExtY/dc->vportExtY)):		\
+		(abs((y)*dc->wndExtY/dc->vportExtY)))
+	
+    metrics->tmHeight           = HDPTOLP(metrics->tmHeight);
+    metrics->tmAscent           = HDPTOLP(metrics->tmAscent);
+    metrics->tmDescent          = HDPTOLP(metrics->tmDescent);
+    metrics->tmInternalLeading  = HDPTOLP(metrics->tmInternalLeading);
+    metrics->tmExternalLeading  = HDPTOLP(metrics->tmExternalLeading);
+    metrics->tmAveCharWidth     = WDPTOLP(metrics->tmAveCharWidth);
+    metrics->tmMaxCharWidth     = WDPTOLP(metrics->tmMaxCharWidth);
+    metrics->tmOverhang         = WDPTOLP(metrics->tmOverhang);
 
-    dprintf_font(stdnimp,"text metrics:
+    dprintf_font(stddeb,"text metrics:
     Weight = %03i\t FirstChar = %03i\t AveCharWidth = %i
     Italic = % 3i\t LastChar = %03i\t\t MaxCharWidth = %i
     UnderLined = %01i\t DefaultChar = %03i\t Overhang = %i
@@ -819,7 +852,7 @@
 /***********************************************************************
  *           GetTextMetrics32W    (GDI32.237)
  */
-BOOL32 GetTextMetrics32W( HDC32 hdc, TEXTMETRIC32W *metrics )
+BOOL32 WINAPI GetTextMetrics32W( HDC32 hdc, TEXTMETRIC32W *metrics )
 {
     TEXTMETRIC32A tm;
     if (!GetTextMetrics32A( (HDC16)hdc, &tm )) return FALSE;
@@ -831,8 +864,8 @@
 /***********************************************************************
  *           GetCharWidth16    (GDI.350)
  */
-BOOL16 GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
-                       LPINT16 buffer )
+BOOL16 WINAPI GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
+                              LPINT16 buffer )
 {
     BOOL32	retVal = FALSE;
 
@@ -867,8 +900,8 @@
 /***********************************************************************
  *           GetCharWidth32A    (GDI32.155)
  */
-BOOL32 GetCharWidth32A( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
-                        LPINT32 buffer )
+BOOL32 WINAPI GetCharWidth32A( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
+                               LPINT32 buffer )
 {
     UINT32 i, extra;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -895,8 +928,8 @@
 /***********************************************************************
  *           GetCharWidth32W    (GDI32.158)
  */
-BOOL32 GetCharWidth32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
-                        LPINT32 buffer )
+BOOL32 WINAPI GetCharWidth32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
+                               LPINT32 buffer )
 {
     return GetCharWidth32A( hdc, firstChar, lastChar, buffer );
 }
@@ -908,7 +941,7 @@
  *
  *           SetMapperFlags16    (GDI.349)
  */
-DWORD SetMapperFlags16( HDC16 hDC, DWORD dwFlag )
+DWORD WINAPI SetMapperFlags16( HDC16 hDC, DWORD dwFlag )
 {
     return SetMapperFlags32( hDC, dwFlag );
 }
@@ -917,19 +950,30 @@
 /***********************************************************************
  *           SetMapperFlags32    (GDI32.322)
  */
-DWORD SetMapperFlags32( HDC32 hDC, DWORD dwFlag )
+DWORD WINAPI SetMapperFlags32( HDC32 hDC, DWORD dwFlag )
 {
     dprintf_font(stdnimp,"SetmapperFlags(%04x, %08lX) // Empty Stub !\n",
                  hDC, dwFlag);
     return 0L;
 }
 
+/***********************************************************************
+ *          GetAspectRatioFilterEx16  (GDI.486)
+ */
+BOOL16 GetAspectRatioFilterEx16( HDC16 hdc, LPVOID pAspectRatio )
+{
+  dprintf_font(stdnimp, 
+      "GetAspectRatioFilterEx(%04x, %p): // Empty Stub !\n",
+	       hdc, pAspectRatio);
+  return FALSE;
+}
+
 
 /***********************************************************************
  *           GetCharABCWidths16   (GDI.307)
  */
-BOOL16 GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
-                           LPABC16 abc )
+BOOL16 WINAPI GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar,
+                                  LPABC16 abc )
 {
     ABC32 abc32;
     if (!GetCharABCWidths32A( hdc, firstChar, lastChar, &abc32 )) return FALSE;
@@ -943,8 +987,8 @@
 /***********************************************************************
  *           GetCharABCWidths32A   (GDI32.149)
  */
-BOOL32 GetCharABCWidths32A( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
-                            LPABC32 abc )
+BOOL32 WINAPI GetCharABCWidths32A(HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
+                                  LPABC32 abc )
 {
     /* No TrueType fonts in Wine so far */
     fprintf( stdnimp, "STUB: GetCharABCWidths(%04x,%04x,%04x,%p)\n",
@@ -956,8 +1000,8 @@
 /***********************************************************************
  *           GetCharABCWidths32W   (GDI32.152)
  */
-BOOL32 GetCharABCWidths32W( HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
-                            LPABC32 abc )
+BOOL32 WINAPI GetCharABCWidths32W(HDC32 hdc, UINT32 firstChar, UINT32 lastChar,
+                                  LPABC32 abc )
 {
     return GetCharABCWidths32A( hdc, firstChar, lastChar, abc );
 }
@@ -966,9 +1010,9 @@
 /***********************************************************************
  *           GetGlyphOutline16    (GDI.309)
  */
-DWORD GetGlyphOutline16( HDC16 hdc, UINT16 uChar, UINT16 fuFormat,
-                         LPGLYPHMETRICS16 lpgm, DWORD cbBuffer,
-                         LPVOID lpBuffer, const MAT2 *lpmat2 )
+DWORD WINAPI GetGlyphOutline16( HDC16 hdc, UINT16 uChar, UINT16 fuFormat,
+                                LPGLYPHMETRICS16 lpgm, DWORD cbBuffer,
+                                LPVOID lpBuffer, const MAT2 *lpmat2 )
 {
     fprintf( stdnimp,"GetGlyphOutLine16(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
              hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
@@ -979,9 +1023,9 @@
 /***********************************************************************
  *           GetGlyphOutline32A    (GDI32.186)
  */
-DWORD GetGlyphOutline32A( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
-                         LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
-                         LPVOID lpBuffer, const MAT2 *lpmat2 )
+DWORD WINAPI GetGlyphOutline32A( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
+                                 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
+                                 LPVOID lpBuffer, const MAT2 *lpmat2 )
 {
     fprintf( stdnimp,"GetGlyphOutLine32A(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
              hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
@@ -991,9 +1035,9 @@
 /***********************************************************************
  *           GetGlyphOutline32W    (GDI32.187)
  */
-DWORD GetGlyphOutline32W( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
-                         LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
-                         LPVOID lpBuffer, const MAT2 *lpmat2 )
+DWORD WINAPI GetGlyphOutline32W( HDC32 hdc, UINT32 uChar, UINT32 fuFormat,
+                                 LPGLYPHMETRICS32 lpgm, DWORD cbBuffer,
+                                 LPVOID lpBuffer, const MAT2 *lpmat2 )
 {
     fprintf( stdnimp,"GetGlyphOutLine32W(%04x, '%c', %04x, %p, %ld, %p, %p) // - empty stub!\n",
              hdc, uChar, fuFormat, lpgm, cbBuffer, lpBuffer, lpmat2 );
@@ -1003,8 +1047,9 @@
 /***********************************************************************
  *           CreateScalableFontResource16   (GDI.310)
  */
-BOOL16 CreateScalableFontResource16( UINT16 fHidden, LPCSTR lpszResourceFile,
-                                     LPCSTR fontFile, LPCSTR path )
+BOOL16 WINAPI CreateScalableFontResource16( UINT16 fHidden,
+                                            LPCSTR lpszResourceFile,
+                                            LPCSTR fontFile, LPCSTR path )
 {
     return CreateScalableFontResource32A( fHidden, lpszResourceFile,
                                           fontFile, path );
@@ -1013,9 +1058,10 @@
 /***********************************************************************
  *           CreateScalableFontResource32A   (GDI32.62)
  */
-BOOL32 CreateScalableFontResource32A( DWORD fHidden, LPCSTR lpszResourceFile,
-                                      LPCSTR lpszFontFile,
-                                      LPCSTR lpszCurrentPath )
+BOOL32 WINAPI CreateScalableFontResource32A( DWORD fHidden,
+                                             LPCSTR lpszResourceFile,
+                                             LPCSTR lpszFontFile,
+                                             LPCSTR lpszCurrentPath )
 {
     /* fHidden=1 - only visible for the calling app, read-only, not
      * enumbered with EnumFonts/EnumFontFamilies
@@ -1029,9 +1075,10 @@
 /***********************************************************************
  *           CreateScalableFontResource32W   (GDI32.63)
  */
-BOOL32 CreateScalableFontResource32W( DWORD fHidden, LPCWSTR lpszResourceFile,
-                                      LPCWSTR lpszFontFile,
-                                      LPCWSTR lpszCurrentPath )
+BOOL32 WINAPI CreateScalableFontResource32W( DWORD fHidden,
+                                             LPCWSTR lpszResourceFile,
+                                             LPCWSTR lpszFontFile,
+                                             LPCWSTR lpszCurrentPath )
 {
     fprintf(stdnimp,"CreateScalableFontResource32W(%ld,%p,%p,%p) // empty stub\n",
             fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath );
@@ -1042,7 +1089,7 @@
 /*************************************************************************
  *             GetRasterizerCaps16   (GDI.313)
  */
-BOOL16 GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes )
+BOOL16 WINAPI GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes)
 {
     return GetRasterizerCaps32( lprs, cbNumBytes );
 }
@@ -1051,7 +1098,7 @@
 /*************************************************************************
  *             GetRasterizerCaps32   (GDI32.216)
  */
-BOOL32 GetRasterizerCaps32( LPRASTERIZER_STATUS lprs, UINT32 cbNumBytes )
+BOOL32 WINAPI GetRasterizerCaps32( LPRASTERIZER_STATUS lprs, UINT32 cbNumBytes)
 {
   RASTERIZER_STATUS rs;
 
@@ -1065,8 +1112,8 @@
 /*************************************************************************
  *             GetKerningPairs16   (GDI.332)
  */
-INT16 GetKerningPairs16( HDC16 hDC, INT16 cPairs,
-                         LPKERNINGPAIR16 lpKerningPairs )
+INT16 WINAPI GetKerningPairs16( HDC16 hDC, INT16 cPairs,
+                                LPKERNINGPAIR16 lpKerningPairs )
 {
     /* At this time kerning is ignored (set to 0) */
     int i;
@@ -1080,8 +1127,8 @@
 /*************************************************************************
  *             GetKerningPairs32A   (GDI32.192)
  */
-DWORD GetKerningPairs32A( HDC32 hDC, DWORD cPairs,
-                          LPKERNINGPAIR32 lpKerningPairs )
+DWORD WINAPI GetKerningPairs32A( HDC32 hDC, DWORD cPairs,
+                                 LPKERNINGPAIR32 lpKerningPairs )
 {
     int i;
     fprintf(stdnimp,"GetKerningPairs32: almost empty stub!\n");
@@ -1093,9 +1140,16 @@
 /*************************************************************************
  *             GetKerningPairs32W   (GDI32.193)
  */
-DWORD GetKerningPairs32W( HDC32 hDC, DWORD cPairs,
-                          LPKERNINGPAIR32 lpKerningPairs )
+DWORD WINAPI GetKerningPairs32W( HDC32 hDC, DWORD cPairs,
+                                 LPKERNINGPAIR32 lpKerningPairs )
 {
     return GetKerningPairs32A( hDC, cPairs, lpKerningPairs );
 }
 
+BOOL32 WINAPI TranslateCharSetInfo(LPDWORD lpSrc,LPCHARSETINFO lpCs,DWORD dwFlags) {
+    fprintf(stderr,"TranslateCharSetInfo(%p,%p,0x%08lx), stub.\n",
+    	lpSrc,lpCs,dwFlags
+    );
+    return TRUE;
+}
+
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index 3d59435..6c80245 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -231,11 +231,13 @@
     {
 	/* Create default palette */
 
+      /* DR well *this* palette can't be moveable (?) */
+
 	HPALETTE16 hpalette = PALETTE_Init();
 
 	if( hpalette )
 	{
-	    StockObjects[DEFAULT_PALETTE] = (GDIOBJHDR *)GDI_HEAP_LIN_ADDR( hpalette );
+	    StockObjects[DEFAULT_PALETTE] = (GDIOBJHDR *)GDI_HEAP_LOCK( hpalette );
 	    return TRUE;
 	}
     }
@@ -250,12 +252,17 @@
 {
     static DWORD count = 0;
     GDIOBJHDR * obj;
-    HGDIOBJ16 handle = GDI_HEAP_ALLOC( size );
+    HGDIOBJ16 handle;
+    if ( magic == DC_MAGIC || magic == METAFILE_DC_MAGIC )
+      handle = GDI_HEAP_ALLOC( size );
+    else 
+      handle = GDI_HEAP_ALLOC_MOVEABLE( size );
     if (!handle) return 0;
-    obj = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    obj = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     obj->hNext   = 0;
     obj->wMagic  = magic;
     obj->dwCount = ++count;
+    GDI_HEAP_UNLOCK( handle );
     return handle;
 }
 
@@ -271,10 +278,10 @@
     if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
         return TRUE;
     
-    object = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     if (!object) return FALSE;
     object->wMagic = 0;  /* Mark it as invalid */
-
+ 
       /* Free object */
     
     GDI_HEAP_FREE( handle );
@@ -286,6 +293,8 @@
  *
  * Return a pointer to the GDI object associated to the handle.
  * Return NULL if the object has the wrong magic number.
+ * Movable GDI objects are locked in memory: it is up to the caller to unlock
+ * it after the caller is done with the pointer.
  */
 GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16 handle, WORD magic )
 {
@@ -294,9 +303,13 @@
     if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
       ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
     else 
-      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+      ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     if (!ptr) return NULL;
-    if ((magic != MAGIC_DONTCARE) && (ptr->wMagic != magic)) return NULL;
+    if ((magic != MAGIC_DONTCARE) && (ptr->wMagic != magic)) 
+    {
+      GDI_HEAP_UNLOCK( handle );
+      return NULL;
+    }
     return ptr;
 }
 
@@ -304,7 +317,7 @@
 /***********************************************************************
  *           DeleteObject16    (GDI.69)
  */
-BOOL16 DeleteObject16( HGDIOBJ16 obj )
+BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
 {
     return DeleteObject32( obj );
 }
@@ -313,12 +326,15 @@
 /***********************************************************************
  *           DeleteObject32    (GDI32.70)
  */
-BOOL32 DeleteObject32( HGDIOBJ32 obj )
+BOOL32 WINAPI DeleteObject32( HGDIOBJ32 obj )
 {
       /* Check if object is valid */
 
-    GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( obj );
-    if (!header || HIWORD(obj)) return FALSE;
+    GDIOBJHDR * header;
+    if (HIWORD(obj)) return FALSE;
+    if ((obj >= FIRST_STOCK_HANDLE) && (obj <= LAST_STOCK_HANDLE))
+        return TRUE;
+    if (!(header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj ))) return FALSE;
 
     dprintf_gdi(stddeb, "DeleteObject: %04x\n", obj );
 
@@ -340,7 +356,7 @@
 /***********************************************************************
  *           GetStockObject16    (GDI.87)
  */
-HGDIOBJ16 GetStockObject16( INT16 obj )
+HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
 {
     return (HGDIOBJ16)GetStockObject32( obj );
 }
@@ -349,7 +365,7 @@
 /***********************************************************************
  *           GetStockObject32    (GDI32.220)
  */
-HGDIOBJ32 GetStockObject32( INT32 obj )
+HGDIOBJ32 WINAPI GetStockObject32( INT32 obj )
 {
     if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
     if (!StockObjects[obj]) return 0;
@@ -362,73 +378,86 @@
 /***********************************************************************
  *           GetObject16    (GDI.82)
  */
-INT16 GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
+INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
 {
     GDIOBJHDR * ptr = NULL;
+    INT16 result = 0;
     dprintf_gdi(stddeb, "GetObject16: %04x %d %p\n", handle, count, buffer );
     if (!count) return 0;
 
     if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
       ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
     else
-      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+      ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     if (!ptr) return 0;
     
     switch(ptr->wMagic)
-    {
+      {
       case PEN_MAGIC:
-	  return PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
+	result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
+	break;
       case BRUSH_MAGIC: 
-	  return BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
+	result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
+	break;
       case BITMAP_MAGIC: 
-	  return BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
+	result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
+	break;
       case FONT_MAGIC:
-	  return FONT_GetObject16( (FONTOBJ *)ptr, count, buffer );
+	result = FONT_GetObject16( (FONTOBJ *)ptr, count, buffer );
+	break;
       case PALETTE_MAGIC:
-	  return PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
-    }
-    return 0;
+	result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
+	break;
+      }
+    GDI_HEAP_UNLOCK( handle );
+    return result;
 }
 
 
 /***********************************************************************
  *           GetObject32A    (GDI32.204)
  */
-INT32 GetObject32A( HANDLE32 handle, INT32 count, LPVOID buffer )
+INT32 WINAPI GetObject32A( HANDLE32 handle, INT32 count, LPVOID buffer )
 {
     GDIOBJHDR * ptr = NULL;
+    INT32 result = 0;
     dprintf_gdi(stddeb, "GetObject32A: %08x %d %p\n", handle, count, buffer );
     if (!count) return 0;
 
     if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
       ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
     else
-      ptr = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+      ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     if (!ptr) return 0;
     
     switch(ptr->wMagic)
     {
       case PEN_MAGIC:
-	  return PEN_GetObject32( (PENOBJ *)ptr, count, buffer );
+	  result = PEN_GetObject32( (PENOBJ *)ptr, count, buffer );
+	  break;
       case BRUSH_MAGIC: 
-	  return BRUSH_GetObject32( (BRUSHOBJ *)ptr, count, buffer );
+	  result = BRUSH_GetObject32( (BRUSHOBJ *)ptr, count, buffer );
+	  break;
       case BITMAP_MAGIC: 
-	  return BITMAP_GetObject32( (BITMAPOBJ *)ptr, count, buffer );
+	  result = BITMAP_GetObject32( (BITMAPOBJ *)ptr, count, buffer );
+	  break;
       case FONT_MAGIC:
-	  return FONT_GetObject32A( (FONTOBJ *)ptr, count, buffer );
+	  result = FONT_GetObject32A( (FONTOBJ *)ptr, count, buffer );
+	  break;
       case PALETTE_MAGIC:
           fprintf( stderr, "GetObject32: magic %04x not implemented\n",
                    ptr->wMagic );
           break;
     }
-    return 0;
+    GDI_HEAP_UNLOCK( handle );
+    return result;
 }
 
 
 /***********************************************************************
  *           GetObject32W    (GDI32.206)
  */
-INT32 GetObject32W( HANDLE32 handle, INT32 count, LPVOID buffer )
+INT32 WINAPI GetObject32W( HANDLE32 handle, INT32 count, LPVOID buffer )
 {
     return GetObject32A( handle, count, buffer );
 }
@@ -437,7 +466,7 @@
 /***********************************************************************
  *           SelectObject16    (GDI.45)
  */
-HGDIOBJ16 SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
+HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
 {
     return (HGDIOBJ16)SelectObject32( hdc, handle );
 }
@@ -446,7 +475,7 @@
 /***********************************************************************
  *           SelectObject32    (GDI32.299)
  */
-HGDIOBJ32 SelectObject32( HDC32 hdc, HGDIOBJ32 handle )
+HGDIOBJ32 WINAPI SelectObject32( HDC32 hdc, HGDIOBJ32 handle )
 {
     DC * dc = DC_GetDCPtr( hdc );
     if (!dc || !dc->funcs->pSelectObject) return 0;
@@ -458,7 +487,7 @@
 /***********************************************************************
  *           UnrealizeObject16    (GDI.150)
  */
-BOOL16 UnrealizeObject16( HGDIOBJ16 obj )
+BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
 {
     return UnrealizeObject32( obj );
 }
@@ -467,11 +496,12 @@
 /***********************************************************************
  *           UnrealizeObject    (GDI32.358)
  */
-BOOL32 UnrealizeObject32( HGDIOBJ32 obj )
+BOOL32 WINAPI UnrealizeObject32( HGDIOBJ32 obj )
 {
-      /* Check if object is valid */
+    BOOL32 result = TRUE;
+  /* Check if object is valid */
 
-    GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( obj );
+    GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj );
     if (!header) return FALSE;
 
     dprintf_gdi( stddeb, "UnrealizeObject: %04x\n", obj );
@@ -481,21 +511,23 @@
     switch(header->wMagic)
     {
     case PALETTE_MAGIC: 
-        return PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
+        result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
+	break;
 
     case BRUSH_MAGIC:
         /* Windows resets the brush origin. We don't need to. */
         break;
     }
-    return TRUE;
+    GDI_HEAP_UNLOCK( obj );
+    return result;
 }
 
 
 /***********************************************************************
  *           EnumObjects16    (GDI.71)
  */
-INT16 EnumObjects16( HDC16 hdc, INT16 nObjType, GOBJENUMPROC16 lpEnumFunc,
-                     LPARAM lParam )
+INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
+                            GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
 {
     /* Solid colors to enumerate */
     static const COLORREF solid_colors[] =
@@ -573,8 +605,8 @@
 /***********************************************************************
  *           EnumObjects32    (GDI32.89)
  */
-INT32 EnumObjects32( HDC32 hdc, INT32 nObjType, GOBJENUMPROC32 lpEnumFunc,
-                     LPARAM lParam )
+INT32 WINAPI EnumObjects32( HDC32 hdc, INT32 nObjType,
+                            GOBJENUMPROC32 lpEnumFunc, LPARAM lParam )
 {
     /* Solid colors to enumerate */
     static const COLORREF solid_colors[] =
@@ -648,12 +680,19 @@
 
 /***********************************************************************
  *           IsGDIObject    (GDI.462)
+ * 
+ * returns type of object if valid (W95 system programming secrets p. 264-5)
  */
-BOOL16 IsGDIObject( HGDIOBJ16 handle )
+BOOL16 WINAPI IsGDIObject( HGDIOBJ16 handle )
 {
-    GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LIN_ADDR( handle );
+    GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
     if (object)
-      return (object->wMagic>=PEN_MAGIC && object->wMagic<= METAFILE_DC_MAGIC);
+    {
+        UINT16 magic = object->wMagic;
+        GDI_HEAP_UNLOCK( handle );
+        if (magic >= PEN_MAGIC && magic <= METAFILE_DC_MAGIC)
+            return magic - PEN_MAGIC + 1;
+    }
     return FALSE;
 }
 
@@ -661,7 +700,7 @@
 /***********************************************************************
  *           MulDiv16   (GDI.128)
  */
-INT16 MulDiv16( INT16 foo, INT16 bar, INT16 baz )
+INT16 WINAPI MulDiv16( INT16 foo, INT16 bar, INT16 baz )
 {
     INT32 ret;
     if (!baz) return -32768;
@@ -674,7 +713,7 @@
 /***********************************************************************
  *           MulDiv32   (KERNEL32.391)
  */
-INT32 MulDiv32( INT32 foo, INT32 bar, INT32 baz )
+INT32 WINAPI MulDiv32( INT32 foo, INT32 bar, INT32 baz )
 {
 #ifdef __GNUC__
     long long ret;
diff --git a/objects/linedda.c b/objects/linedda.c
index d0cf871..7297860 100644
--- a/objects/linedda.c
+++ b/objects/linedda.c
@@ -11,8 +11,8 @@
 /**********************************************************************
  *           LineDDA16   (GDI.100)
  */
-void LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd, INT16 nYEnd,
-                LINEDDAPROC16 callback, LPARAM lParam )
+void WINAPI LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd, INT16 nYEnd,
+                       LINEDDAPROC16 callback, LPARAM lParam )
 {
     LineDDA32( nXStart, nYStart, nXEnd, nYEnd,
                (LINEDDAPROC32)callback, lParam );
@@ -22,8 +22,8 @@
 /**********************************************************************
  *           LineDDA32   (GDI32.248)
  */
-BOOL32 LineDDA32( INT32 nXStart, INT32 nYStart, INT32 nXEnd, INT32 nYEnd,
-                  LINEDDAPROC32 callback, LPARAM lParam )
+BOOL32 WINAPI LineDDA32(INT32 nXStart, INT32 nYStart, INT32 nXEnd, INT32 nYEnd,
+                        LINEDDAPROC32 callback, LPARAM lParam )
 {
     INT32 xadd = 1, yadd = 1;
     INT32 err,erradd;
diff --git a/objects/metafile.c b/objects/metafile.c
index 87e0b34..ad8622a 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -57,7 +57,7 @@
 /******************************************************************
  *         GetMetafile16   (GDI.124)
  */
-HMETAFILE16 GetMetaFile16( LPCSTR lpFilename )
+HMETAFILE16 WINAPI GetMetaFile16( LPCSTR lpFilename )
 {
     return GetMetaFile32A( lpFilename );
 }
@@ -66,7 +66,7 @@
 /******************************************************************
  *         GetMetafile32A   (GDI32.197)
  */
-HMETAFILE32 GetMetaFile32A( LPCSTR lpFilename )
+HMETAFILE32 WINAPI GetMetaFile32A( LPCSTR lpFilename )
 {
   HMETAFILE16 hmf;
   METAHEADER *mh;
@@ -137,7 +137,7 @@
 /******************************************************************
  *         GetMetafile32W   (GDI32.199)
  */
-HMETAFILE32 GetMetaFile32W( LPCWSTR lpFilename )
+HMETAFILE32 WINAPI GetMetaFile32W( LPCWSTR lpFilename )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFilename );
     HMETAFILE32 ret = GetMetaFile32A( p );
@@ -150,7 +150,7 @@
  *         CopyMetaFile16   (GDI.151)
  */
 
-HMETAFILE16 CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename )
+HMETAFILE16 WINAPI CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename )
 {
     return CopyMetaFile32A( hSrcMetaFile, lpFilename );
 }
@@ -159,7 +159,7 @@
 /******************************************************************
  *         CopyMetaFile32A   (GDI32.23)
  */
-HMETAFILE32 CopyMetaFile32A( HMETAFILE32 hSrcMetaFile, LPCSTR lpFilename )
+HMETAFILE32 WINAPI CopyMetaFile32A(HMETAFILE32 hSrcMetaFile, LPCSTR lpFilename)
 {
     HMETAFILE16 handle = 0;
     METAHEADER *mh;
@@ -201,7 +201,8 @@
 /******************************************************************
  *         CopyMetaFile32W   (GDI32.24)
  */
-HMETAFILE32 CopyMetaFile32W( HMETAFILE32 hSrcMetaFile, LPCWSTR lpFilename )
+HMETAFILE32 WINAPI CopyMetaFile32W( HMETAFILE32 hSrcMetaFile,
+                                    LPCWSTR lpFilename )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFilename );
     HMETAFILE32 ret = CopyMetaFile32A( hSrcMetaFile, p );
@@ -215,7 +216,7 @@
  *         (This is not exactly what windows does, see "Undoc Win")
  */
 
-BOOL16 IsValidMetaFile(HMETAFILE16 hmf)
+BOOL16 WINAPI IsValidMetaFile(HMETAFILE16 hmf)
 {
     BOOL16 resu=FALSE;
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
@@ -234,7 +235,7 @@
 /******************************************************************
  *         PlayMetafile16   (GDI.123)
  */
-BOOL16 PlayMetaFile16( HDC16 hdc, HMETAFILE16 hmf )
+BOOL16 WINAPI PlayMetaFile16( HDC16 hdc, HMETAFILE16 hmf )
 {
     return PlayMetaFile32( hdc, hmf );
 }
@@ -243,7 +244,7 @@
 /******************************************************************
  *         PlayMetafile32   (GDI32.265)
  */
-BOOL32 PlayMetaFile32( HDC32 hdc, HMETAFILE32 hmf )
+BOOL32 WINAPI PlayMetaFile32( HDC32 hdc, HMETAFILE32 hmf )
 {
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
     METARECORD *mr;
@@ -262,7 +263,7 @@
     hPen = dc->w.hPen;
     hBrush = dc->w.hBrush;
     hFont = dc->w.hFont;
-
+    GDI_HEAP_UNLOCK(hdc);
     /* create the handle table */
     hHT = GlobalAlloc16(GMEM_MOVEABLE|GMEM_ZEROINIT,
 		      sizeof(HANDLETABLE16) * mh->mtNoObjects);
@@ -299,8 +300,8 @@
  *            EnumMetaFile16   (GDI.175)
  *                                    Niels de carpentier, april 1996
  */
-BOOL16 EnumMetaFile16( HDC16 hdc, HMETAFILE16 hmf, MFENUMPROC16 lpEnumFunc,
-                       LPARAM lpData )
+BOOL16 WINAPI EnumMetaFile16( HDC16 hdc, HMETAFILE16 hmf,
+                              MFENUMPROC16 lpEnumFunc, LPARAM lpData )
 {
     METAHEADER *mh = (METAHEADER *)GlobalLock16(hmf);
     METARECORD *mr;
@@ -321,7 +322,8 @@
     hPen = dc->w.hPen;
     hBrush = dc->w.hBrush;
     hFont = dc->w.hFont;
-   
+    GDI_HEAP_UNLOCK(hdc);
+
     /* create the handle table */
     
     hHT = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT,
@@ -365,8 +367,8 @@
 /******************************************************************
  *             PlayMetaFileRecord16   (GDI.176)
  */
-void PlayMetaFileRecord16( HDC16 hdc, HANDLETABLE16 *ht, METARECORD *mr,
-                           UINT16 nHandles )
+void WINAPI PlayMetaFileRecord16( HDC16 hdc, HANDLETABLE16 *ht, METARECORD *mr,
+                                  UINT16 nHandles )
 {
     short s1;
     HANDLE16 hndl;
@@ -818,7 +820,7 @@
  * Trade in a meta file object handle for a handle to the meta file memory
  */
 
-HGLOBAL16 GetMetaFileBits(HMETAFILE16 hmf)
+HGLOBAL16 WINAPI GetMetaFileBits(HMETAFILE16 hmf)
 {
     dprintf_metafile(stddeb,"GetMetaFileBits: hMem out: %04x\n", hmf);
 
@@ -830,7 +832,7 @@
  *
  * Trade in a meta file memory handle for a handle to a meta file object
  */
-HMETAFILE16 SetMetaFileBits( HGLOBAL16 hMem )
+HMETAFILE16 WINAPI SetMetaFileBits( HGLOBAL16 hMem )
 {
     dprintf_metafile(stddeb,"SetMetaFileBits: hmf out: %04x\n", hMem);
 
@@ -840,7 +842,7 @@
 /******************************************************************
  *         SetMetaFileBitsBetter   (GDI.196)
  */
-HMETAFILE16 SetMetaFileBitsBetter( HMETAFILE16 hMeta )
+HMETAFILE16 WINAPI SetMetaFileBitsBetter( HMETAFILE16 hMeta )
 {
    if( IsValidMetaFile( hMeta ) )
        return (HMETAFILE16)GlobalReAlloc16( hMeta, 0, 
@@ -1044,7 +1046,10 @@
 	len = sizeof(METARECORD) + sizeof(BITMAPINFOHEADER) + 
 	      (bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes) + 6;
 	if (!(hmr = GlobalAlloc16(GMEM_MOVEABLE, len)))
+	  {
+	    GDI_HEAP_UNLOCK((HGDIOBJ16)logbrush->lbHatch);
 	    return FALSE;
+	  }
 	mr = (METARECORD *)GlobalLock16(hmr);
 	memset(mr, 0, len);
 	mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
@@ -1060,6 +1065,7 @@
 	memcpy(mr->rdParam + (sizeof(BITMAPINFOHEADER) / 2) + 4,
 	       PTR_SEG_TO_LIN(bmp->bitmap.bmBits),
 	       bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes);
+	GDI_HEAP_UNLOCK(logbrush->lbHatch);
 	break;
 
     case BS_DIBPATTERN:
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index 514cb78..2a3cb2d 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -249,6 +249,17 @@
 
 static XpmColorSymbol *OBM_Colors = NULL;
 
+/* This structure holds the arguments for OBM_CreateBitmaps() */
+typedef struct
+{
+    char     **data;      /* In: bitmap data */
+    BOOL32     color;     /* In: color or monochrome */
+    BOOL32     need_mask; /* In: do we need a mask? */
+    HBITMAP16  bitmap;    /* Out: resulting bitmap */
+    HBITMAP16  mask;      /* Out: resulting mask (if needed) */
+    POINT32    hotspot;   /* Out: bitmap hotspot */
+} OBM_BITMAP_DESCR;
+
 
 /***********************************************************************
  *           OBM_InitColorSymbols
@@ -293,7 +304,7 @@
     hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
     if (!hbitmap) return 0;
 
-    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
+    bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
     bmpObjPtr->size.cx = width;
     bmpObjPtr->size.cy = height;
     bmpObjPtr->pixmap  = pixmap;
@@ -304,6 +315,7 @@
     bmpObjPtr->bitmap.bmPlanes     = 1;
     bmpObjPtr->bitmap.bmBitsPixel  = bpp;
     bmpObjPtr->bitmap.bmBits       = NULL;
+    GDI_HEAP_UNLOCK( hbitmap );
     return hbitmap;
 }
 
@@ -313,8 +325,7 @@
  *
  * Create the 2 bitmaps from XPM data.
  */
-static BOOL32 OBM_CreateBitmaps( char **data, BOOL32 color, HBITMAP16 *hBitmap,
-                                 HBITMAP16 *hBitmapMask, POINT32 *hotspot )
+static BOOL32 OBM_CreateBitmaps( OBM_BITMAP_DESCR *descr )
 {
     Pixmap pixmap, pixmask;
     XpmAttributes *attrs;
@@ -323,11 +334,11 @@
     attrs = (XpmAttributes *)xmalloc( XpmAttributesSize() );
     attrs->valuemask    = XpmColormap | XpmDepth | XpmColorSymbols |XpmHotspot;
     attrs->colormap     = COLOR_GetColormap();
-    attrs->depth        = color ? screenDepth : 1;
+    attrs->depth        = descr->color ? screenDepth : 1;
     attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
     attrs->numsymbols   = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
         
-    err = XpmCreatePixmapFromData( display, rootWindow, data,
+    err = XpmCreatePixmapFromData( display, rootWindow, descr->data,
                                    &pixmap, &pixmask, attrs );
 
     if (err != XpmSuccess)
@@ -335,22 +346,20 @@
         free( attrs );
         return FALSE;
     }
-    if (hotspot)
-    {
-        hotspot->x = attrs->x_hotspot;
-        hotspot->y = attrs->y_hotspot;
-    }
-    *hBitmap = OBM_MakeBitmap( attrs->width, attrs->height,
-                               attrs->depth, pixmap );
-    if (hBitmapMask) *hBitmapMask = OBM_MakeBitmap(attrs->width, attrs->height,
-                                                   1, pixmask );
+    descr->hotspot.x = attrs->x_hotspot;
+    descr->hotspot.y = attrs->y_hotspot;
+    descr->bitmap = OBM_MakeBitmap( attrs->width, attrs->height,
+                                    attrs->depth, pixmap );
+    if (descr->need_mask)
+        descr->mask = OBM_MakeBitmap( attrs->width, attrs->height,
+                                      1, pixmask );
     free( attrs );
-    if (!*hBitmap)
+    if (!descr->bitmap)
     {
         if (pixmap) XFreePixmap( display, pixmap );
         if (pixmask) XFreePixmap( display, pixmask );
-        if (*hBitmap) GDI_FreeObject( *hBitmap );
-        if (hBitmapMask && *hBitmapMask) GDI_FreeObject( *hBitmapMask );
+        if (descr->bitmap) GDI_FreeObject( descr->bitmap );
+        if (descr->need_mask && descr->mask) GDI_FreeObject( descr->mask );
         return FALSE;
     }
     else return TRUE;
@@ -362,22 +371,23 @@
  */
 HBITMAP16 OBM_LoadBitmap( WORD id )
 {
-    HBITMAP16 hbitmap;
+    OBM_BITMAP_DESCR descr;
 
     if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
     id -= OBM_FIRST;
 
     if (!OBM_InitColorSymbols()) return 0;
-    
-    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 5,
-                              OBM_Pixmaps_Data[id].data,
-                              OBM_Pixmaps_Data[id].color,
-                              &hbitmap, NULL, NULL ))
+
+    descr.data      = OBM_Pixmaps_Data[id].data;
+    descr.color     = OBM_Pixmaps_Data[id].color;
+    descr.need_mask = FALSE;
+
+    if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
     {
         fprintf( stderr, "Error creating OEM bitmap %d\n", OBM_FIRST+id );
         return 0;
     }
-    return hbitmap;
+    return descr.bitmap;
 }
 
 
@@ -386,11 +396,10 @@
  */
 HGLOBAL16 OBM_LoadCursorIcon( WORD id, BOOL32 fCursor )
 {
+    OBM_BITMAP_DESCR descr;
     HGLOBAL16 handle;
     CURSORICONINFO *pInfo;
     BITMAPOBJ *bmpXor, *bmpAnd;
-    HBITMAP16 hXorBits, hAndBits;
-    POINT32 hotspot;
     int sizeXor, sizeAnd;
 
     if (fCursor)
@@ -412,37 +421,39 @@
 
     if (!OBM_InitColorSymbols()) return 0;
     
-    if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 5,
-                           fCursor ? OBM_Cursors_Data[id] : OBM_Icons_Data[id],
-                           !fCursor, &hXorBits, &hAndBits, &hotspot ))
+    descr.data      = fCursor ? OBM_Cursors_Data[id] : OBM_Icons_Data[id];
+    descr.color     = !fCursor;
+    descr.need_mask = TRUE;
+
+    if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
     {
         fprintf( stderr, "Error creating OEM cursor/icon %d\n", id );
         return 0;
     }
 
-    bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( hXorBits, BITMAP_MAGIC );
-    bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( hAndBits, BITMAP_MAGIC );
+    bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC );
+    bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC );
     sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
     sizeAnd = bmpXor->bitmap.bmHeight * BITMAP_WIDTH_BYTES( bmpXor->bitmap.bmWidth, 1 );
 
     if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
                                   sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
     {
-        DeleteObject32( hXorBits );
-        DeleteObject32( hAndBits );
+        DeleteObject32( descr.bitmap );
+        DeleteObject32( descr.mask );
         return 0;
     }
 
     pInfo = (CURSORICONINFO *)GlobalLock16( handle );
-    pInfo->ptHotSpot.x   = hotspot.x;
-    pInfo->ptHotSpot.y   = hotspot.y;
+    pInfo->ptHotSpot.x   = descr.hotspot.x;
+    pInfo->ptHotSpot.y   = descr.hotspot.y;
     pInfo->nWidth        = bmpXor->bitmap.bmWidth;
     pInfo->nHeight       = bmpXor->bitmap.bmHeight;
     pInfo->nWidthBytes   = bmpXor->bitmap.bmWidthBytes;
     pInfo->bPlanes       = bmpXor->bitmap.bmPlanes;
     pInfo->bBitsPerPixel = bmpXor->bitmap.bmBitsPixel;
 
-    if (hAndBits)
+    if (descr.mask)
     {
           /* Invert the mask */
 
@@ -466,12 +477,12 @@
         }
     }
 
-    if (hAndBits) GetBitmapBits32( hAndBits, sizeAnd, (char *)(pInfo + 1) );
+    if (descr.mask) GetBitmapBits32( descr.mask, sizeAnd, (char *)(pInfo + 1));
     else memset( (char *)(pInfo + 1), 0xff, sizeAnd );
-    GetBitmapBits32( hXorBits, sizeXor, (char *)(pInfo + 1) + sizeAnd );
+    GetBitmapBits32( descr.bitmap, sizeXor, (char *)(pInfo + 1) + sizeAnd );
 
-    DeleteObject32( hXorBits );
-    DeleteObject32( hAndBits );
+    DeleteObject32( descr.bitmap );
+    DeleteObject32( descr.mask );
 
     if (fCursor) OBM_Cursors[id] = handle;
     return handle;
diff --git a/objects/palette.c b/objects/palette.c
index 74207b8..0049425 100644
--- a/objects/palette.c
+++ b/objects/palette.c
@@ -64,6 +64,8 @@
 
     palObj->mapping = xmalloc( sizeof(int) * 20 );
 
+    GDI_HEAP_UNLOCK( hpalette );
+
     free( palPtr );
     return hpalette;
 }
@@ -82,7 +84,7 @@
 /***********************************************************************
  *           CreatePalette16    (GDI.360)
  */
-HPALETTE16 CreatePalette16( const LOGPALETTE* palette )
+HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
 {
     return CreatePalette32( palette );
 }
@@ -91,7 +93,7 @@
 /***********************************************************************
  *           CreatePalette32    (GDI32.53)
  */
-HPALETTE32 CreatePalette32( const LOGPALETTE* palette )
+HPALETTE32 WINAPI CreatePalette32( const LOGPALETTE* palette )
 {
     PALETTEOBJ * palettePtr;
     HPALETTE32 hpalette;
@@ -103,11 +105,12 @@
     hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC );
     if (!hpalette) return 0;
 
-    palettePtr = (PALETTEOBJ *) GDI_HEAP_LIN_ADDR( hpalette );
+    palettePtr = (PALETTEOBJ *) GDI_HEAP_LOCK( hpalette );
     memcpy( &palettePtr->logpalette, palette, size );
     PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry, 
 			  palettePtr->logpalette.palNumEntries);
     palettePtr->mapping = NULL;
+    GDI_HEAP_UNLOCK( hpalette );
 
     dprintf_palette(stddeb,"returning %04x\n", hpalette);
     return hpalette;
@@ -117,8 +120,8 @@
 /***********************************************************************
  *           GetPaletteEntries16    (GDI.363)
  */
-UINT16 GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, UINT16 count,
-                            LPPALETTEENTRY entries )
+UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
+                                   UINT16 count, LPPALETTEENTRY entries )
 {
     return GetPaletteEntries32( hpalette, start, count, entries );
 }
@@ -127,8 +130,8 @@
 /***********************************************************************
  *           GetPaletteEntries32    (GDI32.209)
  */
-UINT32 GetPaletteEntries32( HPALETTE32 hpalette, UINT32 start, UINT32 count,
-                            LPPALETTEENTRY entries )
+UINT32 WINAPI GetPaletteEntries32( HPALETTE32 hpalette, UINT32 start,
+                                   UINT32 count, LPPALETTEENTRY entries )
 {
     PALETTEOBJ * palPtr;
     INT32 numEntries;
@@ -140,13 +143,18 @@
     if (!palPtr) return 0;
 
     numEntries = palPtr->logpalette.palNumEntries;
-    if (start >= numEntries) return 0;
+    if (start >= numEntries) 
+    {
+      GDI_HEAP_UNLOCK( hpalette );
+      return 0;
+    }
     if (start+count > numEntries) count = numEntries - start;
     memcpy( entries, &palPtr->logpalette.palPalEntry[start],
 	    count * sizeof(PALETTEENTRY) );
     for( numEntries = 0; numEntries < count ; numEntries++ )
          if (entries[numEntries].peFlags & 0xF0)
              entries[numEntries].peFlags = 0;
+    GDI_HEAP_UNLOCK( hpalette );
     return count;
 }
 
@@ -154,8 +162,8 @@
 /***********************************************************************
  *           SetPaletteEntries16    (GDI.364)
  */
-UINT16 SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, UINT16 count,
-                            LPPALETTEENTRY entries )
+UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
+                                   UINT16 count, LPPALETTEENTRY entries )
 {
     return SetPaletteEntries32( hpalette, start, count, entries );
 }
@@ -164,8 +172,8 @@
 /***********************************************************************
  *           SetPaletteEntries32    (GDI32.326)
  */
-UINT32 SetPaletteEntries32( HPALETTE32 hpalette, UINT32 start, UINT32 count,
-                            LPPALETTEENTRY entries )
+UINT32 WINAPI SetPaletteEntries32( HPALETTE32 hpalette, UINT32 start,
+                                   UINT32 count, LPPALETTEENTRY entries )
 {
     PALETTEOBJ * palPtr;
     INT32 numEntries;
@@ -177,7 +185,11 @@
     if (!palPtr) return 0;
 
     numEntries = palPtr->logpalette.palNumEntries;
-    if (start >= numEntries) return 0;
+    if (start >= numEntries) 
+    {
+      GDI_HEAP_UNLOCK( hpalette );
+      return 0;
+    }
     if (start+count > numEntries) count = numEntries - start;
     memcpy( &palPtr->logpalette.palPalEntry[start], entries,
 	    count * sizeof(PALETTEENTRY) );
@@ -185,7 +197,7 @@
 			  palPtr->logpalette.palNumEntries);
     free(palPtr->mapping);
     palPtr->mapping = NULL;
-
+    GDI_HEAP_UNLOCK( hpalette );
     return count;
 }
 
@@ -193,7 +205,7 @@
 /***********************************************************************
  *           ResizePalette16   (GDI.368)
  */
-BOOL16 ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
+BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
 {
     return ResizePalette32( hPal, cEntries );
 }
@@ -202,7 +214,7 @@
 /***********************************************************************
  *           ResizePalette32   (GDI32.289)
  */
-BOOL32 ResizePalette32( HPALETTE32 hPal, UINT32 cEntries )
+BOOL32 WINAPI ResizePalette32( HPALETTE32 hPal, UINT32 cEntries )
 {
     PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
     UINT32	 cPrevEnt, prevVer;
@@ -219,7 +231,9 @@
 	      				sizeof(int*) + sizeof(GDIOBJHDR);
     size += sizeof(int*) + sizeof(GDIOBJHDR);
     mapping = palPtr->mapping;
-
+    
+    GDI_HEAP_UNLOCK( hPal );
+    
     hPal = GDI_HEAP_REALLOC( hPal, size );
     palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
     if( !palPtr ) return FALSE;
@@ -236,6 +250,7 @@
     }
     palPtr->logpalette.palNumEntries = cEntries;
     palPtr->logpalette.palVersion = prevVer;
+    GDI_HEAP_UNLOCK( hPal );
     return TRUE;
 }
 
@@ -243,28 +258,47 @@
 /***********************************************************************
  *           AnimatePalette16   (GDI.367)
  */
-BOOL16 AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex, UINT16 NumEntries,
-                         LPPALETTEENTRY PaletteColors )
+void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
+                              UINT16 NumEntries, LPPALETTEENTRY PaletteColors)
 {
-    return AnimatePalette32( hPal, StartIndex, NumEntries, PaletteColors );
+    AnimatePalette32( hPal, StartIndex, NumEntries, PaletteColors );
 }
 
 
 /***********************************************************************
  *           AnimatePalette32   (GDI32.6)
+ *
+ * FIXME: should use existing mapping when animating a primary palette
  */
-BOOL32 AnimatePalette32( HPALETTE32 hPal, UINT32 StartIndex, UINT32 NumEntries,
-                         LPPALETTEENTRY PaletteColors )
+BOOL32 WINAPI AnimatePalette32( HPALETTE32 hPal, UINT32 StartIndex,
+                               UINT32 NumEntries, LPPALETTEENTRY PaletteColors)
 {
-    fprintf(stdnimp,"AnimatePalette: empty stub! \n");
-    return TRUE;
+    dprintf_palette(stddeb, "AnimatePalette: %04x (%i - %i)", hPal, 
+                    StartIndex, StartIndex + NumEntries );
+
+    if( hPal != STOCK_DEFAULT_PALETTE ) 
+    {
+        PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
+
+	if( (StartIndex + NumEntries) < palPtr->logpalette.palNumEntries )
+	{
+	    UINT32 u;
+	    for( u = 0; u < NumEntries; u++ )
+		palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
+	    COLOR_SetMapping(palPtr, StartIndex, NumEntries,
+                             hPal != hPrimaryPalette );
+            GDI_HEAP_UNLOCK( hPal );
+	    return TRUE;
+	}
+    }
+    return FALSE;
 }
 
 
 /***********************************************************************
  *           SetSystemPaletteUse16   (GDI.373)
  */
-UINT16 SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
+UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
 {
     return SetSystemPaletteUse32( hdc, use );
 }
@@ -273,7 +307,7 @@
 /***********************************************************************
  *           SetSystemPaletteUse32   (GDI32.335)
  */
-UINT32 SetSystemPaletteUse32( HDC32 hdc, UINT32 use )
+UINT32 WINAPI SetSystemPaletteUse32( HDC32 hdc, UINT32 use )
 {
     UINT32 old = SystemPaletteUse;
     fprintf( stdnimp,"SetSystemPaletteUse(%04x,%04x) // empty stub !!!\n",
@@ -286,7 +320,7 @@
 /***********************************************************************
  *           GetSystemPaletteUse16   (GDI.374)
  */
-UINT16 GetSystemPaletteUse16( HDC16 hdc )
+UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
 {
     return SystemPaletteUse;
 }
@@ -295,7 +329,7 @@
 /***********************************************************************
  *           GetSystemPaletteUse32   (GDI32.223)
  */
-UINT32 GetSystemPaletteUse32( HDC32 hdc )
+UINT32 WINAPI GetSystemPaletteUse32( HDC32 hdc )
 {
     return SystemPaletteUse;
 }
@@ -304,8 +338,8 @@
 /***********************************************************************
  *           GetSystemPaletteEntries16   (GDI.375)
  */
-UINT16 GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
-                                  LPPALETTEENTRY entries )
+UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
+                                         LPPALETTEENTRY entries )
 {
     return GetSystemPaletteEntries32( hdc, start, count, entries );
 }
@@ -314,8 +348,8 @@
 /***********************************************************************
  *           GetSystemPaletteEntries32   (GDI32.222)
  */
-UINT32 GetSystemPaletteEntries32( HDC32 hdc, UINT32 start, UINT32 count,
-                                  LPPALETTEENTRY entries )
+UINT32 WINAPI GetSystemPaletteEntries32( HDC32 hdc, UINT32 start, UINT32 count,
+                                         LPPALETTEENTRY entries )
 {
     UINT32 i;
     DC *dc;
@@ -323,7 +357,11 @@
     dprintf_palette(stddeb,"GetSystemPaletteEntries: hdc = %04x, cound = %i", hdc, count );
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
-    if (start >= dc->w.devCaps->sizePalette) return 0;
+    if (start >= dc->w.devCaps->sizePalette)
+      {
+	GDI_HEAP_UNLOCK( hdc );
+	return 0;
+      }
     if (start+count >= dc->w.devCaps->sizePalette)
 	count = dc->w.devCaps->sizePalette - start;
     for (i = 0; i < count; i++)
@@ -333,6 +371,7 @@
         dprintf_palette( stddeb,"\tidx(%02x) -> RGB(%08lx)\n",
                          start + i, *(COLORREF*)(entries + i) );
     }
+    GDI_HEAP_UNLOCK( hdc );
     return count;
 }
 
@@ -340,7 +379,7 @@
 /***********************************************************************
  *           GetNearestPaletteIndex16   (GDI.370)
  */
-UINT16 GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
+UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
 {
     return GetNearestPaletteIndex32( hpalette, color );
 }
@@ -349,7 +388,7 @@
 /***********************************************************************
  *           GetNearestPaletteIndex32   (GDI32.203)
  */
-UINT32 GetNearestPaletteIndex32( HPALETTE32 hpalette, COLORREF color )
+UINT32 WINAPI GetNearestPaletteIndex32( HPALETTE32 hpalette, COLORREF color )
 {
     PALETTEOBJ*	palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
     UINT32 index  = 0;
@@ -361,6 +400,7 @@
 
     dprintf_palette(stddeb,"GetNearestPaletteIndex(%04x,%06lx): returning %d\n", 
                     hpalette, color, index );
+    GDI_HEAP_UNLOCK( hpalette );
     return index;
 }
 
@@ -368,7 +408,7 @@
 /***********************************************************************
  *           GetNearestColor16   (GDI.154)
  */
-COLORREF GetNearestColor16( HDC16 hdc, COLORREF color )
+COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
 {
     return GetNearestColor32( hdc, color );
 }
@@ -377,7 +417,7 @@
 /***********************************************************************
  *           GetNearestColor32   (GDI32.202)
  */
-COLORREF GetNearestColor32( HDC32 hdc, COLORREF color )
+COLORREF WINAPI GetNearestColor32( HDC32 hdc, COLORREF color )
 {
     COLORREF 	 nearest = 0xFADECAFE;
     DC 		*dc;
@@ -391,10 +431,12 @@
 
       nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
 					  palObj->logpalette.palNumEntries, color );
+      GDI_HEAP_UNLOCK( dc->w.hPalette );
     }
 
     dprintf_palette(stddeb,"GetNearestColor(%06lx): returning %06lx\n", 
                     color, nearest );
+    GDI_HEAP_UNLOCK( hdc );    
     return nearest;
 }
 
@@ -431,6 +473,7 @@
 BOOL32 PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
 {
     free( palette->mapping );
+    if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
     return GDI_FreeObject( hpalette );
 }
 
@@ -438,7 +481,7 @@
 /***********************************************************************
  *           GDISelectPalette    (GDI.361)
  */
-HPALETTE16 GDISelectPalette( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
+HPALETTE16 WINAPI GDISelectPalette( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
 {
     HPALETTE16 prev;
     DC *dc;
@@ -453,6 +496,7 @@
     }
     prev = dc->w.hPalette;
     dc->w.hPalette = hpal;
+    GDI_HEAP_UNLOCK( hdc );
     if (!wBkg) hPrimaryPalette = hpal; 
     return prev;
 }
@@ -461,7 +505,7 @@
 /***********************************************************************
  *           GDIRealizePalette    (GDI.362)
  */
-UINT16 GDIRealizePalette( HDC16 hdc )
+UINT16 WINAPI GDIRealizePalette( HDC16 hdc )
 {
     PALETTEOBJ* palPtr;
     int realized = 0;
@@ -481,12 +525,16 @@
 
         palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
         
-	realized = COLOR_SetMapping(palPtr, dc->w.hPalette != hPrimaryPalette 
-                                  || dc->w.hPalette == STOCK_DEFAULT_PALETTE );
+        realized = COLOR_SetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
+                                    (dc->w.hPalette != hPrimaryPalette) ||
+                                    (dc->w.hPalette == STOCK_DEFAULT_PALETTE));
+	GDI_HEAP_UNLOCK( dc->w.hPalette );
 	hLastRealizedPalette = dc->w.hPalette;
     }
-    else dprintf_palette(stddeb, " skipping ");
+    else dprintf_palette(stddeb, " skipping (hLastRealizedPalette = %04x) ",
+			 hLastRealizedPalette);
     
+    GDI_HEAP_UNLOCK( hdc );
     dprintf_palette(stdnimp, " realized %i colors\n", realized );
     return (UINT16)realized;
 }
@@ -495,7 +543,7 @@
 /***********************************************************************
  *           RealizeDefaultPalette    (GDI.365)
  */
-UINT16 RealizeDefaultPalette( HDC16 hdc )
+UINT16 WINAPI RealizeDefaultPalette( HDC16 hdc )
 {
     DC          *dc;
     PALETTEOBJ*  palPtr;
@@ -510,7 +558,11 @@
 	if (!dc) return 0;
     }
 
-    if ( dc->w.flags & DC_MEMORY ) return 0;
+    if ( dc->w.flags & DC_MEMORY ) 
+      {
+	GDI_HEAP_UNLOCK( hdc );
+	return 0;
+      }
 
     hPrimaryPalette = STOCK_DEFAULT_PALETTE;
     hLastRealizedPalette = STOCK_DEFAULT_PALETTE;
@@ -533,18 +585,23 @@
 /***********************************************************************
  *           IsDCCurrentPalette   (GDI.412)
  */
-BOOL16 IsDCCurrentPalette(HDC16 hDC)
+BOOL16 WINAPI IsDCCurrentPalette(HDC16 hDC)
 {
     DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
-    return (dc)?(dc->w.hPalette == hPrimaryPalette):FALSE;
+    if (dc) 
+    {
+      GDI_HEAP_UNLOCK( hDC );
+      return dc->w.hPalette == hPrimaryPalette;
+    }
+    return FALSE;
 }
 
 
 /***********************************************************************
  *           SelectPalette16    (USER.282)
  */
-HPALETTE16 SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
-                            BOOL16 bForceBackground )
+HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
+                                   BOOL16 bForceBackground )
 {
     return SelectPalette32( hDC, hPal, bForceBackground );
 }
@@ -553,8 +610,8 @@
 /***********************************************************************
  *           SelectPalette32    (GDI32.300)
  */
-HPALETTE32 SelectPalette32( HDC32 hDC, HPALETTE32 hPal,
-                            BOOL32 bForceBackground )
+HPALETTE32 WINAPI SelectPalette32( HDC32 hDC, HPALETTE32 hPal,
+                                   BOOL32 bForceBackground )
 {
     WORD	wBkgPalette = 1;
     PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
@@ -565,6 +622,7 @@
 
     dprintf_palette(stddeb," entries = %d\n", 
 			    lpt->logpalette.palNumEntries);
+    GDI_HEAP_UNLOCK( hPal );
 
     if( hPal != STOCK_DEFAULT_PALETTE )
     {
@@ -584,7 +642,7 @@
 /***********************************************************************
  *           RealizePalette16    (USER.283)
  */
-UINT16 RealizePalette16( HDC16 hDC )
+UINT16 WINAPI RealizePalette16( HDC16 hDC )
 {
     return RealizePalette32( hDC );
 }
@@ -593,7 +651,7 @@
 /***********************************************************************
  *           RealizePalette32    (GDI32.280)
  */
-UINT32 RealizePalette32( HDC32 hDC )
+UINT32 WINAPI RealizePalette32( HDC32 hDC )
 {
     UINT32 realized = GDIRealizePalette( hDC );
 
@@ -615,7 +673,7 @@
 /**********************************************************************
  *            UpdateColors16   (GDI.366)
  */
-INT16 UpdateColors16( HDC16 hDC )
+INT16 WINAPI UpdateColors16( HDC16 hDC )
 {
     HWND32 hWnd = WindowFromDC32( hDC );
 
@@ -631,7 +689,7 @@
 /**********************************************************************
  *            UpdateColors32   (GDI32.359)
  */
-BOOL32 UpdateColors32( HDC32 hDC )
+BOOL32 WINAPI UpdateColors32( HDC32 hDC )
 {
     UpdateColors16( hDC );
     return TRUE;
diff --git a/objects/pen.c b/objects/pen.c
index f33b791..c2c63ad 100644
--- a/objects/pen.c
+++ b/objects/pen.c
@@ -15,7 +15,7 @@
 /***********************************************************************
  *           CreatePen16    (GDI.61)
  */
-HPEN16 CreatePen16( INT16 style, INT16 width, COLORREF color )
+HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
 {
     LOGPEN32 logpen = { style, { width, 0 }, color };
     dprintf_gdi(stddeb, "CreatePen16: %d %d %06lx\n", style, width, color );
@@ -26,7 +26,7 @@
 /***********************************************************************
  *           CreatePen32    (GDI32.55)
  */
-HPEN32 CreatePen32( INT32 style, INT32 width, COLORREF color )
+HPEN32 WINAPI CreatePen32( INT32 style, INT32 width, COLORREF color )
 {
     LOGPEN32 logpen = { style, { width, 0 }, color };
     dprintf_gdi(stddeb, "CreatePen32: %d %d %06lx\n", style, width, color );
@@ -37,7 +37,7 @@
 /***********************************************************************
  *           CreatePenIndirect16    (GDI.62)
  */
-HPEN16 CreatePenIndirect16( const LOGPEN16 * pen )
+HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
 {
     PENOBJ * penPtr;
     HPEN16 hpen;
@@ -45,10 +45,11 @@
     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
     if (!hpen) return 0;
-    penPtr = (PENOBJ *)GDI_HEAP_LIN_ADDR( hpen );
+    penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
     penPtr->logpen.lopnStyle = pen->lopnStyle;
     penPtr->logpen.lopnColor = pen->lopnColor;
     CONV_POINT16TO32( &pen->lopnWidth, &penPtr->logpen.lopnWidth );
+    GDI_HEAP_UNLOCK( hpen );
     return hpen;
 }
 
@@ -56,7 +57,7 @@
 /***********************************************************************
  *           CreatePenIndirect32    (GDI32.56)
  */
-HPEN32 CreatePenIndirect32( const LOGPEN32 * pen )
+HPEN32 WINAPI CreatePenIndirect32( const LOGPEN32 * pen )
 {
     PENOBJ * penPtr;
     HPEN32 hpen;
@@ -64,10 +65,11 @@
     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
     hpen = GDI_AllocObject( sizeof(PENOBJ), PEN_MAGIC );
     if (!hpen) return 0;
-    penPtr = (PENOBJ *)GDI_HEAP_LIN_ADDR( hpen );
+    penPtr = (PENOBJ *)GDI_HEAP_LOCK( hpen );
     penPtr->logpen.lopnStyle = pen->lopnStyle;
     penPtr->logpen.lopnWidth = pen->lopnWidth;
     penPtr->logpen.lopnColor = pen->lopnColor;
+    GDI_HEAP_UNLOCK( hpen );
     return hpen;
 }
 
diff --git a/objects/region.c b/objects/region.c
index 9148e6d..a8e86e8 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -27,7 +27,7 @@
 /***********************************************************************
  *           OffsetRgn16    (GDI.101)
  */
-INT16 OffsetRgn16( HRGN16 hrgn, INT16 x, INT16 y )
+INT16 WINAPI OffsetRgn16( HRGN16 hrgn, INT16 x, INT16 y )
 {
     return OffsetRgn32( hrgn, x, y );
 }
@@ -36,13 +36,18 @@
 /***********************************************************************
  *           OffsetRgn32   (GDI32.256)
  */
-INT32 OffsetRgn32( HRGN32 hrgn, INT32 x, INT32 y )
+INT32 WINAPI OffsetRgn32( HRGN32 hrgn, INT32 x, INT32 y )
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
     if (!obj) return ERROR;
     dprintf_region(stddeb, "OffsetRgn: %04x %d,%d\n", hrgn, x, y );
-    if (!obj->xrgn) return NULLREGION;
+    if (!obj->xrgn) 
+    {
+      GDI_HEAP_UNLOCK( hrgn );
+      return NULLREGION;
+    }
     XOffsetRegion( obj->xrgn, x, y );
+    GDI_HEAP_UNLOCK( hrgn );
     return COMPLEXREGION;
 }
 
@@ -50,7 +55,7 @@
 /***********************************************************************
  *           GetRgnBox16    (GDI.134)
  */
-INT16 GetRgnBox16( HRGN16 hrgn, LPRECT16 rect )
+INT16 WINAPI GetRgnBox16( HRGN16 hrgn, LPRECT16 rect )
 {
     RGNOBJ * obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC );
     if (!obj) return ERROR;
@@ -58,12 +63,14 @@
     if (!obj->xrgn)
     {
         SetRectEmpty16( rect );
+	GDI_HEAP_UNLOCK( hrgn );
         return NULLREGION;
     }
     else
     {
         XRectangle xrect;
         XClipBox( obj->xrgn, &xrect );
+	GDI_HEAP_UNLOCK(hrgn);
         SetRect16( rect, xrect.x, xrect.y,
                    xrect.x + xrect.width, xrect.y + xrect.height);
         return COMPLEXREGION;
@@ -74,7 +81,7 @@
 /***********************************************************************
  *           GetRgnBox32    (GDI32.219)
  */
-INT32 GetRgnBox32( HRGN32 hrgn, LPRECT32 rect )
+INT32 WINAPI GetRgnBox32( HRGN32 hrgn, LPRECT32 rect )
 {
     RECT16 r;
     INT16 ret = GetRgnBox16( hrgn, &r );
@@ -86,7 +93,7 @@
 /***********************************************************************
  *           CreateRectRgn16    (GDI.64)
  */
-HRGN16 CreateRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
+HRGN16 WINAPI CreateRectRgn16(INT16 left, INT16 top, INT16 right, INT16 bottom)
 {
     return (HRGN16)CreateRectRgn32( left, top, right, bottom );
 }
@@ -95,13 +102,13 @@
 /***********************************************************************
  *           CreateRectRgn32   (GDI32.59)
  */
-HRGN32 CreateRectRgn32( INT32 left, INT32 top, INT32 right, INT32 bottom )
+HRGN32 WINAPI CreateRectRgn32(INT32 left, INT32 top, INT32 right, INT32 bottom)
 {
     HRGN32 hrgn;
     RGNOBJ *obj;
 
     if (!(hrgn = GDI_AllocObject( sizeof(RGNOBJ), REGION_MAGIC ))) return 0;
-    obj = (RGNOBJ *) GDI_HEAP_LIN_ADDR( hrgn );
+    obj = (RGNOBJ *) GDI_HEAP_LOCK( hrgn );
     if ((right > left) && (bottom > top))
     {
 	XRectangle rect = { left, top, right - left, bottom - top };
@@ -115,6 +122,7 @@
     else obj->xrgn = 0;
     dprintf_region( stddeb, "CreateRectRgn(%d,%d-%d,%d): returning %04x\n",
                     left, top, right, bottom, hrgn );
+    GDI_HEAP_UNLOCK( hrgn );
     return hrgn;
 }
 
@@ -122,7 +130,7 @@
 /***********************************************************************
  *           CreateRectRgnIndirect16    (GDI.65)
  */
-HRGN16 CreateRectRgnIndirect16( const RECT16* rect )
+HRGN16 WINAPI CreateRectRgnIndirect16( const RECT16* rect )
 {
     return CreateRectRgn32( rect->left, rect->top, rect->right, rect->bottom );
 }
@@ -131,7 +139,7 @@
 /***********************************************************************
  *           CreateRectRgnIndirect32    (GDI32.60)
  */
-HRGN32 CreateRectRgnIndirect32( const RECT32* rect )
+HRGN32 WINAPI CreateRectRgnIndirect32( const RECT32* rect )
 {
     return CreateRectRgn32( rect->left, rect->top, rect->right, rect->bottom );
 }
@@ -140,8 +148,8 @@
 /***********************************************************************
  *           SetRectRgn16    (GDI.172)
  */
-VOID SetRectRgn16( HRGN16 hrgn, INT16 left, INT16 top,
-                   INT16 right, INT16 bottom )
+VOID WINAPI SetRectRgn16( HRGN16 hrgn, INT16 left, INT16 top,
+                          INT16 right, INT16 bottom )
 {
     SetRectRgn32( hrgn, left, top, right, bottom );
 }
@@ -150,8 +158,8 @@
 /***********************************************************************
  *           SetRectRgn32    (GDI32.332)
  */
-VOID SetRectRgn32( HRGN32 hrgn, INT32 left, INT32 top,
-                   INT32 right, INT32 bottom )
+VOID WINAPI SetRectRgn32( HRGN32 hrgn, INT32 left, INT32 top,
+                          INT32 right, INT32 bottom )
 {
     RGNOBJ * obj;
 
@@ -167,14 +175,16 @@
             XUnionRectWithRegion( &rect, obj->xrgn, obj->xrgn );
     }
     else obj->xrgn = 0;
+    GDI_HEAP_UNLOCK( hrgn );
 }
 
 
 /***********************************************************************
  *           CreateRoundRectRgn16    (GDI.444)
  */
-HRGN16 CreateRoundRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom,
-                             INT16 ellipse_width, INT16 ellipse_height )
+HRGN16 WINAPI CreateRoundRectRgn16( INT16 left, INT16 top,
+                                    INT16 right, INT16 bottom,
+                                    INT16 ellipse_width, INT16 ellipse_height )
 {
     return (HRGN16)CreateRoundRectRgn32( left, top, right, bottom,
                                          ellipse_width, ellipse_height );
@@ -184,8 +194,9 @@
 /***********************************************************************
  *           CreateRoundRectRgn32    (GDI32.61)
  */
-HRGN32 CreateRoundRectRgn32( INT32 left, INT32 top, INT32 right, INT32 bottom,
-                             INT32 ellipse_width, INT32 ellipse_height )
+HRGN32 WINAPI CreateRoundRectRgn32( INT32 left, INT32 top,
+                                    INT32 right, INT32 bottom,
+                                    INT32 ellipse_width, INT32 ellipse_height )
 {
     RGNOBJ * obj;
     HRGN32 hrgn;
@@ -201,7 +212,7 @@
       /* Create region */
 
     if (!(hrgn = GDI_AllocObject( sizeof(RGNOBJ), REGION_MAGIC ))) return 0;
-    obj = (RGNOBJ *) GDI_HEAP_LIN_ADDR( hrgn );
+    obj = (RGNOBJ *) GDI_HEAP_LOCK( hrgn );
     obj->xrgn = XCreateRegion();
     dprintf_region(stddeb,"CreateRoundRectRgn(%d,%d-%d,%d %dx%d): return=%04x\n",
                left, top, right, bottom, ellipse_width, ellipse_height, hrgn );
@@ -273,6 +284,7 @@
         rect.height = bottom - top + 1;
         XUnionRectWithRegion( &rect, obj->xrgn, obj->xrgn );
     }
+    GDI_HEAP_UNLOCK( hrgn );
     return hrgn;
 }
 
@@ -280,7 +292,8 @@
 /***********************************************************************
  *           CreateEllipticRgn16    (GDI.54)
  */
-HRGN16 CreateEllipticRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
+HRGN16 WINAPI CreateEllipticRgn16( INT16 left, INT16 top,
+                                   INT16 right, INT16 bottom )
 {
     return (HRGN16)CreateRoundRectRgn32( left, top, right, bottom,
                                          right-left, bottom-top );
@@ -290,7 +303,8 @@
 /***********************************************************************
  *           CreateEllipticRgn32    (GDI32.39)
  */
-HRGN32 CreateEllipticRgn32( INT32 left, INT32 top, INT32 right, INT32 bottom )
+HRGN32 WINAPI CreateEllipticRgn32( INT32 left, INT32 top,
+                                   INT32 right, INT32 bottom )
 {
     return CreateRoundRectRgn32( left, top, right, bottom,
                                  right-left, bottom-top );
@@ -300,7 +314,7 @@
 /***********************************************************************
  *           CreateEllipticRgnIndirect16    (GDI.55)
  */
-HRGN16 CreateEllipticRgnIndirect16( const RECT16 *rect )
+HRGN16 WINAPI CreateEllipticRgnIndirect16( const RECT16 *rect )
 {
     return CreateRoundRectRgn32( rect->left, rect->top, rect->right,
                                  rect->bottom, rect->right - rect->left,
@@ -311,7 +325,7 @@
 /***********************************************************************
  *           CreateEllipticRgnIndirect32    (GDI32.40)
  */
-HRGN32 CreateEllipticRgnIndirect32( const RECT32 *rect )
+HRGN32 WINAPI CreateEllipticRgnIndirect32( const RECT32 *rect )
 {
     return CreateRoundRectRgn32( rect->left, rect->top, rect->right,
                                  rect->bottom, rect->right - rect->left,
@@ -322,7 +336,8 @@
 /***********************************************************************
  *           CreatePolygonRgn16    (GDI.63)
  */
-HRGN16 CreatePolygonRgn16( const POINT16 * points, INT16 count, INT16 mode )
+HRGN16 WINAPI CreatePolygonRgn16( const POINT16 * points, INT16 count,
+                                  INT16 mode )
 {
     return CreatePolyPolygonRgn16( points, &count, 1, mode );
 }
@@ -331,8 +346,9 @@
 /***********************************************************************
  *           CreatePolyPolygonRgn16    (GDI.451)
  */
-HRGN16 CreatePolyPolygonRgn16( const POINT16 * points, const INT16 * count,
-                               INT16 nbpolygons, INT16 mode )
+HRGN16 WINAPI CreatePolyPolygonRgn16( const POINT16 * points,
+                                      const INT16 * count,
+                                      INT16 nbpolygons, INT16 mode )
 {
     int		i,nrofpts;
     LPINT32	count32;
@@ -360,7 +376,8 @@
 /***********************************************************************
  *           CreatePolygonRgn32    (GDI32.58)
  */
-HRGN32 CreatePolygonRgn32( const POINT32 *points, INT32 count, INT32 mode )
+HRGN32 WINAPI CreatePolygonRgn32( const POINT32 *points, INT32 count,
+                                  INT32 mode )
 {
     return CreatePolyPolygonRgn32( points, &count, 1, mode );
 }
@@ -369,8 +386,9 @@
 /***********************************************************************
  *           CreatePolyPolygonRgn32    (GDI32.57)
  */
-HRGN32 CreatePolyPolygonRgn32( const POINT32 * points, const INT32 * count,
-                               INT32 nbpolygons, INT32 mode )
+HRGN32 WINAPI CreatePolyPolygonRgn32( const POINT32 * points,
+                                      const INT32 * count,
+                                      INT32 nbpolygons, INT32 mode )
 {
     RGNOBJ * obj;
     HRGN32 hrgn;
@@ -395,7 +413,7 @@
 	HeapFree( GetProcessHeap(), 0, xpoints );
 	return 0;
     }
-    obj = (RGNOBJ *) GDI_HEAP_LIN_ADDR( hrgn );
+    obj = (RGNOBJ *) GDI_HEAP_LOCK( hrgn );
     obj->xrgn = 0;
     dprintf_region(stddeb, "CreatePolyPolygonRgn: %d polygons, returning %04x\n",
                    nbpolygons, hrgn );
@@ -430,6 +448,7 @@
     }
 
     HeapFree( GetProcessHeap(), 0, xpoints );
+    GDI_HEAP_UNLOCK( hrgn );
     return hrgn;
 }
 
@@ -437,7 +456,7 @@
 /***********************************************************************
  *           PtInRegion16    (GDI.161)
  */
-BOOL16 PtInRegion16( HRGN16 hrgn, INT16 x, INT16 y )
+BOOL16 WINAPI PtInRegion16( HRGN16 hrgn, INT16 x, INT16 y )
 {
     return PtInRegion32( hrgn, x, y );
 }
@@ -446,50 +465,59 @@
 /***********************************************************************
  *           PtInRegion32    (GDI32.278)
  */
-BOOL32 PtInRegion32( HRGN32 hrgn, INT32 x, INT32 y )
+BOOL32 WINAPI PtInRegion32( HRGN32 hrgn, INT32 x, INT32 y )
 {
     RGNOBJ * obj;
+    BOOL32 result;
     
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) return FALSE;
-    return XPointInRegion( obj->xrgn, x, y );
+    if (!obj->xrgn) result = FALSE;
+    else result = XPointInRegion( obj->xrgn, x, y );
+    GDI_HEAP_UNLOCK( hrgn );
+    return result;
 }
 
 
 /***********************************************************************
  *           RectInRegion16    (GDI.181)
  */
-BOOL16 RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
+BOOL16 WINAPI RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
 {
     RGNOBJ * obj;
-    
+    BOOL16 result;
+
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) return FALSE;
-    return (XRectInRegion( obj->xrgn, rect->left, rect->top,
+    if (!obj->xrgn) result = FALSE;
+    else result = (XRectInRegion( obj->xrgn, rect->left, rect->top,
                            rect->right-rect->left,
                            rect->bottom-rect->top ) != RectangleOut);
+    GDI_HEAP_UNLOCK( hrgn );
+    return result;
 }
 
 
 /***********************************************************************
  *           RectInRegion32    (GDI32.281)
  */
-BOOL32 RectInRegion32( HRGN32 hrgn, const RECT32 *rect )
+BOOL32 WINAPI RectInRegion32( HRGN32 hrgn, const RECT32 *rect )
 {
     RGNOBJ * obj;
+    BOOL32 result;
     
     if (!(obj = (RGNOBJ *) GDI_GetObjPtr( hrgn, REGION_MAGIC ))) return FALSE;
-    if (!obj->xrgn) return FALSE;
-    return (XRectInRegion( obj->xrgn, rect->left, rect->top,
+    if (!obj->xrgn) result = FALSE;
+    else result = (XRectInRegion( obj->xrgn, rect->left, rect->top,
                            rect->right-rect->left,
                            rect->bottom-rect->top ) != RectangleOut);
+    GDI_HEAP_UNLOCK( hrgn );
+    return result;
 }
 
 
 /***********************************************************************
  *           EqualRgn16    (GDI.72)
  */
-BOOL16 EqualRgn16( HRGN16 rgn1, HRGN16 rgn2 )
+BOOL16 WINAPI EqualRgn16( HRGN16 rgn1, HRGN16 rgn2 )
 {
     return EqualRgn32( rgn1, rgn2 );
 }
@@ -498,13 +526,22 @@
 /***********************************************************************
  *           EqualRgn32    (GDI32.90)
  */
-BOOL32 EqualRgn32( HRGN32 rgn1, HRGN32 rgn2 )
+BOOL32 WINAPI EqualRgn32( HRGN32 rgn1, HRGN32 rgn2 )
 {
     RGNOBJ *obj1, *obj2;
+    BOOL32 result;
+
     if (!(obj1 = (RGNOBJ *) GDI_GetObjPtr( rgn1, REGION_MAGIC ))) return FALSE;
-    if (!(obj2 = (RGNOBJ *) GDI_GetObjPtr( rgn2, REGION_MAGIC ))) return FALSE;
-    if (!obj1->xrgn || !obj2->xrgn) return (!obj1->xrgn && !obj2->xrgn);
-    return XEqualRegion( obj1->xrgn, obj2->xrgn );
+    if (!(obj2 = (RGNOBJ *) GDI_GetObjPtr( rgn2, REGION_MAGIC ))) 
+    {
+      GDI_HEAP_UNLOCK( rgn1 );
+      return FALSE;
+    }
+    if (!obj1->xrgn || !obj2->xrgn) result = (!obj1->xrgn && !obj2->xrgn);
+    else result = XEqualRegion( obj1->xrgn, obj2->xrgn );
+    GDI_HEAP_UNLOCK( rgn1 );
+    GDI_HEAP_UNLOCK( rgn2 );
+    return result;
 }
 
 
@@ -558,6 +595,7 @@
     else
       ret = COMPLEXREGION;
     XUnionRectWithRegion( &rect, rgnObj->xrgn, rgnObj->xrgn );
+    GDI_HEAP_UNLOCK( hRgn );
   }
   return ret;
 }
@@ -575,13 +613,20 @@
 
     destObj = (RGNOBJ*) GDI_GetObjPtr( hDest, REGION_MAGIC );
     srcObj  = (RGNOBJ*) GDI_GetObjPtr( hSrc, REGION_MAGIC );
-    if (!srcObj->xrgn) return FALSE;
+    if (!srcObj->xrgn) 
+    {
+      GDI_HEAP_UNLOCK( hDest );
+      GDI_HEAP_UNLOCK( hSrc );
+      return FALSE;
+    }
     REGION_CopyRegion( srcObj, destObj );
     XShrinkRegion( destObj->xrgn, -x, -y );
     result = XCreateRegion();
     XSubtractRegion( destObj->xrgn, srcObj->xrgn, result );
     XDestroyRegion( destObj->xrgn );
     destObj->xrgn = result;
+    GDI_HEAP_UNLOCK( hDest );
+    GDI_HEAP_UNLOCK( hSrc );
     return TRUE;
 }
 
@@ -589,7 +634,7 @@
 /***********************************************************************
  *           CombineRgn16    (GDI.451)
  */
-INT16 CombineRgn16( HRGN16 hDest, HRGN16 hSrc1, HRGN16 hSrc2, INT16 mode )
+INT16 WINAPI CombineRgn16(HRGN16 hDest, HRGN16 hSrc1, HRGN16 hSrc2, INT16 mode)
 {
     return (INT16)CombineRgn32( hDest, hSrc1, hSrc2, mode );
 }
@@ -600,10 +645,11 @@
  *
  * Note: The behavior is correct even if src and dest regions are the same.
  */
-INT32 CombineRgn32( HRGN32 hDest, HRGN32 hSrc1, HRGN32 hSrc2, INT32 mode )
+INT32 WINAPI CombineRgn32(HRGN32 hDest, HRGN32 hSrc1, HRGN32 hSrc2, INT32 mode)
 {
     RGNOBJ *destObj, *src1Obj, *src2Obj;
     Region destrgn;
+    INT32 result;
 
     dprintf_region(stddeb, "CombineRgn: %04x,%04x -> %04x mode=%x\n", 
 		   hSrc1, hSrc2, hDest, mode );
@@ -611,12 +657,24 @@
     if (!(destObj = (RGNOBJ *) GDI_GetObjPtr( hDest, REGION_MAGIC )))
 	return ERROR;
     if (!(src1Obj = (RGNOBJ *) GDI_GetObjPtr( hSrc1, REGION_MAGIC )))
+    {
+        GDI_HEAP_UNLOCK( hDest );
 	return ERROR;
-    if (mode == RGN_COPY) return REGION_CopyRegion( src1Obj, destObj );
+    }
+    if (mode == RGN_COPY) 
+    {
+       result = REGION_CopyRegion( src1Obj, destObj );
+       GDI_HEAP_UNLOCK( hDest );
+       GDI_HEAP_UNLOCK( hSrc1 );
+       return result;
+    }
 
     if (!(src2Obj = (RGNOBJ *) GDI_GetObjPtr( hSrc2, REGION_MAGIC )))
-        return ERROR;
-
+    {
+       GDI_HEAP_UNLOCK( hDest );
+       GDI_HEAP_UNLOCK( hSrc1 );
+       return ERROR;
+    }
       /* Some optimizations for null regions */
 
     if (!src1Obj->xrgn || !src2Obj->xrgn)
@@ -625,26 +683,48 @@
         {
         case RGN_DIFF:
             if (src1Obj->xrgn)
-                return REGION_CopyRegion( src1Obj, destObj );
+	    {
+                result = REGION_CopyRegion( src1Obj, destObj );
+		GDI_HEAP_UNLOCK( hDest );
+		GDI_HEAP_UNLOCK( hSrc1 );
+		GDI_HEAP_UNLOCK( hSrc2 );
+		return result;
+	    }
             /* else fall through */
         case RGN_AND:
             if (destObj->xrgn) XDestroyRegion( destObj->xrgn );
 	    destObj->xrgn = 0;
+	    GDI_HEAP_UNLOCK( hDest );
+	    GDI_HEAP_UNLOCK( hSrc1 );
+	    GDI_HEAP_UNLOCK( hSrc2 );
 	    return NULLREGION;
         case RGN_OR:
         case RGN_XOR:
             if (src1Obj->xrgn)
-                return REGION_CopyRegion( src1Obj, destObj );
+                result = REGION_CopyRegion( src1Obj, destObj );
             else
-                return REGION_CopyRegion( src2Obj, destObj );
+                result = REGION_CopyRegion( src2Obj, destObj );
+	    GDI_HEAP_UNLOCK( hDest );
+	    GDI_HEAP_UNLOCK( hSrc1 );
+	    GDI_HEAP_UNLOCK( hSrc2 );
+	    return result;
 	default:
+	    GDI_HEAP_UNLOCK( hDest );
+	    GDI_HEAP_UNLOCK( hSrc1 );
+	    GDI_HEAP_UNLOCK( hSrc2 );
 	    return ERROR;
         }
     }
 
       /* Perform the operation with the two X regions */
 
-    if (!(destrgn = XCreateRegion())) return ERROR;
+    if (!(destrgn = XCreateRegion()))
+    {
+      GDI_HEAP_UNLOCK( hDest );
+      GDI_HEAP_UNLOCK( hSrc1 );
+      GDI_HEAP_UNLOCK( hSrc2 );
+      return ERROR;
+    }
     switch(mode)
     {
     case RGN_AND:
@@ -661,6 +741,9 @@
         break;
     default:
         XDestroyRegion( destrgn );
+	GDI_HEAP_UNLOCK( hDest );
+	GDI_HEAP_UNLOCK( hSrc1 );
+	GDI_HEAP_UNLOCK( hSrc2 );
         return ERROR;
     }
     if (destObj->xrgn) XDestroyRegion( destObj->xrgn );
@@ -669,7 +752,13 @@
     {
         XDestroyRegion( destObj->xrgn );
         destObj->xrgn = 0;
+	GDI_HEAP_UNLOCK( hDest );
+	GDI_HEAP_UNLOCK( hSrc1 );
+	GDI_HEAP_UNLOCK( hSrc2 );
         return NULLREGION;
     }
+    GDI_HEAP_UNLOCK( hDest );
+    GDI_HEAP_UNLOCK( hSrc1 );
+    GDI_HEAP_UNLOCK( hSrc2 );
     return COMPLEXREGION;
 }
diff --git a/objects/text.c b/objects/text.c
index 176ddd6..1b46830 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -182,8 +182,8 @@
 /***********************************************************************
  *           DrawText16    (USER.85)
  */
-INT16 DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
-                  LPRECT16 rect, UINT16 flags )
+INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
+                         LPRECT16 rect, UINT16 flags )
 {
     SIZE16 size;
     const char *strPtr;
@@ -285,8 +285,8 @@
 /***********************************************************************
  *           DrawText32A    (USER32.163)
  */
-INT32 DrawText32A( HDC32 hdc, LPCSTR str, INT32 count,
-                   LPRECT32 rect, UINT32 flags )
+INT32 WINAPI DrawText32A( HDC32 hdc, LPCSTR str, INT32 count,
+                          LPRECT32 rect, UINT32 flags )
 {
     RECT16 rect16;
     INT16 ret;
@@ -303,8 +303,8 @@
 /***********************************************************************
  *           DrawText32W    (USER32.166)
  */
-INT32 DrawText32W( HDC32 hdc, LPCWSTR str, INT32 count,
-                   LPRECT32 rect, UINT32 flags )
+INT32 WINAPI DrawText32W( HDC32 hdc, LPCWSTR str, INT32 count,
+                          LPRECT32 rect, UINT32 flags )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
     INT32 ret = DrawText32A( hdc, p, count, rect, flags );
@@ -316,9 +316,9 @@
 /***********************************************************************
  *           ExtTextOut16    (GDI.351)
  */
-BOOL16 ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
-                     const RECT16 *lprect, LPCSTR str, UINT16 count,
-                     const INT16 *lpDx )
+BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
+                            const RECT16 *lprect, LPCSTR str, UINT16 count,
+                            const INT16 *lpDx )
 {
     BOOL32	ret;
     int		i;
@@ -338,9 +338,9 @@
 /***********************************************************************
  *           ExtTextOut32A    (GDI32.98)
  */
-BOOL32 ExtTextOut32A( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
-                      const RECT32 *lprect, LPCSTR str, UINT32 count,
-                      const INT32 *lpDx )
+BOOL32 WINAPI ExtTextOut32A( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
+                             const RECT32 *lprect, LPCSTR str, UINT32 count,
+                             const INT32 *lpDx )
 {
     DC * dc = DC_GetDCPtr( hdc );
     return dc && dc->funcs->pExtTextOut && 
@@ -351,9 +351,9 @@
 /***********************************************************************
  *           ExtTextOut32W    (GDI32.99)
  */
-BOOL32 ExtTextOut32W( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
-                      const RECT32 *lprect, LPCWSTR str, UINT32 count,
-                      const INT32 *lpDx )
+BOOL32 WINAPI ExtTextOut32W( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
+                             const RECT32 *lprect, LPCWSTR str, UINT32 count,
+                             const INT32 *lpDx )
 {
     LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
     INT32 ret = ExtTextOut32A( hdc, x, y, flags, lprect, p, count, lpDx );
@@ -365,7 +365,7 @@
 /***********************************************************************
  *           TextOut16    (GDI.33)
  */
-BOOL16 TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
+BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
 {
     return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
 }
@@ -374,7 +374,7 @@
 /***********************************************************************
  *           TextOut32A    (GDI32.355)
  */
-BOOL32 TextOut32A( HDC32 hdc, INT32 x, INT32 y, LPCSTR str, INT32 count )
+BOOL32 WINAPI TextOut32A( HDC32 hdc, INT32 x, INT32 y, LPCSTR str, INT32 count )
 {
     return ExtTextOut32A( hdc, x, y, 0, NULL, str, count, NULL );
 }
@@ -383,7 +383,7 @@
 /***********************************************************************
  *           TextOut32W    (GDI32.356)
  */
-BOOL32 TextOut32W( HDC32 hdc, INT32 x, INT32 y, LPCWSTR str, INT32 count )
+BOOL32 WINAPI TextOut32W(HDC32 hdc, INT32 x, INT32 y, LPCWSTR str, INT32 count)
 {
     return ExtTextOut32W( hdc, x, y, 0, NULL, str, count, NULL );
 }
@@ -392,9 +392,9 @@
 /***********************************************************************
  *           GrayString16   (USER.185)
  */
-BOOL16 GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
-                     LPARAM lParam, INT16 cch, INT16 x, INT16 y,
-                     INT16 cx, INT16 cy )
+BOOL16 WINAPI GrayString16( HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc,
+                            LPARAM lParam, INT16 cch, INT16 x, INT16 y,
+                            INT16 cx, INT16 cy )
 {
     BOOL16 ret;
     COLORREF current_color;
@@ -411,9 +411,9 @@
 /***********************************************************************
  *           GrayString32A   (USER32.314)
  */
-BOOL32 GrayString32A( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 gsprc,
-                      LPARAM lParam, INT32 cch, INT32 x, INT32 y,
-                      INT32 cx, INT32 cy )
+BOOL32 WINAPI GrayString32A( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 gsprc,
+                             LPARAM lParam, INT32 cch, INT32 x, INT32 y,
+                             INT32 cx, INT32 cy )
 {
     BOOL32 ret;
     COLORREF current_color;
@@ -430,9 +430,9 @@
 /***********************************************************************
  *           GrayString32W   (USER32.315)
  */
-BOOL32 GrayString32W( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 gsprc,
-                      LPARAM lParam, INT32 cch, INT32 x, INT32 y,
-                      INT32 cx, INT32 cy )
+BOOL32 WINAPI GrayString32W( HDC32 hdc, HBRUSH32 hbr, GRAYSTRINGPROC32 gsprc,
+                             LPARAM lParam, INT32 cch, INT32 x, INT32 y,
+                             INT32 cx, INT32 cy )
 {
     BOOL32 ret;
     COLORREF current_color;
@@ -523,8 +523,9 @@
 /***********************************************************************
  *           TabbedTextOut16    (USER.196)
  */
-LONG TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr, INT16 count, 
-                      INT16 cTabStops, const INT16 *lpTabPos, INT16 nTabOrg )
+LONG WINAPI TabbedTextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR lpstr,
+                             INT16 count, INT16 cTabStops,
+                             const INT16 *lpTabPos, INT16 nTabOrg )
 {
     dprintf_text( stddeb, "TabbedTextOut16: %04x %d,%d '%.*s' %d\n",
                   hdc, x, y, count, lpstr, count );
@@ -536,8 +537,9 @@
 /***********************************************************************
  *           TabbedTextOut32A    (USER32.541)
  */
-LONG TabbedTextOut32A( HDC32 hdc, INT32 x, INT32 y, LPCSTR lpstr, INT32 count, 
-                       INT32 cTabStops, const INT32 *lpTabPos, INT32 nTabOrg )
+LONG WINAPI TabbedTextOut32A( HDC32 hdc, INT32 x, INT32 y, LPCSTR lpstr,
+                              INT32 count, INT32 cTabStops,
+                              const INT32 *lpTabPos, INT32 nTabOrg )
 {
     dprintf_text( stddeb, "TabbedTextOut32A: %04x %d,%d '%.*s' %d\n",
                   hdc, x, y, count, lpstr, count );
@@ -549,8 +551,9 @@
 /***********************************************************************
  *           TabbedTextOut32W    (USER32.542)
  */
-LONG TabbedTextOut32W( HDC32 hdc, INT32 x, INT32 y, LPCWSTR str, INT32 count, 
-                       INT32 cTabStops, const INT32 *lpTabPos, INT32 nTabOrg )
+LONG WINAPI TabbedTextOut32W( HDC32 hdc, INT32 x, INT32 y, LPCWSTR str,
+                              INT32 count, INT32 cTabStops,
+                              const INT32 *lpTabPos, INT32 nTabOrg )
 {
     LONG ret;
     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
@@ -565,8 +568,8 @@
 /***********************************************************************
  *           GetTabbedTextExtent16    (USER.197)
  */
-DWORD GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count, 
-                             INT16 cTabStops, const INT16 *lpTabPos )
+DWORD WINAPI GetTabbedTextExtent16( HDC16 hdc, LPCSTR lpstr, INT16 count, 
+                                    INT16 cTabStops, const INT16 *lpTabPos )
 {
     dprintf_text( stddeb, "GetTabbedTextExtent: %04x '%.*s' %d\n",
                   hdc, count, lpstr, count );
@@ -578,8 +581,8 @@
 /***********************************************************************
  *           GetTabbedTextExtent32A    (USER32.292)
  */
-DWORD GetTabbedTextExtent32A( HDC32 hdc, LPCSTR lpstr, INT32 count, 
-                              INT32 cTabStops, const INT32 *lpTabPos )
+DWORD WINAPI GetTabbedTextExtent32A( HDC32 hdc, LPCSTR lpstr, INT32 count, 
+                                     INT32 cTabStops, const INT32 *lpTabPos )
 {
     dprintf_text( stddeb, "GetTabbedTextExtent: %04x '%.*s' %d\n",
                   hdc, count, lpstr, count );
@@ -591,8 +594,8 @@
 /***********************************************************************
  *           GetTabbedTextExtent32W    (USER32.293)
  */
-DWORD GetTabbedTextExtent32W( HDC32 hdc, LPCWSTR lpstr, INT32 count, 
-                              INT32 cTabStops, const INT32 *lpTabPos )
+DWORD WINAPI GetTabbedTextExtent32W( HDC32 hdc, LPCWSTR lpstr, INT32 count, 
+                                     INT32 cTabStops, const INT32 *lpTabPos )
 {
     LONG ret;
     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
@@ -605,11 +608,13 @@
 /***********************************************************************
  *           GetTextCharset    (USER32.226) (USER.612)
  */
-INT32 GetTextCharset32(HDC32 hdc) {
+INT32 WINAPI GetTextCharset32(HDC32 hdc)
+{
     fprintf(stdnimp,"GetTextCharset(0x%x)\n",hdc);
     return DEFAULT_CHARSET; /* FIXME */
 }
 
-INT16 GetTextCharset16(HDC16 hdc) {
+INT16 WINAPI GetTextCharset16(HDC16 hdc)
+{
     return GetTextCharset32(hdc);
 }
diff --git a/scheduler/process.c b/scheduler/process.c
index 05fa39d..2819562 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -219,7 +219,7 @@
 /*********************************************************************
  *           CloseHandle   (KERNEL32.23)
  */
-BOOL32 CloseHandle( HANDLE32 handle )
+BOOL32 WINAPI CloseHandle( HANDLE32 handle )
 {
     BOOL32 ret = FALSE;
     K32OBJ *ptr = NULL;
@@ -350,7 +350,7 @@
 /***********************************************************************
  *           ExitProcess   (KERNEL32.100)
  */
-void ExitProcess( DWORD status )
+void WINAPI ExitProcess( DWORD status )
 {
     TASK_KillCurrentTask( status );
 }
@@ -359,7 +359,7 @@
 /***********************************************************************
  *           GetCurrentProcess   (KERNEL32.198)
  */
-HANDLE32 GetCurrentProcess(void)
+HANDLE32 WINAPI GetCurrentProcess(void)
 {
     return 0x7fffffff;
 }
@@ -368,7 +368,7 @@
 /***********************************************************************
  *           GetCurrentProcessId   (KERNEL32.199)
  */
-DWORD GetCurrentProcessId(void)
+DWORD WINAPI GetCurrentProcessId(void)
 {
     return (DWORD)pCurrentProcess;
 }
@@ -377,7 +377,7 @@
 /***********************************************************************
  *      GetEnvironmentStrings32A   (KERNEL32.210) (KERNEL32.211)
  */
-LPSTR GetEnvironmentStrings32A(void)
+LPSTR WINAPI GetEnvironmentStrings32A(void)
 {
     assert( pCurrentProcess );
     return pCurrentProcess->env_db->environ;
@@ -387,7 +387,7 @@
 /***********************************************************************
  *      GetEnvironmentStrings32W   (KERNEL32.212)
  */
-LPWSTR GetEnvironmentStrings32W(void)
+LPWSTR WINAPI GetEnvironmentStrings32W(void)
 {
     INT32 size;
     LPWSTR ret, pW;
@@ -414,7 +414,7 @@
 /***********************************************************************
  *           FreeEnvironmentStrings32A   (KERNEL32.141)
  */
-BOOL32 FreeEnvironmentStrings32A( LPSTR ptr )
+BOOL32 WINAPI FreeEnvironmentStrings32A( LPSTR ptr )
 {
     assert( pCurrentProcess );
     if (ptr != pCurrentProcess->env_db->environ)
@@ -429,7 +429,7 @@
 /***********************************************************************
  *           FreeEnvironmentStrings32W   (KERNEL32.142)
  */
-BOOL32 FreeEnvironmentStrings32W( LPWSTR ptr )
+BOOL32 WINAPI FreeEnvironmentStrings32W( LPWSTR ptr )
 {
     assert( pCurrentProcess );
     return HeapFree( GetProcessHeap(), 0, ptr );
@@ -439,7 +439,7 @@
 /***********************************************************************
  *          GetEnvironmentVariable32A   (KERNEL32.213)
  */
-DWORD GetEnvironmentVariable32A( LPCSTR name, LPSTR value, DWORD size )
+DWORD WINAPI GetEnvironmentVariable32A( LPCSTR name, LPSTR value, DWORD size )
 {
     LPSTR p;
     INT32 len, res;
@@ -470,7 +470,7 @@
 /***********************************************************************
  *           GetEnvironmentVariable32W   (KERNEL32.214)
  */
-DWORD GetEnvironmentVariable32W( LPCWSTR nameW, LPWSTR valW, DWORD size )
+DWORD WINAPI GetEnvironmentVariable32W( LPCWSTR nameW, LPWSTR valW, DWORD size)
 {
     LPSTR name = HEAP_strdupWtoA( GetProcessHeap(), 0, nameW );
     LPSTR val  = HeapAlloc( GetProcessHeap(), 0, size );
@@ -485,7 +485,7 @@
 /***********************************************************************
  *           SetEnvironmentVariable32A   (KERNEL32.484)
  */
-BOOL32 SetEnvironmentVariable32A( LPCSTR name, LPCSTR value )
+BOOL32 WINAPI SetEnvironmentVariable32A( LPCSTR name, LPCSTR value )
 {
     INT32 size, len, res;
     LPSTR p, env, new_env;
@@ -535,7 +535,7 @@
 /***********************************************************************
  *           SetEnvironmentVariable32W   (KERNEL32.485)
  */
-BOOL32 SetEnvironmentVariable32W( LPCWSTR name, LPCWSTR value )
+BOOL32 WINAPI SetEnvironmentVariable32W( LPCWSTR name, LPCWSTR value )
 {
     LPSTR nameA  = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
     LPSTR valueA = HEAP_strdupWtoA( GetProcessHeap(), 0, value );
@@ -549,7 +549,8 @@
 /***********************************************************************
  *           ExpandEnvironmentVariablesA   (KERNEL32.103)
  */
-DWORD ExpandEnvironmentStrings32A( LPCSTR src, LPSTR dst, DWORD len) {
+DWORD WINAPI ExpandEnvironmentStrings32A( LPCSTR src, LPSTR dst, DWORD len)
+{
 	LPCSTR s;
         LPSTR d;
 	HANDLE32	heap = GetProcessHeap();
@@ -622,7 +623,8 @@
 /***********************************************************************
  *           ExpandEnvironmentVariablesA   (KERNEL32.104)
  */
-DWORD ExpandEnvironmentStrings32W( LPCWSTR src, LPWSTR dst, DWORD len) {
+DWORD WINAPI ExpandEnvironmentStrings32W( LPCWSTR src, LPWSTR dst, DWORD len)
+{
 	HANDLE32	heap = GetProcessHeap();
 	LPSTR		srcA = HEAP_strdupWtoA(heap,0,src);
 	LPSTR		dstA = HeapAlloc(heap,0,len);
@@ -637,7 +639,7 @@
 /***********************************************************************
  *           GetProcessHeap    (KERNEL32.259)
  */
-HANDLE32 GetProcessHeap(void)
+HANDLE32 WINAPI GetProcessHeap(void)
 {
     if (!pCurrentProcess) return SystemHeap;  /* For the boot-up code */
     return pCurrentProcess->heap;
@@ -647,7 +649,7 @@
 /***********************************************************************
  *           GetThreadLocale    (KERNEL32.295)
  */
-LCID GetThreadLocale(void)
+LCID WINAPI GetThreadLocale(void)
 {
     return pCurrentProcess->locale;
 }
@@ -656,7 +658,7 @@
 /***********************************************************************
  *           SetPriorityClass   (KERNEL32.503)
  */
-BOOL32 SetPriorityClass( HANDLE32 hprocess, DWORD priorityclass )
+BOOL32 WINAPI SetPriorityClass( HANDLE32 hprocess, DWORD priorityclass )
 {
     PDB32	*pdb;
 
@@ -688,7 +690,7 @@
 /***********************************************************************
  *           GetPriorityClass   (KERNEL32.250)
  */
-DWORD GetPriorityClass(HANDLE32 hprocess)
+DWORD WINAPI GetPriorityClass(HANDLE32 hprocess)
 {
     PDB32	*pdb;
     DWORD	ret;
@@ -726,7 +728,7 @@
  * FIXME: These should be allocated when a console is created, or inherited
  *        from the parent.
  */
-HANDLE32 GetStdHandle( DWORD std_handle )
+HANDLE32 WINAPI GetStdHandle( DWORD std_handle )
 {
     HFILE32 hFile;
     int fd;
@@ -771,7 +773,7 @@
 /***********************************************************************
  *           SetStdHandle    (KERNEL32.506)
  */
-BOOL32 SetStdHandle( DWORD std_handle, HANDLE32 handle )
+BOOL32 WINAPI SetStdHandle( DWORD std_handle, HANDLE32 handle )
 {
     assert( pCurrentProcess );
     switch(std_handle)
@@ -793,8 +795,8 @@
 /***********************************************************************
  *           GetProcessVersion    (KERNEL32)
  */
-DWORD
-GetProcessVersion(DWORD processid) {
+DWORD WINAPI GetProcessVersion(DWORD processid)
+{
 	PDB32	*process;
 	TDB	*pTask;
 
@@ -808,3 +810,65 @@
 		return 0;
 	return (pTask->version&0xff) | (((pTask->version >>8) & 0xff)<<16);
 }
+
+/***********************************************************************
+ *           SetProcessWorkingSetSize    (KERNEL32)
+ */
+BOOL32 WINAPI SetProcessWorkingSetSize(HANDLE32 hProcess,DWORD minset,
+                                       DWORD maxset)
+{
+	fprintf(stderr,"SetProcessWorkingSetSize(0x%08x,%ld,%ld), STUB!\n",
+		hProcess,minset,maxset
+	);
+	return TRUE;
+}
+
+/***********************************************************************
+ *           GetProcessWorkingSetSize    (KERNEL32)
+ */
+BOOL32 WINAPI GetProcessWorkingSetSize(HANDLE32 hProcess,LPDWORD minset,
+                                       LPDWORD maxset)
+{
+	fprintf(stderr,"SetProcessWorkingSetSize(0x%08x,%p,%p), STUB!\n",
+		hProcess,minset,maxset
+	);
+	/* 32 MB working set size */
+	if (minset) *minset = 32*1024*1024;
+	if (maxset) *maxset = 32*1024*1024;
+	return TRUE;
+}
+
+/***********************************************************************
+ *           SetProcessShutdownParameters    (KERNEL32)
+ */
+BOOL32 WINAPI SetProcessShutdownParameters(DWORD level,DWORD flags)
+{
+	fprintf(stderr,"SetProcessShutdownParameters(%ld,0x%08lx), STUB!\n",
+		level,flags
+	);
+	return TRUE;
+}
+
+/***********************************************************************
+ *           ReadProcessMemory    		(KERNEL32)
+ * FIXME: check this, if we ever run win32 binaries in different addressspaces
+ *	  ... and add a sizecheck
+ */
+BOOL32 WINAPI ReadProcessMemory( HANDLE32 hProcess, LPCVOID lpBaseAddress,
+                                 LPVOID lpBuffer, DWORD nSize,
+                                 LPDWORD lpNumberOfBytesRead )
+{
+	memcpy(lpBuffer,lpBaseAddress,nSize);
+	if (lpNumberOfBytesRead) *lpNumberOfBytesRead = nSize;
+	return TRUE;
+}
+
+/***********************************************************************
+ *           ConvertToGlobalHandle    		(KERNEL32)
+ * FIXME: this is not correctly implemented...
+ */
+HANDLE32 WINAPI ConvertToGlobalHandle(HANDLE32 h)
+{
+	fprintf(stderr,"ConvertToGlobalHandle(%d),stub!\n",h);
+	return h;
+}
diff --git a/scheduler/thread.c b/scheduler/thread.c
index 22f78f6..7d1bbe2 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -12,6 +12,8 @@
 #include "selectors.h"
 #include "miscemu.h"
 #include "winnt.h"
+#include "debug.h"
+#include "stddebug.h"
 
 THDB *pCurrentThread = NULL;
 
@@ -114,9 +116,9 @@
  *
  * The only thing missing here is actually getting the thread to run ;-)
  */
-HANDLE32 CreateThread( LPSECURITY_ATTRIBUTES attribs, DWORD stack,
-                       LPTHREAD_START_ROUTINE start, LPVOID param,
-                       DWORD flags, LPDWORD id )
+HANDLE32 WINAPI CreateThread( LPSECURITY_ATTRIBUTES attribs, DWORD stack,
+                              LPTHREAD_START_ROUTINE start, LPVOID param,
+                              DWORD flags, LPDWORD id )
 {
     HANDLE32 handle;
     THDB *thread = THREAD_Create( pCurrentProcess, stack, start );
@@ -136,7 +138,7 @@
 /***********************************************************************
  *           GetCurrentThread   (KERNEL32.200)
  */
-HANDLE32 GetCurrentThread(void)
+HANDLE32 WINAPI GetCurrentThread(void)
 {
     return 0xFFFFFFFE;
 }
@@ -146,7 +148,7 @@
  *           GetCurrentThreadId   (KERNEL32.201)
  * Returns crypted (xor'ed) pointer to THDB in Win95.
  */
-DWORD GetCurrentThreadId(void)
+DWORD WINAPI GetCurrentThreadId(void)
 {
     /* FIXME: should probably use %fs register here */
     assert( pCurrentThread );
@@ -157,7 +159,7 @@
 /**********************************************************************
  *           GetLastError   (KERNEL.148) (KERNEL32.227)
  */
-DWORD GetLastError(void)
+DWORD WINAPI GetLastError(void)
 {
     THDB *thread = (THDB *)GetCurrentThreadId();
     return thread->last_error;
@@ -167,7 +169,7 @@
 /**********************************************************************
  *           SetLastError   (KERNEL.147) (KERNEL32.497)
  */
-void SetLastError( DWORD error )
+void WINAPI SetLastError( DWORD error )
 {
     THDB *thread;
     if (!pCurrentThread) return;  /* FIXME */
@@ -179,7 +181,7 @@
 /**********************************************************************
  *           SetLastErrorEx   (USER32.484)
  */
-void SetLastErrorEx( DWORD error, DWORD type )
+void WINAPI SetLastErrorEx( DWORD error, DWORD type )
 {
     /* FIXME: what about 'type'? */
     SetLastError( error );
@@ -189,7 +191,7 @@
 /**********************************************************************
  *           TlsAlloc   (KERNEL32.530)
  */
-DWORD TlsAlloc(void)
+DWORD WINAPI TlsAlloc(void)
 {
     DWORD i, mask, ret = 0;
     THDB *thread = (THDB *)GetCurrentThreadId();
@@ -216,7 +218,7 @@
 /**********************************************************************
  *           TlsFree   (KERNEL32.531)
  */
-BOOL32 TlsFree( DWORD index )
+BOOL32 WINAPI TlsFree( DWORD index )
 {
     DWORD mask;
     THDB *thread = (THDB *)GetCurrentThreadId();
@@ -246,7 +248,7 @@
 /**********************************************************************
  *           TlsGetValue   (KERNEL32.532)
  */
-LPVOID TlsGetValue( DWORD index )
+LPVOID WINAPI TlsGetValue( DWORD index )
 {
     THDB *thread = (THDB *)GetCurrentThreadId();
     if (index >= 64)
@@ -262,7 +264,7 @@
 /**********************************************************************
  *           TlsSetValue   (KERNEL32.533)
  */
-BOOL32 TlsSetValue( DWORD index, LPVOID value )
+BOOL32 WINAPI TlsSetValue( DWORD index, LPVOID value )
 {
     THDB *thread = (THDB *)GetCurrentThreadId();
     if (index >= 64)
@@ -278,7 +280,7 @@
 /***********************************************************************
  *           GetThreadContext   (KERNEL32.294)
  */
-BOOL32 GetThreadContext( HANDLE32 handle, CONTEXT *context )
+BOOL32 WINAPI GetThreadContext( HANDLE32 handle, CONTEXT *context )
 {
     THDB *thread = (THDB*)PROCESS_GetObjPtr( handle, K32OBJ_THREAD );
     if (!thread) return FALSE;
@@ -291,7 +293,7 @@
 /**********************************************************************
  *           NtCurrentTeb   (NTDLL.89)
  */
-void NtCurrentTeb( CONTEXT *context )
+void WINAPI NtCurrentTeb( CONTEXT *context )
 {
     EAX_reg(context) = GetSelectorBase( FS_reg(context) );
 }
@@ -300,7 +302,7 @@
 /**********************************************************************
  *           GetThreadPriority   (KERNEL32.296)
  */
-INT32 GetThreadPriority(HANDLE32 hthread)
+INT32 WINAPI GetThreadPriority(HANDLE32 hthread)
 {
     THDB *thread;
     INT32 ret;
@@ -315,7 +317,7 @@
 /**********************************************************************
  *           SetThreadPriority   (KERNEL32.514)
  */
-BOOL32 SetThreadPriority(HANDLE32 hthread,INT32 priority)
+BOOL32 WINAPI SetThreadPriority(HANDLE32 hthread,INT32 priority)
 {
     THDB *thread;
     
@@ -324,3 +326,12 @@
     K32OBJ_DecCount( &thread->header );
     return TRUE;
 }
+
+/**********************************************************************
+ *           TerminateThread   (KERNEL32)
+ */
+BOOL32 WINAPI TerminateThread(DWORD threadid,DWORD exitcode)
+{
+    fprintf(stdnimp,"TerminateThread(0x%08lx,%ld), STUB!\n",threadid,exitcode);
+    return TRUE;
+}
diff --git a/tools/build.c b/tools/build.c
index 6ab1a55..327a8e8 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -1327,13 +1327,11 @@
  * functions that need a large stack, like X bitmaps functions.
  *
  * The generated function has the following prototype:
- *   int CallTo32_LargeStack( int (*func)(), int nbargs, ... )
+ *   int CALLTO32_LargeStack( int (*func)(), void *arg );
  *
  * Stack layout:
  *   ...     ...
- * (ebp+20)  arg2
- * (ebp+16)  arg1
- * (ebp+12)  nbargs
+ * (ebp+12)  arg
  * (ebp+8)   func
  * (ebp+4)   ret addr
  * (ebp)     ebp
@@ -1344,22 +1342,16 @@
 
     fprintf( outfile, "\n\t.align 4\n" );
 #ifdef USE_STABS
-    fprintf( outfile, ".stabs \"CallTo32_LargeStack:F1\",36,0,0," PREFIX "CallTo32_LargeStack\n");
+    fprintf( outfile, ".stabs \"CALLTO32_LargeStack:F1\",36,0,0," PREFIX "CALLTO32_LargeStack\n");
 #endif
-    fprintf( outfile, "\t.globl " PREFIX "CallTo32_LargeStack\n" );
-    fprintf( outfile, PREFIX "CallTo32_LargeStack:\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO32_LargeStack\n" );
+    fprintf( outfile, PREFIX "CALLTO32_LargeStack:\n" );
     
     /* Entry code */
 
     fprintf( outfile, "\tpushl %%ebp\n" );
     fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
 
-    /* Save registers */
-
-    fprintf( outfile, "\tpushl %%ecx\n" );
-    fprintf( outfile, "\tpushl %%esi\n" );
-    fprintf( outfile, "\tpushl %%edi\n" );
-
     /* Retrieve the original 32-bit stack pointer and switch to it if any */
 
     fprintf( outfile, "\tmovl " PREFIX "IF1632_Original32_esp, %%eax\n" );
@@ -1368,33 +1360,14 @@
     fprintf( outfile, "\tmovl %%eax,%%esp\n" );
     fprintf( outfile, "no_orig_esp:\n" );
 
-    /* Transfer the arguments */
+    /* Transfer the argument and call the function */
 
-    fprintf( outfile, "\tmovl 12(%%ebp),%%ecx\n" );
-    fprintf( outfile, "\torl %%ecx,%%ecx\n" );
-    fprintf( outfile, "\tje no_args\n" );
-    fprintf( outfile, "\tleal 16(%%ebp),%%esi\n" );
-    fprintf( outfile, "\tshll $2,%%ecx\n" );
-    fprintf( outfile, "\tsubl %%ecx,%%esp\n" );
-    fprintf( outfile, "\tmovl %%esp,%%edi\n" );
-    fprintf( outfile, "\tshrl $2,%%ecx\n" );
-    fprintf( outfile, "\tcld\n" );
-    fprintf( outfile, "\trep; movsl\n" );
-    fprintf( outfile, "no_args:\n" );
-
-    /* Call the function */
-
+    fprintf( outfile, "\tpushl 12(%%ebp)\n" );
     fprintf( outfile, "\tcall 8(%%ebp)\n" );
 
-    /* Switch back to the normal stack */
-
-    fprintf( outfile, "\tleal -12(%%ebp),%%esp\n" );
-
     /* Restore registers and return */
 
-    fprintf( outfile, "\tpopl %%edi\n" );
-    fprintf( outfile, "\tpopl %%esi\n" );
-    fprintf( outfile, "\tpopl %%ecx\n" );
+    fprintf( outfile, "\tmovl %%ebp,%%esp\n" );
     fprintf( outfile, "\tpopl %%ebp\n" );
     fprintf( outfile, "\tret\n" );
 }
@@ -2197,6 +2170,19 @@
     fprintf( outfile, "\t.globl " PREFIX "CallFrom32_%s\n", profile );
     fprintf( outfile, PREFIX "CallFrom32_%s:\n", profile );
 
+#if 0
+    fprintf( outfile, "\tleal 8(%%esp),%%ebp\n" );
+    fprintf( outfile, "\tpushl $%d\n",  /* Nb args */
+             reg_func ? args | 0x80000000 : args);
+    fprintf( outfile, "\tpushl %%ebp\n" );
+    fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallFrom32\n" );
+    fprintf( outfile, "\tadd $8, %%esp\n" );
+    fprintf( outfile, "\tpopl  %%eax\n" );
+    fprintf( outfile, "\tpopl  %%eax\n" );
+    fprintf( outfile, "\tpopl  %%ebp\n" );
+    fprintf( outfile, "\tjmp %%eax\n" );
+#endif
+
     /* Entry code */
 
     fprintf( outfile, "\tleal 8(%%esp),%%ebp\n" );
@@ -2373,10 +2359,6 @@
     fprintf( outfile, "Code_Start:\n\n" );
 #endif
 
-    /* Build the 32-bit large stack callback */
-
-    BuildCall32LargeStack( outfile );
-
     /* Build the callback functions */
 
     for (i = 2; i < argc; i++) BuildCallFrom16Func( outfile, argv[i] );
@@ -2538,6 +2520,10 @@
     fprintf( outfile, "Code_Start:\n\n" );
 #endif
 
+    /* Build the 32-bit large stack callback */
+
+    BuildCall32LargeStack( outfile );
+
     /* Build the callback functions */
 
     for (i = 2; i < argc; i++) BuildCallTo32Func( outfile, atoi(argv[i]) );
diff --git a/tools/fnt2bdf.c b/tools/fnt2bdf.c
index 6795116..d994a99 100644
--- a/tools/fnt2bdf.c
+++ b/tools/fnt2bdf.c
@@ -350,12 +350,12 @@
 
 	case ANSI_CHARSET: 	fputs("ansi-0\n", fs); break;
 	case GREEK_CHARSET: 	fputs("cp125-3\n", fs); break;
-	case TURKISH_CHARSET: 	fputs("iso8859-9", fs); break;
-	case HEBREW_CHARSET: 	fputs("cp125-5", fs); break;
-	case ARABIC_CHARSET: 	fputs("cp125-6", fs); break;
-	case BALTIC_CHARSET: 	fputs("cp125-7", fs); break;
-	case RUSSIAN_CHARSET: 	fputs("cp125-1", fs); break;
-	case EE_CHARSET: 	fputs("iso8859-2", fs); break; 
+	case TURKISH_CHARSET: 	fputs("cp125-4\n", fs); break;
+	case HEBREW_CHARSET: 	fputs("cp125-5\n", fs); break;
+	case ARABIC_CHARSET: 	fputs("cp125-6\n", fs); break;
+	case BALTIC_CHARSET: 	fputs("cp125-7\n", fs); break;
+	case RUSSIAN_CHARSET: 	fputs("cp125-1\n", fs); break;
+	case EE_CHARSET: 	fputs("cp125-0\n", fs); break; 
 	case SYMBOL_CHARSET: 	fputs("misc-fontspecific\n", fs); break;
 	case SHIFTJIS_CHARSET: 	fputs("jisx0208.1983-0\n", fs); break;
 	case DEFAULT_CHARSET:	fputs("iso8859-1\n", fs); break;
diff --git a/win32/advapi.c b/win32/advapi.c
index 9bb1ca7..d6c25c0 100644
--- a/win32/advapi.c
+++ b/win32/advapi.c
@@ -16,8 +16,7 @@
 /***********************************************************************
  *           StartServiceCtrlDispatcherA   [ADVAPI32.196]
  */
-BOOL32
-StartServiceCtrlDispatcher32A(LPSERVICE_TABLE_ENTRY32A servent)
+BOOL32 WINAPI StartServiceCtrlDispatcher32A(LPSERVICE_TABLE_ENTRY32A servent)
 {
 	fprintf(stderr,"StartServiceCtrlDispatcherA(%p (%s)), STUB.\n",
 		servent,
@@ -29,8 +28,7 @@
 /***********************************************************************
  *           StartServiceCtrlDispatcherW   [ADVAPI32.197]
  */
-BOOL32
-StartServiceCtrlDispatcher32W(LPSERVICE_TABLE_ENTRY32W servent)
+BOOL32 WINAPI StartServiceCtrlDispatcher32W(LPSERVICE_TABLE_ENTRY32W servent)
 {
 	char	buffer[200];
 
@@ -46,8 +44,8 @@
 /***********************************************************************
  *           OpenProcessToken   [ADVAPI32.197]
  */
-BOOL32
-OpenProcessToken(HANDLE32 process,DWORD desiredaccess,HANDLE32 *thandle)
+BOOL32 WINAPI OpenProcessToken(HANDLE32 process,DWORD desiredaccess,
+                               HANDLE32 *thandle)
 {
 	fprintf(stdnimp,"OpenProcessToken(%08x,%08lx,%p),stub!\n",
 		process,desiredaccess,thandle
@@ -58,10 +56,9 @@
 /***********************************************************************
  *           OpenThreadToken		[ADVAPI32.114]
  */
-BOOL32
-OpenThreadToken(
-	HANDLE32 thread,DWORD desiredaccess,BOOL32 openasself,HANDLE32 *thandle
-) {
+BOOL32 WINAPI OpenThreadToken( HANDLE32 thread,DWORD desiredaccess,
+                               BOOL32 openasself,HANDLE32 *thandle )
+{
 	fprintf(stdnimp,"OpenThreadToken(%08x,%08lx,%d,%p),stub!\n",
 		thread,desiredaccess,openasself,thandle
 	);
@@ -71,16 +68,14 @@
 /***********************************************************************
  *           LookupPrivilegeValueA   [ADVAPI32.90]
  */
-BOOL32
-LookupPrivilegeValue32A(LPCSTR system,LPCSTR name,LPVOID bla)
+BOOL32 WINAPI LookupPrivilegeValue32A(LPCSTR system,LPCSTR name,LPVOID bla)
 {
 	fprintf(stdnimp,"LookupPrivilegeValue32A(%s,%s,%p),stub\n",
 		system,name,bla
 	);
 	return TRUE;
 }
-BOOL32
-AdjustTokenPrivileges(HANDLE32 TokenHandle,BOOL32 DisableAllPrivileges,
+BOOL32 WINAPI AdjustTokenPrivileges(HANDLE32 TokenHandle,BOOL32 DisableAllPrivileges,
 	LPVOID NewState,DWORD BufferLength,LPVOID PreviousState,
 	LPDWORD ReturnLength )
 {
@@ -90,27 +85,24 @@
 /***********************************************************************
  *           GetTokenInformation	[ADVAPI32.66]
  */
-BOOL32
-GetTokenInformation(
+BOOL32 WINAPI GetTokenInformation(
 	HANDLE32 token,/*TOKEN_INFORMATION_CLASS*/ DWORD tokeninfoclass,LPVOID tokeninfo,
 	DWORD tokeninfolength,LPDWORD retlen
 ) {
-	fprintf(stderr,"GetTokenInformation(%08lx,%d,%p,%ld,%p)\n",
+	fprintf(stderr,"GetTokenInformation(%08x,%ld,%p,%ld,%p)\n",
 		token,tokeninfoclass,tokeninfo,tokeninfolength,retlen
 	);
 	return TRUE;
 }
 
 /*SC_HANDLE*/
-DWORD
-OpenSCManagerA(LPCSTR machine,LPCSTR dbname,DWORD desiredaccess)
+DWORD WINAPI OpenSCManagerA(LPCSTR machine,LPCSTR dbname,DWORD desiredaccess)
 {
 	fprintf(stderr,"OpenSCManagerA(%s,%s,%08lx)\n",machine,dbname,desiredaccess);
 	return 0;
 }
 
-DWORD
-OpenSCManagerW(LPCWSTR machine,LPCWSTR dbname,DWORD desiredaccess)
+DWORD WINAPI OpenSCManagerW(LPCWSTR machine,LPCWSTR dbname,DWORD desiredaccess)
 {
 	LPSTR	machineA = HEAP_strdupWtoA(GetProcessHeap(),0,machine);
 	LPSTR	dbnameA = HEAP_strdupWtoA(GetProcessHeap(),0,dbname);
@@ -120,8 +112,7 @@
 	return 0;
 }
 
-BOOL32
-AllocateLocallyUniqueId(LPLUID lpluid) {
+BOOL32 WINAPI AllocateLocallyUniqueId(LPLUID lpluid) {
 	lpluid->LowPart = time(NULL);
 	lpluid->HighPart = 0;
 	return TRUE;
diff --git a/win32/code_page.c b/win32/code_page.c
index 508172b..7a10618 100644
--- a/win32/code_page.c
+++ b/win32/code_page.c
@@ -17,7 +17,7 @@
 /***********************************************************************
  *           GetACP               (KERNEL32.148)
  */
-UINT32 GetACP(void)
+UINT32 WINAPI GetACP(void)
 {
     return 1252;    /* Windows 3.1 ISO Latin */
 }
@@ -25,7 +25,7 @@
 /***********************************************************************
  *           GetCPInfo            (KERNEL32.154)
  */
-BOOL32 GetCPInfo( UINT32 codepage, LPCPINFO cpinfo )
+BOOL32 WINAPI GetCPInfo( UINT32 codepage, LPCPINFO cpinfo )
 {
     cpinfo->DefaultChar[0] = '?';
     switch (codepage)
@@ -61,7 +61,7 @@
 /***********************************************************************
  *              GetOEMCP                (KERNEL32.248)
  */
-UINT32 GetOEMCP(void)
+UINT32 WINAPI GetOEMCP(void)
 {
     return 437;    /* MS-DOS United States */
 }
@@ -69,7 +69,7 @@
 /***********************************************************************
  *           IsValidCodePage   (KERNEL32.360)
  */
-BOOL32 IsValidCodePage(UINT32 CodePage)
+BOOL32 WINAPI IsValidCodePage(UINT32 CodePage)
 {
     switch ( CodePage )
     {
@@ -85,14 +85,20 @@
 /***********************************************************************
  *              MultiByteToWideChar                (KERNEL32.392)
  */
-int MultiByteToWideChar(UINT32 page, DWORD flags, char *src, int srclen,
-                        WCHAR *dst, int dstlen)
+int WINAPI MultiByteToWideChar(UINT32 page, DWORD flags, char *src, int srclen,
+                               WCHAR *dst, int dstlen)
 {
-    return (srclen==-1) ? strlen(src) * 2: srclen*2; 
+    if (srclen == -1)
+   	 srclen = lstrlen32A(src);
+    if (!dst)
+         return srclen*2;
+
+    lstrcpynAtoW(dst,src,srclen); /* FIXME */
+    return srclen*2;
 }
 
-int WideCharToMultiByte(UINT32 page, DWORD flags, WCHAR *src, int srclen,
-                        char *dst, int dstlen, char* defchar, BOOL32 *used)
+int WINAPI WideCharToMultiByte(UINT32 page, DWORD flags, WCHAR *src, int srclen,
+                               char *dst, int dstlen, char* defchar, BOOL32 *used)
 {
 	int count = 0;
 	int dont_copy= (dstlen==0);
@@ -133,7 +139,7 @@
 /***********************************************************************
  *           IsDBCSLeadByteEx   (KERNEL32.359)
  */
-BOOL32 IsDBCSLeadByteEx( UINT32 codepage, BYTE testchar )
+BOOL32 WINAPI IsDBCSLeadByteEx( UINT32 codepage, BYTE testchar )
 {
     CPINFO cpinfo;
     int i;
@@ -153,7 +159,7 @@
 /***********************************************************************
  *           IsDBCSLeadByte16   (KERNEL.207)
  */
-BOOL16 IsDBCSLeadByte16( BYTE testchar )
+BOOL16 WINAPI IsDBCSLeadByte16( BYTE testchar )
 {
     return IsDBCSLeadByteEx(GetACP(), testchar);
 }
@@ -162,7 +168,7 @@
 /***********************************************************************
  *           IsDBCSLeadByte32   (KERNEL32.358)
  */
-BOOL32 IsDBCSLeadByte32( BYTE testchar )
+BOOL32 WINAPI IsDBCSLeadByte32( BYTE testchar )
 {
     return IsDBCSLeadByteEx(GetACP(), testchar);
 }
@@ -171,8 +177,8 @@
 /***********************************************************************
  *              EnumSystemCodePages32A                (KERNEL32.92)
  */
-BOOL32
-EnumSystemCodePages32A(CODEPAGE_ENUMPROC32A lpfnCodePageEnum,DWORD flags) {
+BOOL32 WINAPI EnumSystemCodePages32A(CODEPAGE_ENUMPROC32A lpfnCodePageEnum,DWORD flags)
+{
 	dprintf_win32(stddeb,"EnumSystemCodePages32A(%p,%08lx)\n",
 		lpfnCodePageEnum,flags
 	);
@@ -183,8 +189,8 @@
 /***********************************************************************
  *              EnumSystemCodePages32W                (KERNEL32.93)
  */
-BOOL32
-EnumSystemCodePages32W( CODEPAGE_ENUMPROC32W lpfnCodePageEnum, DWORD flags)
+BOOL32 WINAPI EnumSystemCodePages32W( CODEPAGE_ENUMPROC32W lpfnCodePageEnum,
+                                      DWORD flags)
 {
     WCHAR	*cp;
     dprintf_win32(stddeb,"EnumSystemCodePages32W(%p,%08lx)\n",
diff --git a/win32/console.c b/win32/console.c
index e8e506d..872ac73 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -26,7 +26,7 @@
 /***********************************************************************
  *           SetConsoleCtrlHandler               (KERNEL32.459)
  */
-BOOL32 SetConsoleCtrlHandler(HANDLER_ROUTINE * func,  BOOL32 a)
+BOOL32 WINAPI SetConsoleCtrlHandler(HANDLER_ROUTINE * func,  BOOL32 a)
 {
 	return 0;
 }
@@ -34,8 +34,8 @@
 /***********************************************************************
  *           GetConsoleScreenBufferInfo   (KERNEL32.190)
  */
-BOOL32 GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput,
-                                   LPCONSOLE_SCREEN_BUFFER_INFO csbi )
+BOOL32 WINAPI GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput,
+                                          LPCONSOLE_SCREEN_BUFFER_INFO csbi )
 {
     csbi->dwSize.x = 80;
     csbi->dwSize.y = 24;
@@ -54,7 +54,7 @@
 /***********************************************************************
  *            GetLargestConsoleWindowSize   (KERNEL32.226)
  */
-DWORD GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput )
+DWORD WINAPI GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput )
 {
     return (DWORD)MAKELONG(dummyinfo.dwMaximumWindowSize.x,dummyinfo.dwMaximumWindowSize.y);
 }
@@ -62,7 +62,7 @@
 /***********************************************************************
  *            GetConsoleCP   (KERNEL32.226)
  */
-UINT32 GetConsoleCP(VOID)
+UINT32 WINAPI GetConsoleCP(VOID)
 {
     return GetACP();
 }
@@ -70,7 +70,7 @@
 /***********************************************************************
  *            GetConsoleOutputCP   (KERNEL32.189)
  */
-UINT32 GetConsoleOutputCP(VOID)
+UINT32 WINAPI GetConsoleOutputCP(VOID)
 {
     return GetConsoleCP();
 }
@@ -78,7 +78,7 @@
 /***********************************************************************
  *            GetConsoleMode   (KERNEL32.188)
  */
-BOOL32 GetConsoleMode(HANDLE32 hcon,LPDWORD mode)
+BOOL32 WINAPI GetConsoleMode(HANDLE32 hcon,LPDWORD mode)
 {
 	*mode = 	ENABLE_PROCESSED_INPUT	|
 			ENABLE_LINE_INPUT	|
@@ -91,7 +91,7 @@
 /***********************************************************************
  *            SetConsoleMode   (KERNEL32.188)
  */
-BOOL32 SetConsoleMode(HANDLE32 hcon,DWORD mode)
+BOOL32 WINAPI SetConsoleMode(HANDLE32 hcon,DWORD mode)
 {
     fprintf(stdnimp,"SetConsoleMode(%08x,%08lx)\n",hcon,mode);
     return TRUE;
@@ -100,7 +100,7 @@
 /***********************************************************************
  *            GetConsoleTitleA   (KERNEL32.191)
  */
-DWORD GetConsoleTitle32A(LPSTR title,DWORD size)
+DWORD WINAPI GetConsoleTitle32A(LPSTR title,DWORD size)
 {
     lstrcpyn32A(title,"Console",size);
     return strlen("Console");
@@ -109,7 +109,7 @@
 /***********************************************************************
  *            GetConsoleTitleW   (KERNEL32.192)
  */
-DWORD GetConsoleTitle32W(LPWSTR title,DWORD size)
+DWORD WINAPI GetConsoleTitle32W(LPWSTR title,DWORD size)
 {
     lstrcpynAtoW(title,"Console",size);
     return strlen("Console");
@@ -118,12 +118,11 @@
 /***********************************************************************
  *            WriteConsoleA   (KERNEL32.567)
  */
-BOOL32 WriteConsole32A(
-	HANDLE32 hConsoleOutput,
-	LPVOID lpBuffer,
-	DWORD nNumberOfCharsToWrite,
-	LPDWORD lpNumberOfCharsWritten,
-	LPVOID lpReserved )
+BOOL32 WINAPI WriteConsole32A( HANDLE32 hConsoleOutput,
+                               LPVOID lpBuffer,
+                               DWORD nNumberOfCharsToWrite,
+                               LPDWORD lpNumberOfCharsWritten,
+                               LPVOID lpReserved )
 {
 	LPSTR	buf = (LPSTR)xmalloc(nNumberOfCharsToWrite+1);
 
@@ -138,12 +137,11 @@
 /***********************************************************************
  *            WriteConsoleW   (KERNEL32.577)
  */
-BOOL32 WriteConsole32W(
-	HANDLE32 hConsoleOutput,
-	LPVOID lpBuffer,
-	DWORD nNumberOfCharsToWrite,
-	LPDWORD lpNumberOfCharsWritten,
-	LPVOID lpReserved )
+BOOL32 WINAPI WriteConsole32W( HANDLE32 hConsoleOutput,
+                               LPVOID lpBuffer,
+                               DWORD nNumberOfCharsToWrite,
+                               LPDWORD lpNumberOfCharsWritten,
+                               LPVOID lpReserved )
 {
 	LPSTR	buf = (LPSTR)xmalloc(2*nNumberOfCharsToWrite+1);
 
@@ -158,12 +156,11 @@
 /***********************************************************************
  *            ReadConsoleA   (KERNEL32.419)
  */
-BOOL32 ReadConsole32A(
-	HANDLE32 hConsoleInput,
-	LPVOID lpBuffer,
-	DWORD nNumberOfCharsToRead,
-	LPDWORD lpNumberOfCharsRead,
-	LPVOID lpReserved )
+BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput,
+                              LPVOID lpBuffer,
+                              DWORD nNumberOfCharsToRead,
+                              LPDWORD lpNumberOfCharsRead,
+                              LPVOID lpReserved )
 {
 	fgets(lpBuffer,nNumberOfCharsToRead,stdin);
 	*lpNumberOfCharsRead = strlen(lpBuffer);
@@ -173,12 +170,11 @@
 /***********************************************************************
  *            ReadConsoleW   (KERNEL32.427)
  */
-BOOL32 ReadConsole32W(
-	HANDLE32 hConsoleInput,
-	LPVOID lpBuffer,
-	DWORD nNumberOfCharsToRead,
-	LPDWORD lpNumberOfCharsRead,
-	LPVOID lpReserved )
+BOOL32 WINAPI ReadConsole32W( HANDLE32 hConsoleInput,
+                              LPVOID lpBuffer,
+                              DWORD nNumberOfCharsToRead,
+                              LPDWORD lpNumberOfCharsRead,
+                              LPVOID lpReserved )
 {
 	LPSTR	buf = (LPSTR)xmalloc(nNumberOfCharsToRead);
 
@@ -191,7 +187,7 @@
 /***********************************************************************
  *            SetConsoleTitle32A   (KERNEL32.476)
  */
-BOOL32 SetConsoleTitle32A(LPCSTR title)
+BOOL32 WINAPI SetConsoleTitle32A(LPCSTR title)
 {
     fprintf(stderr,"SetConsoleTitle(%s)\n",title);
     return TRUE;
@@ -200,7 +196,7 @@
 /***********************************************************************
  *            SetConsoleTitle32W   (KERNEL32.477)
  */
-BOOL32 SetConsoleTitle32W( LPCWSTR title )
+BOOL32 WINAPI SetConsoleTitle32W( LPCWSTR title )
 {
     LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
     fprintf(stderr,"SetConsoleTitle(%s)\n",titleA);
@@ -211,13 +207,13 @@
 /***********************************************************************
  *            FlushConsoleInputBuffer   (KERNEL32.132)
  */
-BOOL32 FlushConsoleInputBuffer(HANDLE32 hConsoleInput){
+BOOL32 WINAPI FlushConsoleInputBuffer(HANDLE32 hConsoleInput){
     fprintf(stderr,"FlushConsoleInputBuffer(%d)\n",hConsoleInput);
     return TRUE;
 }
 
-BOOL32
-SetConsoleCursorPosition(HANDLE32 hcons,COORD c) {
+BOOL32 WINAPI SetConsoleCursorPosition(HANDLE32 hcons,COORD c)
+{
     /* x are columns, y rows */
     if (!c.y) {
     	fprintf(stderr,"\r");
@@ -232,8 +228,8 @@
 /***********************************************************************
  *            GetNumberOfConsoleInputEvents   (KERNEL32.246)
  */
-BOOL32
-GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents) {
+BOOL32 WINAPI GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents)
+{
 	*nrofevents = 1;
 	return TRUE;
 }
diff --git a/win32/cursoricon32.c b/win32/cursoricon32.c
index 4ce417e..b551663 100644
--- a/win32/cursoricon32.c
+++ b/win32/cursoricon32.c
@@ -461,7 +461,7 @@
 /***********************************************************************
  *           LoadCursorW		(USER32.361)
  */
-HCURSOR32 LoadCursor32W(HINSTANCE32 hInstance,LPCWSTR name)
+HCURSOR32 WINAPI LoadCursor32W(HINSTANCE32 hInstance,LPCWSTR name)
 {
     return CURSORICON32_Load( hInstance, name,
                             SYSMETRICS_CXCURSOR, SYSMETRICS_CYCURSOR, 1, TRUE);
@@ -470,7 +470,7 @@
 /***********************************************************************
  *           LoadCursorA		(USER32.358)
  */
-HCURSOR32 LoadCursor32A(HINSTANCE32 hInstance,LPCSTR name)
+HCURSOR32 WINAPI LoadCursor32A(HINSTANCE32 hInstance,LPCSTR name)
 {
 	HCURSOR32 res=0;
 	if(!HIWORD(name))
@@ -488,7 +488,7 @@
 /***********************************************************************
  *           LoadIconW		(USER32.363)
  */
-HICON32 LoadIcon32W(HINSTANCE32 hInstance,LPCWSTR name)
+HICON32 WINAPI LoadIcon32W(HINSTANCE32 hInstance,LPCWSTR name)
 {
     return CURSORICON32_Load( hInstance, name,
                             SYSMETRICS_CXICON, SYSMETRICS_CYICON,
@@ -498,7 +498,7 @@
 /***********************************************************************
  *           LoadIconA		(USER32.362)
  */
-HICON32 LoadIcon32A(HINSTANCE32 hInstance,LPCSTR name)
+HICON32 WINAPI LoadIcon32A(HINSTANCE32 hInstance,LPCSTR name)
 {
 	HICON32 res=0;
 	if(!HIWORD(name))
diff --git a/win32/environment.c b/win32/environment.c
index 2480765..cbe6259 100644
--- a/win32/environment.c
+++ b/win32/environment.c
@@ -18,7 +18,7 @@
 /***********************************************************************
  *           GetCommandLineA      (KERNEL32.161)
  */
-LPCSTR GetCommandLine32A(void)
+LPCSTR WINAPI GetCommandLine32A(void)
 {
     static char buffer[256];
     char *cp;
@@ -39,7 +39,7 @@
 /***********************************************************************
  *           GetCommandLineW      (KERNEL32.162)
  */
-LPCWSTR GetCommandLine32W(void)
+LPCWSTR WINAPI GetCommandLine32W(void)
 {
     static WCHAR buffer[256];
 
@@ -51,7 +51,7 @@
 /***********************************************************************
  *           GetSystemPowerStatus      (KERNEL32.621)
  */
-BOOL32 GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
+BOOL32 WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
 {
     return FALSE;   /* no power management support */
 }
@@ -60,7 +60,8 @@
 /***********************************************************************
  *           SetSystemPowerState      (KERNEL32.630)
  */
-BOOL32 SetSystemPowerState(BOOL32 suspend_or_hibernate, BOOL32 force_flag)
+BOOL32 WINAPI SetSystemPowerState(BOOL32 suspend_or_hibernate,
+                                  BOOL32 force_flag)
 {
     /* suspend_or_hibernate flag: w95 does not support
        this feature anyway */
diff --git a/win32/except.c b/win32/except.c
index 90a28fb..4fbcd9d 100644
--- a/win32/except.c
+++ b/win32/except.c
@@ -45,6 +45,24 @@
 #define TEB_EXCEPTION_FRAME(pcontext) \
     ((PEXCEPTION_FRAME)((TEB *)GET_SEL_BASE((pcontext)->SegFs))->except)
 
+/*******************************************************************
+ *         _local_unwind2  (CRTDLL)
+ */
+void WINAPI CRTDLL__local_unwind2(PEXCEPTION_FRAME endframe,DWORD nr,
+                                  PCONTEXT pcontext)
+{
+	fprintf(stderr,"CRTDLL__local_unwind2(%p,%ld)\n",endframe,nr);
+	return;
+}
+
+/*******************************************************************
+ *         _global_unwind2  (CRTDLL)
+ */
+void WINAPI CRTDLL__global_unwind2(PEXCEPTION_FRAME endframe,PCONTEXT pcontext)
+{
+	RtlUnwind(endframe,NULL/*should point to the return;*/,NULL,0,pcontext);
+	return;
+}
 
 /*******************************************************************
  *         RtlUnwind  (KERNEL32.443)
@@ -52,9 +70,9 @@
  *  This function is undocumented. This is the general idea of 
  *  RtlUnwind, though. Note that error handling is not yet implemented.
  */
-void RtlUnwind( PEXCEPTION_FRAME pEndFrame, LPVOID unusedEip, 
-                PEXCEPTION_RECORD pRecord, DWORD returnEax,
-                PCONTEXT pcontext /* Wine additional parameter */ )
+void WINAPI RtlUnwind( PEXCEPTION_FRAME pEndFrame, LPVOID unusedEip, 
+                       PEXCEPTION_RECORD pRecord, DWORD returnEax,
+                       PCONTEXT pcontext /* Wine additional parameter */ )
 {   
    EXCEPTION_RECORD record;
    DWORD            dispatch;
@@ -94,9 +112,13 @@
        dprintf_win32(stddeb,"exception handler returns 0x%x, dispatch=0x%x\n",
                               retval, (int) dispatch);
   
-       if (retval == ExceptionCollidedUnwind)
+       if (	(retval == ExceptionCollidedUnwind) &&
+           	(TEB_EXCEPTION_FRAME(pcontext) != (LPVOID)dispatch)
+       )
            TEB_EXCEPTION_FRAME(pcontext) = (LPVOID)dispatch;
-       else if (TEB_EXCEPTION_FRAME(pcontext) != pEndFrame)
+       else if (	(TEB_EXCEPTION_FRAME(pcontext) != pEndFrame) &&
+           		(TEB_EXCEPTION_FRAME(pcontext) != TEB_EXCEPTION_FRAME(pcontext)->Prev)
+       )
            TEB_EXCEPTION_FRAME(pcontext) = TEB_EXCEPTION_FRAME(pcontext)->Prev;
        else
           break;  
@@ -107,11 +129,11 @@
 /*******************************************************************
  *         RaiseException  (KERNEL32.418)
  */
-void RaiseException(DWORD dwExceptionCode,
-		    DWORD dwExceptionFlags,
-		    DWORD cArguments,
-		    const LPDWORD lpArguments,
-		    PCONTEXT pcontext /* Wine additional parameter */ )
+void WINAPI RaiseException(DWORD dwExceptionCode,
+                           DWORD dwExceptionFlags,
+                           DWORD cArguments,
+                           const LPDWORD lpArguments,
+                           PCONTEXT pcontext /* Wine additional parameter */ )
 {
     PEXCEPTION_FRAME    pframe; 
     EXCEPTION_RECORD    record;
@@ -162,7 +184,7 @@
 /*******************************************************************
  *         UnhandledExceptionFilter   (KERNEL32.537)
  */
-DWORD UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers)
+DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers)
 {
     char message[80];
 
@@ -187,7 +209,7 @@
 /*************************************************************
  *            SetUnhandledExceptionFilter   (KERNEL32.516)
  */
-LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter(
+LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
                                           LPTOP_LEVEL_EXCEPTION_FILTER filter )
 {
     LPTOP_LEVEL_EXCEPTION_FILTER old = pCurrentProcess->top_filter;
diff --git a/win32/file.c b/win32/file.c
index 170c91a..79b75c6 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -33,8 +33,8 @@
 /***********************************************************************
  *             WriteFile               (KERNEL32.578)
  */
-BOOL32 WriteFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numberOfBytesToWrite,
-                 LPDWORD numberOfBytesWritten, LPOVERLAPPED lpOverlapped)
+BOOL32 WINAPI WriteFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numberOfBytesToWrite,
+                        LPDWORD numberOfBytesWritten, LPOVERLAPPED lpOverlapped)
 {
     LONG	res;
 
@@ -51,8 +51,8 @@
 /***********************************************************************
  *              ReadFile                (KERNEL32.428)
  */
-BOOL32 ReadFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numtoread,
-                LPDWORD numread, LPOVERLAPPED lpOverlapped)
+BOOL32 WINAPI ReadFile(HFILE32 hFile, LPVOID lpBuffer, DWORD numtoread,
+                       LPDWORD numread, LPOVERLAPPED lpOverlapped)
 {
     int actual_read;
 
@@ -74,9 +74,9 @@
  * Doesn't support character devices, pipes, template files, or a
  * lot of the 'attributes' flags yet.
  */
-HFILE32 CreateFile32A(LPCSTR filename, DWORD access, DWORD sharing,
-                      LPSECURITY_ATTRIBUTES security, DWORD creation,
-                      DWORD attributes, HANDLE32 template)
+HFILE32 WINAPI CreateFile32A(LPCSTR filename, DWORD access, DWORD sharing,
+                             LPSECURITY_ATTRIBUTES security, DWORD creation,
+                             DWORD attributes, HANDLE32 template)
 {
     int access_flags, create_flags;
 
@@ -115,9 +115,9 @@
 /*************************************************************************
  *              CreateFile32W              (KERNEL32.48)
  */
-HFILE32 CreateFile32W(LPCWSTR filename, DWORD access, DWORD sharing,
-                      LPSECURITY_ATTRIBUTES security, DWORD creation,
-                      DWORD attributes, HANDLE32 template)
+HFILE32 WINAPI CreateFile32W(LPCWSTR filename, DWORD access, DWORD sharing,
+                             LPSECURITY_ATTRIBUTES security, DWORD creation,
+                             DWORD attributes, HANDLE32 template)
 {
     LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
     HFILE32 res = CreateFile32A( afn, access, sharing, security, creation,
@@ -182,7 +182,7 @@
 /**************************************************************************
  *              SetFileAttributes16	(KERNEL.421)
  */
-BOOL16 SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
+BOOL16 WINAPI SetFileAttributes16( LPCSTR lpFileName, DWORD attributes )
 {
     return SetFileAttributes32A( lpFileName, attributes );
 }
@@ -191,7 +191,7 @@
 /**************************************************************************
  *              SetFileAttributes32A	(KERNEL32.490)
  */
-BOOL32 SetFileAttributes32A(LPCSTR lpFileName, DWORD attributes)
+BOOL32 WINAPI SetFileAttributes32A(LPCSTR lpFileName, DWORD attributes)
 {
     struct stat buf;
     DOS_FULL_NAME full_name;
@@ -221,10 +221,11 @@
     return TRUE;
 }
 
+
 /**************************************************************************
  *              SetFileAttributes32W	(KERNEL32.491)
  */
-BOOL32 SetFileAttributes32W(LPCWSTR lpFileName, DWORD attributes)
+BOOL32 WINAPI SetFileAttributes32W(LPCWSTR lpFileName, DWORD attributes)
 {
     LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
     BOOL32 res = SetFileAttributes32A( afn, attributes );
@@ -232,17 +233,29 @@
     return res;
 }
 
-VOID SetFileApisToOEM()
+
+/**************************************************************************
+ *              SetFileApisToOEM   (KERNEL32.645)
+ */
+VOID WINAPI SetFileApisToOEM(void)
 {
     fprintf(stdnimp,"SetFileApisToOEM(),stub!\n");
 }
 
-VOID SetFileApisToANSI()
+
+/**************************************************************************
+ *              SetFileApisToANSI   (KERNEL32.644)
+ */
+VOID WINAPI SetFileApisToANSI(void)
 {
     fprintf(stdnimp,"SetFileApisToANSI(),stub!\n");
 }
 
-BOOL32 AreFileApisANSI()
+
+/**************************************************************************
+ *              AreFileApisANSI   (KERNEL32.105)
+ */
+BOOL32 WINAPI AreFileApisANSI(void)
 {
     fprintf(stdnimp,"AreFileApisANSI(),stub!\n");
     return TRUE;
diff --git a/win32/init.c b/win32/init.c
index ddd5799..80a8191 100644
--- a/win32/init.c
+++ b/win32/init.c
@@ -21,7 +21,7 @@
 /***********************************************************************
  *              GetModuleHandle         (KERNEL32.237)
  */
-HMODULE32 WIN32_GetModuleHandleA(char *module)
+HMODULE32 WINAPI WIN32_GetModuleHandleA(char *module)
 {
     HMODULE32 hModule;
 
@@ -37,7 +37,7 @@
     return hModule;
 }
 
-HMODULE32 WIN32_GetModuleHandleW(LPCWSTR module)
+HMODULE32 WINAPI WIN32_GetModuleHandleW(LPCWSTR module)
 {
     HMODULE32 hModule;
     LPSTR modulea = HEAP_strdupWtoA( GetProcessHeap(), 0, module );
@@ -50,7 +50,7 @@
 /***********************************************************************
  *              GetStartupInfoA         (KERNEL32.273)
  */
-VOID GetStartupInfo32A(LPSTARTUPINFO32A lpStartupInfo)
+VOID WINAPI GetStartupInfo32A(LPSTARTUPINFO32A lpStartupInfo)
 {
     lpStartupInfo->cb = sizeof(STARTUPINFO32A);
     lpStartupInfo->lpReserved = "<Reserved>";
@@ -67,7 +67,7 @@
 /***********************************************************************
  *              GetStartupInfoW         (KERNEL32.274)
  */
-VOID GetStartupInfo32W(LPSTARTUPINFO32W lpStartupInfo)
+VOID WINAPI GetStartupInfo32W(LPSTARTUPINFO32W lpStartupInfo)
 {
     lpStartupInfo->cb = sizeof(STARTUPINFO32W);
     lpStartupInfo->lpReserved = HEAP_strdupAtoW(GetProcessHeap(),0,"<Reserved>");
@@ -84,8 +84,8 @@
 /***********************************************************************
  *              GetComputerNameA         (KERNEL32.165)
  */
-BOOL32
-GetComputerName32A(LPSTR name,LPDWORD size) {
+BOOL32 WINAPI GetComputerName32A(LPSTR name,LPDWORD size)
+{
 	if (-1==gethostname(name,*size))
 		return FALSE;
 	*size = lstrlen32A(name);
@@ -95,8 +95,8 @@
 /***********************************************************************
  *              GetComputerNameW         (KERNEL32.166)
  */
-BOOL32
-GetComputerName32W(LPWSTR name,LPDWORD size) {
+BOOL32 WINAPI GetComputerName32W(LPWSTR name,LPDWORD size)
+{
 	LPSTR	nameA = (LPSTR)xmalloc(*size);
 
 	if (!GetComputerName32A(nameA,size)) {
@@ -112,7 +112,7 @@
 /***********************************************************************
  *           GetUserNameA   [ADVAPI32.67]
  */
-BOOL32 GetUserName32A(LPSTR lpszName, LPDWORD lpSize)
+BOOL32 WINAPI GetUserName32A(LPSTR lpszName, LPDWORD lpSize)
 {
   size_t len;
   char *name;
@@ -131,7 +131,7 @@
 /***********************************************************************
  *           GetUserNameW   [ADVAPI32.68]
  */
-BOOL32 GetUserName32W(LPWSTR lpszName, LPDWORD lpSize)
+BOOL32 WINAPI GetUserName32W(LPWSTR lpszName, LPDWORD lpSize)
 {
 	LPSTR name = (LPSTR)xmalloc(*lpSize);
 	DWORD	size = *lpSize;
diff --git a/win32/newfns.c b/win32/newfns.c
index b53a503..f8477fc 100644
--- a/win32/newfns.c
+++ b/win32/newfns.c
@@ -16,8 +16,8 @@
 /****************************************************************************
  *		QueryPerformanceCounter (KERNEL32.415)
  */
-BOOL32
-QueryPerformanceCounter(LPLARGE_INTEGER counter) {
+BOOL32 WINAPI QueryPerformanceCounter(LPLARGE_INTEGER counter)
+{
 	/* FIXME: don't know what are good values */
 	counter->LowPart	= 1;
 	counter->HighPart	= 0;
@@ -28,8 +28,8 @@
  *		DisableThreadLibraryCalls (KERNEL32.74)
  * Don't call DllEntryPoint for DLL_THREAD_{ATTACH,DETACH} if set.
  */
-BOOL32
-DisableThreadLibraryCalls(HMODULE32 hModule) {
+BOOL32 WINAPI DisableThreadLibraryCalls(HMODULE32 hModule)
+{
     fprintf(stdnimp, "DisableThreadLibraryCalls Stub called!\n");
     return TRUE;
 }
diff --git a/win32/ordinals.c b/win32/ordinals.c
index a617b0c..28f098f 100644
--- a/win32/ordinals.c
+++ b/win32/ordinals.c
@@ -1,5 +1,5 @@
 /*
- * Win32 ordinal only exported functions
+ * Win32 ordinal only exported functions that can't be stuffed somehwere else.
  *
  * Copyright 1997 Marcus Meissner
  */
@@ -19,57 +19,35 @@
 extern THDB	*pCurrentThread;
 extern PDB32	*pCurrentProcess;
 
+static CRITICAL_SECTION Win16Mutex;
+
+/***********************************************
+ *           GetPWinLock    (KERNEL32)
+ * Return the infamous Win16Mutex.
+ */
+VOID WINAPI GetPWinLock(CRITICAL_SECTION **lock)
+{
+        fprintf(stderr,"GetPWinlock(%p)\n",lock);
+        *lock = &Win16Mutex;
+}
+
 /**********************************************************************
  *           _KERNEL32_88
  */
-DWORD
-WOW32_1(DWORD x,DWORD y) {
+DWORD WINAPI WOW32_1(DWORD x,DWORD y)
+{
     fprintf(stderr,"WOW32_1(0x%08lx,0x%08lx), stub!\n",x,y);
     return 0;
 }
 
-/**********************************************************************
- *           WOWGetVDMPointer	(KERNEL32.55)
- * Get linear from segmented pointer. (MSDN lib)
- */
-LPVOID
-WOWGetVDMPointer(DWORD vp,DWORD nrofbytes,BOOL32 protected) {
-    /* FIXME: add size check too */
-    fprintf(stdnimp,"WOWGetVDMPointer(%08lx,%ld,%d)\n",vp,nrofbytes,protected);
-    if (protected)
-	return PTR_SEG_TO_LIN(vp);
-    else
-	return DOSMEM_MapRealToLinear(vp);
-}
-
-/**********************************************************************
- *           WOWGetVDMPointerFix (KERNEL32.55)
- * Dito, but fix heapsegment (MSDN lib)
- */
-LPVOID
-WOWGetVDMPointerFix(DWORD vp,DWORD nrofbytes,BOOL32 protected) {
-    /* FIXME: fix heapsegment */
-    fprintf(stdnimp,"WOWGetVDMPointerFix(%08lx,%ld,%d)\n",vp,nrofbytes,protected);
-    return WOWGetVDMPointer(vp,nrofbytes,protected);
-}
-
-/**********************************************************************
- *           WOWGetVDMPointerUnFix (KERNEL32.56)
- */
-void
-WOWGetVDMPointerUnfix(DWORD vp) {
-    fprintf(stdnimp,"WOWGetVDMPointerUnfix(%08lx), STUB\n",vp);
-    /* FIXME: unfix heapsegment */
-}
-
 
 /***********************************************************************
  *           _KERNEL32_18    (KERNEL32.18)
  * 'Of course you cannot directly access Windows internal structures'
  */
 
-DWORD
-_KERNEL32_18(DWORD processid,DWORD action) {
+DWORD WINAPI _KERNEL32_18(DWORD processid,DWORD action)
+{
 	PDB32	*process;
 	TDB	*pTask;
 
@@ -141,290 +119,13 @@
 	/* shouldn't come here */
 }
 
-/***********************************************************************
- *           _KERNEL32_52    (KERNEL32.52)
- * FIXME: what does it really do?
- */
-VOID
-_KERNEL32_52(DWORD arg1,CONTEXT *regs) {
-	fprintf(stderr,"_KERNE32_52(arg1=%08lx,%08lx)\n",arg1,EDI_reg(regs));
-
-	EAX_reg(regs) = (DWORD)WIN32_GetProcAddress16(EDI_reg(regs),"ThkBuf");
-
-	fprintf(stderr,"	GetProcAddress16(\"ThkBuf\") returns %08lx\n",
-			EAX_reg(regs)
-	);
-}
-
-/***********************************************************************
- *           GetPWinLock    (KERNEL32) FIXME
- * get mutex? critical section for 16 bit mode?
- */
-VOID
-GetPWinLock(CRITICAL_SECTION **lock) {
-	static CRITICAL_SECTION plock;
-	fprintf(stderr,"GetPWinlock(%p)\n",lock);
-	*lock = &plock;
-}
-
-/***********************************************************************
- * 		_KERNEL32_43 	(KERNEL32.42)
- * A thunkbuffer link routine 
- * The thunkbuf looks like:
- *
- *	00: DWORD	length		? don't know exactly
- *	04: SEGPTR	ptr		? where does it point to?
- * The pointer ptr is written into the first DWORD of 'thunk'.
- * (probably correct implemented)
- */
-BOOL32
-_KERNEL32_43(LPDWORD thunk,LPCSTR thkbuf,DWORD len,LPCSTR dll16,LPCSTR dll32) {
-	HINSTANCE16	hmod;
-	LPDWORD		addr;
-	SEGPTR		segaddr;
-
-	fprintf(stderr,"_KERNEL32_43(%p,%s,0x%08lx,%s,%s)\n",thunk,thkbuf,len,dll16,dll32);
-
-	hmod = LoadLibrary16(dll16);
-	if (hmod<32) {
-		fprintf(stderr,"->failed to load 16bit DLL %s, error %d\n",dll16,hmod);
-		return NULL;
-	}
-	segaddr = (DWORD)WIN32_GetProcAddress16(hmod,(LPSTR)thkbuf);
-	if (!segaddr) {
-		fprintf(stderr,"->no %s exported from %s!\n",thkbuf,dll16);
-		return NULL;
-	}
-	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
-	if (addr[0] != len) {
-		fprintf(stderr,"->thkbuf length mismatch? %ld vs %ld\n",len,addr[0]);
-		return NULL;
-	}
-	if (!addr[1])
-		return 0;
-	*(DWORD*)thunk = addr[1];
-	return addr[1];
-}
-
-/***********************************************************************
- * 		_KERNEL32_45 	(KERNEL32.44)
- * FIXME: not sure what it does
- */
-VOID
-_KERNEL32_45(DWORD x,CONTEXT *context) {
-	fprintf(stderr,"_KERNEL32_45(0x%08lx,%%eax=0x%08lx,%%cx=0x%04lx,%%edx=0x%08lx)\n",
-		x,(DWORD)EAX_reg(context),(DWORD)CX_reg(context),(DWORD)EDX_reg(context)
-	);
-}
-
-/***********************************************************************
- *		(KERNEL32.40)
- * A thunk setup routine.
- * Expects a pointer to a preinitialized thunkbuffer in the first argument
- * looking like:
- *	00..03:		unknown	(some pointer to the 16bit struct?)
- *	04: EB1E		jmp +0x20
- *
- *	06..23:		unknown (space for replacement code, check .90)
- *
- *	24:>E8xxxxxxxx		call <32bitoffset xxxxxxxx>
- *	29: 58			pop eax
- *	2A: 2D2500xxxx		and eax,0x2500xxxx
- *	2F: BAxxxxxxxx		mov edx,xxxxxxxx
- *	34: 68yyyyyyyy		push KERNEL32.90
- *	39: C3			ret
- *
- *	3A: EB1E		jmp +0x20
- *	3E ... 59:	unknown (space for replacement code?)
- *	5A: E8xxxxxxxx		call <32bitoffset xxxxxxxx>
- *	5F: 5A			pop edx
- *	60: 81EA25xxxxxx	sub edx, 0x25xxxxxx
- *	66: 52			push edx
- *	67: 68xxxxxxxx		push xxxxxxxx
- *	6C: 68yyyyyyyy		push KERNEL32.89
- *	71: C3			ret
- *	72: end?
- * This function checks if the code is there, and replaces the yyyyyyyy entries
- * by the functionpointers.
- * The thunkbuf looks like:
- *
- *	00: DWORD	length		? don't know exactly
- *	04: SEGPTR	ptr		? where does it point to?
- * The segpointer ptr is written into the first DWORD of 'thunk'.
- * (probably correct implemented)
- */
-
-LPVOID
-_KERNEL32_41(LPBYTE thunk,LPCSTR thkbuf,DWORD len,LPCSTR dll16,LPCSTR dll32) {
-	HMODULE32	hkrnl32 = WIN32_GetModuleHandleA("KERNEL32");
-	HMODULE16	hmod;
-	LPDWORD		addr,addr2;
-	DWORD		segaddr;
-
-	fprintf(stderr,"KERNEL32_41(%p,%s,%ld,%s,%s)\n",
-		thunk,thkbuf,len,dll16,dll32
-	);
-
-	/* FIXME: add checks for valid code ... */
-	/* write pointers to kernel32.89 and kernel32.90 (+ordinal base of 1) */
-	*(DWORD*)(thunk+0x35) = (DWORD)GetProcAddress32(hkrnl32,(LPSTR)91);
-	*(DWORD*)(thunk+0x6D) = (DWORD)GetProcAddress32(hkrnl32,(LPSTR)90);
-
-	
-	hmod = LoadLibrary16(dll16);
-	if (hmod<32) {
-		fprintf(stderr,"->failed to load 16bit DLL %s, error %d\n",dll16,hmod);
-		return NULL;
-	}
-	segaddr = (DWORD)WIN32_GetProcAddress16(hmod,(LPSTR)thkbuf);
-	if (!segaddr) {
-		fprintf(stderr,"->no %s exported from %s!\n",thkbuf,dll16);
-		return NULL;
-	}
-	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
-	if (addr[0] != len) {
-		fprintf(stderr,"->thkbuf length mismatch? %ld vs %ld\n",len,addr[0]);
-		return NULL;
-	}
-	addr2 = PTR_SEG_TO_LIN(addr[1]);
-	if (HIWORD(addr2))
-		*(DWORD*)thunk = (DWORD)addr2;
-	return addr2;
-}
 
 /***********************************************************************
  *							(KERNEL32.33)
  * Returns some internal value.... probably the default environment database?
  */
-DWORD
-_KERNEL32_34() {
+DWORD WINAPI _KERNEL32_34()
+{
 	fprintf(stderr,"KERNEL32_34(), STUB returning 0\n");
 	return 0;
 }
-
-/***********************************************************************
- *							(KERNEL32.90)
- * Thunk priming? function
- * Rewrites the first part of the thunk to use the QT_Thunk interface.
- * Replaces offset 4 ... 24 by:
- *	
- *  33C9                    xor ecx, ecx
- *  8A4DFC                  mov cl , [ebp-04]
- *  8B148Dxxxxxxxx          mov edx, [4*ecx + (EAX+EDX)]
- *  B8yyyyyyyy              mov eax, QT_Thunk
- *  FFE0                    jmp eax
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- *  CC                      int 03
- * and jumps to the start of that code.
- * (ok)
- */
-VOID
-_KERNEL32_91(CONTEXT *context) {
-	LPBYTE	x;
-
-	fprintf(stderr,"_KERNEL32_91(eax=0x%08lx,edx=0x%08lx)\n",
-		EAX_reg(context),EDX_reg(context)
-	);
-	x = (LPBYTE)EAX_reg(context);
-	*x++ = 0x33;*x++=0xC9; /* xor ecx,ecx */
-	*x++ = 0x8A;*x++=0x4D;*x++=0xFC; /* mov cl,[ebp-04] */
-	*x++ = 0x8B;*x++=0x14;*x++=0x8D;*(DWORD*)x= EAX_reg(context)+EDX_reg(context);
-	x+=4;	/* mov edx, [4*ecx + (EAX+EDX) */
-	*x++ = 0xB8; *(DWORD*)x = (DWORD)GetProcAddress32(WIN32_GetModuleHandleA("KERNEL32"),"QT_Thunk");
-	x+=4; 	/* mov eax , QT_Thunk */
-	*x++ = 0xFF; *x++ = 0xE0;	/* jmp eax */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	*x++ = 0xCC;	/* int 03 */
-	EIP_reg(context) = EAX_reg(context);
-}
-
-/***********************************************************************
- *							(KERNEL32.45)
- * Another thunkbuf link routine.
- * The start of the thunkbuf looks like this:
- * 	00: DWORD	length
- *	04: SEGPTR	address for thunkbuffer pointer
- */
-VOID
-_KERNEL32_46(LPBYTE thunk,LPSTR thkbuf,DWORD len,LPSTR dll16,LPSTR dll32) {
-	LPDWORD		addr;
-	HMODULE16	hmod;
-	SEGPTR		segaddr;
-
-	fprintf(stderr,"KERNEL32_46(%p,%s,%lx,%s,%s)\n",
-		thunk,thkbuf,len,dll16,dll32
-	);
-	hmod = LoadLibrary16(dll16);
-	if (hmod < 32) {
-		fprintf(stderr,"->couldn't load %s, error %d\n",dll16,hmod);
-		return;
-	}
-	segaddr = (SEGPTR)WIN32_GetProcAddress16(hmod,thkbuf);
-	if (!segaddr) {
-		fprintf(stderr,"-> haven't found %s in %s!\n",thkbuf,dll16);
-		return;
-	}
-	addr = (LPDWORD)PTR_SEG_TO_LIN(segaddr);
-	if (addr[0] != len) {
-		fprintf(stderr,"-> length of thkbuf differs from expected length! (%ld vs %ld)\n",addr[0],len);
-		return;
-	}
-	*(DWORD*)PTR_SEG_TO_LIN(addr[1]) = (DWORD)thunk;
-}
-
-/**********************************************************************
- *           _KERNEL32_87
- * Check if thunking is initialized (ss selector set up etc.)
- */
-BOOL32 _KERNEL32_87() {
-    fprintf(stderr,"KERNEL32_87 stub, returning TRUE\n");
-    return TRUE;
-}
-
-/**********************************************************************
- *           _KERNEL32_88
- * One of the real thunking functions
- * Probably implemented totally wrong.
- */
-BOOL32 _KERNEL32_88(DWORD nr,DWORD flags,LPVOID fun,DWORD *hmm) {
-    fprintf(stderr,"KERNEL32_88(%ld,0x%08lx,%p,%p) stub, returning TRUE\n",
-	nr,flags,fun,hmm
-    );
-#ifndef WINELIB
-    switch (nr) {
-    case 0: CallTo32_0(fun);
-	break;
-    case 4: CallTo32_1(fun,hmm[0]);
-	break;
-    case 8: CallTo32_2(fun,hmm[0],hmm[1]);
-	break;
-    default:
-	fprintf(stderr,"    unsupported nr of arguments, %ld\n",nr);
-	break;
-
-    }
-#endif
-    return TRUE;
-}
diff --git a/win32/process.c b/win32/process.c
index deb34dd..ff4f2c5 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -37,7 +37,7 @@
 /***********************************************************************
  *           CreateMutexA    (KERNEL32.52)
  */
-HANDLE32 CreateMutex32A(SECURITY_ATTRIBUTES *sa,BOOL32 on,LPCSTR name)
+HANDLE32 WINAPI CreateMutex32A(SECURITY_ATTRIBUTES *sa,BOOL32 on,LPCSTR name)
 {
 	K32MUTEX	*mut;
 	HANDLE32	handle;
@@ -71,7 +71,7 @@
 /***********************************************************************
  *           CreateMutexW    (KERNEL32.53)
  */
-HANDLE32 CreateMutex32W(SECURITY_ATTRIBUTES *sa, BOOL32 on, LPCWSTR a)
+HANDLE32 WINAPI CreateMutex32W(SECURITY_ATTRIBUTES *sa, BOOL32 on, LPCWSTR a)
 {
 	LPSTR		name = a?HEAP_strdupWtoA(GetProcessHeap(),0,a):NULL;
 	HANDLE32	ret;
@@ -84,9 +84,9 @@
 /***********************************************************************
  *           CreateSemaphoreA    (KERNEL32.60)
  */
-HANDLE32 CreateSemaphore32A(
-	LPSECURITY_ATTRIBUTES sa,LONG initial,LONG max,LPCSTR name
-) {
+HANDLE32 WINAPI CreateSemaphore32A( LPSECURITY_ATTRIBUTES sa,
+                                    LONG initial,LONG max,LPCSTR name )
+{
 	K32SEMAPHORE	*sem;
 	HANDLE32	handle;
 	K32OBJ 		*obj = K32OBJ_FindName( name );
@@ -119,7 +119,7 @@
 /***********************************************************************
  *           CreateSemaphoreW    (KERNEL32.61)
  */
-HANDLE32 CreateSemaphore32W(SECURITY_ATTRIBUTES *sa,LONG initial,LONG max,LPCWSTR a)
+HANDLE32 WINAPI CreateSemaphore32W(SECURITY_ATTRIBUTES *sa,LONG initial,LONG max,LPCWSTR a)
 {
 	LPSTR		name =a?HEAP_strdupWtoA(GetProcessHeap(),0,a):NULL;
 	HANDLE32	ret;
@@ -133,7 +133,7 @@
 /***********************************************************************
  *           OpenSemaphoreA    (KERNEL32.403)
  */
-HANDLE32 OpenSemaphore32A(DWORD desired,BOOL32 inherit,LPCSTR name)
+HANDLE32 WINAPI OpenSemaphore32A(DWORD desired,BOOL32 inherit,LPCSTR name)
 {
 	K32OBJ 		*obj = K32OBJ_FindName( name );
 
@@ -149,7 +149,7 @@
 /***********************************************************************
  *           OpenSemaphoreA    (KERNEL32.404)
  */
-HANDLE32 OpenSemaphore32W(DWORD desired,BOOL32 inherit,LPCWSTR name)
+HANDLE32 WINAPI OpenSemaphore32W(DWORD desired,BOOL32 inherit,LPCWSTR name)
 {
 	LPSTR	nameA = name?HEAP_strdupWtoA(GetProcessHeap(),0,name):NULL;
 	HANDLE32	ret = OpenSemaphore32A(desired,inherit,nameA);
@@ -161,7 +161,8 @@
 /***********************************************************************
  *           ReleaseSemaphore    (KERNEL32.403)
  */
-BOOL32 ReleaseSemaphore(HANDLE32 hSemaphore,LONG lReleaseCount,LPLONG lpPreviousCount) {
+BOOL32 WINAPI ReleaseSemaphore(HANDLE32 hSemaphore,LONG lReleaseCount,LPLONG lpPreviousCount)
+{
 	K32SEMAPHORE	*sem;
 
 	sem = (K32SEMAPHORE*)PROCESS_GetObjPtr(hSemaphore,K32OBJ_SEMAPHORE);
@@ -183,7 +184,7 @@
 /***********************************************************************
  *           OpenMutexA    (KERNEL32.399)
  */
-HANDLE32 OpenMutex32A(DWORD desiredaccess, BOOL32 inherithandle, LPCSTR name)
+HANDLE32 WINAPI OpenMutex32A(DWORD desiredaccess, BOOL32 inherithandle, LPCSTR name)
 {
 	K32OBJ 		*obj = K32OBJ_FindName( name );
 
@@ -199,7 +200,8 @@
 /***********************************************************************
  *           OpenMutexW    (KERNEL32.400)
  */
-HANDLE32 OpenMutex32W(DWORD desiredaccess, BOOL32 inherithandle, LPCWSTR name)
+HANDLE32 WINAPI OpenMutex32W(DWORD desiredaccess, BOOL32 inherithandle,
+                             LPCWSTR name)
 {
 	LPSTR		nameA=name?HEAP_strdupWtoA(GetProcessHeap(),0,name):NULL;
 	HANDLE32	ret = OpenMutex32A(desiredaccess,inherithandle,nameA);
@@ -211,7 +213,7 @@
 /***********************************************************************
  *           ReleaseMutex    (KERNEL32.435)
  */
-BOOL32 ReleaseMutex (HANDLE32 h)
+BOOL32 WINAPI ReleaseMutex (HANDLE32 h)
 {
 	K32MUTEX	*mut = (K32MUTEX*)PROCESS_GetObjPtr(h,K32OBJ_MUTEX);
 
@@ -233,7 +235,8 @@
 /***********************************************************************
  *           CreateEventA    (KERNEL32.43)
  */
-HANDLE32 CreateEvent32A(SECURITY_ATTRIBUTES *sa,BOOL32 au,BOOL32 on,LPCSTR name)
+HANDLE32 WINAPI CreateEvent32A(SECURITY_ATTRIBUTES *sa,BOOL32 au,BOOL32 on,
+                               LPCSTR name)
 {
 	K32EVENT	*evt;
 	HANDLE32	handle;
@@ -263,7 +266,8 @@
 /***********************************************************************
  *           CreateEventW    (KERNEL32.43)
  */
-HANDLE32 CreateEvent32W(SECURITY_ATTRIBUTES *sa, BOOL32 au, BOOL32 on,LPCWSTR name)
+HANDLE32 WINAPI CreateEvent32W(SECURITY_ATTRIBUTES *sa, BOOL32 au,
+                               BOOL32 on,LPCWSTR name)
 {
 	LPSTR nameA=name?HEAP_strdupWtoA(GetProcessHeap(),0,name):NULL;
 	HANDLE32 ret = CreateEvent32A(sa,au,on,nameA);
@@ -275,7 +279,8 @@
 /***********************************************************************
  *           OpenEventA    (KERNEL32.394)
  */
-HANDLE32 OpenEvent32A(DWORD desiredaccess,BOOL32 inherithandle,LPCSTR name) {
+HANDLE32 WINAPI OpenEvent32A(DWORD desiredaccess,BOOL32 inherithandle,LPCSTR name)
+{
 	K32OBJ 		*obj = K32OBJ_FindName( name );
 
 	if (obj) {
@@ -290,7 +295,8 @@
 /***********************************************************************
  *           OpenEventW    (KERNEL32.395)
  */
-HANDLE32 OpenEvent32W(DWORD desiredaccess,BOOL32 inherithandle,LPCWSTR name) {
+HANDLE32 WINAPI OpenEvent32W(DWORD desiredaccess,BOOL32 inherithandle,LPCWSTR name)
+{
 	LPSTR	nameA = name?HEAP_strdupWtoA(GetProcessHeap(),0,name):NULL;
 	HANDLE32	ret = OpenEvent32A(desiredaccess,inherithandle,nameA);
 
@@ -301,7 +307,7 @@
 /***********************************************************************
  *           SetEvent    (KERNEL32.487)
  */
-BOOL32 SetEvent (HANDLE32 h)
+BOOL32 WINAPI SetEvent (HANDLE32 h)
 {
 	fprintf(stderr,"SetEvent(%d) stub\n",h);
 	return 0;
@@ -309,7 +315,7 @@
 /***********************************************************************
  *           ResetEvent    (KERNEL32.439)
  */
-BOOL32 ResetEvent (HANDLE32 h)
+BOOL32 WINAPI ResetEvent (HANDLE32 h)
 {
 	fprintf(stderr,"ResetEvent(%d) stub\n",h);
 	return 0;
@@ -318,16 +324,26 @@
 /***********************************************************************
  *           WaitForSingleObject    (KERNEL32.561)
  */
-DWORD WaitForSingleObject(HANDLE32 h, DWORD timeout)
+DWORD WINAPI WaitForSingleObject(HANDLE32 h, DWORD timeout)
 {
 	fprintf(stderr,"WaitForSingleObject(%d,%ld) stub\n",h,timeout);
 	return 0;
 }
 
 /***********************************************************************
+ *           WaitForSingleObjectEx    (KERNEL32)
+ */
+DWORD WINAPI WaitForSingleObjectEx(HANDLE32 h,DWORD timeout,BOOL32 bAlertable)
+{
+	fprintf(stderr,"WaitForSingleObjectEx(%d,%ld,%d) stub\n",h,timeout,bAlertable);
+	return 0;
+}
+
+
+/***********************************************************************
  *           WaitForMultipleObjects    (USER32.399)
  */
-DWORD MsgWaitForMultipleObjects(
+DWORD WINAPI MsgWaitForMultipleObjects(
 	DWORD nCount,HANDLE32 *pHandles,BOOL32 fWaitAll,DWORD dwMilliseconds,
 	DWORD dwWakeMask
 ) {
@@ -341,20 +357,25 @@
 /***********************************************************************
  *           DuplicateHandle    (KERNEL32.78)
  */
-BOOL32 DuplicateHandle(HANDLE32 a, HANDLE32 b, HANDLE32 c, HANDLE32 * d, DWORD e, BOOL32 f, DWORD g)
+BOOL32 WINAPI DuplicateHandle(HANDLE32 a, HANDLE32 b, HANDLE32 c, HANDLE32 * d, DWORD e, BOOL32 f, DWORD g)
 {
 	fprintf(stderr,"DuplicateHandle(%d,%d,%d,%p,%ld,%d,%ld) stub\n",a,b,c,d,e,f,g);
 	*d = b;
 	return TRUE;
 }
 
+HINSTANCE32 WINAPI LoadLibraryEx32A(LPCSTR libname,HFILE32 hfile,DWORD flags)
+{
+    fprintf(stderr,"LoadLibraryEx32A(%s,%d,0x%08lx)\n",libname,hfile,flags);
+    return LoadLibrary32A(libname);
+}
 
 /***********************************************************************
  *           LoadLibraryA         (KERNEL32.365)
  * copied from LoadLibrary
  * This does not currently support built-in libraries
  */
-HINSTANCE32 LoadLibrary32A(LPCSTR libname)
+HINSTANCE32 WINAPI LoadLibrary32A(LPCSTR libname)
 {
 	HINSTANCE32 handle;
 	dprintf_module( stddeb, "LoadLibrary: (%08x) %s\n", (int)libname, libname);
@@ -376,7 +397,7 @@
 /***********************************************************************
  *           LoadLibrary32W         (KERNEL32.368)
  */
-HINSTANCE32 LoadLibrary32W(LPCWSTR libnameW)
+HINSTANCE32 WINAPI LoadLibrary32W(LPCWSTR libnameW)
 {
     LPSTR libnameA = HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW );
     HINSTANCE32 ret = LoadLibrary32A( libnameA );
@@ -387,7 +408,7 @@
 /***********************************************************************
  *           FreeLibrary
  */
-BOOL32 FreeLibrary32(HINSTANCE32 hLibModule)
+BOOL32 WINAPI FreeLibrary32(HINSTANCE32 hLibModule)
 {
 	fprintf(stderr,"FreeLibrary: empty stub\n");
 	return TRUE;
@@ -396,8 +417,9 @@
 /**********************************************************************
  *          GetProcessAffinityMask
  */
-BOOL32 GetProcessAffinityMask(HANDLE32 hProcess, LPDWORD lpProcessAffinityMask,
-  LPDWORD lpSystemAffinityMask)
+BOOL32 WINAPI GetProcessAffinityMask(HANDLE32 hProcess,
+                                     LPDWORD lpProcessAffinityMask,
+                                     LPDWORD lpSystemAffinityMask)
 {
 	dprintf_task(stddeb,"GetProcessAffinityMask(%x,%lx,%lx)\n",
 		hProcess,(lpProcessAffinityMask?*lpProcessAffinityMask:0),
@@ -415,7 +437,7 @@
  *           SetThreadAffinityMask
  * Works now like the Windows95 (no MP support) version
  */
-BOOL32 SetThreadAffinityMask(HANDLE32 hThread, DWORD dwThreadAffinityMask)
+BOOL32 WINAPI SetThreadAffinityMask(HANDLE32 hThread, DWORD dwThreadAffinityMask)
 {
 	THDB	*thdb = (THDB*)PROCESS_GetObjPtr(hThread,K32OBJ_THREAD);
 
@@ -430,8 +452,7 @@
 	return TRUE;
 }
 
-BOOL32
-CreateProcess32A(
+BOOL32 WINAPI CreateProcess32A(
 	LPCSTR appname,LPSTR cmdline,LPSECURITY_ATTRIBUTES processattributes,
         LPSECURITY_ATTRIBUTES threadattributes,BOOL32 inherithandles,
 	DWORD creationflags,LPVOID env,LPCSTR curdir,
@@ -444,8 +465,7 @@
 	return TRUE;
 }
 
-BOOL32
-ContinueDebugEvent(DWORD pid,DWORD tid,DWORD contstatus) {
+BOOL32 WINAPI ContinueDebugEvent(DWORD pid,DWORD tid,DWORD contstatus) {
 	fprintf(stderr,"ContinueDebugEvent(%ld,%ld,%ld), stub\n",pid,tid,contstatus);
 	return TRUE;
 }
@@ -455,8 +475,7 @@
  *
  * FIXME: implement this better ...
  */
-BOOL32
-GetProcessTimes(
+BOOL32 WINAPI GetProcessTimes(
 	HANDLE32 hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime,
 	LPFILETIME lpKernelTime, LPFILETIME lpUserTime
 ) {
diff --git a/win32/security.c b/win32/security.c
index f8e9afa..4f7ef47 100644
--- a/win32/security.c
+++ b/win32/security.c
@@ -8,23 +8,23 @@
 #include "stddebug.h"
 #include "debug.h"
 
-BOOL32 IsValidSid (LPSID pSid);
-BOOL32 EqualSid (LPSID pSid1, LPSID pSid2);
-BOOL32 EqualPrefixSid (LPSID pSid1, LPSID pSid2);
-DWORD GetSidLengthRequired (BYTE nSubAuthorityCount);
-BOOL32 AllocateAndInitializeSid (LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3,    DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, LPSID *pSid);
-VOID *FreeSid(LPSID pSid);
-BOOL32 InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
-LPSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority (LPSID pSid);
-DWORD *GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority);
-BYTE *GetSidSubAuthorityCount (LPSID pSid);
-DWORD GetLengthSid (LPSID pSid);
-BOOL32 CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
+BOOL32 WINAPI IsValidSid (LPSID pSid);
+BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2);
+BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2);
+DWORD  WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
+BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3,    DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, LPSID *pSid);
+VOID*  WINAPI FreeSid(LPSID pSid);
+BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
+LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(LPSID pSid);
+DWORD* WINAPI GetSidSubAuthority(LPSID pSid, DWORD nSubAuthority);
+BYTE*  WINAPI GetSidSubAuthorityCount(LPSID pSid);
+DWORD  WINAPI GetLengthSid(LPSID pSid);
+BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
 
 /***********************************************************************
  *           IsValidSid  (ADVAPI.80)
  */
-BOOL32 IsValidSid (LPSID pSid) {
+BOOL32 WINAPI IsValidSid (LPSID pSid) {
     if (!pSid || pSid->Revision != SID_REVISION)
         return FALSE;
 
@@ -34,7 +34,7 @@
 /***********************************************************************
  *           EqualSid  (ADVAPI.40)
  */
-BOOL32 EqualSid (LPSID pSid1, LPSID pSid2) {
+BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
         return FALSE;
 
@@ -50,7 +50,7 @@
 /***********************************************************************
  *           EqualPrefixSid  (ADVAPI.39)
  */
-BOOL32 EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
+BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
         return FALSE;
 
@@ -67,14 +67,14 @@
 /***********************************************************************
  *           GetSidLengthRequired  (ADVAPI.63)
  */
-DWORD GetSidLengthRequired (BYTE nSubAuthorityCount) {
+DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
     return sizeof (SID) + (nSubAuthorityCount - 1 * sizeof (DWORD));
 }
 
 /***********************************************************************
  *           AllocateAndInitializeSid  (ADVAPI.11)
  */
-BOOL32 AllocateAndInitializeSid (LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
     BYTE nSubAuthorityCount,
     DWORD nSubAuthority0, DWORD nSubAuthority1,
     DWORD nSubAuthority2, DWORD nSubAuthority3,
@@ -112,7 +112,7 @@
 /***********************************************************************
  *           FreeSid  (ADVAPI.42)
  */
-VOID *FreeSid(LPSID pSid) {
+VOID* WINAPI FreeSid(LPSID pSid) {
     free(pSid);
     return NULL;
 }
@@ -120,8 +120,9 @@
 /***********************************************************************
  *           InitializeSid  (ADVAPI.74)
  */
-BOOL32 InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
-                    BYTE nSubAuthorityCount) {
+BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+                    BYTE nSubAuthorityCount)
+{
     int i;
 
     pSid->Revision = SID_REVISION;
@@ -139,36 +140,41 @@
 /***********************************************************************
  *           GetSidIdentifierAuthority  (ADVAPI.62)
  */
-LPSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority (LPSID pSid) {
+LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
+{
     return &pSid->IdentifierAuthority;
 }
 
 /***********************************************************************
  *           GetSidSubAuthority  (ADVAPI.64)
  */
-DWORD *GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority) {
+DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
+{
     return &pSid->SubAuthority[nSubAuthority];
 }
 
 /***********************************************************************
  *           GetSidSubAuthorityCount  (ADVAPI.65)
  */
-BYTE *GetSidSubAuthorityCount (LPSID pSid) {
+BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
+{
     return &pSid->SubAuthorityCount;
 }
 
 /***********************************************************************
  *           GetLengthSid  (ADVAPI.48)
  */
-DWORD GetLengthSid (LPSID pSid) {
+DWORD WINAPI GetLengthSid (LPSID pSid)
+{
     return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
 }
 
 /***********************************************************************
  *           CopySid  (ADVAPI.24)
  */
-BOOL32 CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
-              LPSID pSourceSid) {
+BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
+                       LPSID pSourceSid)
+{
 
     if (!IsValidSid(pSourceSid))
         return FALSE;
diff --git a/win32/thread.c b/win32/thread.c
index 93153a0..4d4da74 100644
--- a/win32/thread.c
+++ b/win32/thread.c
@@ -38,7 +38,7 @@
 * The returned number need not be equal to the result!!!!		*
 ************************************************************************/
 
-LONG InterlockedIncrement(LPLONG lpAddend)
+LONG WINAPI InterlockedIncrement(LPLONG lpAddend)
 {
 #if defined(__i386__)&&defined(__GNUC__)
 	long ret;
@@ -78,7 +78,7 @@
 * The returned number need not be equal to the result!!!!		*
 ************************************************************************/
 
-LONG InterlockedDecrement(LPLONG lpAddend)
+LONG WINAPI InterlockedDecrement(LPLONG lpAddend)
 {
 #if defined(__i386__)&&defined(__GNUC__)	
 	LONG ret;
@@ -111,7 +111,7 @@
 *           InterlockedExchange				[KERNEL32]	*
 ************************************************************************/
 
-LONG InterlockedExchange(LPLONG target, LONG value)
+LONG WINAPI InterlockedExchange(LPLONG target, LONG value)
 {
 #if defined(__i386__)&&defined(__GNUC__)	
 	LONG ret;
@@ -145,7 +145,7 @@
 *           InitializeCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-void InitializeCriticalSection(CRITICAL_SECTION *pcritical)
+void WINAPI InitializeCriticalSection(CRITICAL_SECTION *pcritical)
 {
    pcritical->LockCount=-1;
    pcritical->RecursionCount=0;
@@ -158,7 +158,7 @@
 *           DeleteCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-void DeleteCriticalSection(CRITICAL_SECTION *pcritical)
+void WINAPI DeleteCriticalSection(CRITICAL_SECTION *pcritical)
 {
    semctl((int) pcritical->LockSemaphore,0,IPC_RMID,(union semun)NULL);
    pcritical->Reserved=-1;
@@ -168,7 +168,7 @@
 *           EnterCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-void EnterCriticalSection (CRITICAL_SECTION *pcritical)
+void WINAPI EnterCriticalSection (CRITICAL_SECTION *pcritical)
 {
    if( InterlockedIncrement(&(pcritical->LockCount)))
    {   
@@ -195,7 +195,7 @@
 *           TryEnterCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-BOOL32 TryEnterCriticalSection (CRITICAL_SECTION *pcritical)
+BOOL32 WINAPI TryEnterCriticalSection (CRITICAL_SECTION *pcritical)
 {
    if( InterlockedIncrement(&(pcritical->LockCount)))
    {
@@ -215,7 +215,7 @@
 *           LeaveCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-void LeaveCriticalSection (CRITICAL_SECTION *pcritical)
+void WINAPI LeaveCriticalSection(CRITICAL_SECTION *pcritical)
 {
    /* do we actually own this critical section ??? */
    if( pcritical->OwningThread!= (HANDLE32) GetCurrentThreadId())
@@ -245,7 +245,7 @@
 *           ReinitializeCriticalSection			[KERNEL32]	*
 ************************************************************************/
 
-void ReinitializeCriticalSection(CRITICAL_SECTION *lpCrit)
+void WINAPI ReinitializeCriticalSection(CRITICAL_SECTION *lpCrit)
 {
    /* hmm ?????? */	
 }
@@ -254,7 +254,7 @@
 *           MakeCriticalSectionGlobal			[KERNEL32]	*
 ************************************************************************/
 
-void MakeCriticalSectionGlobal(CRITICAL_SECTION *lpCrit)
+void WINAPI MakeCriticalSectionGlobal(CRITICAL_SECTION *lpCrit)
 {
    /* nothing (SysV Semaphores are already global) */
    return;	
diff --git a/win32/time.c b/win32/time.c
index 4994190..67c3cb5 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -16,7 +16,7 @@
 /***********************************************************************
  *              GetLocalTime            (KERNEL32.228)
  */
-VOID GetLocalTime(LPSYSTEMTIME systime)
+VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
 {
     time_t local_time;
     struct tm *local_tm;
@@ -39,7 +39,7 @@
 /***********************************************************************
  *              GetSystemTime            (KERNEL32.285)
  */
-VOID GetSystemTime(LPSYSTEMTIME systime)
+VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
 {
     time_t local_time;
     struct tm *local_tm;
@@ -63,7 +63,7 @@
 /***********************************************************************
  *              SetSystemTime            (KERNEL32.507)
  */
-BOOL32 SetSystemTime(const SYSTEMTIME *systime)
+BOOL32 WINAPI SetSystemTime(const SYSTEMTIME *systime)
 {
     struct timeval tv;
     struct timezone tz;
@@ -99,7 +99,7 @@
 /***********************************************************************
  *              GetTimeZoneInformation  (KERNEL32.302)
  */
-DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
+DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
 {
     time_t gmt, lt;
 
@@ -118,7 +118,7 @@
 /***********************************************************************
  *              SetTimeZoneInformation  (KERNEL32.515)
  */
-BOOL32 SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
+BOOL32 WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
 {
     struct timezone tz;
 
@@ -135,7 +135,7 @@
 /***********************************************************************
  *              Sleep  (KERNEL32.523)
  */
-VOID Sleep(DWORD cMilliseconds)
+VOID WINAPI Sleep(DWORD cMilliseconds)
 {
     if(cMilliseconds == INFINITE32)
         while(1) sleep(1000); /* Spin forever */
diff --git a/win32/user32.c b/win32/user32.c
index 5a1192a..3080596 100644
--- a/win32/user32.c
+++ b/win32/user32.c
@@ -22,7 +22,7 @@
 /***********************************************************************
  *          GetMessage32A   (USER32.269)
  */
-BOOL32 GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
+BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
 {
     BOOL32 ret;
     MSG16 *msg = SEGPTR_NEW(MSG16);
@@ -37,7 +37,7 @@
 /***********************************************************************
  *          GetMessage32W   (USER32.273)
  */
-BOOL32 GetMessage32W(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
+BOOL32 WINAPI GetMessage32W(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
 {
     BOOL32 ret;
     MSG16 *msg = SEGPTR_NEW(MSG16);
@@ -52,8 +52,8 @@
 /***********************************************************************
  *         PeekMessageA
  */
-BOOL32 PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
-                       UINT32 min,UINT32 max,UINT32 wRemoveMsg)
+BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
+                              UINT32 min,UINT32 max,UINT32 wRemoveMsg)
 {
 	MSG16 msg;
 	BOOL32 ret;
@@ -66,8 +66,8 @@
 /***********************************************************************
  *         PeekMessageW
  */
-BOOL32 PeekMessage32W( LPMSG32 lpmsg, HWND32 hwnd,
-                       UINT32 min,UINT32 max,UINT32 wRemoveMsg)
+BOOL32 WINAPI PeekMessage32W( LPMSG32 lpmsg, HWND32 hwnd,
+                              UINT32 min,UINT32 max,UINT32 wRemoveMsg)
 {
 	/* FIXME: Should perform Unicode translation on specific messages */
 	return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
diff --git a/windows/caret.c b/windows/caret.c
index 00de7ff..315ce72 100644
--- a/windows/caret.c
+++ b/windows/caret.c
@@ -65,7 +65,8 @@
     /* So now it's always a toggle */
 
     Caret.on = !Caret.on;
-    if (!(hdc = GetDCEx32( Caret.hwnd, 0, DCX_USESTYLE | DCX_CACHE ))) return;
+    /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
+    if (!(hdc = GetDCEx32( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return;
     hPrevBrush = SelectObject32( hdc, Caret.hBrush );
     PatBlt32( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
     SelectObject32( hdc, hPrevBrush );
@@ -125,7 +126,8 @@
 /*****************************************************************
  *           CreateCaret16   (USER.163)
  */
-void CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap, INT16 width, INT16 height )
+void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap,
+                           INT16 width, INT16 height )
 {
     CreateCaret32( hwnd, bitmap, width, height );
 }
@@ -133,8 +135,8 @@
 /*****************************************************************
  *           CreateCaret32   (USER32.65)
  */
-BOOL32 CreateCaret32( HWND32 hwnd, HBITMAP32 bitmap,
-                      INT32 width, INT32 height )
+BOOL32 WINAPI CreateCaret32( HWND32 hwnd, HBITMAP32 bitmap,
+                             INT32 width, INT32 height )
 {
     dprintf_caret(stddeb,"CreateCaret: hwnd=%04x\n", hwnd);
 
@@ -175,7 +177,7 @@
 /*****************************************************************
  *           DestroyCaret16   (USER.164)
  */
-void DestroyCaret16(void)
+void WINAPI DestroyCaret16(void)
 {
     DestroyCaret32();
 }
@@ -184,7 +186,7 @@
 /*****************************************************************
  *           DestroyCaret32   (USER32.130)
  */
-BOOL32 DestroyCaret32(void)
+BOOL32 WINAPI DestroyCaret32(void)
 {
     if (!Caret.hwnd) return FALSE;
 
@@ -202,7 +204,7 @@
 /*****************************************************************
  *           SetCaretPos16   (USER.165)
  */
-void SetCaretPos16( INT16 x, INT16 y )
+void WINAPI SetCaretPos16( INT16 x, INT16 y )
 {
     SetCaretPos32( x, y );
 }
@@ -211,7 +213,7 @@
 /*****************************************************************
  *           SetCaretPos32   (USER32.465)
  */
-BOOL32 SetCaretPos32( INT32 x, INT32 y)
+BOOL32 WINAPI SetCaretPos32( INT32 x, INT32 y)
 {
     if (!Caret.hwnd) return FALSE;
     if ((x == Caret.x) && (y == Caret.y)) return TRUE;
@@ -234,7 +236,7 @@
 /*****************************************************************
  *           HideCaret16   (USER.166)
  */
-void HideCaret16( HWND16 hwnd )
+void WINAPI HideCaret16( HWND16 hwnd )
 {
     HideCaret32( hwnd );
 }
@@ -243,7 +245,7 @@
 /*****************************************************************
  *           HideCaret32   (USER32.316)
  */
-BOOL32 HideCaret32( HWND32 hwnd )
+BOOL32 WINAPI HideCaret32( HWND32 hwnd )
 {
     if (!Caret.hwnd) return FALSE;
     if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
@@ -261,7 +263,7 @@
 /*****************************************************************
  *           ShowCaret16   (USER.167)
  */
-void ShowCaret16( HWND16 hwnd )
+void WINAPI ShowCaret16( HWND16 hwnd )
 {
     ShowCaret32( hwnd );
 }
@@ -270,7 +272,7 @@
 /*****************************************************************
  *           ShowCaret32   (USER32.528)
  */
-BOOL32 ShowCaret32( HWND32 hwnd )
+BOOL32 WINAPI ShowCaret32( HWND32 hwnd )
 {
     if (!Caret.hwnd) return FALSE;
     if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
@@ -294,7 +296,7 @@
 /*****************************************************************
  *           SetCaretBlinkTime16   (USER.168)
  */
-void SetCaretBlinkTime16( UINT16 msecs )
+void WINAPI SetCaretBlinkTime16( UINT16 msecs )
 {
     SetCaretBlinkTime32( msecs );
 }
@@ -302,7 +304,7 @@
 /*****************************************************************
  *           SetCaretBlinkTime32   (USER32.464)
  */
-BOOL32 SetCaretBlinkTime32( UINT32 msecs )
+BOOL32 WINAPI SetCaretBlinkTime32( UINT32 msecs )
 {
     if (!Caret.hwnd) return FALSE;
 
@@ -318,7 +320,7 @@
 /*****************************************************************
  *           GetCaretBlinkTime16   (USER.169)
  */
-UINT16 GetCaretBlinkTime16(void)
+UINT16 WINAPI GetCaretBlinkTime16(void)
 {
     return (UINT16)GetCaretBlinkTime32();
 }
@@ -327,7 +329,7 @@
 /*****************************************************************
  *           GetCaretBlinkTime32   (USER32.208)
  */
-UINT32 GetCaretBlinkTime32(void)
+UINT32 WINAPI GetCaretBlinkTime32(void)
 {
     return Caret.timeout;
 }
@@ -336,7 +338,7 @@
 /*****************************************************************
  *           GetCaretPos16   (USER.183)
  */
-VOID GetCaretPos16( LPPOINT16 pt )
+VOID WINAPI GetCaretPos16( LPPOINT16 pt )
 {
     if (!Caret.hwnd || !pt) return;
 
@@ -350,7 +352,7 @@
 /*****************************************************************
  *           GetCaretPos32   (USER32.209)
  */
-BOOL32 GetCaretPos32( LPPOINT32 pt )
+BOOL32 WINAPI GetCaretPos32( LPPOINT32 pt )
 {
     if (!Caret.hwnd || !pt) return FALSE;
     pt->x = Caret.x;
diff --git a/windows/class.c b/windows/class.c
index 4cc7eb6..e6422e9 100644
--- a/windows/class.c
+++ b/windows/class.c
@@ -304,7 +304,7 @@
 /***********************************************************************
  *           RegisterClass16    (USER.57)
  */
-ATOM RegisterClass16( const WNDCLASS16 *wc )
+ATOM WINAPI RegisterClass16( const WNDCLASS16 *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -342,7 +342,7 @@
 /***********************************************************************
  *           RegisterClass32A      (USER32.426)
  */
-ATOM RegisterClass32A( const WNDCLASS32A* wc )
+ATOM WINAPI RegisterClass32A( const WNDCLASS32A* wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -379,7 +379,7 @@
 /***********************************************************************
  *           RegisterClass32W      (USER32.429)
  */
-ATOM RegisterClass32W( const WNDCLASS32W* wc )
+ATOM WINAPI RegisterClass32W( const WNDCLASS32W* wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -414,7 +414,7 @@
 /***********************************************************************
  *           RegisterClassEx16    (USER.397)
  */
-ATOM RegisterClassEx16( const WNDCLASSEX16 *wc )
+ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -449,7 +449,7 @@
 /***********************************************************************
  *           RegisterClassEx32A      (USER32.427)
  */
-ATOM RegisterClassEx32A( const WNDCLASSEX32A* wc )
+ATOM WINAPI RegisterClassEx32A( const WNDCLASSEX32A* wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -484,7 +484,7 @@
 /***********************************************************************
  *           RegisterClassEx32W      (USER32.428)
  */
-ATOM RegisterClassEx32W( const WNDCLASSEX32W* wc )
+ATOM WINAPI RegisterClassEx32W( const WNDCLASSEX32W* wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -519,7 +519,7 @@
 /***********************************************************************
  *           UnregisterClass16    (USER.403)
  */
-BOOL16 UnregisterClass16( SEGPTR className, HINSTANCE16 hInstance )
+BOOL16 WINAPI UnregisterClass16( SEGPTR className, HINSTANCE16 hInstance )
 {
     CLASS *classPtr;
     ATOM atom;
@@ -535,7 +535,7 @@
 /***********************************************************************
  *           UnregisterClass32A    (USER32.562)
  */
-BOOL32 UnregisterClass32A( LPCSTR className, HINSTANCE32 hInstance )
+BOOL32 WINAPI UnregisterClass32A( LPCSTR className, HINSTANCE32 hInstance )
 {
     CLASS *classPtr;
     ATOM atom;
@@ -551,7 +551,7 @@
 /***********************************************************************
  *           UnregisterClass32W    (USER32.563)
  */
-BOOL32 UnregisterClass32W( LPCWSTR className, HINSTANCE32 hInstance )
+BOOL32 WINAPI UnregisterClass32W( LPCWSTR className, HINSTANCE32 hInstance )
 {
     CLASS *classPtr;
     ATOM atom;
@@ -567,7 +567,7 @@
 /***********************************************************************
  *           GetClassWord16    (USER.129)
  */
-WORD GetClassWord16( HWND16 hwnd, INT16 offset )
+WORD WINAPI GetClassWord16( HWND16 hwnd, INT16 offset )
 {
     return GetClassWord32( hwnd, offset );
 }
@@ -576,7 +576,7 @@
 /***********************************************************************
  *           GetClassWord32    (USER32.218)
  */
-WORD GetClassWord32( HWND32 hwnd, INT32 offset )
+WORD WINAPI GetClassWord32( HWND32 hwnd, INT32 offset )
 {
     WND * wndPtr;
     
@@ -607,7 +607,7 @@
 /***********************************************************************
  *           GetClassLong16    (USER.131)
  */
-LONG GetClassLong16( HWND16 hwnd, INT16 offset )
+LONG WINAPI GetClassLong16( HWND16 hwnd, INT16 offset )
 {
     WND *wndPtr;
     LONG ret;
@@ -629,7 +629,7 @@
 /***********************************************************************
  *           GetClassLong32A    (USER32.214)
  */
-LONG GetClassLong32A( HWND32 hwnd, INT32 offset )
+LONG WINAPI GetClassLong32A( HWND32 hwnd, INT32 offset )
 {
     WND * wndPtr;
     
@@ -663,7 +663,7 @@
 /***********************************************************************
  *           GetClassLong32W    (USER32.215)
  */
-LONG GetClassLong32W( HWND32 hwnd, INT32 offset )
+LONG WINAPI GetClassLong32W( HWND32 hwnd, INT32 offset )
 {
     WND * wndPtr;
 
@@ -684,7 +684,7 @@
 /***********************************************************************
  *           SetClassWord16    (USER.130)
  */
-WORD SetClassWord16( HWND16 hwnd, INT16 offset, WORD newval )
+WORD WINAPI SetClassWord16( HWND16 hwnd, INT16 offset, WORD newval )
 {
     return SetClassWord32( hwnd, offset, newval );
 }
@@ -693,7 +693,7 @@
 /***********************************************************************
  *           SetClassWord32    (USER32.468)
  */
-WORD SetClassWord32( HWND32 hwnd, INT32 offset, WORD newval )
+WORD WINAPI SetClassWord32( HWND32 hwnd, INT32 offset, WORD newval )
 {
     WND * wndPtr;
     WORD retval = 0;
@@ -737,7 +737,7 @@
 /***********************************************************************
  *           SetClassLong16    (USER.132)
  */
-LONG SetClassLong16( HWND16 hwnd, INT16 offset, LONG newval )
+LONG WINAPI SetClassLong16( HWND16 hwnd, INT16 offset, LONG newval )
 {
     WND *wndPtr;
     LONG retval;
@@ -761,7 +761,7 @@
 /***********************************************************************
  *           SetClassLong32A    (USER32.466)
  */
-LONG SetClassLong32A( HWND32 hwnd, INT32 offset, LONG newval )
+LONG WINAPI SetClassLong32A( HWND32 hwnd, INT32 offset, LONG newval )
 {
     WND * wndPtr;
     LONG retval = 0;
@@ -813,7 +813,7 @@
 /***********************************************************************
  *           SetClassLong32W    (USER32.467)
  */
-LONG SetClassLong32W( HWND32 hwnd, INT32 offset, LONG newval )
+LONG WINAPI SetClassLong32W( HWND32 hwnd, INT32 offset, LONG newval )
 {
     WND *wndPtr;
     LONG retval;
@@ -839,7 +839,7 @@
 /***********************************************************************
  *           GetClassName16      (USER.58)
  */
-INT16 GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
+INT16 WINAPI GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
 {
     WND *wndPtr;
     if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
@@ -850,7 +850,7 @@
 /***********************************************************************
  *           GetClassName32A      (USER32.216)
  */
-INT32 GetClassName32A( HWND32 hwnd, LPSTR buffer, INT32 count )
+INT32 WINAPI GetClassName32A( HWND32 hwnd, LPSTR buffer, INT32 count )
 {
     WND *wndPtr;
     if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
@@ -861,7 +861,7 @@
 /***********************************************************************
  *           GetClassName32W      (USER32.217)
  */
-INT32 GetClassName32W( HWND32 hwnd, LPWSTR buffer, INT32 count )
+INT32 WINAPI GetClassName32W( HWND32 hwnd, LPWSTR buffer, INT32 count )
 {
     WND *wndPtr;
     if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
@@ -872,15 +872,19 @@
 /***********************************************************************
  *           GetClassInfo16      (USER.404)
  */
-BOOL16 GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
+BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name,
+                              WNDCLASS16 *wc )
 {
     ATOM atom;
     CLASS *classPtr;
 
     hInstance = GetExePtr( hInstance );
     if (!(atom = GlobalFindAtom16( name )) ||
-        !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
-        (hInstance != classPtr->hInstance)) return FALSE;
+        !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
+        return FALSE;
+    if ((hInstance != classPtr->hInstance) &&
+        !(classPtr->style & CS_GLOBALCLASS)) /*BWCC likes to pass hInstance=0*/
+        return FALSE;
     wc->style         = (UINT16)classPtr->style;
     wc->lpfnWndProc   = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
     wc->cbClsExtra    = (INT16)classPtr->cbClsExtra;
@@ -900,7 +904,8 @@
 /***********************************************************************
  *           GetClassInfo32A      (USER32.210)
  */
-BOOL32 GetClassInfo32A( HINSTANCE32 hInstance, LPCSTR name, WNDCLASS32A *wc )
+BOOL32 WINAPI GetClassInfo32A( HINSTANCE32 hInstance, LPCSTR name,
+                               WNDCLASS32A *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -929,7 +934,8 @@
 /***********************************************************************
  *           GetClassInfo32W      (USER32.213)
  */
-BOOL32 GetClassInfo32W( HINSTANCE32 hInstance, LPCWSTR name, WNDCLASS32W *wc )
+BOOL32 WINAPI GetClassInfo32W( HINSTANCE32 hInstance, LPCWSTR name,
+                               WNDCLASS32W *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -961,7 +967,8 @@
  * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
  * same in Win16 as in Win32. --AJ
  */
-BOOL16 GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
+BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name,
+                                WNDCLASSEX16 *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -990,8 +997,8 @@
 /***********************************************************************
  *           GetClassInfoEx32A      (USER32.211)
  */
-BOOL32 GetClassInfoEx32A( HINSTANCE32 hInstance, LPCSTR name,
-                          WNDCLASSEX32A *wc )
+BOOL32 WINAPI GetClassInfoEx32A( HINSTANCE32 hInstance, LPCSTR name,
+                                 WNDCLASSEX32A *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -1019,8 +1026,8 @@
 /***********************************************************************
  *           GetClassInfoEx32W      (USER32.212)
  */
-BOOL32 GetClassInfoEx32W( HINSTANCE32 hInstance, LPCWSTR name,
-                          WNDCLASSEX32W *wc )
+BOOL32 WINAPI GetClassInfoEx32W( HINSTANCE32 hInstance, LPCWSTR name,
+                                 WNDCLASSEX32W *wc )
 {
     ATOM atom;
     CLASS *classPtr;
@@ -1048,7 +1055,7 @@
 /***********************************************************************
  *           ClassFirst      (TOOLHELP.69)
  */
-BOOL16 ClassFirst( CLASSENTRY *pClassEntry )
+BOOL16 WINAPI ClassFirst( CLASSENTRY *pClassEntry )
 {
     pClassEntry->wNext = 1;
     return ClassNext( pClassEntry );
@@ -1058,7 +1065,7 @@
 /***********************************************************************
  *           ClassNext      (TOOLHELP.70)
  */
-BOOL16 ClassNext( CLASSENTRY *pClassEntry )
+BOOL16 WINAPI ClassNext( CLASSENTRY *pClassEntry )
 {
     int i;
     CLASS *class = firstClass;
diff --git a/windows/clipboard.c b/windows/clipboard.c
index ce261c0..d51dbd4 100644
--- a/windows/clipboard.c
+++ b/windows/clipboard.c
@@ -178,7 +178,7 @@
 
   selectionWait=True;
   while(selectionWait) 
-        EVENT_WaitXEvent( TRUE, FALSE );
+        EVENT_WaitNetEvent( TRUE, FALSE );
 
   /* we treat Unix text as CF_OEMTEXT */
   dprintf_clipboard(stddeb,"\tgot CF_OEMTEXT = %i\n", 
@@ -212,7 +212,7 @@
 /**************************************************************************
  *            OpenClipboard16   (USER.137)
  */
-BOOL16 OpenClipboard16( HWND16 hWnd )
+BOOL16 WINAPI OpenClipboard16( HWND16 hWnd )
 {
     return OpenClipboard32( hWnd );
 }
@@ -221,7 +221,7 @@
 /**************************************************************************
  *            OpenClipboard32   (USER32.406)
  */
-BOOL32 OpenClipboard32( HWND32 hWnd )
+BOOL32 WINAPI OpenClipboard32( HWND32 hWnd )
 {
     BOOL32 bRet = FALSE;
     dprintf_clipboard(stddeb,"OpenClipboard(%04x) = ", hWnd);
@@ -241,7 +241,7 @@
 /**************************************************************************
  *            CloseClipboard16   (USER.138)
  */
-BOOL16 CloseClipboard16(void)
+BOOL16 WINAPI CloseClipboard16(void)
 {
     return CloseClipboard32();
 }
@@ -250,7 +250,7 @@
 /**************************************************************************
  *            CloseClipboard32   (USER32.53)
  */
-BOOL32 CloseClipboard32(void)
+BOOL32 WINAPI CloseClipboard32(void)
 {
     dprintf_clipboard(stddeb,"CloseClipboard(); !\n");
 
@@ -266,7 +266,7 @@
 /**************************************************************************
  *            EmptyClipboard16   (USER.139)
  */
-BOOL16 EmptyClipboard16(void)
+BOOL16 WINAPI EmptyClipboard16(void)
 {
     return EmptyClipboard32();
 }
@@ -275,7 +275,7 @@
 /**************************************************************************
  *            EmptyClipboard32   (USER32.168)
  */
-BOOL32 EmptyClipboard32(void)
+BOOL32 WINAPI EmptyClipboard32(void)
 {
     LPCLIPFORMAT lpFormat = ClipFormats; 
 
@@ -316,7 +316,7 @@
 /**************************************************************************
  *            GetClipboardOwner16   (USER.140)
  */
-HWND16 GetClipboardOwner16(void)
+HWND16 WINAPI GetClipboardOwner16(void)
 {
     return hWndClipOwner;
 }
@@ -325,7 +325,7 @@
 /**************************************************************************
  *            GetClipboardOwner32   (USER32.224)
  */
-HWND32 GetClipboardOwner32(void)
+HWND32 WINAPI GetClipboardOwner32(void)
 {
     return hWndClipOwner;
 }
@@ -334,7 +334,7 @@
 /**************************************************************************
  *            SetClipboardData16   (USER.141)
  */
-HANDLE16 SetClipboardData16( UINT16 wFormat, HANDLE16 hData )
+HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData )
 {
     LPCLIPFORMAT lpFormat = ClipFormats; 
     Window       owner;
@@ -391,7 +391,7 @@
 /**************************************************************************
  *            SetClipboardData32   (USER32.469)
  */
-HANDLE32 SetClipboardData32( UINT32 wFormat, HANDLE32 hData )
+HANDLE32 WINAPI SetClipboardData32( UINT32 wFormat, HANDLE32 hData )
 {
     fprintf( stderr, "SetClipboardData: empty stub\n" );
     return 0;
@@ -450,7 +450,7 @@
 /**************************************************************************
  *             GetClipboardData16   (USER.142)
  */
-HANDLE16 GetClipboardData16( UINT16 wFormat )
+HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat )
 {
     LPCLIPFORMAT lpRender = ClipFormats; 
     LPCLIPFORMAT lpUpdate = NULL;
@@ -499,7 +499,7 @@
 /**************************************************************************
  *             GetClipboardData32   (USER32.221)
  */
-HANDLE32 GetClipboardData32( UINT32 wFormat )
+HANDLE32 WINAPI GetClipboardData32( UINT32 wFormat )
 {
     fprintf( stderr, "GetClipboardData32: empty stub\n" );
     return 0;
@@ -508,7 +508,7 @@
 /**************************************************************************
  *           CountClipboardFormats16   (USER.143)
  */
-INT16 CountClipboardFormats16(void)
+INT16 WINAPI CountClipboardFormats16(void)
 {
     return CountClipboardFormats32();
 }
@@ -517,7 +517,7 @@
 /**************************************************************************
  *           CountClipboardFormats32   (USER32.62)
  */
-INT32 CountClipboardFormats32(void)
+INT32 WINAPI CountClipboardFormats32(void)
 {
     INT32 FormatCount = 0;
     LPCLIPFORMAT lpFormat = ClipFormats; 
@@ -548,7 +548,7 @@
 /**************************************************************************
  *            EnumClipboardFormats16   (USER.144)
  */
-UINT16 EnumClipboardFormats16( UINT16 wFormat )
+UINT16 WINAPI EnumClipboardFormats16( UINT16 wFormat )
 {
     return EnumClipboardFormats32( wFormat );
 }
@@ -557,7 +557,7 @@
 /**************************************************************************
  *            EnumClipboardFormats32   (USER32.178)
  */
-UINT32 EnumClipboardFormats32( UINT32 wFormat )
+UINT32 WINAPI EnumClipboardFormats32( UINT32 wFormat )
 {
     LPCLIPFORMAT lpFormat = ClipFormats; 
 
@@ -600,7 +600,7 @@
 /**************************************************************************
  *            RegisterClipboardFormat16  (USER.145)
  */
-UINT16 RegisterClipboardFormat16( LPCSTR FormatName )
+UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName )
 {
     LPCLIPFORMAT lpNewFormat; 
     LPCLIPFORMAT lpFormat = ClipFormats; 
@@ -646,7 +646,7 @@
 /**************************************************************************
  *            RegisterClipboardFormat32A   (USER32.430)
  */
-UINT32 RegisterClipboardFormat32A( LPCSTR formatName )
+UINT32 WINAPI RegisterClipboardFormat32A( LPCSTR formatName )
 {
     return RegisterClipboardFormat16( formatName );
 }
@@ -655,7 +655,7 @@
 /**************************************************************************
  *            RegisterClipboardFormat32W   (USER32.431)
  */
-UINT32 RegisterClipboardFormat32W( LPCWSTR formatName )
+UINT32 WINAPI RegisterClipboardFormat32W( LPCWSTR formatName )
 {
     LPSTR aFormat = HEAP_strdupWtoA( GetProcessHeap(), 0, formatName );
     UINT32 ret = RegisterClipboardFormat32A( aFormat );
@@ -666,7 +666,7 @@
 /**************************************************************************
  *            GetClipboardFormatName16   (USER.146)
  */
-INT16 GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxlen )
+INT16 WINAPI GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxlen )
 {
     return GetClipboardFormatName32A( wFormat, retStr, maxlen );
 }
@@ -675,7 +675,7 @@
 /**************************************************************************
  *            GetClipboardFormatName32A   (USER32.222)
  */
-INT32 GetClipboardFormatName32A( UINT32 wFormat, LPSTR retStr, INT32 maxlen )
+INT32 WINAPI GetClipboardFormatName32A( UINT32 wFormat, LPSTR retStr, INT32 maxlen )
 {
     LPCLIPFORMAT lpFormat = ClipFormats; 
 
@@ -702,7 +702,7 @@
 /**************************************************************************
  *            GetClipboardFormatName32W   (USER32.223)
  */
-INT32 GetClipboardFormatName32W( UINT32 wFormat, LPWSTR retStr, INT32 maxlen )
+INT32 WINAPI GetClipboardFormatName32W( UINT32 wFormat, LPWSTR retStr, INT32 maxlen )
 {
     LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, maxlen );
     INT32 ret = GetClipboardFormatName32A( wFormat, p, maxlen );
@@ -715,7 +715,7 @@
 /**************************************************************************
  *            SetClipboardViewer16   (USER.147)
  */
-HWND16 SetClipboardViewer16( HWND16 hWnd )
+HWND16 WINAPI SetClipboardViewer16( HWND16 hWnd )
 {
     return SetClipboardViewer32( hWnd );
 }
@@ -724,11 +724,11 @@
 /**************************************************************************
  *            SetClipboardViewer32   (USER32.470)
  */
-HWND32 SetClipboardViewer32( HWND32 hWnd )
+HWND32 WINAPI SetClipboardViewer32( HWND32 hWnd )
 {
     HWND32 hwndPrev = hWndViewer;
 
-    dprintf_clipboard(stddeb,"SetClipboardViewer(%04x)\n", hWnd);
+    dprintf_clipboard(stddeb,"SetClipboardViewer(%04x): returning %04x\n", hWnd, hwndPrev);
 
     hWndViewer = hWnd;
     return hwndPrev;
@@ -738,7 +738,7 @@
 /**************************************************************************
  *           GetClipboardViewer16   (USER.148)
  */
-HWND16 GetClipboardViewer16(void)
+HWND16 WINAPI GetClipboardViewer16(void)
 {
     return hWndViewer;
 }
@@ -747,7 +747,7 @@
 /**************************************************************************
  *           GetClipboardViewer32   (USER32.225)
  */
-HWND32 GetClipboardViewer32(void)
+HWND32 WINAPI GetClipboardViewer32(void)
 {
     return hWndViewer;
 }
@@ -756,7 +756,7 @@
 /**************************************************************************
  *           ChangeClipboardChain16   (USER.149)
  */
-BOOL16 ChangeClipboardChain16(HWND16 hWnd, HWND16 hWndNext)
+BOOL16 WINAPI ChangeClipboardChain16(HWND16 hWnd, HWND16 hWndNext)
 {
     return ChangeClipboardChain32(hWnd,hWndNext);
 }
@@ -764,7 +764,7 @@
 /**************************************************************************
  *           ChangeClipboardChain32   (USER32.21)
  */
-BOOL32 ChangeClipboardChain32(HWND32 hWnd, HWND32 hWndNext)
+BOOL32 WINAPI ChangeClipboardChain32(HWND32 hWnd, HWND32 hWndNext)
 {
     BOOL32 bRet = 0;
 
@@ -786,7 +786,7 @@
 /**************************************************************************
  *           IsClipboardFormatAvailable16   (USER.193)
  */
-BOOL16 IsClipboardFormatAvailable16( UINT16 wFormat )
+BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
 {
     return IsClipboardFormatAvailable32( wFormat );
 }
@@ -795,7 +795,7 @@
 /**************************************************************************
  *           IsClipboardFormatAvailable32   (USER32.339)
  */
-BOOL32 IsClipboardFormatAvailable32( UINT32 wFormat )
+BOOL32 WINAPI IsClipboardFormatAvailable32( UINT32 wFormat )
 {
     dprintf_clipboard(stddeb,"IsClipboardFormatAvailable(%04X) !\n", wFormat);
 
@@ -809,7 +809,7 @@
 /**************************************************************************
  *             GetOpenClipboardWindow16   (USER.248)
  */
-HWND16 GetOpenClipboardWindow16(void)
+HWND16 WINAPI GetOpenClipboardWindow16(void)
 {
     return hWndClipWindow;
 }
@@ -818,7 +818,7 @@
 /**************************************************************************
  *             GetOpenClipboardWindow32   (USER32.276)
  */
-HWND32 GetOpenClipboardWindow32(void)
+HWND32 WINAPI GetOpenClipboardWindow32(void)
 {
     return hWndClipWindow;
 }
@@ -827,7 +827,7 @@
 /**************************************************************************
  *             GetPriorityClipboardFormat16   (USER.402)
  */
-INT16 GetPriorityClipboardFormat16( UINT16 *lpPriorityList, INT16 nCount)
+INT16 WINAPI GetPriorityClipboardFormat16( UINT16 *lpPriorityList, INT16 nCount)
 {
     fprintf( stderr, "GetPriorityClipboardFormat16(%p, %d): stub\n",
              lpPriorityList, nCount );
@@ -838,7 +838,7 @@
 /**************************************************************************
  *             GetPriorityClipboardFormat32   (USER32
  */
-INT32 GetPriorityClipboardFormat32( UINT32 *lpPriorityList, INT32 nCount )
+INT32 WINAPI GetPriorityClipboardFormat32( UINT32 *lpPriorityList, INT32 nCount )
 {
     fprintf( stderr, "GetPriorityClipboardFormat32(%p, %d): stub\n",
              lpPriorityList, nCount );
diff --git a/windows/dce.c b/windows/dce.c
index 5e925f6..d54654c 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -95,7 +95,7 @@
 /**********************************************************************
  *          WindowFromDC16   (USER32.580)
  */
-HWND16 WindowFromDC16( HDC16 hDC )
+HWND16 WINAPI WindowFromDC16( HDC16 hDC )
 {
     return (HWND16)WindowFromDC32( hDC );
 }
@@ -104,7 +104,7 @@
 /**********************************************************************
  *          WindowFromDC32   (USER32.580)
  */
-HWND32 WindowFromDC32( HDC32 hDC )
+HWND32 WINAPI WindowFromDC32( HDC32 hDC )
 {
     DCE *dce = firstDCE;
     while (dce && (dce->hDC != hDC)) dce = dce->next;
@@ -417,7 +417,7 @@
 /***********************************************************************
  *           GetDCEx16    (USER.359)
  */
-HDC16 GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
+HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
 {
     return (HDC16)GetDCEx32( hwnd, hrgnClip, flags );
 }
@@ -428,7 +428,7 @@
  *
  * Unimplemented flags: DCX_LOCKWINDOWUPDATE
  */
-HDC32 GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
+HDC32 WINAPI GetDCEx32( HWND32 hwnd, HRGN32 hrgnClip, DWORD flags )
 {
     HRGN32 	hrgnVisible;
     HDC32 	hdc = 0;
@@ -583,7 +583,7 @@
 /***********************************************************************
  *           GetDC16    (USER.66)
  */
-HDC16 GetDC16( HWND16 hwnd )
+HDC16 WINAPI GetDC16( HWND16 hwnd )
 {
     return (HDC16)GetDC32( hwnd );
 }
@@ -592,7 +592,7 @@
 /***********************************************************************
  *           GetDC32    (USER32.229)
  */
-HDC32 GetDC32( HWND32 hwnd )
+HDC32 WINAPI GetDC32( HWND32 hwnd )
 {
     if (!hwnd)
         return GetDCEx32( GetDesktopWindow32(), 0, DCX_CACHE | DCX_WINDOW );
@@ -603,7 +603,7 @@
 /***********************************************************************
  *           GetWindowDC16    (USER.67)
  */
-HDC16 GetWindowDC16( HWND16 hwnd )
+HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
 {
     if (!hwnd) hwnd = GetDesktopWindow16();
     return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
@@ -613,7 +613,7 @@
 /***********************************************************************
  *           GetWindowDC32    (USER32.)
  */
-HDC32 GetWindowDC32( HWND32 hwnd )
+HDC32 WINAPI GetWindowDC32( HWND32 hwnd )
 {
     if (!hwnd) hwnd = GetDesktopWindow32();
     return GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
@@ -623,7 +623,7 @@
 /***********************************************************************
  *           ReleaseDC16    (USER.68)
  */
-INT16 ReleaseDC16( HWND16 hwnd, HDC16 hdc )
+INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
 {
     return (INT32)ReleaseDC32( hwnd, hdc );
 }
@@ -632,7 +632,7 @@
 /***********************************************************************
  *           ReleaseDC32    (USER32.439)
  */
-INT32 ReleaseDC32( HWND32 hwnd, HDC32 hdc )
+INT32 WINAPI ReleaseDC32( HWND32 hwnd, HDC32 hdc )
 {
     DCE * dce = firstDCE;
     
@@ -674,7 +674,7 @@
  *
  * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..  
  */
-BOOL16 DCHook( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
+BOOL16 WINAPI DCHook( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
 {
     HRGN32 hVisRgn;
     DCE *dce = firstDCE;;
@@ -729,7 +729,7 @@
 /***********************************************************************
  *           LockWindowUpdate16   (USER.294)
  */
-BOOL16 LockWindowUpdate16( HWND16 hwnd )
+BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
 {
     return LockWindowUpdate32( hwnd );
 }
@@ -738,7 +738,7 @@
 /***********************************************************************
  *           LockWindowUpdate32   (USER32.377)
  */
-BOOL32 LockWindowUpdate32( HWND32 hwnd )
+BOOL32 WINAPI LockWindowUpdate32( HWND32 hwnd )
 {
     /* FIXME? DCX_LOCKWINDOWUPDATE is unimplemented */
     return TRUE;
diff --git a/windows/defdlg.c b/windows/defdlg.c
index 3c5c082..1285d73 100644
--- a/windows/defdlg.c
+++ b/windows/defdlg.c
@@ -248,7 +248,8 @@
 /***********************************************************************
  *           DefDlgProc16   (USER.308)
  */
-LRESULT DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
+LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
+                             LPARAM lParam )
 {
     DIALOGINFO * dlgInfo;
     BOOL16 result = FALSE;
@@ -302,7 +303,8 @@
 /***********************************************************************
  *           DefDlgProc32A   (USER32.119)
  */
-LRESULT DefDlgProc32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI DefDlgProc32A( HWND32 hwnd, UINT32 msg,
+                              WPARAM32 wParam, LPARAM lParam )
 {
     DIALOGINFO * dlgInfo;
     BOOL16 result = FALSE;
@@ -356,7 +358,8 @@
 /***********************************************************************
  *           DefDlgProc32W   (USER32.120)
  */
-LRESULT DefDlgProc32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI DefDlgProc32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
+                              LPARAM lParam )
 {
     DIALOGINFO * dlgInfo;
     BOOL16 result = FALSE;
diff --git a/windows/defwnd.c b/windows/defwnd.c
index 7b59447..a5b5af4 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -359,8 +359,8 @@
 /***********************************************************************
  *           DefWindowProc16   (USER.107)
  */
-LRESULT DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
-                         LPARAM lParam )
+LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
+                                LPARAM lParam )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     LRESULT result = 0;
@@ -426,8 +426,8 @@
 /***********************************************************************
  *           DefWindowProc32A   (USER32.125)
  */
-LRESULT DefWindowProc32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                          LPARAM lParam )
+LRESULT WINAPI DefWindowProc32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
+                                 LPARAM lParam )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     LRESULT result = 0;
@@ -487,8 +487,8 @@
 /***********************************************************************
  *           DefWindowProc32W   (USER32.126)
  */
-LRESULT DefWindowProc32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
-                          LPARAM lParam )
+LRESULT WINAPI DefWindowProc32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
+                                 LPARAM lParam )
 {
     LRESULT result;
 
diff --git a/windows/dialog.c b/windows/dialog.c
index 8b2f580..21ef5b0 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -618,8 +618,8 @@
 /***********************************************************************
  *           CreateDialog16   (USER.89)
  */
-HWND16 CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
-                       HWND16 owner, DLGPROC16 dlgProc )
+HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
+                              HWND16 owner, DLGPROC16 dlgProc )
 {
     return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
 }
@@ -628,8 +628,9 @@
 /***********************************************************************
  *           CreateDialogParam16   (USER.241)
  */
-HWND16 CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
-                            HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
+HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
+                                   HWND16 owner, DLGPROC16 dlgProc,
+                                   LPARAM param )
 {
     HWND16 hwnd = 0;
     HRSRC16 hRsrc;
@@ -652,8 +653,9 @@
 /***********************************************************************
  *           CreateDialogParam32A   (USER32.72)
  */
-HWND32 CreateDialogParam32A( HINSTANCE32 hInst, LPCSTR name,
-                             HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
+HWND32 WINAPI CreateDialogParam32A( HINSTANCE32 hInst, LPCSTR name,
+                                    HWND32 owner, DLGPROC32 dlgProc,
+                                    LPARAM param )
 {
     if (HIWORD(name))
     {
@@ -669,8 +671,9 @@
 /***********************************************************************
  *           CreateDialogParam32W   (USER32.73)
  */
-HWND32 CreateDialogParam32W( HINSTANCE32 hInst, LPCWSTR name,
-                             HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
+HWND32 WINAPI CreateDialogParam32W( HINSTANCE32 hInst, LPCWSTR name,
+                                    HWND32 owner, DLGPROC32 dlgProc,
+                                    LPARAM param )
 {
     HANDLE32 hrsrc = FindResource32W( hInst, name, (LPWSTR)RT_DIALOG );
     if (!hrsrc) return 0;
@@ -683,8 +686,8 @@
 /***********************************************************************
  *           CreateDialogIndirect16   (USER.219)
  */
-HWND16 CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
-                               HWND16 owner, DLGPROC16 dlgProc )
+HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
+                                      HWND16 owner, DLGPROC16 dlgProc )
 {
     return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
 }
@@ -693,9 +696,10 @@
 /***********************************************************************
  *           CreateDialogIndirectParam16   (USER.242)
  */
-HWND16 CreateDialogIndirectParam16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
-                                    HWND16 owner, DLGPROC16 dlgProc,
-                                    LPARAM param )
+HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
+                                           LPCVOID dlgTemplate,
+                                           HWND16 owner, DLGPROC16 dlgProc,
+                                           LPARAM param )
 {
     return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
                                   dlgProc, param, WIN_PROC_16 );
@@ -705,9 +709,10 @@
 /***********************************************************************
  *           CreateDialogIndirectParam32A   (USER32.69)
  */
-HWND32 CreateDialogIndirectParam32A( HINSTANCE32 hInst, LPCVOID dlgTemplate,
-                                     HWND32 owner, DLGPROC32 dlgProc,
-                                     LPARAM param )
+HWND32 WINAPI CreateDialogIndirectParam32A( HINSTANCE32 hInst,
+                                            LPCVOID dlgTemplate,
+                                            HWND32 owner, DLGPROC32 dlgProc,
+                                            LPARAM param )
 {
     return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
                                   (DLGPROC16)dlgProc, param, WIN_PROC_32A );
@@ -717,9 +722,10 @@
 /***********************************************************************
  *           CreateDialogIndirectParam32W   (USER32.71)
  */
-HWND32 CreateDialogIndirectParam32W( HINSTANCE32 hInst, LPCVOID dlgTemplate,
-                                     HWND32 owner, DLGPROC32 dlgProc,
-                                     LPARAM param )
+HWND32 WINAPI CreateDialogIndirectParam32W( HINSTANCE32 hInst,
+                                            LPCVOID dlgTemplate,
+                                            HWND32 owner, DLGPROC32 dlgProc,
+                                            LPARAM param )
 {
     return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
                                   (DLGPROC16)dlgProc, param, WIN_PROC_32W );
@@ -763,8 +769,8 @@
 /***********************************************************************
  *           DialogBox16   (USER.87)
  */
-INT16 DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
-                   HWND16 owner, DLGPROC16 dlgProc )
+INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
+                          HWND16 owner, DLGPROC16 dlgProc )
 {
     return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
 }
@@ -773,8 +779,8 @@
 /***********************************************************************
  *           DialogBoxParam16   (USER.239)
  */
-INT16 DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
-                        HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
+INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
+                               HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
 {
     HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
     if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
@@ -785,8 +791,8 @@
 /***********************************************************************
  *           DialogBoxParam32A   (USER32.138)
  */
-INT32 DialogBoxParam32A( HINSTANCE32 hInst, LPCSTR name,
-                         HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
+INT32 WINAPI DialogBoxParam32A( HINSTANCE32 hInst, LPCSTR name,
+                                HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
 {
     HWND32 hwnd = CreateDialogParam32A( hInst, name, owner, dlgProc, param );
     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
@@ -797,8 +803,8 @@
 /***********************************************************************
  *           DialogBoxParam32W   (USER32.139)
  */
-INT32 DialogBoxParam32W( HINSTANCE32 hInst, LPCWSTR name,
-                         HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
+INT32 WINAPI DialogBoxParam32W( HINSTANCE32 hInst, LPCWSTR name,
+                                HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
 {
     HWND32 hwnd = CreateDialogParam32W( hInst, name, owner, dlgProc, param );
     if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
@@ -809,8 +815,8 @@
 /***********************************************************************
  *           DialogBoxIndirect16   (USER.218)
  */
-INT16 DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
-                           HWND16 owner, DLGPROC16 dlgProc )
+INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
+                                  HWND16 owner, DLGPROC16 dlgProc )
 {
     return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
 }
@@ -819,8 +825,9 @@
 /***********************************************************************
  *           DialogBoxIndirectParam16   (USER.240)
  */
-INT16 DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
-                                HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
+INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
+                                       HWND16 owner, DLGPROC16 dlgProc,
+                                       LPARAM param )
 {
     HWND16 hwnd;
     LPCVOID ptr;
@@ -836,8 +843,9 @@
 /***********************************************************************
  *           DialogBoxIndirectParam32A   (USER32.135)
  */
-INT32 DialogBoxIndirectParam32A( HINSTANCE32 hInstance, LPCVOID template,
-                                 HWND32 owner, DLGPROC32 dlgProc, LPARAM param)
+INT32 WINAPI DialogBoxIndirectParam32A(HINSTANCE32 hInstance, LPCVOID template,
+                                       HWND32 owner, DLGPROC32 dlgProc,
+                                       LPARAM param )
 {
     HWND32 hwnd = CreateDialogIndirectParam32A( hInstance, template,
                                                 owner, dlgProc, param );
@@ -849,8 +857,9 @@
 /***********************************************************************
  *           DialogBoxIndirectParam32W   (USER32.137)
  */
-INT32 DialogBoxIndirectParam32W( HINSTANCE32 hInstance, LPCVOID template,
-                                 HWND32 owner, DLGPROC32 dlgProc, LPARAM param)
+INT32 WINAPI DialogBoxIndirectParam32W(HINSTANCE32 hInstance, LPCVOID template,
+                                       HWND32 owner, DLGPROC32 dlgProc,
+                                       LPARAM param )
 {
     HWND32 hwnd = CreateDialogIndirectParam32W( hInstance, template,
                                                 owner, dlgProc, param );
@@ -862,7 +871,7 @@
 /***********************************************************************
  *           EndDialog16   (USER32.173)
  */
-BOOL16 EndDialog16( HWND16 hwnd, INT16 retval )
+BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
 {
     return EndDialog32( hwnd, retval );
 }
@@ -871,7 +880,7 @@
 /***********************************************************************
  *           EndDialog32   (USER32.173)
  */
-BOOL32 EndDialog32( HWND32 hwnd, INT32 retval )
+BOOL32 WINAPI EndDialog32( HWND32 hwnd, INT32 retval )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
@@ -998,7 +1007,7 @@
 /***********************************************************************
  *           IsDialogMessage16   (USER.90)
  */
-BOOL16 IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
+BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
 {
     BOOL32 ret, translate, dispatch;
 
@@ -1017,7 +1026,7 @@
 /***********************************************************************
  *           IsDialogMessage32A   (USER32.341)
  */
-BOOL32 IsDialogMessage32A( HWND32 hwndDlg, LPMSG32 msg )
+BOOL32 WINAPI IsDialogMessage32A( HWND32 hwndDlg, LPMSG32 msg )
 {
     BOOL32 ret, translate, dispatch;
 
@@ -1036,7 +1045,7 @@
 /***********************************************************************
  *           IsDialogMessage32W   (USER32.342)
  */
-BOOL32 IsDialogMessage32W( HWND32 hwndDlg, LPMSG32 msg )
+BOOL32 WINAPI IsDialogMessage32W( HWND32 hwndDlg, LPMSG32 msg )
 {
     BOOL32 ret, translate, dispatch;
 
@@ -1055,7 +1064,7 @@
 /****************************************************************
  *         GetDlgCtrlID16   (USER.277)
  */
-INT16 GetDlgCtrlID16( HWND16 hwnd )
+INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
     if (wndPtr) return wndPtr->wIDmenu;
@@ -1066,7 +1075,7 @@
 /****************************************************************
  *         GetDlgCtrlID32   (USER32.233)
  */
-INT32 GetDlgCtrlID32( HWND32 hwnd )
+INT32 WINAPI GetDlgCtrlID32( HWND32 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
     if (wndPtr) return wndPtr->wIDmenu;
@@ -1077,7 +1086,7 @@
 /***********************************************************************
  *           GetDlgItem16   (USER.91)
  */
-HWND16 GetDlgItem16( HWND16 hwndDlg, INT16 id )
+HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
 {
     WND *pWnd;
 
@@ -1091,7 +1100,7 @@
 /***********************************************************************
  *           GetDlgItem32   (USER32.234)
  */
-HWND32 GetDlgItem32( HWND32 hwndDlg, INT32 id )
+HWND32 WINAPI GetDlgItem32( HWND32 hwndDlg, INT32 id )
 {
     WND *pWnd;
 
@@ -1105,8 +1114,8 @@
 /*******************************************************************
  *           SendDlgItemMessage16   (USER.101)
  */
-LRESULT SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
-                              WPARAM16 wParam, LPARAM lParam )
+LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
+                                     WPARAM16 wParam, LPARAM lParam )
 {
     HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
     if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
@@ -1117,8 +1126,8 @@
 /*******************************************************************
  *           SendDlgItemMessage32A   (USER32.451)
  */
-LRESULT SendDlgItemMessage32A( HWND32 hwnd, INT32 id, UINT32 msg,
-                               WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI SendDlgItemMessage32A( HWND32 hwnd, INT32 id, UINT32 msg,
+                                      WPARAM32 wParam, LPARAM lParam )
 {
     HWND32 hwndCtrl = GetDlgItem32( hwnd, id );
     if (hwndCtrl) return SendMessage32A( hwndCtrl, msg, wParam, lParam );
@@ -1129,8 +1138,8 @@
 /*******************************************************************
  *           SendDlgItemMessage32W   (USER32.452)
  */
-LRESULT SendDlgItemMessage32W( HWND32 hwnd, INT32 id, UINT32 msg,
-                               WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI SendDlgItemMessage32W( HWND32 hwnd, INT32 id, UINT32 msg,
+                                      WPARAM32 wParam, LPARAM lParam )
 {
     HWND32 hwndCtrl = GetDlgItem32( hwnd, id );
     if (hwndCtrl) return SendMessage32W( hwndCtrl, msg, wParam, lParam );
@@ -1141,7 +1150,7 @@
 /*******************************************************************
  *           SetDlgItemText16   (USER.92)
  */
-void SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
+void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
 {
     SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
 }
@@ -1150,7 +1159,7 @@
 /*******************************************************************
  *           SetDlgItemText32A   (USER32.477)
  */
-void SetDlgItemText32A( HWND32 hwnd, INT32 id, LPCSTR lpString )
+void WINAPI SetDlgItemText32A( HWND32 hwnd, INT32 id, LPCSTR lpString )
 {
     SendDlgItemMessage32A( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
 }
@@ -1159,7 +1168,7 @@
 /*******************************************************************
  *           SetDlgItemText32W   (USER32.478)
  */
-void SetDlgItemText32W( HWND32 hwnd, INT32 id, LPCWSTR lpString )
+void WINAPI SetDlgItemText32W( HWND32 hwnd, INT32 id, LPCWSTR lpString )
 {
     SendDlgItemMessage32W( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
 }
@@ -1168,7 +1177,7 @@
 /***********************************************************************
  *           GetDlgItemText16   (USER.93)
  */
-INT16 GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
+INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
 {
     return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
                                         len, (LPARAM)str );
@@ -1178,7 +1187,7 @@
 /***********************************************************************
  *           GetDlgItemText32A   (USER32.236)
  */
-INT32 GetDlgItemText32A( HWND32 hwnd, INT32 id, LPSTR str, UINT32 len )
+INT32 WINAPI GetDlgItemText32A( HWND32 hwnd, INT32 id, LPSTR str, UINT32 len )
 {
     return (INT32)SendDlgItemMessage32A( hwnd, id, WM_GETTEXT,
                                          len, (LPARAM)str );
@@ -1188,7 +1197,7 @@
 /***********************************************************************
  *           GetDlgItemText32W   (USER32.237)
  */
-INT32 GetDlgItemText32W( HWND32 hwnd, INT32 id, LPWSTR str, UINT32 len )
+INT32 WINAPI GetDlgItemText32W( HWND32 hwnd, INT32 id, LPWSTR str, UINT32 len )
 {
     return (INT32)SendDlgItemMessage32W( hwnd, id, WM_GETTEXT,
                                          len, (LPARAM)str );
@@ -1198,7 +1207,7 @@
 /*******************************************************************
  *           SetDlgItemInt16   (USER.94)
  */
-void SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
+void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
 {
     return SetDlgItemInt32( hwnd, (UINT32)(UINT16)id, value, fSigned );
 }
@@ -1207,7 +1216,8 @@
 /*******************************************************************
  *           SetDlgItemInt32   (USER32.476)
  */
-void SetDlgItemInt32( HWND32 hwnd, INT32 id, UINT32 value, BOOL32 fSigned )
+void WINAPI SetDlgItemInt32( HWND32 hwnd, INT32 id, UINT32 value,
+                             BOOL32 fSigned )
 {
     char str[20];
 
@@ -1220,8 +1230,8 @@
 /***********************************************************************
  *           GetDlgItemInt16   (USER.95)
  */
-UINT16 GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
-                        BOOL16 fSigned )
+UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
+                               BOOL16 fSigned )
 {
     UINT32 result;
     BOOL32 ok;
@@ -1245,8 +1255,8 @@
 /***********************************************************************
  *           GetDlgItemInt32   (USER32.235)
  */
-UINT32 GetDlgItemInt32( HWND32 hwnd, INT32 id, BOOL32 *translated,
-                        BOOL32 fSigned )
+UINT32 WINAPI GetDlgItemInt32( HWND32 hwnd, INT32 id, BOOL32 *translated,
+                               BOOL32 fSigned )
 {
     char str[30];
     char * endptr;
@@ -1278,7 +1288,7 @@
 /***********************************************************************
  *           CheckDlgButton16   (USER.97)
  */
-BOOL16 CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
+BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
 {
     SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
     return TRUE;
@@ -1288,7 +1298,7 @@
 /***********************************************************************
  *           CheckDlgButton32   (USER32.44)
  */
-BOOL32 CheckDlgButton32( HWND32 hwnd, INT32 id, UINT32 check )
+BOOL32 WINAPI CheckDlgButton32( HWND32 hwnd, INT32 id, UINT32 check )
 {
     SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
     return TRUE;
@@ -1298,7 +1308,7 @@
 /***********************************************************************
  *           IsDlgButtonChecked16   (USER.98)
  */
-UINT16 IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
+UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
 {
     return (UINT16)SendDlgItemMessage32A( hwnd, id, BM_GETCHECK32, 0, 0 );
 }
@@ -1307,7 +1317,7 @@
 /***********************************************************************
  *           IsDlgButtonChecked32   (USER32.343)
  */
-UINT32 IsDlgButtonChecked32( HWND32 hwnd, UINT32 id )
+UINT32 WINAPI IsDlgButtonChecked32( HWND32 hwnd, UINT32 id )
 {
     return (UINT32)SendDlgItemMessage32A( hwnd, id, BM_GETCHECK32, 0, 0 );
 }
@@ -1316,8 +1326,8 @@
 /***********************************************************************
  *           CheckRadioButton16   (USER.96)
  */
-BOOL16 CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID, UINT16 lastID,
-                           UINT16 checkID )
+BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
+                                  UINT16 lastID, UINT16 checkID )
 {
     return CheckRadioButton32( hwndDlg, firstID, lastID, checkID );
 }
@@ -1326,8 +1336,8 @@
 /***********************************************************************
  *           CheckRadioButton32   (USER32.47)
  */
-BOOL32 CheckRadioButton32( HWND32 hwndDlg, UINT32 firstID, UINT32 lastID,
-                           UINT32 checkID )
+BOOL32 WINAPI CheckRadioButton32( HWND32 hwndDlg, UINT32 firstID,
+                                  UINT32 lastID, UINT32 checkID )
 {
     WND *pWnd = WIN_FindWndPtr( hwndDlg );
     if (!pWnd) return FALSE;
@@ -1352,7 +1362,7 @@
 /***********************************************************************
  *           GetDialogBaseUnits   (USER.243) (USER32.232)
  */
-DWORD GetDialogBaseUnits(void)
+DWORD WINAPI GetDialogBaseUnits(void)
 {
     return MAKELONG( xBaseUnit, yBaseUnit );
 }
@@ -1361,7 +1371,7 @@
 /***********************************************************************
  *           MapDialogRect16   (USER.103)
  */
-void MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
+void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
 {
     DIALOGINFO * dlgInfo;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
@@ -1377,7 +1387,7 @@
 /***********************************************************************
  *           MapDialogRect32   (USER32.381)
  */
-void MapDialogRect32( HWND32 hwnd, LPRECT32 rect )
+void WINAPI MapDialogRect32( HWND32 hwnd, LPRECT32 rect )
 {
     DIALOGINFO * dlgInfo;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
@@ -1393,7 +1403,8 @@
 /***********************************************************************
  *           GetNextDlgGroupItem16   (USER.227)
  */
-HWND16 GetNextDlgGroupItem16(HWND16 hwndDlg, HWND16 hwndCtrl, BOOL16 fPrevious)
+HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
+                                     BOOL16 fPrevious )
 {
     return (HWND16)GetNextDlgGroupItem32( hwndDlg, hwndCtrl, fPrevious );
 }
@@ -1402,7 +1413,8 @@
 /***********************************************************************
  *           GetNextDlgGroupItem32   (USER32.274)
  */
-HWND32 GetNextDlgGroupItem32(HWND32 hwndDlg, HWND32 hwndCtrl, BOOL32 fPrevious)
+HWND32 WINAPI GetNextDlgGroupItem32( HWND32 hwndDlg, HWND32 hwndCtrl,
+                                     BOOL32 fPrevious )
 {
     WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
 
@@ -1452,7 +1464,8 @@
 /***********************************************************************
  *           GetNextDlgTabItem16   (USER.228)
  */
-HWND16 GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl, BOOL16 fPrevious )
+HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
+                                   BOOL16 fPrevious )
 {
     return (HWND16)GetNextDlgTabItem32( hwndDlg, hwndCtrl, fPrevious );
 }
@@ -1461,7 +1474,8 @@
 /***********************************************************************
  *           GetNextDlgTabItem32   (USER32.275)
  */
-HWND32 GetNextDlgTabItem32( HWND32 hwndDlg, HWND32 hwndCtrl, BOOL32 fPrevious )
+HWND32 WINAPI GetNextDlgTabItem32( HWND32 hwndDlg, HWND32 hwndCtrl,
+                                   BOOL32 fPrevious )
 {
     WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
 
@@ -1691,7 +1705,7 @@
 /**********************************************************************
  *	    DlgDirSelect    (USER.99)
  */
-BOOL16 DlgDirSelect( HWND16 hwnd, LPSTR str, INT16 id )
+BOOL16 WINAPI DlgDirSelect( HWND16 hwnd, LPSTR str, INT16 id )
 {
     return DlgDirSelectEx16( hwnd, str, 128, id );
 }
@@ -1700,7 +1714,7 @@
 /**********************************************************************
  *	    DlgDirSelectComboBox    (USER.194)
  */
-BOOL16 DlgDirSelectComboBox( HWND16 hwnd, LPSTR str, INT16 id )
+BOOL16 WINAPI DlgDirSelectComboBox( HWND16 hwnd, LPSTR str, INT16 id )
 {
     return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
 }
@@ -1709,7 +1723,7 @@
 /**********************************************************************
  *           DlgDirSelectEx16    (USER.422)
  */
-BOOL16 DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
+BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
 {
     return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
 }
@@ -1718,7 +1732,7 @@
 /**********************************************************************
  *           DlgDirSelectEx32A    (USER32.148)
  */
-BOOL32 DlgDirSelectEx32A( HWND32 hwnd, LPSTR str, INT32 len, INT32 id )
+BOOL32 WINAPI DlgDirSelectEx32A( HWND32 hwnd, LPSTR str, INT32 len, INT32 id )
 {
     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
 }
@@ -1727,7 +1741,7 @@
 /**********************************************************************
  *           DlgDirSelectEx32W    (USER32.149)
  */
-BOOL32 DlgDirSelectEx32W( HWND32 hwnd, LPWSTR str, INT32 len, INT32 id )
+BOOL32 WINAPI DlgDirSelectEx32W( HWND32 hwnd, LPWSTR str, INT32 len, INT32 id )
 {
     return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
 }
@@ -1736,7 +1750,8 @@
 /**********************************************************************
  *           DlgDirSelectComboBoxEx16    (USER.423)
  */
-BOOL16 DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
+BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
+                                        INT16 id )
 {
     return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
 }
@@ -1745,7 +1760,8 @@
 /**********************************************************************
  *           DlgDirSelectComboBoxEx32A    (USER32.146)
  */
-BOOL32 DlgDirSelectComboBoxEx32A( HWND32 hwnd, LPSTR str, INT32 len, INT32 id )
+BOOL32 WINAPI DlgDirSelectComboBoxEx32A( HWND32 hwnd, LPSTR str, INT32 len,
+                                         INT32 id )
 {
     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
 }
@@ -1754,7 +1770,8 @@
 /**********************************************************************
  *           DlgDirSelectComboBoxEx32W    (USER32.147)
  */
-BOOL32 DlgDirSelectComboBoxEx32W( HWND32 hwnd, LPWSTR str, INT32 len, INT32 id)
+BOOL32 WINAPI DlgDirSelectComboBoxEx32W( HWND32 hwnd, LPWSTR str, INT32 len,
+                                         INT32 id)
 {
     return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
 }
@@ -1763,8 +1780,8 @@
 /**********************************************************************
  *	    DlgDirList16    (USER.100)
  */
-INT16 DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox, INT16 idStatic,
-                    UINT16 attrib )
+INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
+                           INT16 idStatic, UINT16 attrib )
 {
     return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
 }
@@ -1773,8 +1790,8 @@
 /**********************************************************************
  *	    DlgDirList32A    (USER32.142)
  */
-INT32 DlgDirList32A( HWND32 hDlg, LPSTR spec, INT32 idLBox, INT32 idStatic,
-                     UINT32 attrib )
+INT32 WINAPI DlgDirList32A( HWND32 hDlg, LPSTR spec, INT32 idLBox,
+                            INT32 idStatic, UINT32 attrib )
 {
     return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
 }
@@ -1783,8 +1800,8 @@
 /**********************************************************************
  *	    DlgDirList32W    (USER32.145)
  */
-INT32 DlgDirList32W( HWND32 hDlg, LPWSTR spec, INT32 idLBox, INT32 idStatic,
-                     UINT32 attrib )
+INT32 WINAPI DlgDirList32W( HWND32 hDlg, LPWSTR spec, INT32 idLBox,
+                            INT32 idStatic, UINT32 attrib )
 {
     return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
 }
@@ -1793,8 +1810,8 @@
 /**********************************************************************
  *	    DlgDirListComboBox16    (USER.195)
  */
-INT16 DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
-                            INT16 idStatic, UINT16 attrib )
+INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
+                                   INT16 idStatic, UINT16 attrib )
 {
     return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
 }
@@ -1803,8 +1820,8 @@
 /**********************************************************************
  *	    DlgDirListComboBox32A    (USER32.143)
  */
-INT32 DlgDirListComboBox32A( HWND32 hDlg, LPSTR spec, INT32 idCBox,
-                             INT32 idStatic, UINT32 attrib )
+INT32 WINAPI DlgDirListComboBox32A( HWND32 hDlg, LPSTR spec, INT32 idCBox,
+                                    INT32 idStatic, UINT32 attrib )
 {
     return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
 }
@@ -1813,8 +1830,8 @@
 /**********************************************************************
  *	    DlgDirListComboBox32W    (USER32.144)
  */
-INT32 DlgDirListComboBox32W( HWND32 hDlg, LPWSTR spec, INT32 idCBox,
-                             INT32 idStatic, UINT32 attrib )
+INT32 WINAPI DlgDirListComboBox32W( HWND32 hDlg, LPWSTR spec, INT32 idCBox,
+                                    INT32 idStatic, UINT32 attrib )
 {
     return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
 }
diff --git a/windows/driver.c b/windows/driver.c
index 942ecc8..2b8df27 100644
--- a/windows/driver.c
+++ b/windows/driver.c
@@ -45,8 +45,8 @@
 /**************************************************************************
  *				SendDriverMessage		[USER.251]
  */
-LRESULT SendDriverMessage(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
-			  LPARAM lParam2)
+LRESULT WINAPI SendDriverMessage(HDRVR16 hDriver, UINT16 msg, LPARAM lParam1,
+                                 LPARAM lParam2)
 {
     LPDRIVERITEM lpdrv;
     LRESULT retval;
@@ -73,7 +73,7 @@
 /**************************************************************************
  *				OpenDriver		        [USER.252]
  */
-HDRVR16 OpenDriver(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
+HDRVR16 WINAPI OpenDriver(LPSTR lpDriverName, LPSTR lpSectionName, LPARAM lParam)
 {
     HDRVR16 hDrvr;
     LPDRIVERITEM lpdrv, lpnewdrv;
@@ -154,7 +154,7 @@
 /**************************************************************************
  *				CloseDriver				[USER.253]
  */
-LRESULT CloseDriver(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
+LRESULT WINAPI CloseDriver(HDRVR16 hDrvr, LPARAM lParam1, LPARAM lParam2)
 {
     LPDRIVERITEM lpdrv;
 
@@ -192,7 +192,7 @@
 /**************************************************************************
  *				GetDriverModuleHandle	[USER.254]
  */
-HMODULE16 GetDriverModuleHandle(HDRVR16 hDrvr)
+HMODULE16 WINAPI GetDriverModuleHandle(HDRVR16 hDrvr)
 {
     LPDRIVERITEM lpdrv;
     HMODULE16 hModule = 0;
@@ -211,8 +211,8 @@
 /**************************************************************************
  *				DefDriverProc			[USER.255]
  */
-LRESULT DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
-		      LPARAM lParam1, LPARAM lParam2)
+LRESULT WINAPI DefDriverProc(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
+                             LPARAM lParam1, LPARAM lParam2)
 {
     switch(wMsg)
     {
@@ -249,7 +249,7 @@
 /**************************************************************************
  *				GetDriverInfo			[USER.256]
  */
-BOOL16 GetDriverInfo(HDRVR16 hDrvr, LPDRIVERINFOSTRUCT16 lpDrvInfo)
+BOOL16 WINAPI GetDriverInfo(HDRVR16 hDrvr, LPDRIVERINFOSTRUCT16 lpDrvInfo)
 {
     LPDRIVERITEM lpdrv;
 
@@ -268,7 +268,7 @@
 /**************************************************************************
  *				GetNextDriver			[USER.257]
  */
-HDRVR16 GetNextDriver(HDRVR16 hDrvr, DWORD dwFlags)
+HDRVR16 WINAPI GetNextDriver(HDRVR16 hDrvr, DWORD dwFlags)
 {
     LPDRIVERITEM lpdrv;
     HDRVR16 hRetDrv = 0;
diff --git a/windows/event.c b/windows/event.c
index dc5c238..541bd46 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -68,6 +68,12 @@
 static Atom dndProtocol = None;
 static Atom dndSelection = None;
 
+/* EVENT_WaitNetEvent() master fd sets */
+
+static fd_set __event_io_set[3];
+static int    __event_max_fd = 0;
+static int    __event_x_connection = 0;
+
 static const char * const event_names[] =
 {
     "", "", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease",
@@ -102,6 +108,38 @@
 
 extern void FOCUS_SetXFocus( HWND32 );
 extern BOOL16 DRAG_QueryUpdate( HWND16, SEGPTR, BOOL32 );
+extern BOOL32 WINSOCK_HandleIO( int* max_fd, int num_pending, fd_set io_set[3] );
+
+/***********************************************************************
+ *           EVENT_Init
+ *
+ * Initialize network IO.
+ */
+BOOL32 EVENT_Init(void)
+{
+    int  i;
+    for( i = 0; i < 3; i++ )
+	FD_ZERO( __event_io_set + i );
+
+    __event_max_fd = __event_x_connection = ConnectionNumber(display);
+    FD_SET( __event_x_connection, &__event_io_set[EVENT_IO_READ] );
+    __event_max_fd++;
+    return TRUE;
+}
+
+/***********************************************************************
+ *          EVENT_AddIO 
+ */
+void EVENT_AddIO( int fd, int io_type )
+{
+    FD_SET( fd, &__event_io_set[io_type] );
+    if( __event_max_fd <= fd ) __event_max_fd = fd + 1;
+}
+
+void EVENT_DeleteIO( int fd, int io_type )
+{
+    FD_CLR( fd, &__event_io_set[io_type] );
+}
 
 /***********************************************************************
  *           EVENT_ProcessEvent
@@ -253,13 +291,13 @@
 }
 
 /***********************************************************************
- *           EVENT_WaitXEvent
+ *           EVENT_WaitNetEvent
  *
- * Wait for an X event, optionally sleeping until one arrives.
+ * Wait for a network event, optionally sleeping until one arrives.
  * Return TRUE if an event is pending, FALSE on timeout or error
  * (for instance lost connection with the server).
  */
-BOOL32 EVENT_WaitXEvent( BOOL32 sleep, BOOL32 peek )
+BOOL32 EVENT_WaitNetEvent( BOOL32 sleep, BOOL32 peek )
 {
     XEvent event;
     LONG maxWait = sleep ? TIMER_GetNextExpiration() : 0;
@@ -270,12 +308,11 @@
 
     if ((maxWait != -1) && !XPending(display))
     {
-        fd_set read_set;
+	int num_pending;
         struct timeval timeout;
-        int fd = ConnectionNumber(display);
-
-        FD_ZERO( &read_set );
-        FD_SET( fd, &read_set );
+	fd_set read_set = __event_io_set[EVENT_IO_READ];
+	fd_set write_set = __event_io_set[EVENT_IO_WRITE];
+	fd_set except_set = __event_io_set[EVENT_IO_EXCEPT];
 
 	timeout.tv_usec = (maxWait % 1000) * 1000;
 	timeout.tv_sec = maxWait / 1000;
@@ -291,8 +328,8 @@
 	}
 	stop_wait_op = STOP_WAIT_X;
 	/* The code up to the next "stop_wait_op = CONT" must be reentrant */
-	if (select( fd+1, &read_set, NULL, NULL, &timeout ) != 1 &&
-	    !XPending(display))
+	num_pending = select( __event_max_fd, &read_set, NULL, NULL, &timeout );
+	if ( num_pending == 0 )
         {
 	    stop_wait_op = CONT;
             TIMER_ExpireTimers();
@@ -300,7 +337,9 @@
 	}
         else stop_wait_op = CONT;
 #else  /* CONFIG_IPC */
-	if (select( fd+1, &read_set, NULL, NULL, &timeout ) != 1)
+	num_pending = select( __event_max_fd, 
+			&read_set, &write_set, &except_set, &timeout );
+	if ( num_pending == 0)
         {
             /* Timeout or error */
             TIMER_ExpireTimers();
@@ -308,9 +347,19 @@
         }
 #endif  /* CONFIG_IPC */
 
+	/*  Winsock asynchronous services */
+
+	if( FD_ISSET( __event_x_connection, &read_set) ) 
+	{
+	    num_pending--;
+	    if( num_pending )
+		WINSOCK_HandleIO( &__event_max_fd, num_pending, __event_io_set );
+	}
+	else /* no X events */
+	    return WINSOCK_HandleIO( &__event_max_fd, num_pending, __event_io_set );
     }
 
-    /* Process the event (and possibly others that occurred in the meantime) */
+    /* Process current X event (and possibly others that occurred in the meantime) */
 
     do
     {
@@ -1050,7 +1099,7 @@
 /**********************************************************************
  *		SetCapture16   (USER.18)
  */
-HWND16 SetCapture16( HWND16 hwnd )
+HWND16 WINAPI SetCapture16( HWND16 hwnd )
 {
     return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
 }
@@ -1059,7 +1108,7 @@
 /**********************************************************************
  *		SetCapture32   (USER32.463)
  */
-HWND32 SetCapture32( HWND32 hwnd )
+HWND32 WINAPI SetCapture32( HWND32 hwnd )
 {
     return EVENT_Capture( hwnd, HTCLIENT );
 }
@@ -1068,7 +1117,7 @@
 /**********************************************************************
  *		ReleaseCapture   (USER.19) (USER32.438)
  */
-void ReleaseCapture(void)
+void WINAPI ReleaseCapture(void)
 {
     dprintf_win(stddeb, "ReleaseCapture() [%04x]\n", captureWnd );
     if( captureWnd ) EVENT_Capture( 0, 0 );
@@ -1078,7 +1127,7 @@
 /**********************************************************************
  *		GetCapture16   (USER.236)
  */
-HWND16 GetCapture16(void)
+HWND16 WINAPI GetCapture16(void)
 {
     return captureWnd;
 }
@@ -1087,7 +1136,7 @@
 /**********************************************************************
  *		GetCapture32   (USER32.207)
  */
-HWND32 GetCapture32(void)
+HWND32 WINAPI GetCapture32(void)
 {
     return captureWnd;
 }
@@ -1096,7 +1145,7 @@
 /***********************************************************************
  *           GetMouseEventProc   (USER.337)
  */
-FARPROC16 GetMouseEventProc(void)
+FARPROC16 WINAPI GetMouseEventProc(void)
 {
     HMODULE16 hmodule = GetModuleHandle16("USER");
     return MODULE_GetEntryPoint( hmodule,
@@ -1107,7 +1156,7 @@
 /***********************************************************************
  *           Mouse_Event   (USER.299)
  */
-void Mouse_Event( CONTEXT *context )
+void WINAPI Mouse_Event( CONTEXT *context )
 {
     /* Register values:
      * AX = mouse event
@@ -1147,7 +1196,7 @@
 /**********************************************************************
  *			EnableHardwareInput   (USER.331)
  */
-BOOL16 EnableHardwareInput(BOOL16 bEnable)
+BOOL16 WINAPI EnableHardwareInput(BOOL16 bEnable)
 {
   BOOL16 bOldState = InputEnabled;
   dprintf_event(stdnimp,"EnableHardwareInput(%d);\n", bEnable);
@@ -1159,7 +1208,7 @@
 /***********************************************************************
  *	     SwapMouseButton16   (USER.186)
  */
-BOOL16 SwapMouseButton16( BOOL16 fSwap )
+BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
 {
     BOOL16 ret = SwappedButtons;
     SwappedButtons = fSwap;
@@ -1170,7 +1219,7 @@
 /***********************************************************************
  *	     SwapMouseButton32   (USER32.536)
  */
-BOOL32 SwapMouseButton32( BOOL32 fSwap )
+BOOL32 WINAPI SwapMouseButton32( BOOL32 fSwap )
 {
     BOOL32 ret = SwappedButtons;
     SwappedButtons = fSwap;
diff --git a/windows/focus.c b/windows/focus.c
index 3c28c8e..28aa847 100644
--- a/windows/focus.c
+++ b/windows/focus.c
@@ -81,7 +81,7 @@
 /*****************************************************************
  *               SetFocus16   (USER.22)
  */
-HWND16 SetFocus16( HWND16 hwnd )
+HWND16 WINAPI SetFocus16( HWND16 hwnd )
 {
     return (HWND16)SetFocus32( hwnd );
 }
@@ -90,7 +90,7 @@
 /*****************************************************************
  *               SetFocus32   (USER32.480)
  */
-HWND32 SetFocus32( HWND32 hwnd )
+HWND32 WINAPI SetFocus32( HWND32 hwnd )
 {
     HWND32 hWndPrevFocus, hwndTop = hwnd;
     WND *wndPtr = WIN_FindWndPtr( hwnd );
@@ -137,7 +137,7 @@
 /*****************************************************************
  *               GetFocus16   (USER.23)
  */
-HWND16 GetFocus16(void)
+HWND16 WINAPI GetFocus16(void)
 {
     return (HWND16)hwndFocus;
 }
@@ -146,7 +146,7 @@
 /*****************************************************************
  *               GetFocus32   (USER32.239)
  */
-HWND32 GetFocus32(void)
+HWND32 WINAPI GetFocus32(void)
 {
     return hwndFocus;
 }
diff --git a/windows/graphics.c b/windows/graphics.c
index a11404b..f924a8f 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -108,8 +108,13 @@
 	    XCopyArea( display, bmp->pixmap, dc->u.x.drawable, 
 		       dc->u.x.gc, xsrc, ysrc, width, height, xdest, ydest );
     }
-    else return FALSE;
+    else 
+    {
+      GDI_HEAP_UNLOCK( hbitmap );
+      return FALSE;
+    }
 
+    GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
 }
 
@@ -234,6 +239,7 @@
 
     XSetClipMask( display, dc->u.x.gc, (bmp) ? bmp->pixmap : None );
 
+    GDI_HEAP_UNLOCK( hMonoBitmap );
     return TRUE;
 }
 
diff --git a/windows/hook.c b/windows/hook.c
index 2b1333d..7166bad 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -1162,7 +1162,7 @@
 /***********************************************************************
  *           SetWindowsHook16   (USER.121)
  */
-FARPROC16 SetWindowsHook16( INT16 id, HOOKPROC16 proc )
+FARPROC16 WINAPI SetWindowsHook16( INT16 id, HOOKPROC16 proc )
 {
     HANDLE16 handle;
     HINSTANCE16 hInst = __winelib ? 0 : FarGetOwner( HIWORD(proc) );
@@ -1186,7 +1186,7 @@
  *
  * FIXME: I don't know if this is correct
  */
-HHOOK SetWindowsHook32A( INT32 id, HOOKPROC32 proc )
+HHOOK WINAPI SetWindowsHook32A( INT32 id, HOOKPROC32 proc )
 {
     HINSTANCE16 hInst = __winelib ? 0 : FarGetOwner( HIWORD(proc) );
 
@@ -1203,7 +1203,7 @@
  *
  * FIXME: I don't know if this is correct
  */
-HHOOK SetWindowsHook32W( INT32 id, HOOKPROC32 proc )
+HHOOK WINAPI SetWindowsHook32W( INT32 id, HOOKPROC32 proc )
 {
     HINSTANCE16 hInst = __winelib ? 0 : FarGetOwner( HIWORD(proc) );
 
@@ -1218,8 +1218,8 @@
 /***********************************************************************
  *           SetWindowsHookEx16   (USER.291)
  */
-HHOOK SetWindowsHookEx16( INT16 id, HOOKPROC16 proc, HINSTANCE16 hInst,
-			  HTASK16 hTask )
+HHOOK WINAPI SetWindowsHookEx16( INT16 id, HOOKPROC16 proc, HINSTANCE16 hInst,
+                                 HTASK16 hTask )
 {
     HANDLE16 handle = HOOK_SetHook( id, proc, HOOK_WIN16, hInst, hTask );
     return (handle) ? (HHOOK)MAKELONG( handle, HOOK_MAGIC ) : (HHOOK)NULL;
@@ -1229,8 +1229,8 @@
 /***********************************************************************
  *           SetWindowsHookEx32A   (USER32.525)
  */
-HHOOK SetWindowsHookEx32A( INT32 id, HOOKPROC32 proc, HINSTANCE32 hInst,
-			   DWORD dwThreadID )
+HHOOK WINAPI SetWindowsHookEx32A( INT32 id, HOOKPROC32 proc, HINSTANCE32 hInst,
+                                  DWORD dwThreadID )
 {
     HANDLE16 handle;
     HTASK16 hTask;
@@ -1248,8 +1248,8 @@
 /***********************************************************************
  *           SetWindowsHookEx32W   (USER32.526)
  */
-HHOOK SetWindowsHookEx32W( INT32 id, HOOKPROC32 proc, HINSTANCE32 hInst,
-			   DWORD dwThreadID )
+HHOOK WINAPI SetWindowsHookEx32W( INT32 id, HOOKPROC32 proc, HINSTANCE32 hInst,
+                                  DWORD dwThreadID )
 {
     HANDLE16 handle;
     HTASK16 hTask;
@@ -1267,7 +1267,7 @@
 /***********************************************************************
  *           UnhookWindowsHook16   (USER.234)
  */
-BOOL16 UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
+BOOL16 WINAPI UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
 {
     HANDLE16 hook = HOOK_GetHook( id , GetTaskQueue(0) );
 
@@ -1287,7 +1287,7 @@
 /***********************************************************************
  *           UnhookWindowsHook32   (USER32.556)
  */
-BOOL32 UnhookWindowsHook32( INT32 id, HOOKPROC32 proc )
+BOOL32 WINAPI UnhookWindowsHook32( INT32 id, HOOKPROC32 proc )
 {
     HANDLE16 hook = HOOK_GetHook( id , GetTaskQueue(0) );
 
@@ -1307,7 +1307,7 @@
 /***********************************************************************
  *           UnhookWindowHookEx16   (USER.292)
  */
-BOOL16 UnhookWindowsHookEx16( HHOOK hhook )
+BOOL16 WINAPI UnhookWindowsHookEx16( HHOOK hhook )
 {
     if (HIWORD(hhook) != HOOK_MAGIC) return FALSE;  /* Not a new format hook */
     return HOOK_RemoveHook( LOWORD(hhook) );
@@ -1317,7 +1317,7 @@
 /***********************************************************************
  *           UnhookWindowHookEx32   (USER32.557)
  */
-BOOL32 UnhookWindowsHookEx32( HHOOK hhook )
+BOOL32 WINAPI UnhookWindowsHookEx32( HHOOK hhook )
 {
     return UnhookWindowsHookEx16( hhook );
 }
@@ -1329,8 +1329,8 @@
  * I wouldn't have separated this into 16 and 32 bit versions, but I
  * need a way to figure out if I need to do a mapping or not.
  */
-LRESULT CallNextHookEx16( HHOOK hhook, INT16 code, WPARAM16 wParam,
-			  LPARAM lParam )
+LRESULT WINAPI CallNextHookEx16( HHOOK hhook, INT16 code, WPARAM16 wParam,
+                                 LPARAM lParam )
 {
     HANDLE16 next;
 
@@ -1346,8 +1346,8 @@
  *
  * There aren't ANSI and UNICODE versions of this.
  */
-LRESULT CallNextHookEx32( HHOOK hhook, INT32 code, WPARAM32 wParam,
-			  LPARAM lParam )
+LRESULT WINAPI CallNextHookEx32( HHOOK hhook, INT32 code, WPARAM32 wParam,
+                                 LPARAM lParam )
 {
     HANDLE16 next;
     INT32 fromtype;	/* figure out Ansi/Unicode */
@@ -1369,8 +1369,8 @@
 /***********************************************************************
  *           DefHookProc16   (USER.235)
  */
-LRESULT DefHookProc16( INT16 code, WPARAM16 wParam, LPARAM lParam,
-		       HHOOK *hhook )
+LRESULT WINAPI DefHookProc16( INT16 code, WPARAM16 wParam, LPARAM lParam,
+                              HHOOK *hhook )
 {
     /* Note: the *hhook parameter is never used, since we rely on the
      * current hook value from the task queue to find the next hook. */
@@ -1384,7 +1384,7 @@
 /***********************************************************************
  *           CallMsgFilter16   (USER.123)
  */
-BOOL16 CallMsgFilter16( SEGPTR msg, INT16 code )
+BOOL16 WINAPI CallMsgFilter16( SEGPTR msg, INT16 code )
 {
     if (GetSysModalWindow16()) return FALSE;
     if (HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0, (LPARAM)msg )) return TRUE;
@@ -1399,7 +1399,7 @@
  * FIXME: There are ANSI and UNICODE versions of this, plus an unspecified
  * version, plus USER (the 16bit one) has a CallMsgFilter32 function.
  */
-BOOL32 CallMsgFilter32A( LPMSG32 msg, INT32 code )
+BOOL32 WINAPI CallMsgFilter32A( LPMSG32 msg, INT32 code )
 {
     if (GetSysModalWindow16()) return FALSE;	/* ??? */
     if (HOOK_CallHooks32A( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
@@ -1411,10 +1411,11 @@
 /***********************************************************************
  *           CallMsgFilter32W   (USER32.15)
  */
-BOOL32 CallMsgFilter32W( LPMSG32 msg, INT32 code )
+BOOL32 WINAPI CallMsgFilter32W( LPMSG32 msg, INT32 code )
 {
     if (GetSysModalWindow16()) return FALSE;	/* ??? */
     if (HOOK_CallHooks32W( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
       return TRUE;
     return HOOK_CallHooks32W( WH_MSGFILTER, code, 0, (LPARAM)msg );
 }
+
diff --git a/windows/keyboard.c b/windows/keyboard.c
index c1965ca..be31d59 100644
--- a/windows/keyboard.c
+++ b/windows/keyboard.c
@@ -108,7 +108,7 @@
 /*
  * Table for vkey to scancode translation - 5/29/97 chrisf@america.com 
  */
-static BYTE vkey2scode[512] = {
+static const BYTE vkey2scode[512] = {
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x0e,0x0f,0x00,0x00,0x00,0x1c,0x00,0x00,
   0x2a,0x1d,0x38,0x00,0x3a,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
   0x39,0x49,0x51,0x4f,0x47,0x4b,0x48,0x4d, 0x50,0x00,0x00,0x00,0x00,0x52,0x53,0x00,
@@ -482,7 +482,7 @@
 /**********************************************************************
  *		GetKeyState			[USER.106]
  */
-WORD GetKeyState16(INT16 vkey)
+WORD WINAPI GetKeyState16(INT16 vkey)
 {
     return GetKeyState32(vkey);
 }
@@ -493,7 +493,7 @@
  * keyboard-input message.  This function retrieves the state of the key
  * at the time the input message was generated.  (SDK 3.1 Vol 2. p 390)
  */
-WORD GetKeyState32(INT32 vkey)
+WORD WINAPI GetKeyState32(INT32 vkey)
 {
     INT32 retval;
 
@@ -524,7 +524,7 @@
  * keyboard-input message.  This function retrieves the state of the keyboard
  * at the time the input message was generated.  (SDK 3.1 Vol 2. p 387)
  */
-VOID GetKeyboardState(LPBYTE lpKeyState)
+VOID WINAPI GetKeyboardState(LPBYTE lpKeyState)
 {
     dprintf_key(stddeb, "GetKeyboardState()\n");
     if (lpKeyState != NULL) {
@@ -538,7 +538,7 @@
 /**********************************************************************
  *      SetKeyboardState            [USER.223][USER32.483]
  */
-VOID SetKeyboardState(LPBYTE lpKeyState)
+VOID WINAPI SetKeyboardState(LPBYTE lpKeyState)
 {
     dprintf_key(stddeb, "SetKeyboardState()\n");
     if (lpKeyState != NULL) {
@@ -562,7 +562,7 @@
  * mouse or key had been depressed since the last call to 
  * GetAsyncKeyState.
  */
-WORD GetAsyncKeyState32(INT32 nKey)
+WORD WINAPI GetAsyncKeyState32(INT32 nKey)
 {
     short retval;	
 
@@ -595,7 +595,7 @@
 /**********************************************************************
  *            GetAsyncKeyState        (USER.249)
  */
-WORD GetAsyncKeyState16(INT16 nKey)
+WORD WINAPI GetAsyncKeyState16(INT16 nKey)
 {
     return GetAsyncKeyState32(nKey);
 }
@@ -607,7 +607,7 @@
  *
  * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP  -messages
  */
-INT32 TranslateAccelerator32(HWND32 hWnd, HACCEL32 hAccel, LPMSG32 msg)
+INT32 WINAPI TranslateAccelerator32(HWND32 hWnd, HACCEL32 hAccel, LPMSG32 msg)
 {
     MSG16	msg16;
 
@@ -615,7 +615,7 @@
     return TranslateAccelerator16(hWnd,hAccel,&msg16);
 }
 	
-INT16 TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
+INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
 {
     ACCELHEADER	*lpAccelTbl;
     int 	i;
@@ -755,7 +755,7 @@
 /******************************************************************************
  *    	OemKeyScan			[KEYBOARD.128][USER32.400]
  */
-DWORD OemKeyScan(WORD wOemChar)
+DWORD WINAPI OemKeyScan(WORD wOemChar)
 {
     dprintf_keyboard(stddeb,"*OemKeyScan (%d)\n",wOemChar);
 
@@ -780,7 +780,7 @@
  * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
  */
 
-WORD VkKeyScan32A(CHAR cChar)
+WORD WINAPI VkKeyScan32A(CHAR cChar)
 {
 	KeyCode keycode;
 	KeySym keysym;    	
@@ -827,7 +827,7 @@
 /******************************************************************************
  *    	VkKeyScan			[KEYBOARD.129]
  */
-WORD VkKeyScan16(CHAR cChar)
+WORD WINAPI VkKeyScan16(CHAR cChar)
 {
 	return VkKeyScan32A(cChar);
 }
@@ -835,7 +835,7 @@
 /******************************************************************************
  *    	VkKeyScanW			[USER32.575]
  */
-WORD VkKeyScan32W(WCHAR cChar)
+WORD WINAPI VkKeyScan32W(WCHAR cChar)
 {
 	return VkKeyScan32A((CHAR)cChar); /* FIXME: check unicode */
 }
@@ -843,7 +843,7 @@
 /******************************************************************************
  *    	GetKeyboardType			[KEYBOARD.130]
  */
-INT16 GetKeyboardType16(INT16 nTypeFlag)
+INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
 {
   return GetKeyboardType32(nTypeFlag);
 }
@@ -851,7 +851,7 @@
 /******************************************************************************
  *    	GetKeyboardType			[USER32.254]
  */
-INT32 GetKeyboardType32(INT32 nTypeFlag)
+INT32 WINAPI GetKeyboardType32(INT32 nTypeFlag)
 {
   dprintf_keyboard(stddeb,"GetKeyboardType(%d)\n",nTypeFlag);
   switch(nTypeFlag)
@@ -875,22 +875,24 @@
 /******************************************************************************
  *    	MapVirtualKeyA			[USER32.382]
  */
-UINT32 MapVirtualKey32A(UINT32 code, UINT32 maptype) {
-	return MapVirtualKey16(code,maptype);
+UINT32 WINAPI MapVirtualKey32A(UINT32 code, UINT32 maptype)
+{
+    return MapVirtualKey16(code,maptype);
 }
 
 /******************************************************************************
  *    	MapVirtualKeyA			[USER32.384]
  */
-UINT32 MapVirtualKey32W(UINT32 code, UINT32 maptype) {
-	return MapVirtualKey16(code,maptype);
+UINT32 WINAPI MapVirtualKey32W(UINT32 code, UINT32 maptype)
+{
+    return MapVirtualKey16(code,maptype);
 }
 
 /******************************************************************************
  *    	MapVirtualKeyA			[KEYBOARD.131]
  * MapVirtualKey translates keycodes from one format to another
  */
-UINT16 MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
+UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
 {
 #define returnMVK(value) { dprintf_keyboard(stddeb,"returning 0x%x.\n",value); return value; }
 
@@ -936,7 +938,7 @@
 /****************************************************************************
  *	GetKBCodePage16   (KEYBOARD.132)
  */
-INT16 GetKBCodePage16(void)
+INT16 WINAPI GetKBCodePage16(void)
 {
     dprintf_keyboard(stddeb,"GetKBCodePage()\n");
     return 850;
@@ -946,7 +948,7 @@
 /****************************************************************************
  *	GetKBCodePage32   (USER32.245)
  */
-UINT32 GetKBCodePage32(void)
+UINT32 WINAPI GetKBCodePage32(void)
 {
     dprintf_keyboard(stddeb,"GetKbCodePage()\n");
     return 850;
@@ -956,7 +958,7 @@
 /****************************************************************************
  *	GetKeyNameText32W   (USER32.247)
  */
-INT32 GetKeyNameText32W(LONG lParam, LPWSTR lpBuffer, INT32 nSize)
+INT32 WINAPI GetKeyNameText32W(LONG lParam, LPWSTR lpBuffer, INT32 nSize)
 {
 	LPSTR buf = xmalloc(nSize);
 	int	res = GetKeyNameText32A(lParam,buf,nSize);
@@ -969,7 +971,7 @@
 /****************************************************************************
  *	GetKeyNameText32A   (USER32.246)
  */
-INT32 GetKeyNameText32A(LONG lParam, LPSTR lpBuffer, INT32 nSize)
+INT32 WINAPI GetKeyNameText32A(LONG lParam, LPSTR lpBuffer, INT32 nSize)
 {
 	return GetKeyNameText16(lParam,lpBuffer,nSize);
 }
@@ -977,7 +979,7 @@
 /****************************************************************************
  *	GetKeyNameText16   (KEYBOARD.133)
  */
-INT16 GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
+INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
 {
   /*	int i; */
 	
@@ -1002,8 +1004,8 @@
 /****************************************************************************
  *	ToAscii   (KEYBOARD.4)
  */
-INT16 ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState, 
-	LPVOID lpChar, UINT16 flags) 
+INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState, 
+                       LPVOID lpChar, UINT16 flags) 
 {
     return ToAscii32(virtKey,scanCode,lpKeyState,lpChar,flags);
 }
@@ -1011,10 +1013,9 @@
 /****************************************************************************
  *	ToAscii   (USER32.545)
  */
-INT32 ToAscii32(
-	UINT32 virtKey,UINT32 scanCode,LPBYTE lpKeyState,
-	LPWORD lpChar,UINT32 flags
-) {
+INT32 WINAPI ToAscii32( UINT32 virtKey,UINT32 scanCode,LPBYTE lpKeyState,
+                        LPWORD lpChar,UINT32 flags )
+{
     XKeyEvent e;
     KeySym keysym;
     static XComposeStatus cs;
@@ -1178,3 +1179,14 @@
 		ret, *(char*)lpChar);
     return ret;
 }
+
+
+/***********************************************************************
+ *           GetKeyboardLayout			(USER32.249)
+ */
+/*HKL*/ HANDLE32 WINAPI GetKeyboardLayout(DWORD dwLayout)
+{
+	fprintf(stderr,"GetKeyboardLayout(%ld),STUB!\n",dwLayout);
+	return 0;
+}
+
diff --git a/windows/mdi.c b/windows/mdi.c
index 39c673e..fe881b9 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -615,23 +615,29 @@
  HDC32 		hDCSrc  = CreateCompatibleDC32(0);
  HDC32		hDCDest	= CreateCompatibleDC32(hDCSrc);
  HBITMAP16	hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
- HBITMAP16	hbCopy,hb_src,hb_dest;
+ HBITMAP16	hbCopy;
+ HANDLE16	hobjSrc, hobjDest;
 
- hb_src = SelectObject32(hDCSrc,hbClose);
+ hobjSrc = SelectObject32(hDCSrc, hbClose);
  hbCopy = CreateCompatibleBitmap32(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
- hb_dest = SelectObject32(hDCDest,hbCopy);
+ hobjDest = SelectObject32(hDCDest, hbCopy);
 
  BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
           hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
- 
- SelectObject32(hDCSrc,hb_src);
- SelectObject32(hDCDest,hb_dest);
-
+  
+ SelectObject32(hDCSrc, hobjSrc);
  DeleteObject32(hbClose);
-
- DeleteDC32(hDCDest);
  DeleteDC32(hDCSrc);
 
+ hobjSrc = SelectObject32( hDCDest, GetStockObject32(BLACK_PEN) );
+
+ MoveToEx32( hDCDest, SYSMETRICS_CXSIZE - 1, 0, NULL );
+ LineTo32( hDCDest, SYSMETRICS_CXSIZE - 1, SYSMETRICS_CYSIZE - 1);
+
+ SelectObject32(hDCDest, hobjSrc );
+ SelectObject32(hDCDest, hobjDest);
+ DeleteDC32(hDCDest);
+
  return hbCopy;
 }
 
@@ -897,7 +903,8 @@
  *
  * This function is the handler for all MDI requests.
  */
-LRESULT MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam,
+                                LPARAM lParam)
 {
     LPCREATESTRUCT16     cs;
     MDICLIENTINFO       *ci;
@@ -1090,8 +1097,8 @@
 /***********************************************************************
  *           DefFrameProc16   (USER.445)
  */
-LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message, 
-                        WPARAM16 wParam, LPARAM lParam )
+LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
+                               UINT16 message, WPARAM16 wParam, LPARAM lParam )
 {
     HWND16	         childHwnd;
     MDICLIENTINFO*       ci;
@@ -1188,8 +1195,8 @@
 /***********************************************************************
  *           DefFrameProc32A   (USER32.121)
  */
-LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message, 
-                         WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient,
+                                UINT32 message, WPARAM32 wParam, LPARAM lParam)
 {
     if (hwndMDIClient)
     {
@@ -1228,8 +1235,8 @@
 /***********************************************************************
  *           DefFrameProc32W   (USER32.122)
  */
-LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message, 
-                         WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient,
+                                UINT32 message, WPARAM32 wParam, LPARAM lParam)
 {
     if (hwndMDIClient)
     {
@@ -1265,8 +1272,8 @@
 /***********************************************************************
  *           DefMDIChildProc16   (USER.447)
  */
-LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
-                           WPARAM16 wParam, LPARAM lParam )
+LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
+                                  WPARAM16 wParam, LPARAM lParam )
 {
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
@@ -1411,8 +1418,8 @@
 /***********************************************************************
  *           DefMDIChildProc32A   (USER32.123)
  */
-LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
-                            WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
+                                   WPARAM32 wParam, LPARAM lParam )
 {
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
@@ -1463,8 +1470,8 @@
 /***********************************************************************
  *           DefMDIChildProc32W   (USER32.124)
  */
-LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
-                            WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
+                                   WPARAM32 wParam, LPARAM lParam )
 {
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
@@ -1509,7 +1516,7 @@
 /**********************************************************************
  *             TranslateMDISysAccel32   (USER32.554)
  */
-BOOL32 TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
+BOOL32 WINAPI TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
 {
     MSG16 msg16;
  
@@ -1522,7 +1529,7 @@
 /**********************************************************************
  *             TranslateMDISysAccel16   (USER.451)
  */
-BOOL16 TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
+BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
 {
     WND* clientWnd = WIN_FindWndPtr( hwndClient);
 
@@ -1570,7 +1577,7 @@
 /***********************************************************************
  *           CalcChildScroll   (USER.462)
  */
-void CalcChildScroll( HWND16 hwnd, WORD scroll )
+void WINAPI CalcChildScroll( HWND16 hwnd, WORD scroll )
 {
     RECT32 childRect, clientRect;
     INT32  vmin, vmax, hmin, hmax, vpos, hpos;
@@ -1620,7 +1627,7 @@
 /***********************************************************************
  *           ScrollChildren16   (USER.463)
  */
-void ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
+void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
 {
     return ScrollChildren32( hWnd, uMsg, wParam, lParam );
 }
@@ -1629,7 +1636,8 @@
 /***********************************************************************
  *           ScrollChildren32   (USER32.447)
  */
-void ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
+void WINAPI ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
+                             LPARAM lParam)
 {
     WND	*wndPtr = WIN_FindWndPtr(hWnd);
     INT32 newPos = -1;
@@ -1694,8 +1702,10 @@
  SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
 
  if( uMsg == WM_VSCROLL )
-     ScrollWindow32(hWnd ,0 ,curPos - newPos, NULL, NULL);
+     ScrollWindowEx32(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL, 
+			SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
  else
-     ScrollWindow32(hWnd ,curPos - newPos, 0, NULL, NULL);
+     ScrollWindowEx32(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
+			SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
 }
 
diff --git a/windows/message.c b/windows/message.c
index 6bd4f4d..6d4aa84 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -419,7 +419,7 @@
 
     /* If the queue is empty, attempt to fill it */
     if (!sysMsgQueue->msgCount && XPending(display))
-        EVENT_WaitXEvent( FALSE, FALSE );
+        EVENT_WaitNetEvent( FALSE, FALSE );
 
     for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
     {
@@ -515,7 +515,7 @@
 /**********************************************************************
  *           SetDoubleClickTime16   (USER.20)
  */
-void SetDoubleClickTime16( UINT16 interval )
+void WINAPI SetDoubleClickTime16( UINT16 interval )
 {
     SetDoubleClickTime32( interval );
 }		
@@ -524,7 +524,7 @@
 /**********************************************************************
  *           SetDoubleClickTime32   (USER32.479)
  */
-BOOL32 SetDoubleClickTime32( UINT32 interval )
+BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
 {
     doubleClickSpeed = interval ? interval : 500;
     return TRUE;
@@ -534,7 +534,7 @@
 /**********************************************************************
  *           GetDoubleClickTime16   (USER.21)
  */
-UINT16 GetDoubleClickTime16(void)
+UINT16 WINAPI GetDoubleClickTime16(void)
 {
     return doubleClickSpeed;
 }		
@@ -543,7 +543,7 @@
 /**********************************************************************
  *           GetDoubleClickTime32   (USER32.238)
  */
-UINT32 GetDoubleClickTime32(void)
+UINT32 WINAPI GetDoubleClickTime32(void)
 {
     return doubleClickSpeed;
 }		
@@ -632,7 +632,7 @@
 /***********************************************************************
  *           ReplyMessage16   (USER.115)
  */
-void ReplyMessage16( LRESULT result )
+void WINAPI ReplyMessage16( LRESULT result )
 {
     MESSAGEQUEUE *senderQ;
     MESSAGEQUEUE *queue;
@@ -892,8 +892,8 @@
 /***********************************************************************
  *           PeekMessage16   (USER.109)
  */
-BOOL16 PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
-                      UINT16 last, UINT16 flags )
+BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
+                             UINT16 last, UINT16 flags )
 {
     return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
 }
@@ -902,7 +902,7 @@
 /***********************************************************************
  *           GetMessage16   (USER.108)
  */
-BOOL16 GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last ) 
+BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
 {
     MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
     MSG_PeekMessage( lpmsg,
@@ -918,8 +918,8 @@
 /***********************************************************************
  *           PostMessage16   (USER.110)
  */
-BOOL16 PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
-                      LPARAM lParam )
+BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
+                             LPARAM lParam )
 {
     MSG16 	msg;
     WND 	*wndPtr;
@@ -963,8 +963,8 @@
 /***********************************************************************
  *           PostMessage32A   (USER32.418)
  */
-BOOL32 PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
-                       LPARAM lParam )
+BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                              LPARAM lParam )
 {
     /* FIXME */
     return PostMessage16( hwnd, message, wParam, lParam );
@@ -974,8 +974,8 @@
 /***********************************************************************
  *           PostMessage32W   (USER32.419)
  */
-BOOL32 PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
-                       LPARAM lParam )
+BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
+                              LPARAM lParam )
 {
     /* FIXME */
     return PostMessage16( hwnd, message, wParam, lParam );
@@ -985,8 +985,8 @@
 /***********************************************************************
  *           PostAppMessage16   (USER.116)
  */
-BOOL16 PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
-                         LPARAM lParam )
+BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
+                                LPARAM lParam )
 {
     MSG16 msg;
 
@@ -1006,7 +1006,8 @@
 /***********************************************************************
  *           SendMessage16   (USER.111)
  */
-LRESULT SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam)
+LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
+                              LPARAM lParam)
 {
     WND * wndPtr;
     WND **list, **ppWnd;
@@ -1103,7 +1104,8 @@
 /***********************************************************************
  *           SendMessage32A   (USER32.453)
  */
-LRESULT SendMessage32A(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
+                               LPARAM lParam )
 {
     WND * wndPtr;
     WND **list, **ppWnd;
@@ -1153,7 +1155,8 @@
 /***********************************************************************
  *           SendMessage32W   (USER32.458)
  */
-LRESULT SendMessage32W(HWND32 hwnd, UINT32 msg, WPARAM32 wParam, LPARAM lParam)
+LRESULT WINAPI SendMessage32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
+                               LPARAM lParam )
 {
     WND * wndPtr;
     WND **list, **ppWnd;
@@ -1202,7 +1205,7 @@
 /***********************************************************************
  *           WaitMessage    (USER.112) (USER32.577)
  */
-void WaitMessage( void )
+void WINAPI WaitMessage( void )
 {
     QUEUE_WaitBits( QS_ALLINPUT );
 }
@@ -1402,7 +1405,7 @@
 /***********************************************************************
  *           TranslateMessage16   (USER.113)
  */
-BOOL16 TranslateMessage16( const MSG16 *msg )
+BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
 {
     return MSG_DoTranslateMessage( msg->message, msg->hwnd,
                                    msg->wParam, msg->lParam );
@@ -1412,7 +1415,7 @@
 /***********************************************************************
  *           TranslateMessage32   (USER32.555)
  */
-BOOL32 TranslateMessage32( const MSG32 *msg )
+BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
 {
     return MSG_DoTranslateMessage( msg->message, msg->hwnd,
                                    msg->wParam, msg->lParam );
@@ -1422,7 +1425,7 @@
 /***********************************************************************
  *           DispatchMessage16   (USER.114)
  */
-LONG DispatchMessage16( const MSG16* msg )
+LONG WINAPI DispatchMessage16( const MSG16* msg )
 {
     WND * wndPtr;
     LONG retval;
@@ -1467,7 +1470,7 @@
 /***********************************************************************
  *           DispatchMessage32A   (USER32.140)
  */
-LONG DispatchMessage32A( const MSG32* msg )
+LONG WINAPI DispatchMessage32A( const MSG32* msg )
 {
     WND * wndPtr;
     LONG retval;
@@ -1514,7 +1517,7 @@
 /***********************************************************************
  *           DispatchMessage32W   (USER32.141)
  */
-LONG DispatchMessage32W( const MSG32* msg )
+LONG WINAPI DispatchMessage32W( const MSG32* msg )
 {
     WND * wndPtr;
     LONG retval;
@@ -1561,7 +1564,7 @@
 /***********************************************************************
  *           RegisterWindowMessage16   (USER.118)
  */
-WORD RegisterWindowMessage16( SEGPTR str )
+WORD WINAPI RegisterWindowMessage16( SEGPTR str )
 {
     dprintf_msg(stddeb, "RegisterWindowMessage16: %08lx\n", (DWORD)str );
     return GlobalAddAtom16( str );
@@ -1571,7 +1574,7 @@
 /***********************************************************************
  *           RegisterWindowMessage32A   (USER32.436)
  */
-WORD RegisterWindowMessage32A( LPCSTR str )
+WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
 {
     dprintf_msg(stddeb, "RegisterWindowMessage32A: %s\n", str );
     return GlobalAddAtom32A( str );
@@ -1581,7 +1584,7 @@
 /***********************************************************************
  *           RegisterWindowMessage32W   (USER32.437)
  */
-WORD RegisterWindowMessage32W( LPCWSTR str )
+WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
 {
     dprintf_msg(stddeb, "RegisterWindowMessage32W: %p\n", str );
     return GlobalAddAtom32W( str );
@@ -1591,7 +1594,7 @@
 /***********************************************************************
  *           GetTickCount   (USER.13) (KERNEL32.299)
  */
-DWORD GetTickCount(void)
+DWORD WINAPI GetTickCount(void)
 {
     struct timeval t;
     gettimeofday( &t, NULL );
@@ -1604,7 +1607,7 @@
  *
  * (effectively identical to GetTickCount)
  */
-DWORD GetCurrentTime16(void)
+DWORD WINAPI GetCurrentTime16(void)
 {
     return GetTickCount();
 }
@@ -1613,7 +1616,7 @@
 /***********************************************************************
  *           InSendMessage16    (USER.192)
  */
-BOOL16 InSendMessage16(void)
+BOOL16 WINAPI InSendMessage16(void)
 {
     return InSendMessage32();
 }
@@ -1622,7 +1625,7 @@
 /***********************************************************************
  *           InSendMessage32    (USER32.319)
  */
-BOOL32 InSendMessage32(void)
+BOOL32 WINAPI InSendMessage32(void)
 {
     MESSAGEQUEUE *queue;
 
diff --git a/windows/msgbox.c b/windows/msgbox.c
index 27a9793..a2cb5be 100644
--- a/windows/msgbox.c
+++ b/windows/msgbox.c
@@ -26,8 +26,8 @@
  *
  * Dialog procedure for message boxes.
  */
-static LRESULT MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
-                               WPARAM32 wParam, LPARAM lParam )
+static LRESULT CALLBACK MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
+                                        WPARAM32 wParam, LPARAM lParam )
 {
   LPMSGBOX lpmb;
   RECT32 rect, textrect;
@@ -184,7 +184,7 @@
 /**************************************************************************
  *           MessageBox16   (USER.1)
  */
-INT16 MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type )
+INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
 {
     return MessageBox32A( hwnd, text, title, type );
 }
@@ -193,7 +193,7 @@
 /**************************************************************************
  *           MessageBox32A   (USER32.390)
  */
-INT32 MessageBox32A( HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type )
+INT32 WINAPI MessageBox32A(HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type)
 {
     MSGBOX mbox;
 
@@ -211,7 +211,8 @@
 /**************************************************************************
  *           MessageBox32W   (USER32.395)
  */
-INT32 MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title, UINT32 type )
+INT32 WINAPI MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title,
+                            UINT32 type )
 {
     LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
     LPSTR textA  = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
@@ -225,8 +226,9 @@
 /**************************************************************************
  *           MessageBoxEx32A   (USER32.391)
  */
-INT32
-MessageBoxEx32A(HWND32 hWnd,LPCSTR text,LPCSTR title,UINT32 type,WORD langid) {
+INT32 WINAPI MessageBoxEx32A( HWND32 hWnd, LPCSTR text, LPCSTR title,
+                              UINT32 type, WORD langid )
+{
     /* ignore language id for now */
     return MessageBox32A(hWnd,text,title,type);
 }
@@ -234,8 +236,8 @@
 /**************************************************************************
  *           MessageBoxEx32W   (USER32.392)
  */
-INT32
-MessageBoxEx32W(HWND32 hWnd,LPCWSTR text,LPCWSTR title,UINT32 type,WORD langid)
+INT32 WINAPI MessageBoxEx32W( HWND32 hWnd, LPCWSTR text, LPCWSTR title,
+                              UINT32 type, WORD langid )
 {
     /* ignore language id for now */
     return MessageBox32W(hWnd,text,title,type);
@@ -245,7 +247,7 @@
 /**************************************************************************
  *           FatalAppExit16   (KERNEL.137)
  */
-void FatalAppExit16( UINT16 action, LPCSTR str )
+void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
 {
     FatalAppExit32A( action, str );
 }
@@ -254,7 +256,7 @@
 /**************************************************************************
  *           FatalAppExit32A   (KERNEL32.108)
  */
-void FatalAppExit32A( UINT32 action, LPCSTR str )
+void WINAPI FatalAppExit32A( UINT32 action, LPCSTR str )
 {
     MessageBox32A( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
     TASK_KillCurrentTask(0);
@@ -264,7 +266,7 @@
 /**************************************************************************
  *           FatalAppExit32W   (KERNEL32.109)
  */
-void FatalAppExit32W( UINT32 action, LPCWSTR str )
+void WINAPI FatalAppExit32W( UINT32 action, LPCWSTR str )
 {
     MessageBox32W( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
     TASK_KillCurrentTask(0);
diff --git a/windows/nonclient.c b/windows/nonclient.c
index b1ef586..03f6091 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -164,7 +164,7 @@
 /***********************************************************************
  *           AdjustWindowRect16    (USER.102)
  */
-BOOL16 AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
+BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
 {
     return AdjustWindowRectEx16( rect, style, menu, 0 );
 }
@@ -173,7 +173,7 @@
 /***********************************************************************
  *           AdjustWindowRect32    (USER32.)
  */
-BOOL32 AdjustWindowRect32( LPRECT32 rect, DWORD style, BOOL32 menu )
+BOOL32 WINAPI AdjustWindowRect32( LPRECT32 rect, DWORD style, BOOL32 menu )
 {
     return AdjustWindowRectEx32( rect, style, menu, 0 );
 }
@@ -182,8 +182,8 @@
 /***********************************************************************
  *           AdjustWindowRectEx16    (USER.454)
  */
-BOOL16 AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
-                             BOOL16 menu, DWORD exStyle )
+BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
+                                    BOOL16 menu, DWORD exStyle )
 {
       /* Correct the window style */
 
@@ -209,8 +209,8 @@
 /***********************************************************************
  *           AdjustWindowRectEx32    (USER32.)
  */
-BOOL32 AdjustWindowRectEx32( LPRECT32 rect, DWORD style,
-                             BOOL32 menu, DWORD exStyle )
+BOOL32 WINAPI AdjustWindowRectEx32( LPRECT32 rect, DWORD style,
+                                    BOOL32 menu, DWORD exStyle )
 {
     RECT16 rect16;
     BOOL32 ret;
diff --git a/windows/painting.c b/windows/painting.c
index 48f0d51..77a3748 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -92,7 +92,7 @@
 /***********************************************************************
  *           BeginPaint16    (USER.39)
  */
-HDC16 BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps ) 
+HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps ) 
 {
     BOOL32 bIcon;
     HRGN32 hrgnUpdate;
@@ -156,7 +156,7 @@
 /***********************************************************************
  *           BeginPaint32    (USER32.9)
  */
-HDC32 BeginPaint32( HWND32 hwnd, PAINTSTRUCT32 *lps )
+HDC32 WINAPI BeginPaint32( HWND32 hwnd, PAINTSTRUCT32 *lps )
 {
     PAINTSTRUCT16 ps;
 
@@ -176,7 +176,7 @@
 /***********************************************************************
  *           EndPaint16    (USER.40)
  */
-BOOL16 EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
+BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
 {
     ReleaseDC16( hwnd, lps->hdc );
     ShowCaret32( hwnd );
@@ -187,7 +187,7 @@
 /***********************************************************************
  *           EndPaint32    (USER32.175)
  */
-BOOL32 EndPaint32( HWND32 hwnd, const PAINTSTRUCT32 *lps )
+BOOL32 WINAPI EndPaint32( HWND32 hwnd, const PAINTSTRUCT32 *lps )
 {
     ReleaseDC32( hwnd, lps->hdc );
     ShowCaret32( hwnd );
@@ -198,7 +198,7 @@
 /***********************************************************************
  *           FillWindow    (USER.324)
  */
-void FillWindow( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
+void WINAPI FillWindow( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
 {
     RECT16 rect;
     GetClientRect16( hwnd, &rect );
@@ -210,8 +210,8 @@
 /***********************************************************************
  *           PaintRect    (USER.325)
  */
-void PaintRect( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
-                HBRUSH16 hbrush, const RECT16 *rect)
+void WINAPI PaintRect( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
+                       HBRUSH16 hbrush, const RECT16 *rect)
 {
       /* Send WM_CTLCOLOR message if needed */
 
@@ -229,7 +229,7 @@
 /***********************************************************************
  *           GetControlBrush    (USER.326)
  */
-HBRUSH16 GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 control )
+HBRUSH16 WINAPI GetControlBrush( HWND16 hwnd, HDC16 hdc, UINT16 control )
 {
     return (HBRUSH16)SendMessage32A( GetParent32(hwnd), WM_CTLCOLOR+control,
                                      (WPARAM32)hdc, (LPARAM)hwnd );
@@ -462,8 +462,8 @@
 /***********************************************************************
  *           RedrawWindow32    (USER32.425)
  */
-BOOL32 RedrawWindow32( HWND32 hwnd, const RECT32 *rectUpdate,
-                       HRGN32 hrgnUpdate, UINT32 flags )
+BOOL32 WINAPI RedrawWindow32( HWND32 hwnd, const RECT32 *rectUpdate,
+                              HRGN32 hrgnUpdate, UINT32 flags )
 {
     return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
 }
@@ -472,8 +472,8 @@
 /***********************************************************************
  *           RedrawWindow16    (USER.290)
  */
-BOOL16 RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
-                       HRGN16 hrgnUpdate, UINT16 flags )
+BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
+                              HRGN16 hrgnUpdate, UINT16 flags )
 {
     if (rectUpdate)
     {
@@ -489,7 +489,7 @@
 /***********************************************************************
  *           UpdateWindow16   (USER.124)
  */
-void UpdateWindow16( HWND16 hwnd )
+void WINAPI UpdateWindow16( HWND16 hwnd )
 {
     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
 }
@@ -497,7 +497,7 @@
 /***********************************************************************
  *           UpdateWindow32   (USER32.566)
  */
-void UpdateWindow32( HWND32 hwnd )
+void WINAPI UpdateWindow32( HWND32 hwnd )
 {
     PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
 }
@@ -505,7 +505,7 @@
 /***********************************************************************
  *           InvalidateRgn16   (USER.126)
  */
-void InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
+void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
 {
     PAINT_RedrawWindow((HWND32)hwnd, NULL, (HRGN32)hrgn, 
 		       RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
@@ -515,7 +515,7 @@
 /***********************************************************************
  *           InvalidateRgn32   (USER32.328)
  */
-void InvalidateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
+void WINAPI InvalidateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
 {
     PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
 }
@@ -524,7 +524,7 @@
 /***********************************************************************
  *           InvalidateRect16   (USER.125)
  */
-void InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
+void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
 {
     RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
 }
@@ -533,7 +533,7 @@
 /***********************************************************************
  *           InvalidateRect32   (USER32.327)
  */
-void InvalidateRect32( HWND32 hwnd, const RECT32 *rect, BOOL32 erase )
+void WINAPI InvalidateRect32( HWND32 hwnd, const RECT32 *rect, BOOL32 erase )
 {
     PAINT_RedrawWindow( hwnd, rect, 0, 
 			RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
@@ -543,7 +543,7 @@
 /***********************************************************************
  *           ValidateRgn16   (USER.128)
  */
-void ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
+void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
 {
     PAINT_RedrawWindow( (HWND32)hwnd, NULL, (HRGN32)hrgn, 
 			RDW_VALIDATE | RDW_NOCHILDREN, 0 );
@@ -553,7 +553,7 @@
 /***********************************************************************
  *           ValidateRgn32   (USER32.571)
  */
-void ValidateRgn32( HWND32 hwnd, HRGN32 hrgn )
+void WINAPI ValidateRgn32( HWND32 hwnd, HRGN32 hrgn )
 {
     PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
 }
@@ -562,7 +562,7 @@
 /***********************************************************************
  *           ValidateRect16   (USER.127)
  */
-void ValidateRect16( HWND16 hwnd, const RECT16 *rect )
+void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
 {
     RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
 }
@@ -571,7 +571,7 @@
 /***********************************************************************
  *           ValidateRect32   (USER32.570)
  */
-void ValidateRect32( HWND32 hwnd, const RECT32 *rect )
+void WINAPI ValidateRect32( HWND32 hwnd, const RECT32 *rect )
 {
     PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
 }
@@ -580,7 +580,7 @@
 /***********************************************************************
  *           GetUpdateRect16   (USER.190)
  */
-BOOL16 GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
+BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
 {
     RECT32 r;
     BOOL16 ret;
@@ -595,7 +595,7 @@
 /***********************************************************************
  *           GetUpdateRect32   (USER32.296)
  */
-BOOL32 GetUpdateRect32( HWND32 hwnd, LPRECT32 rect, BOOL32 erase )
+BOOL32 WINAPI GetUpdateRect32( HWND32 hwnd, LPRECT32 rect, BOOL32 erase )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr) return FALSE;
@@ -618,7 +618,7 @@
 /***********************************************************************
  *           GetUpdateRgn16   (USER.237)
  */
-INT16 GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
+INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
 {
     return GetUpdateRgn32( hwnd, hrgn, erase );
 }
@@ -627,7 +627,7 @@
 /***********************************************************************
  *           GetUpdateRgn32   (USER32.297)
  */
-INT32 GetUpdateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
+INT32 WINAPI GetUpdateRgn32( HWND32 hwnd, HRGN32 hrgn, BOOL32 erase )
 {
     INT32 retval;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
@@ -647,7 +647,7 @@
 /***********************************************************************
  *           ExcludeUpdateRgn16   (USER.238)
  */
-INT16 ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
+INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
 {
     return ExcludeUpdateRgn32( hdc, hwnd );
 }
@@ -656,7 +656,7 @@
 /***********************************************************************
  *           ExcludeUpdateRgn32   (USER32.194)
  */
-INT32 ExcludeUpdateRgn32( HDC32 hdc, HWND32 hwnd )
+INT32 WINAPI ExcludeUpdateRgn32( HDC32 hdc, HWND32 hwnd )
 {
     RECT32 rect;
     WND * wndPtr;
diff --git a/windows/property.c b/windows/property.c
index ab6daf4..09eebed 100644
--- a/windows/property.c
+++ b/windows/property.c
@@ -47,7 +47,7 @@
 /***********************************************************************
  *           GetProp16   (USER.25)
  */
-HANDLE16 GetProp16( HWND16 hwnd, LPCSTR str )
+HANDLE16 WINAPI GetProp16( HWND16 hwnd, LPCSTR str )
 {
     return (HANDLE16)GetProp32A( hwnd, str );
 }
@@ -56,7 +56,7 @@
 /***********************************************************************
  *           GetProp32A   (USER32.280)
  */
-HANDLE32 GetProp32A( HWND32 hwnd, LPCSTR str )
+HANDLE32 WINAPI GetProp32A( HWND32 hwnd, LPCSTR str )
 {
     PROPERTY *prop = PROP_FindProp( hwnd, str );
 
@@ -74,7 +74,7 @@
 /***********************************************************************
  *           GetProp32W   (USER32.281)
  */
-HANDLE32 GetProp32W( HWND32 hwnd, LPCWSTR str )
+HANDLE32 WINAPI GetProp32W( HWND32 hwnd, LPCWSTR str )
 {
     LPSTR strA;
     HANDLE32 ret;
@@ -90,7 +90,7 @@
 /***********************************************************************
  *           SetProp16   (USER.26)
  */
-BOOL16 SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
+BOOL16 WINAPI SetProp16( HWND16 hwnd, LPCSTR str, HANDLE16 handle )
 {
     return (BOOL16)SetProp32A( hwnd, str, handle );
 }
@@ -99,7 +99,7 @@
 /***********************************************************************
  *           SetProp32A   (USER32.496)
  */
-BOOL32 SetProp32A( HWND32 hwnd, LPCSTR str, HANDLE32 handle )
+BOOL32 WINAPI SetProp32A( HWND32 hwnd, LPCSTR str, HANDLE32 handle )
 {
     PROPERTY *prop;
 
@@ -131,7 +131,7 @@
 /***********************************************************************
  *           SetProp32W   (USER32.497)
  */
-BOOL32 SetProp32W( HWND32 hwnd, LPCWSTR str, HANDLE32 handle )
+BOOL32 WINAPI SetProp32W( HWND32 hwnd, LPCWSTR str, HANDLE32 handle )
 {
     BOOL32 ret;
     LPSTR strA;
@@ -148,7 +148,7 @@
 /***********************************************************************
  *           RemoveProp16   (USER.24)
  */
-HANDLE16 RemoveProp16( HWND16 hwnd, LPCSTR str )
+HANDLE16 WINAPI RemoveProp16( HWND16 hwnd, LPCSTR str )
 {
     return (HANDLE16)RemoveProp32A( hwnd, str );
 }
@@ -157,7 +157,7 @@
 /***********************************************************************
  *           RemoveProp32A   (USER32.441)
  */
-HANDLE32 RemoveProp32A( HWND32 hwnd, LPCSTR str )
+HANDLE32 WINAPI RemoveProp32A( HWND32 hwnd, LPCSTR str )
 {
     HANDLE32 handle;
     PROPERTY **pprop, *prop;
@@ -195,7 +195,7 @@
 /***********************************************************************
  *           RemoveProp32W   (USER32.442)
  */
-HANDLE32 RemoveProp32W( HWND32 hwnd, LPCWSTR str )
+HANDLE32 WINAPI RemoveProp32W( HWND32 hwnd, LPCWSTR str )
 {
     LPSTR strA;
     HANDLE32 ret;
@@ -231,7 +231,7 @@
 /***********************************************************************
  *           EnumProps16   (USER.27)
  */
-INT16 EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
+INT16 WINAPI EnumProps16( HWND16 hwnd, PROPENUMPROC16 func )
 {
     PROPERTY *prop, *next;
     WND *pWnd;
@@ -257,7 +257,7 @@
 /***********************************************************************
  *           EnumProps32A   (USER32.185)
  */
-INT32 EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
+INT32 WINAPI EnumProps32A( HWND32 hwnd, PROPENUMPROC32A func )
 {
     return EnumPropsEx32A( hwnd, (PROPENUMPROCEX32A)func, 0 );
 }
@@ -266,7 +266,7 @@
 /***********************************************************************
  *           EnumProps32W   (USER32.188)
  */
-INT32 EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
+INT32 WINAPI EnumProps32W( HWND32 hwnd, PROPENUMPROC32W func )
 {
     return EnumPropsEx32W( hwnd, (PROPENUMPROCEX32W)func, 0 );
 }
@@ -275,7 +275,7 @@
 /***********************************************************************
  *           EnumPropsEx32A   (USER32.186)
  */
-INT32 EnumPropsEx32A( HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam )
+INT32 WINAPI EnumPropsEx32A(HWND32 hwnd, PROPENUMPROCEX32A func, LPARAM lParam)
 {
     PROPERTY *prop, *next;
     WND *pWnd;
@@ -302,7 +302,7 @@
 /***********************************************************************
  *           EnumPropsEx32W   (USER32.187)
  */
-INT32 EnumPropsEx32W( HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam )
+INT32 WINAPI EnumPropsEx32W(HWND32 hwnd, PROPENUMPROCEX32W func, LPARAM lParam)
 {
     PROPERTY *prop, *next;
     WND *pWnd;
diff --git a/windows/queue.c b/windows/queue.c
index 4872a35..a0f50c4 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -668,7 +668,7 @@
 /***********************************************************************
  *           PostQuitMessage16   (USER.6)
  */
-void PostQuitMessage16( INT16 exitCode )
+void WINAPI PostQuitMessage16( INT16 exitCode )
 {
     PostQuitMessage32( exitCode );
 }
@@ -677,7 +677,7 @@
 /***********************************************************************
  *           PostQuitMessage32   (USER32.420)
  */
-void PostQuitMessage32( INT32 exitCode )
+void WINAPI PostQuitMessage32( INT32 exitCode )
 {
     MESSAGEQUEUE *queue;
 
@@ -690,7 +690,7 @@
 /***********************************************************************
  *           GetWindowTask16   (USER.224)
  */
-HTASK16 GetWindowTask16( HWND16 hwnd )
+HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
 
@@ -701,7 +701,7 @@
 /***********************************************************************
  *           GetWindowThreadProcessId   (USER32.312)
  */
-DWORD GetWindowThreadProcessId( HWND32 hwnd, LPDWORD process )
+DWORD WINAPI GetWindowThreadProcessId( HWND32 hwnd, LPDWORD process )
 {
     HTASK16 htask;
     TDB	*tdb;
@@ -725,7 +725,7 @@
 /***********************************************************************
  *           SetMessageQueue16   (USER.266)
  */
-BOOL16 SetMessageQueue16( INT16 size )
+BOOL16 WINAPI SetMessageQueue16( INT16 size )
 {
     return SetMessageQueue32( size );
 }
@@ -734,7 +734,7 @@
 /***********************************************************************
  *           SetMessageQueue32   (USER32.493)
  */
-BOOL32 SetMessageQueue32( INT32 size )
+BOOL32 WINAPI SetMessageQueue32( INT32 size )
 {
     HQUEUE16 hQueue, hNewQueue;
     MESSAGEQUEUE *queuePtr;
@@ -781,7 +781,7 @@
 /***********************************************************************
  *           GetQueueStatus16   (USER.334)
  */
-DWORD GetQueueStatus16( UINT16 flags )
+DWORD WINAPI GetQueueStatus16( UINT16 flags )
 {
     MESSAGEQUEUE *queue;
     DWORD ret;
@@ -796,7 +796,7 @@
 /***********************************************************************
  *           GetInputState16   (USER.335)
  */
-BOOL16 GetInputState16(void)
+BOOL16 WINAPI GetInputState16(void)
 {
     return GetInputState32();
 }
@@ -805,7 +805,7 @@
 /***********************************************************************
  *           GetInputState32   (USER32.243)
  */
-BOOL32 GetInputState32(void)
+BOOL32 WINAPI GetInputState32(void)
 {
     MESSAGEQUEUE *queue;
 
@@ -818,7 +818,7 @@
 /***********************************************************************
  *           GetMessagePos   (USER.119) (USER32.271)
  */
-DWORD GetMessagePos(void)
+DWORD WINAPI GetMessagePos(void)
 {
     MESSAGEQUEUE *queue;
 
@@ -830,7 +830,7 @@
 /***********************************************************************
  *           GetMessageTime   (USER.120) (USER32.272)
  */
-LONG GetMessageTime(void)
+LONG WINAPI GetMessageTime(void)
 {
     MESSAGEQUEUE *queue;
 
@@ -842,7 +842,7 @@
 /***********************************************************************
  *           GetMessageExtraInfo   (USER.288) (USER32.270)
  */
-LONG GetMessageExtraInfo(void)
+LONG WINAPI GetMessageExtraInfo(void)
 {
     MESSAGEQUEUE *queue;
 
diff --git a/windows/rect.c b/windows/rect.c
index 61d76c2..7605666 100644
--- a/windows/rect.c
+++ b/windows/rect.c
@@ -11,7 +11,8 @@
 /***********************************************************************
  *           SetRect16    (USER.72)
  */
-void SetRect16(LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom)
+void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
+                       INT16 right, INT16 bottom )
 {
     rect->left   = left;
     rect->right  = right;
@@ -23,7 +24,8 @@
 /***********************************************************************
  *           SetRect32    (USER32.498)
  */
-void SetRect32(LPRECT32 rect, INT32 left, INT32 top, INT32 right, INT32 bottom)
+void WINAPI SetRect32( LPRECT32 rect, INT32 left, INT32 top,
+                       INT32 right, INT32 bottom )
 {
     rect->left   = left;
     rect->right  = right;
@@ -35,7 +37,7 @@
 /***********************************************************************
  *           SetRectEmpty16    (USER.73)
  */
-void SetRectEmpty16( LPRECT16 rect )
+void WINAPI SetRectEmpty16( LPRECT16 rect )
 {
     rect->left = rect->right = rect->top = rect->bottom = 0;
 }
@@ -44,7 +46,7 @@
 /***********************************************************************
  *           SetRectEmpty32    (USER32.499)
  */
-void SetRectEmpty32( LPRECT32 rect )
+void WINAPI SetRectEmpty32( LPRECT32 rect )
 {
     rect->left = rect->right = rect->top = rect->bottom = 0;
 }
@@ -53,7 +55,7 @@
 /***********************************************************************
  *           CopyRect16    (USER.74)
  */
-BOOL16 CopyRect16( RECT16 *dest, const RECT16 *src )
+BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
 {
     *dest = *src;
     return TRUE;
@@ -63,7 +65,7 @@
 /***********************************************************************
  *           CopyRect32    (USER32.61)
  */
-BOOL32 CopyRect32( RECT32 *dest, const RECT32 *src )
+BOOL32 WINAPI CopyRect32( RECT32 *dest, const RECT32 *src )
 {
     *dest = *src;
     return TRUE;
@@ -73,7 +75,7 @@
 /***********************************************************************
  *           IsRectEmpty16    (USER.75)
  */
-BOOL16 IsRectEmpty16( const RECT16 *rect )
+BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
 {
     return ((rect->left == rect->right) || (rect->top == rect->bottom));
 }
@@ -82,7 +84,7 @@
 /***********************************************************************
  *           IsRectEmpty32    (USER32.346)
  */
-BOOL32 IsRectEmpty32( const RECT32 *rect )
+BOOL32 WINAPI IsRectEmpty32( const RECT32 *rect )
 {
     return ((rect->left == rect->right) || (rect->top == rect->bottom));
 }
@@ -91,7 +93,7 @@
 /***********************************************************************
  *           PtInRect16    (USER.76)
  */
-BOOL16 PtInRect16( const RECT16 *rect, POINT16 pt )
+BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
 {
     return ((pt.x >= rect->left) && (pt.x < rect->right) &&
 	    (pt.y >= rect->top) && (pt.y < rect->bottom));
@@ -101,7 +103,7 @@
 /***********************************************************************
  *           PtInRect32    (USER32.423)
  */
-BOOL32 PtInRect32( const RECT32 *rect, POINT32 pt )
+BOOL32 WINAPI PtInRect32( const RECT32 *rect, POINT32 pt )
 {
     return ((pt.x >= rect->left) && (pt.x < rect->right) &&
 	    (pt.y >= rect->top) && (pt.y < rect->bottom));
@@ -111,7 +113,7 @@
 /***********************************************************************
  *           OffsetRect16    (USER.77)
  */
-void OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
+void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
 {
     rect->left   += x;
     rect->right  += x;
@@ -123,7 +125,7 @@
 /***********************************************************************
  *           OffsetRect32    (USER32.405)
  */
-void OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
+void WINAPI OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
 {
     rect->left   += x;
     rect->right  += x;
@@ -135,7 +137,7 @@
 /***********************************************************************
  *           InflateRect16    (USER.78)
  */
-void InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
+void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
 {
     rect->left   -= x;
     rect->top 	 -= y;
@@ -147,7 +149,7 @@
 /***********************************************************************
  *           InflateRect32    (USER32.320)
  */
-void InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
+void WINAPI InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
 {
     rect->left   -= x;
     rect->top 	 -= y;
@@ -159,7 +161,8 @@
 /***********************************************************************
  *           IntersectRect16    (USER.79)
  */
-BOOL16 IntersectRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
+BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
+                               const RECT16 *src2 )
 {
     if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
 	(src1->left >= src2->right) || (src2->left >= src1->right) ||
@@ -179,7 +182,8 @@
 /***********************************************************************
  *           IntersectRect32    (USER32.326)
  */
-BOOL32 IntersectRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
+BOOL32 WINAPI IntersectRect32( LPRECT32 dest, const RECT32 *src1,
+                               const RECT32 *src2 )
 {
     if (IsRectEmpty32(src1) || IsRectEmpty32(src2) ||
 	(src1->left >= src2->right) || (src2->left >= src1->right) ||
@@ -199,7 +203,8 @@
 /***********************************************************************
  *           UnionRect16    (USER.80)
  */
-BOOL16 UnionRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
+BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
+                           const RECT16 *src2 )
 {
     if (IsRectEmpty16(src1))
     {
@@ -228,7 +233,8 @@
 /***********************************************************************
  *           UnionRect32    (USER32.558)
  */
-BOOL32 UnionRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
+BOOL32 WINAPI UnionRect32( LPRECT32 dest, const RECT32 *src1,
+                           const RECT32 *src2 )
 {
     if (IsRectEmpty32(src1))
     {
@@ -257,7 +263,7 @@
 /***********************************************************************
  *           EqualRect16    (USER.244)
  */
-BOOL16 EqualRect16( const RECT16* rect1, const RECT16* rect2 )
+BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
 {
     return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
 	    (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
@@ -267,7 +273,7 @@
 /***********************************************************************
  *           EqualRect32    (USER32.193)
  */
-BOOL32 EqualRect32( const RECT32* rect1, const RECT32* rect2 )
+BOOL32 WINAPI EqualRect32( const RECT32* rect1, const RECT32* rect2 )
 {
     return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
 	    (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
@@ -277,7 +283,8 @@
 /***********************************************************************
  *           SubtractRect16    (USER.373)
  */
-BOOL16 SubtractRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
+BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
+                              const RECT16 *src2 )
 {
     RECT16 tmp;
 
@@ -312,7 +319,8 @@
 /***********************************************************************
  *           SubtractRect32    (USER32.535)
  */
-BOOL32 SubtractRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
+BOOL32 WINAPI SubtractRect32( LPRECT32 dest, const RECT32 *src1,
+                              const RECT32 *src2 )
 {
     RECT32 tmp;
 
diff --git a/windows/scroll.c b/windows/scroll.c
index 85371bf..fdc9f4a 100644
--- a/windows/scroll.c
+++ b/windows/scroll.c
@@ -26,8 +26,8 @@
 /*************************************************************************
  *             ScrollWindow16   (USER.61)
  */
-void ScrollWindow16( HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
-                     const RECT16 *clipRect )
+void WINAPI ScrollWindow16(HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
+                           const RECT16 *clipRect )
 {
     RECT32 rect32, clipRect32;
 
@@ -39,9 +39,11 @@
 
 /*************************************************************************
  *             ScrollWindow32   (USER32.449)
+ *
+ * FIXME: verify clipping region calculations
  */
-BOOL32 ScrollWindow32( HWND32 hwnd, INT32 dx, INT32 dy, const RECT32 *rect,
-                       const RECT32 *clipRect )
+BOOL32 WINAPI ScrollWindow32( HWND32 hwnd, INT32 dx, INT32 dy,
+                              const RECT32 *rect, const RECT32 *clipRect )
 {
     HDC32  	hdc;
     HRGN32 	hrgnUpdate,hrgnClip;
@@ -122,8 +124,9 @@
 /*************************************************************************
  *             ScrollDC16   (USER.221)
  */
-BOOL16 ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
-                   const RECT16 *cliprc, HRGN16 hrgnUpdate, LPRECT16 rcUpdate )
+BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
+                          const RECT16 *cliprc, HRGN16 hrgnUpdate,
+                          LPRECT16 rcUpdate )
 {
     RECT32 rect32, clipRect32, rcUpdate32;
     BOOL16 ret;
@@ -143,8 +146,9 @@
  * Both 'rc' and 'rLClip' are in logical units but update info is 
  * returned in device coordinates.
  */
-BOOL32 ScrollDC32( HDC32 hdc, INT32 dx, INT32 dy, const RECT32 *rc,
-                   const RECT32 *prLClip, HRGN32 hrgnUpdate, LPRECT32 rcUpdate )
+BOOL32 WINAPI ScrollDC32( HDC32 hdc, INT32 dx, INT32 dy, const RECT32 *rc,
+                          const RECT32 *prLClip, HRGN32 hrgnUpdate,
+                          LPRECT32 rcUpdate )
 {
     RECT32 rDClip, rLClip;
     HRGN32 hrgnClip = 0;
@@ -294,9 +298,10 @@
 /*************************************************************************
  *             ScrollWindowEx16   (USER.319)
  */
-INT16 ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy, const RECT16 *rect,
-                        const RECT16 *clipRect, HRGN16 hrgnUpdate,
-                        LPRECT16 rcUpdate, UINT16 flags )
+INT16 WINAPI ScrollWindowEx16( HWND16 hwnd, INT16 dx, INT16 dy,
+                               const RECT16 *rect, const RECT16 *clipRect,
+                               HRGN16 hrgnUpdate, LPRECT16 rcUpdate,
+                               UINT16 flags )
 {
     RECT32 rect32, clipRect32, rcUpdate32;
     BOOL16 ret;
@@ -313,7 +318,7 @@
 /*************************************************************************
  *             SCROLL_FixCaret
  */
-BOOL32 SCROLL_FixCaret(HWND32 hWnd, LPRECT32 lprc, UINT32 flags)
+static BOOL32 SCROLL_FixCaret(HWND32 hWnd, LPRECT32 lprc, UINT32 flags)
 {
    HWND32 hCaret = CARET_GetHwnd();
 
@@ -341,10 +346,13 @@
 
 /*************************************************************************
  *             ScrollWindowEx32   (USER32.450)
+ *
+ * NOTE: Use this function instead of ScrollWindow32
  */
-INT32 ScrollWindowEx32( HWND32 hwnd, INT32 dx, INT32 dy, const RECT32 *rect,
-                        const RECT32 *clipRect, HRGN32 hrgnUpdate,
-                        LPRECT32 rcUpdate, UINT32 flags )
+INT32 WINAPI ScrollWindowEx32( HWND32 hwnd, INT32 dx, INT32 dy,
+                               const RECT32 *rect, const RECT32 *clipRect,
+                               HRGN32 hrgnUpdate, LPRECT32 rcUpdate,
+                               UINT32 flags )
 {
     INT32  retVal = NULLREGION;
     BOOL32 bCaret = FALSE, bOwnRgn = TRUE;
@@ -390,12 +398,14 @@
 	    if( dy > 0 ) dst.y = (src.y = dc->w.DCOrgY + cliprc.top) + dy;
 	    else src.y = (dst.y = dc->w.DCOrgY + cliprc.top) - dy;
 
-	    if( bUpdate )
-  		XSetGraphicsExposures( display, dc->u.x.gc, True );
+	    if( bUpdate ) /* handles non-Wine windows hanging over the scrolled area */
+		XSetGraphicsExposures( display, dc->u.x.gc, True );
+
 	    XSetFunction( display, dc->u.x.gc, GXcopy );
 	    XCopyArea( display, dc->u.x.drawable, dc->u.x.drawable, dc->u.x.gc, 
 		       src.x, src.y, cliprc.right - cliprc.left - abs(dx),
 		       cliprc.bottom - cliprc.top - abs(dy), dst.x, dst.y );
+
 	    if( bUpdate )
 		XSetGraphicsExposures( display, dc->u.x.gc, False );
 
@@ -434,7 +444,7 @@
 	    for( w = wnd->child; w; w = w->next )
 	    {
 		 CONV_RECT16TO32( &w->rectWindow, &r );
-	         if( IntersectRect32(&r, &r, &cliprc) )
+	         if( !clipRect || IntersectRect32(&r, &r, &cliprc) )
 		     SetWindowPos32(w->hwndSelf, 0, w->rectWindow.left + dx,
 				    w->rectWindow.top  + dy, 0,0, SWP_NOZORDER |
 				    SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW |
@@ -443,8 +453,8 @@
 	}
 
 	if( flags & (SW_INVALIDATE | SW_ERASE) )
-            PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
-					((flags & SW_ERASE) ? RDW_ERASENOW : 0), 0 );
+	    PAINT_RedrawWindow( hwnd, NULL, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE |
+		((flags & SW_ERASE) ? RDW_ERASENOW : 0) | ((flags & SW_SCROLLCHILDREN) ? RDW_ALLCHILDREN : 0 ), 0 );
 
 	if( bCaret )
 	{
diff --git a/windows/syscolor.c b/windows/syscolor.c
index 14d06ea..9f86835 100644
--- a/windows/syscolor.c
+++ b/windows/syscolor.c
@@ -175,7 +175,7 @@
 /*************************************************************************
  *             GetSysColor16   (USER.180)
  */
-COLORREF GetSysColor16( INT16 nIndex )
+COLORREF WINAPI GetSysColor16( INT16 nIndex )
 {
     return SysColors[nIndex];
 }
@@ -184,7 +184,7 @@
 /*************************************************************************
  *             GetSysColor32   (USER32.288)
  */
-COLORREF GetSysColor32( INT32 nIndex )
+COLORREF WINAPI GetSysColor32( INT32 nIndex )
 {
     return SysColors[nIndex];
 }
@@ -193,8 +193,8 @@
 /*************************************************************************
  *             SetSysColors16   (USER.181)
  */
-VOID SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
-                     const COLORREF *lpColorValues )
+VOID WINAPI SetSysColors16( INT16 nChanges, const INT16 *lpSysColor,
+                            const COLORREF *lpColorValues )
 {
     int i;
 
@@ -217,8 +217,8 @@
 /*************************************************************************
  *             SetSysColors32   (USER32.504)
  */
-BOOL32 SetSysColors32( INT32 nChanges, const INT32 *lpSysColor,
-                       const COLORREF *lpColorValues )
+BOOL32 WINAPI SetSysColors32( INT32 nChanges, const INT32 *lpSysColor,
+                              const COLORREF *lpColorValues )
 {
     int i;
 
diff --git a/windows/sysmetrics.c b/windows/sysmetrics.c
index 525088e..58fd85d 100644
--- a/windows/sysmetrics.c
+++ b/windows/sysmetrics.c
@@ -136,7 +136,7 @@
 /***********************************************************************
  *           GetSystemMetrics16    (USER.179)
  */
-INT16 GetSystemMetrics16( INT16 index )
+INT16 WINAPI GetSystemMetrics16( INT16 index )
 {
     if ((index < 0) || (index > SM_CMETRICS)) return 0;
     else return sysMetrics[index];    
@@ -146,7 +146,7 @@
 /***********************************************************************
  *           GetSystemMetrics32    (USER32.291)
  */
-INT32 GetSystemMetrics32( INT32 index )
+INT32 WINAPI GetSystemMetrics32( INT32 index )
 {
     if ((index < 0) || (index > SM_CMETRICS)) return 0;
     else return sysMetrics[index];    
diff --git a/windows/timer.c b/windows/timer.c
index b08e892..a28a375 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -301,7 +301,8 @@
 /***********************************************************************
  *           SetTimer16   (USER.10)
  */
-UINT16 SetTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout, TIMERPROC16 proc )
+UINT16 WINAPI SetTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout,
+                          TIMERPROC16 proc )
 {
     dprintf_timer( stddeb, "SetTimer16: %04x %d %d %08lx\n",
                    hwnd, id, timeout, (LONG)proc );
@@ -313,7 +314,8 @@
 /***********************************************************************
  *           SetTimer32   (USER32.510)
  */
-UINT32 SetTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout, TIMERPROC32 proc )
+UINT32 WINAPI SetTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout,
+                          TIMERPROC32 proc )
 {
     dprintf_timer( stddeb, "SetTimer32: %04x %d %d %08lx\n",
                    hwnd, id, timeout, (LONG)proc );
@@ -325,8 +327,8 @@
 /***********************************************************************
  *           SetSystemTimer16   (USER.11)
  */
-UINT16 SetSystemTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout,
-                         TIMERPROC16 proc )
+UINT16 WINAPI SetSystemTimer16( HWND16 hwnd, UINT16 id, UINT16 timeout,
+                                TIMERPROC16 proc )
 {
     dprintf_timer( stddeb, "SetSystemTimer16: %04x %d %d %08lx\n", 
                    hwnd, id, timeout, (LONG)proc );
@@ -338,8 +340,8 @@
 /***********************************************************************
  *           SetSystemTimer32   (USER32.508)
  */
-UINT32 SetSystemTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout,
-                         TIMERPROC32 proc )
+UINT32 WINAPI SetSystemTimer32( HWND32 hwnd, UINT32 id, UINT32 timeout,
+                                TIMERPROC32 proc )
 {
     dprintf_timer( stddeb, "SetSystemTimer32: %04x %d %d %08lx\n", 
                    hwnd, id, timeout, (LONG)proc );
@@ -351,7 +353,7 @@
 /***********************************************************************
  *           KillTimer16   (USER.12)
  */
-BOOL16 KillTimer16( HWND16 hwnd, UINT16 id )
+BOOL16 WINAPI KillTimer16( HWND16 hwnd, UINT16 id )
 {
     dprintf_timer(stddeb, "KillTimer16: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, FALSE );
@@ -361,7 +363,7 @@
 /***********************************************************************
  *           KillTimer32   (USER32.353)
  */
-BOOL32 KillTimer32( HWND32 hwnd, UINT32 id )
+BOOL32 WINAPI KillTimer32( HWND32 hwnd, UINT32 id )
 {
     dprintf_timer(stddeb, "KillTimer32: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, FALSE );
@@ -371,7 +373,7 @@
 /***********************************************************************
  *           KillSystemTimer16   (USER.182)
  */
-BOOL16 KillSystemTimer16( HWND16 hwnd, UINT16 id )
+BOOL16 WINAPI KillSystemTimer16( HWND16 hwnd, UINT16 id )
 {
     dprintf_timer( stddeb, "KillSystemTimer16: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, TRUE );
@@ -381,7 +383,7 @@
 /***********************************************************************
  *           KillSystemTimer32   (USER32.352)
  */
-BOOL32 KillSystemTimer32( HWND32 hwnd, UINT32 id )
+BOOL32 WINAPI KillSystemTimer32( HWND32 hwnd, UINT32 id )
 {
     dprintf_timer( stddeb, "KillSystemTimer32: %04x %d\n", hwnd, id );
     return TIMER_KillTimer( hwnd, id, TRUE );
diff --git a/windows/user.c b/windows/user.c
index 44edddf..8c7c9a5 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -28,7 +28,7 @@
 /***********************************************************************
  *           GetFreeSystemResources   (USER.284)
  */
-WORD GetFreeSystemResources( WORD resType )
+WORD WINAPI GetFreeSystemResources( WORD resType )
 {
     int userPercent, gdiPercent;
 
@@ -63,7 +63,7 @@
 /***********************************************************************
  *           SystemHeapInfo   (TOOLHELP.71)
  */
-BOOL16 SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
+BOOL16 WINAPI SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
 {
     pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
     pHeapInfo->wGDIFreePercent  = GetFreeSystemResources( GFSR_GDIRESOURCES );
@@ -76,7 +76,7 @@
 /***********************************************************************
  *           TimerCount   (TOOLHELP.80)
  */
-BOOL16 TimerCount( TIMERINFO *pTimerInfo )
+BOOL16 WINAPI TimerCount( TIMERINFO *pTimerInfo )
 {
     /* FIXME
      * In standard mode, dwmsSinceStart = dwmsThisVM 
@@ -97,7 +97,7 @@
 /**********************************************************************
  *           InitApp   (USER.5)
  */
-INT16 InitApp( HINSTANCE16 hInstance )
+INT16 WINAPI InitApp( HINSTANCE16 hInstance )
 {
     int queueSize;
 
@@ -162,7 +162,7 @@
 /***********************************************************************
  *           ExitWindows16   (USER.7)
  */
-BOOL16 ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
+BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
 {
     return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
 }
@@ -171,7 +171,7 @@
 /***********************************************************************
  *           ExitWindowsExec16   (USER.246)
  */
-BOOL16 ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
+BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
 {
 fprintf(stdnimp, "ExitWindowsExec() : Should run the following in DOS-mode :\n\t\"%s %s\"\n",
 	lpszExe, lpszParams);
@@ -182,7 +182,7 @@
 /***********************************************************************
  *           ExitWindowsEx   (USER32.195)
  */
-BOOL32 ExitWindowsEx( UINT32 flags, DWORD reserved )
+BOOL32 WINAPI ExitWindowsEx( UINT32 flags, DWORD reserved )
 {
     int i;
     BOOL32 result;
diff --git a/windows/win.c b/windows/win.c
index 3200d5a..9f4375b 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -97,7 +97,7 @@
     fprintf( stderr, "Window %04x (%p):\n", hwnd, ptr );
     fprintf( stderr,
              "next=%p  child=%p  parent=%p  owner=%p  class=%p '%s'\n"
-             "inst=%04x  taskQ=%04x  updRgn=%04x  active=%04x dce=%p  idmenu=%04x\n"
+             "inst=%04x  taskQ=%04x  updRgn=%04x  active=%04x dce=%p  idmenu=%08x\n"
              "style=%08lx  exstyle=%08lx  wndproc=%08x  text='%s'\n"
              "client=%d,%d-%d,%d  window=%d,%d-%d,%d"
              "sysmenu=%04x  flags=%04x  props=%p  vscroll=%p  hscroll=%p\n",
@@ -544,7 +544,7 @@
         if (!cs->hwndParent || (cs->hwndParent == pWndDesktop->hwndSelf))
             wndPtr->owner = NULL;
         else
-            wndPtr->owner = WIN_FindWndPtr(WIN_GetTopParent(cs->hwndParent));
+            wndPtr->owner = WIN_GetTopParentPtr(WIN_FindWndPtr(cs->hwndParent));
     }
 
     wndPtr->window         = 0;
@@ -692,7 +692,7 @@
 
     /* Set the window menu */
 
-    if ((cs->style & WS_CAPTION) && !(cs->style & WS_CHILD))
+    if ((wndPtr->dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
     {
         if (cs->hMenu) SetMenu32(hwnd, cs->hMenu);
         else
@@ -786,10 +786,10 @@
 /***********************************************************************
  *           CreateWindow16   (USER.41)
  */
-HWND16 CreateWindow16( LPCSTR className, LPCSTR windowName,
-                       DWORD style, INT16 x, INT16 y, INT16 width,
-                       INT16 height, HWND16 parent, HMENU16 menu,
-                       HINSTANCE16 instance, LPVOID data ) 
+HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
+                              DWORD style, INT16 x, INT16 y, INT16 width,
+                              INT16 height, HWND16 parent, HMENU16 menu,
+                              HINSTANCE16 instance, LPVOID data ) 
 {
     return CreateWindowEx16( 0, className, windowName, style,
 			   x, y, width, height, parent, menu, instance, data );
@@ -799,10 +799,11 @@
 /***********************************************************************
  *           CreateWindowEx16   (USER.452)
  */
-HWND16 CreateWindowEx16( DWORD exStyle, LPCSTR className, LPCSTR windowName,
-                         DWORD style, INT16 x, INT16 y, INT16 width,
-                         INT16 height, HWND16 parent, HMENU16 menu,
-                         HINSTANCE16 instance, LPVOID data ) 
+HWND16 WINAPI CreateWindowEx16( DWORD exStyle, LPCSTR className,
+                                LPCSTR windowName, DWORD style, INT16 x,
+                                INT16 y, INT16 width, INT16 height,
+                                HWND16 parent, HMENU16 menu,
+                                HINSTANCE16 instance, LPVOID data ) 
 {
     ATOM classAtom;
     CREATESTRUCT32A cs;
@@ -841,10 +842,11 @@
 /***********************************************************************
  *           CreateWindowEx32A   (USER32.82)
  */
-HWND32 CreateWindowEx32A( DWORD exStyle, LPCSTR className, LPCSTR windowName,
-                          DWORD style, INT32 x, INT32 y, INT32 width,
-                          INT32 height, HWND32 parent, HMENU32 menu,
-                          HINSTANCE32 instance, LPVOID data )
+HWND32 WINAPI CreateWindowEx32A( DWORD exStyle, LPCSTR className,
+                                 LPCSTR windowName, DWORD style, INT32 x,
+                                 INT32 y, INT32 width, INT32 height,
+                                 HWND32 parent, HMENU32 menu,
+                                 HINSTANCE32 instance, LPVOID data )
 {
     ATOM classAtom;
     CREATESTRUCT32A cs;
@@ -880,10 +882,11 @@
 /***********************************************************************
  *           CreateWindowEx32W   (USER32.83)
  */
-HWND32 CreateWindowEx32W( DWORD exStyle, LPCWSTR className, LPCWSTR windowName,
-                          DWORD style, INT32 x, INT32 y, INT32 width,
-                          INT32 height, HWND32 parent, HMENU32 menu,
-                          HINSTANCE32 instance, LPVOID data )
+HWND32 WINAPI CreateWindowEx32W( DWORD exStyle, LPCWSTR className,
+                                 LPCWSTR windowName, DWORD style, INT32 x,
+                                 INT32 y, INT32 width, INT32 height,
+                                 HWND32 parent, HMENU32 menu,
+                                 HINSTANCE32 instance, LPVOID data )
 {
     ATOM classAtom;
     CREATESTRUCT32W cs;
@@ -963,16 +966,18 @@
 
 
 /***********************************************************************
- *           DestroyWindow   (USER.53)
+ *           DestroyWindow16   (USER.53)
  */
-BOOL16 DestroyWindow16( HWND16 hwnd )
+BOOL16 WINAPI DestroyWindow16( HWND16 hwnd )
 {
     return DestroyWindow32(hwnd);
 }
+
+
 /***********************************************************************
- *           DestroyWindow   (USER32.134)
+ *           DestroyWindow32   (USER32.134)
  */
-BOOL32 DestroyWindow32( HWND32 hwnd )
+BOOL32 WINAPI DestroyWindow32( HWND32 hwnd )
 {
     WND * wndPtr;
 
@@ -1060,7 +1065,7 @@
 /***********************************************************************
  *           CloseWindow16   (USER.43)
  */
-BOOL16 CloseWindow16( HWND16 hwnd )
+BOOL16 WINAPI CloseWindow16( HWND16 hwnd )
 {
     return CloseWindow32( hwnd );
 }
@@ -1069,7 +1074,7 @@
 /***********************************************************************
  *           CloseWindow32   (USER32.55)
  */
-BOOL32 CloseWindow32( HWND32 hwnd )
+BOOL32 WINAPI CloseWindow32( HWND32 hwnd )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr || (wndPtr->dwStyle & WS_CHILD)) return FALSE;
@@ -1081,7 +1086,7 @@
 /***********************************************************************
  *           OpenIcon16   (USER.44)
  */
-BOOL16 OpenIcon16( HWND16 hwnd )
+BOOL16 WINAPI OpenIcon16( HWND16 hwnd )
 {
     return OpenIcon32( hwnd );
 }
@@ -1090,7 +1095,7 @@
 /***********************************************************************
  *           OpenIcon32   (USER32.409)
  */
-BOOL32 OpenIcon32( HWND32 hwnd )
+BOOL32 WINAPI OpenIcon32( HWND32 hwnd )
 {
     if (!IsIconic32( hwnd )) return FALSE;
     ShowWindow32( hwnd, SW_SHOWNORMAL );
@@ -1158,7 +1163,7 @@
 /***********************************************************************
  *           FindWindow16   (USER.50)
  */
-HWND16 FindWindow16( SEGPTR className, LPCSTR title )
+HWND16 WINAPI FindWindow16( SEGPTR className, LPCSTR title )
 {
     return FindWindowEx16( 0, 0, className, title );
 }
@@ -1167,8 +1172,8 @@
 /***********************************************************************
  *           FindWindowEx16   (USER.427)
  */
-HWND16 FindWindowEx16( HWND16 parent, HWND16 child,
-                       SEGPTR className, LPCSTR title )
+HWND16 WINAPI FindWindowEx16( HWND16 parent, HWND16 child,
+                              SEGPTR className, LPCSTR title )
 {
     ATOM atom = 0;
 
@@ -1189,7 +1194,7 @@
 /***********************************************************************
  *           FindWindow32A   (USER32.197)
  */
-HWND32 FindWindow32A( LPCSTR className, LPCSTR title )
+HWND32 WINAPI FindWindow32A( LPCSTR className, LPCSTR title )
 {
     return FindWindowEx32A( 0, 0, className, title );
 }
@@ -1198,8 +1203,8 @@
 /***********************************************************************
  *           FindWindowEx32A   (USER32.198)
  */
-HWND32 FindWindowEx32A( HWND32 parent, HWND32 child,
-                        LPCSTR className, LPCSTR title )
+HWND32 WINAPI FindWindowEx32A( HWND32 parent, HWND32 child,
+                               LPCSTR className, LPCSTR title )
 {
     ATOM atom = 0;
 
@@ -1216,8 +1221,8 @@
 /***********************************************************************
  *           FindWindowEx32W   (USER32.199)
  */
-HWND32 FindWindowEx32W( HWND32 parent, HWND32 child,
-                        LPCWSTR className, LPCWSTR title )
+HWND32 WINAPI FindWindowEx32W( HWND32 parent, HWND32 child,
+                               LPCWSTR className, LPCWSTR title )
 {
     ATOM atom = 0;
     char *buffer;
@@ -1239,7 +1244,7 @@
 /***********************************************************************
  *           FindWindow32W   (USER32.200)
  */
-HWND32 FindWindow32W( LPCWSTR className, LPCWSTR title )
+HWND32 WINAPI FindWindow32W( LPCWSTR className, LPCWSTR title )
 {
     return FindWindowEx32W( 0, 0, className, title );
 }
@@ -1257,7 +1262,7 @@
 /**********************************************************************
  *           GetDesktopWindow16   (USER.286)
  */
-HWND16 GetDesktopWindow16(void)
+HWND16 WINAPI GetDesktopWindow16(void)
 {
     return (HWND16)pWndDesktop->hwndSelf;
 }
@@ -1266,7 +1271,7 @@
 /**********************************************************************
  *           GetDesktopWindow32   (USER32.231)
  */
-HWND32 GetDesktopWindow32(void)
+HWND32 WINAPI GetDesktopWindow32(void)
 {
     return pWndDesktop->hwndSelf;
 }
@@ -1278,7 +1283,7 @@
  * Exactly the same thing as GetDesktopWindow(), but not documented.
  * Don't ask me why...
  */
-HWND16 GetDesktopHwnd(void)
+HWND16 WINAPI GetDesktopHwnd(void)
 {
     return (HWND16)pWndDesktop->hwndSelf;
 }
@@ -1287,7 +1292,7 @@
 /*******************************************************************
  *           EnableWindow16   (USER.34)
  */
-BOOL16 EnableWindow16( HWND16 hwnd, BOOL16 enable )
+BOOL16 WINAPI EnableWindow16( HWND16 hwnd, BOOL16 enable )
 {
     return EnableWindow32( hwnd, enable );
 }
@@ -1296,7 +1301,7 @@
 /*******************************************************************
  *           EnableWindow32   (USER32.171)
  */
-BOOL32 EnableWindow32( HWND32 hwnd, BOOL32 enable )
+BOOL32 WINAPI EnableWindow32( HWND32 hwnd, BOOL32 enable )
 {
     WND *wndPtr;
 
@@ -1326,7 +1331,7 @@
 /***********************************************************************
  *           IsWindowEnabled16   (USER.35)
  */ 
-BOOL16 IsWindowEnabled16(HWND16 hWnd)
+BOOL16 WINAPI IsWindowEnabled16(HWND16 hWnd)
 {
     return IsWindowEnabled32(hWnd);
 }
@@ -1335,7 +1340,7 @@
 /***********************************************************************
  *           IsWindowEnabled32   (USER32.348)
  */ 
-BOOL32 IsWindowEnabled32(HWND32 hWnd)
+BOOL32 WINAPI IsWindowEnabled32(HWND32 hWnd)
 {
     WND * wndPtr; 
 
@@ -1347,7 +1352,7 @@
 /***********************************************************************
  *           IsWindowUnicode   (USER32.349)
  */
-BOOL32 IsWindowUnicode( HWND32 hwnd )
+BOOL32 WINAPI IsWindowUnicode( HWND32 hwnd )
 {
     WND * wndPtr; 
 
@@ -1359,7 +1364,7 @@
 /**********************************************************************
  *	     GetWindowWord16    (USER.133)
  */
-WORD GetWindowWord16( HWND16 hwnd, INT16 offset )
+WORD WINAPI GetWindowWord16( HWND16 hwnd, INT16 offset )
 {
     return GetWindowWord32( hwnd, offset );
 }
@@ -1368,7 +1373,7 @@
 /**********************************************************************
  *	     GetWindowWord32    (USER32.313)
  */
-WORD GetWindowWord32( HWND32 hwnd, INT32 offset )
+WORD WINAPI GetWindowWord32( HWND32 hwnd, INT32 offset )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr) return 0;
@@ -1383,7 +1388,7 @@
     }
     switch(offset)
     {
-    case GWW_ID:         return wndPtr->wIDmenu;
+    case GWW_ID:         return (WORD)wndPtr->wIDmenu;
     case GWW_HWNDPARENT: return wndPtr->parent ? wndPtr->parent->hwndSelf : 0;
     case GWW_HINSTANCE:  return (WORD)wndPtr->hInstance;
     default:
@@ -1407,7 +1412,7 @@
 /**********************************************************************
  *	     SetWindowWord16    (USER.134)
  */
-WORD SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval )
+WORD WINAPI SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval )
 {
     return SetWindowWord32( hwnd, offset, newval );
 }
@@ -1416,7 +1421,7 @@
 /**********************************************************************
  *	     SetWindowWord32    (USER32.523)
  */
-WORD SetWindowWord32( HWND32 hwnd, INT32 offset, WORD newval )
+WORD WINAPI SetWindowWord32( HWND32 hwnd, INT32 offset, WORD newval )
 {
     WORD *ptr, retval;
     WND * wndPtr = WIN_FindWndPtr( hwnd );
@@ -1473,7 +1478,7 @@
         case GWL_USERDATA:   return wndPtr->userdata;
         case GWL_STYLE:      return wndPtr->dwStyle;
         case GWL_EXSTYLE:    return wndPtr->dwExStyle;
-        case GWL_ID:         return wndPtr->wIDmenu;
+        case GWL_ID:         return (LONG)wndPtr->wIDmenu;
         case GWL_WNDPROC:    return (LONG)WINPROC_GetProc( wndPtr->winproc,
                                                            type );
         case GWL_HWNDPARENT: return wndPtr->parent ?
@@ -1548,7 +1553,7 @@
 /**********************************************************************
  *	     GetWindowLong16    (USER.135)
  */
-LONG GetWindowLong16( HWND16 hwnd, INT16 offset )
+LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
 {
     return WIN_GetWindowLong( (HWND32)hwnd, offset, WIN_PROC_16 );
 }
@@ -1557,7 +1562,7 @@
 /**********************************************************************
  *	     GetWindowLong32A    (USER32.304)
  */
-LONG GetWindowLong32A( HWND32 hwnd, INT32 offset )
+LONG WINAPI GetWindowLong32A( HWND32 hwnd, INT32 offset )
 {
     return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32A );
 }
@@ -1566,7 +1571,7 @@
 /**********************************************************************
  *	     GetWindowLong32W    (USER32.305)
  */
-LONG GetWindowLong32W( HWND32 hwnd, INT32 offset )
+LONG WINAPI GetWindowLong32W( HWND32 hwnd, INT32 offset )
 {
     return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32W );
 }
@@ -1575,7 +1580,7 @@
 /**********************************************************************
  *	     SetWindowLong16    (USER.136)
  */
-LONG SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
+LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
 {
     return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_16 );
 }
@@ -1584,7 +1589,7 @@
 /**********************************************************************
  *	     SetWindowLong32A    (USER32.516)
  */
-LONG SetWindowLong32A( HWND32 hwnd, INT32 offset, LONG newval )
+LONG WINAPI SetWindowLong32A( HWND32 hwnd, INT32 offset, LONG newval )
 {
     return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32A );
 }
@@ -1593,7 +1598,7 @@
 /**********************************************************************
  *	     SetWindowLong32W    (USER32.517)
  */
-LONG SetWindowLong32W( HWND32 hwnd, INT32 offset, LONG newval )
+LONG WINAPI SetWindowLong32W( HWND32 hwnd, INT32 offset, LONG newval )
 {
     return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32W );
 }
@@ -1602,7 +1607,7 @@
 /*******************************************************************
  *	     GetWindowText16    (USER.36)
  */
-INT16 GetWindowText16( HWND16 hwnd, SEGPTR lpString, INT16 nMaxCount )
+INT16 WINAPI GetWindowText16( HWND16 hwnd, SEGPTR lpString, INT16 nMaxCount )
 {
     return (INT16)SendMessage16(hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
 }
@@ -1611,7 +1616,7 @@
 /*******************************************************************
  *	     GetWindowText32A    (USER32.308)
  */
-INT32 GetWindowText32A( HWND32 hwnd, LPSTR lpString, INT32 nMaxCount )
+INT32 WINAPI GetWindowText32A( HWND32 hwnd, LPSTR lpString, INT32 nMaxCount )
 {
     return (INT32)SendMessage32A( hwnd, WM_GETTEXT, nMaxCount,
                                   (LPARAM)lpString );
@@ -1621,7 +1626,7 @@
 /*******************************************************************
  *	     GetWindowText32W    (USER32.311)
  */
-INT32 GetWindowText32W( HWND32 hwnd, LPWSTR lpString, INT32 nMaxCount )
+INT32 WINAPI GetWindowText32W( HWND32 hwnd, LPWSTR lpString, INT32 nMaxCount )
 {
     return (INT32)SendMessage32W( hwnd, WM_GETTEXT, nMaxCount,
                                   (LPARAM)lpString );
@@ -1631,25 +1636,25 @@
 /*******************************************************************
  *	     SetWindowText16    (USER.37)
  */
-void SetWindowText16( HWND16 hwnd, SEGPTR lpString )
+void WINAPI SetWindowText16( HWND16 hwnd, SEGPTR lpString )
 {
     SendMessage16( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
 }
 
 
 /*******************************************************************
- *	     SetWindowText32A    (USER32.)
+ *	     SetWindowText32A    (USER32.521)
  */
-void SetWindowText32A( HWND32 hwnd, LPCSTR lpString )
+void WINAPI SetWindowText32A( HWND32 hwnd, LPCSTR lpString )
 {
     SendMessage32A( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
 }
 
 
 /*******************************************************************
- *	     SetWindowText32W    (USER32.)
+ *	     SetWindowText32W    (USER32.522)
  */
-void SetWindowText32W( HWND32 hwnd, LPCWSTR lpString )
+void WINAPI SetWindowText32W( HWND32 hwnd, LPCWSTR lpString )
 {
     SendMessage32W( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
 }
@@ -1658,7 +1663,7 @@
 /*******************************************************************
  *         GetWindowTextLength16    (USER.38)
  */
-INT16 GetWindowTextLength16( HWND16 hwnd )
+INT16 WINAPI GetWindowTextLength16( HWND16 hwnd )
 {
     return (INT16)SendMessage16( hwnd, WM_GETTEXTLENGTH, 0, 0 );
 }
@@ -1667,7 +1672,7 @@
 /*******************************************************************
  *         GetWindowTextLength32A   (USER32.309)
  */
-INT32 GetWindowTextLength32A( HWND32 hwnd )
+INT32 WINAPI GetWindowTextLength32A( HWND32 hwnd )
 {
     return SendMessage32A( hwnd, WM_GETTEXTLENGTH, 0, 0 );
 }
@@ -1675,7 +1680,7 @@
 /*******************************************************************
  *         GetWindowTextLength32W   (USER32.309)
  */
-INT32 GetWindowTextLength32W( HWND32 hwnd )
+INT32 WINAPI GetWindowTextLength32W( HWND32 hwnd )
 {
     return SendMessage32W( hwnd, WM_GETTEXTLENGTH, 0, 0 );
 }
@@ -1684,7 +1689,7 @@
 /*******************************************************************
  *         IsWindow16   (USER.47)
  */
-BOOL16 IsWindow16( HWND16 hwnd )
+BOOL16 WINAPI IsWindow16( HWND16 hwnd )
 {
     return IsWindow32( hwnd );
 }
@@ -1693,7 +1698,7 @@
 /*******************************************************************
  *         IsWindow32   (USER32.347)
  */
-BOOL32 IsWindow32( HWND32 hwnd )
+BOOL32 WINAPI IsWindow32( HWND32 hwnd )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     return ((wndPtr != NULL) && (wndPtr->dwMagic == WND_MAGIC));
@@ -1703,7 +1708,7 @@
 /*****************************************************************
  *         GetParent16   (USER.46)
  */
-HWND16 GetParent16( HWND16 hwnd )
+HWND16 WINAPI GetParent16( HWND16 hwnd )
 {
     return (HWND16)GetParent32( hwnd );
 }
@@ -1712,7 +1717,7 @@
 /*****************************************************************
  *         GetParent32   (USER32.277)
  */
-HWND32 GetParent32( HWND32 hwnd )
+HWND32 WINAPI GetParent32( HWND32 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
     if (!wndPtr) return 0;
@@ -1720,6 +1725,16 @@
     return wndPtr ? wndPtr->hwndSelf : 0;
 }
 
+/*****************************************************************
+ *         WIN_GetTopParent
+ *
+ * Get the top-level parent for a child window.
+ */
+WND* WIN_GetTopParentPtr( WND* pWnd )
+{
+    while( pWnd && (pWnd->dwStyle & WS_CHILD)) pWnd = pWnd->parent;
+    return pWnd;
+}
 
 /*****************************************************************
  *         WIN_GetTopParent
@@ -1728,8 +1743,7 @@
  */
 HWND32 WIN_GetTopParent( HWND32 hwnd )
 {
-    WND *wndPtr = WIN_FindWndPtr( hwnd );
-    while (wndPtr && (wndPtr->dwStyle & WS_CHILD)) wndPtr = wndPtr->parent;
+    WND *wndPtr = WIN_GetTopParentPtr ( WIN_FindWndPtr( hwnd ) );
     return wndPtr ? wndPtr->hwndSelf : 0;
 }
 
@@ -1737,7 +1751,7 @@
 /*****************************************************************
  *         SetParent16   (USER.233)
  */
-HWND16 SetParent16( HWND16 hwndChild, HWND16 hwndNewParent )
+HWND16 WINAPI SetParent16( HWND16 hwndChild, HWND16 hwndNewParent )
 {
     return SetParent32( hwndChild, hwndNewParent );
 }
@@ -1746,7 +1760,7 @@
 /*****************************************************************
  *         SetParent32   (USER32.494)
  */
-HWND32 SetParent32( HWND32 hwndChild, HWND32 hwndNewParent )
+HWND32 WINAPI SetParent32( HWND32 hwndChild, HWND32 hwndNewParent )
 {
     HWND32 oldParent;
 
@@ -1769,7 +1783,7 @@
 /*******************************************************************
  *         IsChild16    (USER.48)
  */
-BOOL16 IsChild16( HWND16 parent, HWND16 child )
+BOOL16 WINAPI IsChild16( HWND16 parent, HWND16 child )
 {
     return IsChild32(parent,child);
 }
@@ -1778,7 +1792,7 @@
 /*******************************************************************
  *         IsChild32    (USER32.338)
  */
-BOOL32 IsChild32( HWND32 parent, HWND32 child )
+BOOL32 WINAPI IsChild32( HWND32 parent, HWND32 child )
 {
     WND * wndPtr = WIN_FindWndPtr( child );
     while (wndPtr && (wndPtr->dwStyle & WS_CHILD))
@@ -1793,7 +1807,7 @@
 /***********************************************************************
  *           IsWindowVisible16   (USER.49)
  */
-BOOL16 IsWindowVisible16( HWND16 hwnd )
+BOOL16 WINAPI IsWindowVisible16( HWND16 hwnd )
 {
     return IsWindowVisible32(hwnd);
 }
@@ -1802,7 +1816,7 @@
 /***********************************************************************
  *           IsWindowVisible32   (USER32.350)
  */
-BOOL32 IsWindowVisible32( HWND32 hwnd )
+BOOL32 WINAPI IsWindowVisible32( HWND32 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr( hwnd );
     while (wndPtr && (wndPtr->dwStyle & WS_CHILD))
@@ -1836,7 +1850,7 @@
 /*******************************************************************
  *         GetTopWindow16    (USER.229)
  */
-HWND16 GetTopWindow16( HWND16 hwnd )
+HWND16 WINAPI GetTopWindow16( HWND16 hwnd )
 {
     return GetTopWindow32(hwnd);
 }
@@ -1845,7 +1859,7 @@
 /*******************************************************************
  *         GetTopWindow32    (USER.229)
  */
-HWND32 GetTopWindow32( HWND32 hwnd )
+HWND32 WINAPI GetTopWindow32( HWND32 hwnd )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (wndPtr && wndPtr->child) return wndPtr->child->hwndSelf;
@@ -1856,7 +1870,7 @@
 /*******************************************************************
  *         GetWindow16    (USER.262)
  */
-HWND16 GetWindow16( HWND16 hwnd, WORD rel )
+HWND16 WINAPI GetWindow16( HWND16 hwnd, WORD rel )
 {
     return GetWindow32( hwnd,rel );
 }
@@ -1865,7 +1879,7 @@
 /*******************************************************************
  *         GetWindow32    (USER32.301)
  */
-HWND32 GetWindow32( HWND32 hwnd, WORD rel )
+HWND32 WINAPI GetWindow32( HWND32 hwnd, WORD rel )
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
     if (!wndPtr) return 0;
@@ -1908,7 +1922,7 @@
 /*******************************************************************
  *         GetNextWindow16    (USER.230)
  */
-HWND16 GetNextWindow16( HWND16 hwnd, WORD flag )
+HWND16 WINAPI GetNextWindow16( HWND16 hwnd, WORD flag )
 {
     if ((flag != GW_HWNDNEXT) && (flag != GW_HWNDPREV)) return 0;
     return GetWindow16( hwnd, flag );
@@ -1917,7 +1931,7 @@
 /*******************************************************************
  *         ShowOwnedPopups16  (USER.265)
  */
-void ShowOwnedPopups16( HWND16 owner, BOOL16 fShow )
+void WINAPI ShowOwnedPopups16( HWND16 owner, BOOL16 fShow )
 {
     ShowOwnedPopups32( owner, fShow );
 }
@@ -1926,7 +1940,7 @@
 /*******************************************************************
  *         ShowOwnedPopups32  (USER32.530)
  */
-BOOL32 ShowOwnedPopups32( HWND32 owner, BOOL32 fShow )
+BOOL32 WINAPI ShowOwnedPopups32( HWND32 owner, BOOL32 fShow )
 {
     WND *pWnd = pWndDesktop->child;
     while (pWnd)
@@ -1943,7 +1957,7 @@
 /*******************************************************************
  *         GetLastActivePopup16   (USER.287)
  */
-HWND16 GetLastActivePopup16( HWND16 hwnd )
+HWND16 WINAPI GetLastActivePopup16( HWND16 hwnd )
 {
     return GetLastActivePopup32( hwnd );
 }
@@ -1951,7 +1965,7 @@
 /*******************************************************************
  *         GetLastActivePopup32   (USER32.255)
  */
-HWND32 GetLastActivePopup32( HWND32 hwnd )
+HWND32 WINAPI GetLastActivePopup32( HWND32 hwnd )
 {
     WND *wndPtr;
     wndPtr = WIN_FindWndPtr(hwnd);
@@ -2016,7 +2030,7 @@
 /*******************************************************************
  *           EnumWindows16   (USER.54)
  */
-BOOL16 EnumWindows16( WNDENUMPROC16 lpEnumFunc, LPARAM lParam )
+BOOL16 WINAPI EnumWindows16( WNDENUMPROC16 lpEnumFunc, LPARAM lParam )
 {
     WND **list, **ppWnd;
 
@@ -2042,7 +2056,7 @@
 /*******************************************************************
  *           EnumWindows32   (USER32.192)
  */
-BOOL32 EnumWindows32( WNDENUMPROC32 lpEnumFunc, LPARAM lParam )
+BOOL32 WINAPI EnumWindows32( WNDENUMPROC32 lpEnumFunc, LPARAM lParam )
 {
     return (BOOL32)EnumWindows16( (WNDENUMPROC16)lpEnumFunc, lParam );
 }
@@ -2051,7 +2065,8 @@
 /**********************************************************************
  *           EnumTaskWindows16   (USER.225)
  */
-BOOL16 EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func, LPARAM lParam )
+BOOL16 WINAPI EnumTaskWindows16( HTASK16 hTask, WNDENUMPROC16 func,
+                                 LPARAM lParam )
 {
     WND **list, **ppWnd;
     HQUEUE16 hQueue = GetTaskQueue( hTask );
@@ -2078,7 +2093,7 @@
 /**********************************************************************
  *           EnumThreadWindows   (USER32.189)
  */
-BOOL32 EnumThreadWindows( DWORD id, WNDENUMPROC32 func, LPARAM lParam )
+BOOL32 WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC32 func, LPARAM lParam )
 {
     THDB	*tdb = (THDB*)id;
 
@@ -2116,7 +2131,8 @@
 /**********************************************************************
  *           EnumChildWindows16   (USER.55)
  */
-BOOL16 EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func, LPARAM lParam )
+BOOL16 WINAPI EnumChildWindows16( HWND16 parent, WNDENUMPROC16 func,
+                                  LPARAM lParam )
 {
     WND **list, *pParent;
 
@@ -2131,7 +2147,8 @@
 /**********************************************************************
  *           EnumChildWindows32   (USER32.177)
  */
-BOOL32 EnumChildWindows32( HWND32 parent, WNDENUMPROC32 func, LPARAM lParam )
+BOOL32 WINAPI EnumChildWindows32( HWND32 parent, WNDENUMPROC32 func,
+                                  LPARAM lParam )
 {
     return (BOOL32)EnumChildWindows16( (HWND16)parent, (WNDENUMPROC16)func,
                                        lParam );
@@ -2141,7 +2158,7 @@
 /*******************************************************************
  *           AnyPopup16   (USER.52)
  */
-BOOL16 AnyPopup16(void)
+BOOL16 WINAPI AnyPopup16(void)
 {
     return AnyPopup32();
 }
@@ -2150,7 +2167,7 @@
 /*******************************************************************
  *           AnyPopup32   (USER32.3)
  */
-BOOL32 AnyPopup32(void)
+BOOL32 WINAPI AnyPopup32(void)
 {
     WND *wndPtr;
     for (wndPtr = pWndDesktop->child; wndPtr; wndPtr = wndPtr->next)
@@ -2162,7 +2179,7 @@
 /*******************************************************************
  *            FlashWindow16   (USER.105)
  */
-BOOL16 FlashWindow16( HWND16 hWnd, BOOL16 bInvert )
+BOOL16 WINAPI FlashWindow16( HWND16 hWnd, BOOL16 bInvert )
 {
     return FlashWindow32( hWnd, bInvert );
 }
@@ -2171,7 +2188,7 @@
 /*******************************************************************
  *            FlashWindow32   (USER32.201)
  */
-BOOL32 FlashWindow32( HWND32 hWnd, BOOL32 bInvert )
+BOOL32 WINAPI FlashWindow32( HWND32 hWnd, BOOL32 bInvert )
 {
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
@@ -2214,7 +2231,7 @@
 /*******************************************************************
  *           SetSysModalWindow16   (USER.188)
  */
-HWND16 SetSysModalWindow16( HWND16 hWnd )
+HWND16 WINAPI SetSysModalWindow16( HWND16 hWnd )
 {
     HWND32 hWndOldModal = hwndSysModal;
     hwndSysModal = hWnd;
@@ -2226,7 +2243,7 @@
 /*******************************************************************
  *           GetSysModalWindow16   (USER.52)
  */
-HWND16 GetSysModalWindow16(void)
+HWND16 WINAPI GetSysModalWindow16(void)
 {
     return hwndSysModal;
 }
@@ -2307,7 +2324,7 @@
 /*******************************************************************
  *             DragDetect   (USER.465)
  */
-BOOL16 DragDetect16( HWND16 hWnd, POINT16 pt )
+BOOL16 WINAPI DragDetect16( HWND16 hWnd, POINT16 pt )
 {
     POINT32 pt32;
     CONV_POINT16TO32( &pt, &pt32 );
@@ -2317,7 +2334,7 @@
 /*******************************************************************
  *             DragDetect32   (USER32.150)
  */
-BOOL32 DragDetect32( HWND32 hWnd, POINT32 pt )
+BOOL32 WINAPI DragDetect32( HWND32 hWnd, POINT32 pt )
 {
     MSG16 msg;
     RECT16  rect;
@@ -2356,8 +2373,8 @@
 /******************************************************************************
  *             DragObject16   (USER.464)
  */
-DWORD DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
-                    HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
+DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
+                           HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
 {
     MSG16	msg;
     LPDRAGINFO	lpDragInfo;
diff --git a/windows/winhelp.c b/windows/winhelp.c
index 49ae2ca..856d2d5 100644
--- a/windows/winhelp.c
+++ b/windows/winhelp.c
@@ -14,8 +14,8 @@
 /**********************************************************************
  *             WinHelp16   (USER.171)
  */
-BOOL16 WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
-                  DWORD dwData )
+BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
+                         DWORD dwData )
 {
     return WinHelp32A( hWnd, lpHelpFile, wCommand,
                        (DWORD)PTR_SEG_TO_LIN(dwData) );
@@ -25,8 +25,8 @@
 /**********************************************************************
  *             WinHelp32A   (USER32.578)
  */
-BOOL32 WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
-                   DWORD dwData )
+BOOL32 WINAPI WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
+                          DWORD dwData )
 {
 	static WORD WM_WINHELP=0;
 	HWND32 hDest;
@@ -103,8 +103,8 @@
 /**********************************************************************
  *             WinHelp32W   (USER32.579)
  */
-BOOL32 WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
-                   DWORD dwData )
+BOOL32 WINAPI WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
+                          DWORD dwData )
 {
     LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
     BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
diff --git a/windows/winpos.c b/windows/winpos.c
index 472b011..e418e7e 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -150,14 +150,14 @@
 /***********************************************************************
  *           ArrangeIconicWindows16   (USER.170)
  */
-UINT16 ArrangeIconicWindows16( HWND16 parent) 
+UINT16 WINAPI ArrangeIconicWindows16( HWND16 parent) 
 {
     return ArrangeIconicWindows32(parent);
 }
 /***********************************************************************
  *           ArrangeIconicWindows32   (USER32.6)
  */
-UINT32 ArrangeIconicWindows32( HWND32 parent )
+UINT32 WINAPI ArrangeIconicWindows32( HWND32 parent )
 {
     RECT32 rectParent;
     HWND32 hwndChild;
@@ -196,7 +196,7 @@
 /***********************************************************************
  *             SwitchToThisWindow16   (USER.172)
  */
-void SwitchToThisWindow16( HWND16 hwnd, BOOL16 restore )
+void WINAPI SwitchToThisWindow16( HWND16 hwnd, BOOL16 restore )
 {
     SwitchToThisWindow32( hwnd, restore );
 }
@@ -205,7 +205,7 @@
 /***********************************************************************
  *             SwitchToThisWindow32   (USER32.538)
  */
-void SwitchToThisWindow32( HWND32 hwnd, BOOL32 restore )
+void WINAPI SwitchToThisWindow32( HWND32 hwnd, BOOL32 restore )
 {
     ShowWindow32( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
 }
@@ -214,7 +214,7 @@
 /***********************************************************************
  *           GetWindowRect16   (USER.32)
  */
-void GetWindowRect16( HWND16 hwnd, LPRECT16 rect ) 
+void WINAPI GetWindowRect16( HWND16 hwnd, LPRECT16 rect ) 
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd ); 
     if (!wndPtr) return;
@@ -228,7 +228,7 @@
 /***********************************************************************
  *           GetWindowRect32   (USER.32)
  */
-void GetWindowRect32( HWND32 hwnd, LPRECT32 rect ) 
+void WINAPI GetWindowRect32( HWND32 hwnd, LPRECT32 rect ) 
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd ); 
     if (!wndPtr) return;
@@ -242,7 +242,7 @@
 /***********************************************************************
  *           GetClientRect16   (USER.33)
  */
-void GetClientRect16( HWND16 hwnd, LPRECT16 rect ) 
+void WINAPI GetClientRect16( HWND16 hwnd, LPRECT16 rect ) 
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
 
@@ -258,7 +258,7 @@
 /***********************************************************************
  *           GetClientRect32   (USER32.219)
  */
-void GetClientRect32( HWND32 hwnd, LPRECT32 rect ) 
+void WINAPI GetClientRect32( HWND32 hwnd, LPRECT32 rect ) 
 {
     WND * wndPtr = WIN_FindWndPtr( hwnd );
 
@@ -274,7 +274,7 @@
 /*******************************************************************
  *         ClientToScreen16   (USER.28)
  */
-BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
+BOOL16 WINAPI ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
 {
     MapWindowPoints16( hwnd, 0, lppnt, 1 );
     return TRUE;
@@ -284,7 +284,7 @@
 /*******************************************************************
  *         ClientToScreen32   (USER32.51)
  */
-BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
+BOOL32 WINAPI ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
 {
     MapWindowPoints32( hwnd, 0, lppnt, 1 );
     return TRUE;
@@ -294,7 +294,7 @@
 /*******************************************************************
  *         ScreenToClient16   (USER.29)
  */
-void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
+void WINAPI ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
 {
     MapWindowPoints16( 0, hwnd, lppnt, 1 );
 }
@@ -303,7 +303,7 @@
 /*******************************************************************
  *         ScreenToClient32   (USER32.446)
  */
-void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
+void WINAPI ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
 {
     MapWindowPoints32( 0, hwnd, lppnt, 1 );
 }
@@ -388,7 +388,7 @@
 /*******************************************************************
  *         WindowFromPoint16   (USER.30)
  */
-HWND16  WindowFromPoint16( POINT16 pt )
+HWND16 WINAPI WindowFromPoint16( POINT16 pt )
 {
     WND *pWnd;
     WINPOS_WindowFromPoint( WIN_GetDesktop(), pt, &pWnd );
@@ -399,7 +399,7 @@
 /*******************************************************************
  *         WindowFromPoint32   (USER32.581)
  */
-HWND32 WindowFromPoint32( POINT32 pt )
+HWND32 WINAPI WindowFromPoint32( POINT32 pt )
 {
     WND *pWnd;
     POINT16 pt16;
@@ -412,7 +412,7 @@
 /*******************************************************************
  *         ChildWindowFromPoint16   (USER.191)
  */
-HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
+HWND16 WINAPI ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
 {
     POINT32 pt32;
     CONV_POINT16TO32( &pt, &pt32 );
@@ -423,7 +423,7 @@
 /*******************************************************************
  *         ChildWindowFromPoint32   (USER32.48)
  */
-HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
+HWND32 WINAPI ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
 {
     /* pt is in the client coordinates */
 
@@ -500,8 +500,8 @@
 /*******************************************************************
  *         MapWindowPoints16   (USER.258)
  */
-void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
-                        LPPOINT16 lppt, UINT16 count )
+void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
+                               LPPOINT16 lppt, UINT16 count )
 {
     POINT32 offset;
 
@@ -518,8 +518,8 @@
 /*******************************************************************
  *         MapWindowPoints32   (USER32.385)
  */
-void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
-                        LPPOINT32 lppt, UINT32 count )
+void WINAPI MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
+                               LPPOINT32 lppt, UINT32 count )
 {
     POINT32 offset;
 
@@ -536,14 +536,16 @@
 /***********************************************************************
  *           IsIconic16   (USER.31)
  */
-BOOL16 IsIconic16(HWND16 hWnd)
+BOOL16 WINAPI IsIconic16(HWND16 hWnd)
 {
     return IsIconic32(hWnd);
 }
+
+
 /***********************************************************************
  *           IsIconic32   (USER32.344)
  */
-BOOL32 IsIconic32(HWND32 hWnd)
+BOOL32 WINAPI IsIconic32(HWND32 hWnd)
 {
     WND * wndPtr = WIN_FindWndPtr(hWnd);
     if (wndPtr == NULL) return FALSE;
@@ -554,14 +556,16 @@
 /***********************************************************************
  *           IsZoomed   (USER.272)
  */
-BOOL16 IsZoomed16(HWND16 hWnd)
+BOOL16 WINAPI IsZoomed16(HWND16 hWnd)
 {
     return IsZoomed32(hWnd);
 }
+
+
 /***********************************************************************
  *           IsZoomed   (USER32.351)
  */
-BOOL32 IsZoomed32(HWND32 hWnd)
+BOOL32 WINAPI IsZoomed32(HWND32 hWnd)
 {
     WND * wndPtr = WIN_FindWndPtr(hWnd);
     if (wndPtr == NULL) return FALSE;
@@ -572,7 +576,7 @@
 /*******************************************************************
  *         GetActiveWindow    (USER.60)
  */
-HWND16 GetActiveWindow16(void)
+HWND16 WINAPI GetActiveWindow16(void)
 {
     return (HWND16)hwndActive;
 }
@@ -580,7 +584,7 @@
 /*******************************************************************
  *         GetActiveWindow    (USER32.204)
  */
-HWND32 GetActiveWindow32(void)
+HWND32 WINAPI GetActiveWindow32(void)
 {
     return (HWND32)hwndActive;
 }
@@ -591,22 +595,25 @@
  */
 static BOOL32 WINPOS_CanActivate(WND* pWnd)
 {
- return (pWnd) ? ((!(pWnd->dwStyle & WS_DISABLED) &&
-                     pWnd->dwStyle & WS_VISIBLE ) ? TRUE : FALSE) : FALSE;
+    if( pWnd && ((pWnd->dwStyle & (WS_DISABLED | WS_VISIBLE | WS_CHILD)) 
+	== WS_VISIBLE) ) return TRUE;
+    return FALSE;
 }
 
 
 /*******************************************************************
- *         SetActiveWindow    (USER.59)
+ *         SetActiveWindow16    (USER.59)
  */
-HWND16 SetActiveWindow16( HWND16 hwnd )
+HWND16 WINAPI SetActiveWindow16( HWND16 hwnd )
 {
     return SetActiveWindow32(hwnd);
 }
+
+
 /*******************************************************************
- *         SetActiveWindow    (USER.59)
+ *         SetActiveWindow32    (USER32.462)
  */
-HWND32 SetActiveWindow32( HWND32 hwnd )
+HWND32 WINAPI SetActiveWindow32( HWND32 hwnd )
 {
     HWND32 prev = hwndActive;
     WND *wndPtr = WIN_FindWndPtr( hwnd );
@@ -619,35 +626,39 @@
 
 
 /***********************************************************************
- *           BringWindowToTop   (USER.45)
+ *           BringWindowToTop16   (USER.45)
  */
-BOOL16 BringWindowToTop16( HWND16 hwnd )
+BOOL16 WINAPI BringWindowToTop16( HWND16 hwnd )
 {
     return BringWindowToTop32(hwnd);
 }
+
+
 /***********************************************************************
- *           BringWindowToTop   (USER32.10)
+ *           BringWindowToTop32   (USER32.10)
  */
-BOOL32 BringWindowToTop32( HWND32 hwnd )
+BOOL32 WINAPI BringWindowToTop32( HWND32 hwnd )
 {
     return SetWindowPos32( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
 }
 
 
 /***********************************************************************
- *           MoveWindow   (USER.56)
+ *           MoveWindow16   (USER.56)
  */
-BOOL16 MoveWindow16(
-	HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy, BOOL16 repaint
-) {
+BOOL16 WINAPI MoveWindow16( HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy,
+                            BOOL16 repaint )
+{
     return MoveWindow32(hwnd,x,y,cx,cy,repaint);
 }
+
+
 /***********************************************************************
- *           MoveWindow   (USER32.398)
+ *           MoveWindow32   (USER32.398)
  */
-BOOL32 MoveWindow32(
-	HWND32 hwnd, INT32 x, INT32 y, INT32 cx, INT32 cy, BOOL32 repaint
-) {    
+BOOL32 WINAPI MoveWindow32( HWND32 hwnd, INT32 x, INT32 y, INT32 cx, INT32 cy,
+                            BOOL32 repaint )
+{    
     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
     if (!repaint) flags |= SWP_NOREDRAW;
     dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n", 
@@ -900,16 +911,18 @@
 }
 
 /***********************************************************************
- *           ShowWindow   (USER.42)
+ *           ShowWindow16   (USER.42)
  */
-BOOL16 ShowWindow16( HWND16 hwnd, INT16 cmd ) 
+BOOL16 WINAPI ShowWindow16( HWND16 hwnd, INT16 cmd ) 
 {    
     return ShowWindow32(hwnd,cmd);
 }
+
+
 /***********************************************************************
- *           ShowWindow   (USER.42)
+ *           ShowWindow32   (USER.42)
  */
-BOOL32 ShowWindow32( HWND32 hwnd, INT32 cmd ) 
+BOOL32 WINAPI ShowWindow32( HWND32 hwnd, INT32 cmd ) 
 {    
     WND* 	wndPtr = WIN_FindWndPtr( hwnd );
     BOOL32 	wasVisible, showFlag;
@@ -1019,7 +1032,8 @@
 /***********************************************************************
  *           GetInternalWindowPos16   (USER.460)
  */
-UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
+UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd,
+                                      LPPOINT16 ptIcon )
 {
     WINDOWPLACEMENT16 wndpl;
     if (GetWindowPlacement16( hwnd, &wndpl )) 
@@ -1035,7 +1049,8 @@
 /***********************************************************************
  *           GetInternalWindowPos32   (USER32.244)
  */
-UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
+UINT32 WINAPI GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd,
+                                      LPPOINT32 ptIcon )
 {
     WINDOWPLACEMENT32 wndpl;
     if (GetWindowPlacement32( hwnd, &wndpl ))
@@ -1050,7 +1065,7 @@
 /***********************************************************************
  *           GetWindowPlacement16   (USER.370)
  */
-BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
+BOOL16 WINAPI GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
 {
     WND *pWnd = WIN_FindWndPtr( hwnd );
     if( pWnd )
@@ -1079,7 +1094,7 @@
 /***********************************************************************
  *           GetWindowPlacement32   (USER32.306)
  */
-BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *pwpl32 )
+BOOL32 WINAPI GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *pwpl32 )
 {
     if( pwpl32 )
     {
@@ -1152,15 +1167,16 @@
 /***********************************************************************
  *           SetWindowPlacement16   (USER.371)
  */
-BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
+BOOL16 WINAPI SetWindowPlacement16(HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl)
 {
-    return WINPOS_SetPlacement( hwnd, wndpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
+    return WINPOS_SetPlacement( hwnd, wndpl,
+                                PLACE_MIN | PLACE_MAX | PLACE_RECT );
 }
 
 /***********************************************************************
  *           SetWindowPlacement32   (USER32.518)
  */
-BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *pwpl32 )
+BOOL32 WINAPI SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *pwpl32 )
 {
     if( pwpl32 )
     {
@@ -1180,8 +1196,8 @@
 /***********************************************************************
  *           SetInternalWindowPos16   (USER.461)
  */
-void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
-                             LPRECT16 rect, LPPOINT16 pt )
+void WINAPI SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
+                                    LPRECT16 rect, LPPOINT16 pt )
 {
     if( IsWindow16(hwnd) )
     {
@@ -1211,8 +1227,8 @@
 /***********************************************************************
  *           SetInternalWindowPos32   (USER32.482)
  */
-void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
-                             LPRECT32 rect, LPPOINT32 pt )
+void WINAPI SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
+                                    LPRECT32 rect, LPPOINT32 pt )
 {
     if( IsWindow32(hwnd) )
     {
@@ -1270,7 +1286,9 @@
 /*******************************************************************
  *	   WINPOS_SetActiveWindow
  *
- * back-end to SetActiveWindow
+ * SetActiveWindow() back-end. This is the only function that
+ * can assign active status to a window. It must be called only
+ * for the top level windows.
  */
 BOOL32 WINPOS_SetActiveWindow( HWND32 hWnd, BOOL32 fMouse, BOOL32 fChangeFocus)
 {
@@ -1282,10 +1300,9 @@
     /* paranoid checks */
     if( hWnd == GetDesktopWindow32() || hWnd == hwndActive ) return 0;
 
-/* if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
-	return 0;
-        */
-
+/*  if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
+ *	return 0;
+ */
     wndPtr = WIN_FindWndPtr(hWnd);
     hOldActiveQueue = (pActiveQueue)?pActiveQueue->self : 0;
 
@@ -1432,7 +1449,7 @@
 /*******************************************************************
  *         WINPOS_ActivateOtherWindow
  *
- * DestroyWindow() helper. pWnd must be a top-level window.
+ *  Activates window other than pWnd.
  */
 BOOL32 WINPOS_ActivateOtherWindow(WND* pWnd)
 {
@@ -1446,29 +1463,27 @@
     ( hwndActive || QUEUE_IsExitingQueue(pWnd->hmemTaskQ)) )
       return 0;
 
-  if( pWnd->dwStyle & WS_POPUP &&
-      WINPOS_CanActivate( pWnd->owner ) ) pWndTo = pWnd->owner;
-  else
+  if( !(pWnd->dwStyle & WS_POPUP) || !(pWnd->owner) ||
+      !WINPOS_CanActivate((pWndTo = WIN_GetTopParentPtr(pWnd->owner))) ) 
   {
-    WND* pWndPtr = pWnd;
+      WND* pWndPtr = WIN_GetTopParentPtr(pWnd);
 
-    pWndTo = WIN_FindWndPtr(hwndPrevActive);
+      pWndTo = WIN_FindWndPtr(hwndPrevActive);
 
-    while( !WINPOS_CanActivate(pWndTo) ) 
-    {
-      /* by now owned windows should've been taken care of */
+      while( !WINPOS_CanActivate(pWndTo) ) 
+      {
+	 /* by now owned windows should've been taken care of */
 
-      pWndTo = pWndPtr->next;
-      pWndPtr = pWndTo;
-      if( !pWndTo ) return 0;
-    }
+	  pWndTo = pWndPtr->next;
+	  pWndPtr = pWndTo;
+	  if( !pWndTo ) break;
+      }
   }
 
-  bRet = WINPOS_SetActiveWindow( pWndTo->hwndSelf, FALSE, TRUE );
+  bRet = WINPOS_SetActiveWindow( pWndTo ? pWndTo->hwndSelf : 0, FALSE, TRUE );
 
   /* switch desktop queue to current active */
-  if( pWndTo->parent == WIN_GetDesktop())
-      WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ;
+  if( pWndTo ) WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ;
 
   hwndPrevActive = 0;
   return bRet;  
@@ -1951,8 +1966,8 @@
 /***********************************************************************
  *           SetWindowPos   (USER.232)
  */
-BOOL16 SetWindowPos16( HWND16 hwnd, HWND16 hwndInsertAfter, INT16 x, INT16 y,
-                       INT16 cx, INT16 cy, WORD flags )
+BOOL16 WINAPI SetWindowPos16( HWND16 hwnd, HWND16 hwndInsertAfter,
+                              INT16 x, INT16 y, INT16 cx, INT16 cy, WORD flags)
 {
     return SetWindowPos32(hwnd,(INT32)(INT16)hwndInsertAfter,x,y,cx,cy,flags);
 }
@@ -1960,8 +1975,8 @@
 /***********************************************************************
  *           SetWindowPos   (USER32.519)
  */
-BOOL32 SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter, INT32 x, INT32 y,
-                       INT32 cx, INT32 cy, WORD flags )
+BOOL32 WINAPI SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter,
+                              INT32 x, INT32 y, INT32 cx, INT32 cy, WORD flags)
 {
     WINDOWPOS32 winpos;
     WND *	wndPtr;
@@ -2273,17 +2288,7 @@
 	if (hwnd == CARET_GetHwnd()) DestroyCaret32();
 
 	if (winpos.hwnd == hwndActive)
-	{
-	      /* Activate previously active window if possible */
-	    HWND32 newActive = hwndPrevActive;
-	    if (!IsWindow32(newActive) || (newActive == winpos.hwnd))
-	    {
-		newActive = GetTopWindow32( GetDesktopWindow32() );
-		if (newActive == winpos.hwnd)
-                    newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
-	    }	    
-	    WINPOS_ChangeActiveWindow( newActive, FALSE );
-	}
+	    WINPOS_ActivateOtherWindow( wndPtr );
     }
 
       /* Activate the window */
@@ -2325,7 +2330,7 @@
 /***********************************************************************
  *           BeginDeferWindowPos16   (USER.259)
  */
-HDWP16 BeginDeferWindowPos16( INT16 count )
+HDWP16 WINAPI BeginDeferWindowPos16( INT16 count )
 {
     return BeginDeferWindowPos32( count );
 }
@@ -2334,7 +2339,7 @@
 /***********************************************************************
  *           BeginDeferWindowPos32   (USER32.8)
  */
-HDWP32 BeginDeferWindowPos32( INT32 count )
+HDWP32 WINAPI BeginDeferWindowPos32( INT32 count )
 {
     HDWP32 handle;
     DWP *pDWP;
@@ -2355,8 +2360,9 @@
 /***********************************************************************
  *           DeferWindowPos16   (USER.260)
  */
-HDWP16 DeferWindowPos16( HDWP16 hdwp, HWND16 hwnd, HWND16 hwndAfter,
-                         INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
+HDWP16 WINAPI DeferWindowPos16( HDWP16 hdwp, HWND16 hwnd, HWND16 hwndAfter,
+                                INT16 x, INT16 y, INT16 cx, INT16 cy,
+                                UINT16 flags )
 {
     return DeferWindowPos32( hdwp, hwnd, (INT32)(INT16)hwndAfter,
                              x, y, cx, cy, flags );
@@ -2366,8 +2372,9 @@
 /***********************************************************************
  *           DeferWindowPos32   (USER32.127)
  */
-HDWP32 DeferWindowPos32( HDWP32 hdwp, HWND32 hwnd, HWND32 hwndAfter,
-                         INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags )
+HDWP32 WINAPI DeferWindowPos32( HDWP32 hdwp, HWND32 hwnd, HWND32 hwndAfter,
+                                INT32 x, INT32 y, INT32 cx, INT32 cy,
+                                UINT32 flags )
 {
     DWP *pDWP;
     int i;
@@ -2439,7 +2446,7 @@
 /***********************************************************************
  *           EndDeferWindowPos16   (USER.261)
  */
-BOOL16 EndDeferWindowPos16( HDWP16 hdwp )
+BOOL16 WINAPI EndDeferWindowPos16( HDWP16 hdwp )
 {
     return EndDeferWindowPos32( hdwp );
 }
@@ -2448,7 +2455,7 @@
 /***********************************************************************
  *           EndDeferWindowPos32   (USER32.172)
  */
-BOOL32 EndDeferWindowPos32( HDWP32 hdwp )
+BOOL32 WINAPI EndDeferWindowPos32( HDWP32 hdwp )
 {
     DWP *pDWP;
     WINDOWPOS32 *winpos;
@@ -2471,7 +2478,7 @@
 /***********************************************************************
  *           TileChildWindows   (USER.199)
  */
-void TileChildWindows( HWND16 parent, WORD action )
+void WINAPI TileChildWindows( HWND16 parent, WORD action )
 {
     printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
 }
@@ -2479,7 +2486,7 @@
 /***********************************************************************
  *           CascageChildWindows   (USER.198)
  */
-void CascadeChildWindows( HWND16 parent, WORD action )
+void WINAPI CascadeChildWindows( HWND16 parent, WORD action )
 {
     printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);
 }
diff --git a/windows/winproc.c b/windows/winproc.c
index 10139e6..b2a9207 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -143,6 +143,8 @@
 static LRESULT WINPROC_CallWndProc32( WNDPROC32 proc, HWND32 hwnd, UINT32 msg,
                                       WPARAM32 wParam, LPARAM lParam )
 {
+/*  dprintf_relay( stddeb, "CallTo32(wndproc=%p,hwnd=%08x,msg=%08x,wp=%08x,lp=%08lx)\n",
+                   proc, hwnd, msg, wParam, lParam ); */
     return proc( hwnd, msg, wParam, lParam );
 }
 
@@ -1843,8 +1845,8 @@
 /**********************************************************************
  *	     CallWindowProc16    (USER.122)
  */
-LRESULT CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
-                          WPARAM16 wParam, LPARAM lParam )
+LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
+                                 WPARAM16 wParam, LPARAM lParam )
 {
     LRESULT result;
     WND *wndPtr;
@@ -1899,8 +1901,8 @@
 /**********************************************************************
  *	     CallWindowProc32A    (USER32.17)
  */
-LRESULT CallWindowProc32A( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
-                           WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI CallWindowProc32A( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
+                                  WPARAM32 wParam, LPARAM lParam )
 {
     WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
 
@@ -1936,8 +1938,8 @@
 /**********************************************************************
  *	     CallWindowProc32W    (USER32.18)
  */
-LRESULT CallWindowProc32W( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
-                           WPARAM32 wParam, LPARAM lParam )
+LRESULT WINAPI CallWindowProc32W( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
+                                  WPARAM32 wParam, LPARAM lParam )
 {
     WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
 
diff --git a/wine.ini b/wine.ini
index af8f3ca..8da8b56 100644
--- a/wine.ini
+++ b/wine.ini
@@ -48,10 +48,8 @@
 AllocSystemColors=100
 
 [fonts]
-;Read documentation/fonts before changing this
-Alias0 = MS Sans Serif, -adobe-helvetica-
-;Alias1 = Arial, -adobe-helvetica-, subst
-;Alias2 = Times New Roman, -adobe-times-, subst
+;Read documentation/fonts before adding aliases
+Resolution = 96
 Default = -adobe-times-
 
 [serialports]