Release 960902

Sun Sep  1 19:22:46 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [misc/commdlg.c] [if1632/commdlg.spec]
	Fixed some SEGPTR problems.

	* [windows/winproc.c]
	Added message translation for WM_COMPAREITEM, WM_DELETEITEM
	and WM_MEASUREITEM
	Fixed 16-to-32 translation for WM_HSCROLL/WM_VSCROLL.

Fri Aug 30 13:39:00 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
	* [files/drive.c]
	GetDriveType16 should report CDROMs as DRIVE_REMOTE (ACME setup).

	* [multimedia/audio.c]
	The minimum audiobuffer size shrunk somewhere in linux 1.3.xx
	below 4096 bytes.

	* [multimedia/mcistring.c]
	Segptr string handling fixed & enhanced.

	* [if1632/crtdll.spec][misc/crtdll.c]
	malloc,free,_strupr,_stricmp,_strcmpi added.

	* [if1632/wsock32.spec][misc/winsock.c]
	More direct thunks into unix libc and WsControl-stub added.

Thu Aug 29 23:54:25 1996  Huw D. M. Davies <h.davies1@physics.oxford.ac.uk>

	* [objects/metafile.c]
	Bug fixes to both recording and playback of ExtTextOut().

Tue Aug 27 15:43:21 1996  Slaven Rezic  <eserte@cs.tu-berlin.de>

	* [multimedia/audio.c] [multimedia/mcianim.c]
	  [multimedia/mcicda.c] [multimedia/midi.c]
	Made cdaudio, audio and midi work for FreeBSD.

Sun Aug 25 20:18:56 1996  Jukka Iivonen <iivonen@cc.helsinki.fi>

	* [misc/crtdll.c] [if1632/crtdll.spec]
	Added a lot of functions.

	* [misc/ole2nls.c]
	Added ID values for all languages in GetUserDefaultLCID().
	
Fri Aug 24 21:02:28 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [windows/event.c] [windows/message.c]
	First attempt at hook WH_JOURNALPLAYBACK.
diff --git a/ANNOUNCE b/ANNOUNCE
index 627612c..4e63740 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,13 +1,13 @@
-This is release 960824 of Wine, the MS Windows emulator.  This is still a
+This is release 960902 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-960824: (see ChangeLog for details)
-	- Very preliminary printer support.
-	- Perl script to generate wine.conf.
+WHAT'S NEW with Wine-960902: (see ChangeLog for details)
+	- JOURNALPLAYBACK hook.
+	- Multimedia support for FreeBSD.
 	- Lots of bug fixes.
 
 See the README file in the distribution for installation instructions.
@@ -16,10 +16,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-960824.tar.gz
-  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-960824.tar.gz
-  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-960824.tar.gz
-  ftp://aris.com/pub/linux/ALPHA/Wine/development/Wine-960824.tar.gz
+  ftp://sunsite.unc.edu/pub/Linux/ALPHA/wine/development/Wine-960902.tar.gz
+  ftp://tsx-11.mit.edu/pub/linux/ALPHA/Wine/development/Wine-960902.tar.gz
+  ftp://ftp.infomagic.com/pub/mirrors/linux/wine/development/Wine-960902.tar.gz
+  ftp://aris.com/pub/linux/ALPHA/Wine/development/Wine-960902.tar.gz
 
 It should also be available from any site that mirrors tsx-11 or sunsite.
 
diff --git a/ChangeLog b/ChangeLog
index e30e7a8..d3a1b81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,56 @@
 ----------------------------------------------------------------------
+Sun Sep  1 19:22:46 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
+
+	* [misc/commdlg.c] [if1632/commdlg.spec]
+	Fixed some SEGPTR problems.
+
+	* [windows/winproc.c]
+	Added message translation for WM_COMPAREITEM, WM_DELETEITEM
+	and WM_MEASUREITEM
+	Fixed 16-to-32 translation for WM_HSCROLL/WM_VSCROLL.
+
+Fri Aug 30 13:39:00 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
+	* [files/drive.c]
+	GetDriveType16 should report CDROMs as DRIVE_REMOTE (ACME setup).
+
+	* [multimedia/audio.c]
+	The minimum audiobuffer size shrunk somewhere in linux 1.3.xx
+	below 4096 bytes.
+
+	* [multimedia/mcistring.c]
+	Segptr string handling fixed & enhanced.
+
+	* [if1632/crtdll.spec][misc/crtdll.c]
+	malloc,free,_strupr,_stricmp,_strcmpi added.
+
+	* [if1632/wsock32.spec][misc/winsock.c]
+	More direct thunks into unix libc and WsControl-stub added.
+
+Thu Aug 29 23:54:25 1996  Huw D. M. Davies <h.davies1@physics.oxford.ac.uk>
+
+	* [objects/metafile.c]
+	Bug fixes to both recording and playback of ExtTextOut().
+
+Tue Aug 27 15:43:21 1996  Slaven Rezic  <eserte@cs.tu-berlin.de>
+
+	* [multimedia/audio.c] [multimedia/mcianim.c]
+	  [multimedia/mcicda.c] [multimedia/midi.c]
+	Made cdaudio, audio and midi work for FreeBSD.
+
+Sun Aug 25 20:18:56 1996  Jukka Iivonen <iivonen@cc.helsinki.fi>
+
+	* [misc/crtdll.c] [if1632/crtdll.spec]
+	Added a lot of functions.
+
+	* [misc/ole2nls.c]
+	Added ID values for all languages in GetUserDefaultLCID().
+	
+Fri Aug 24 21:02:28 1996  Albrecht Kleine  <kleine@ak.sax.de>
+
+	* [windows/event.c] [windows/message.c]
+	First attempt at hook WH_JOURNALPLAYBACK.
+
+----------------------------------------------------------------------
 Sat Aug 24 13:57:01 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>
 
 	* [controls/scroll.c]
diff --git a/controls/button.c b/controls/button.c
index c0aca7e..99300f2 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -61,7 +61,7 @@
          ReleaseDC( (wndPtr)->hwndSelf, hdc ); }
 
 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
-    SendMessage32A( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
+    SendMessage32A( GetParent32((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
                     (hdc), (wndPtr)->hwndSelf )
 
 static HBITMAP hbitmapCheckBoxes = 0;
@@ -149,7 +149,7 @@
                                 ((infoPtr->state & 3) + 1), 0 );
                 break;
             }
-            SendMessage32A( GetParent(hWnd), WM_COMMAND,
+            SendMessage32A( GetParent32(hWnd), WM_COMMAND,
                             MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
         }
         break;
@@ -519,6 +519,6 @@
     dis.hDC        = hDC;
     dis.itemData   = 0;
     GetClientRect32( wndPtr->hwndSelf, &dis.rcItem );
-    SendMessage32A( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
+    SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_DRAWITEM,
                     wndPtr->wIDmenu, (LPARAM)&dis );
 }
diff --git a/controls/combo.c b/controls/combo.c
index aac742e..80a016b 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -131,7 +131,7 @@
   if (cstyle & CBS_SORT) style |= LBS_SORT;
   if (cstyle & CBS_HASSTRINGS) style |= LBS_HASSTRINGS;
   style |= LBS_NOTIFY;
-  CreateListBoxStruct(hwnd, ODT_COMBOBOX, style, GetParent(hwnd));
+  CreateListBoxStruct(hwnd, ODT_COMBOBOX, style, GetParent16(hwnd));
   CreateComboStruct(hwnd,cstyle);
 
   lphl = ComboGetListHeader(hwnd);
@@ -726,13 +726,13 @@
                                    InvalidateRect32(hwnd, NULL, TRUE); 
                                   }
                                  }
-                                 SendMessage16(GetParent(hwnd),WM_COMMAND,id,
+                                 SendMessage16(GetParent16(hwnd),WM_COMMAND,id,
                                          MAKELONG(hwnd, CBN_EDITUPDATE));
                                  break;
-                  case EN_CHANGE:SendMessage16(GetParent(hwnd),WM_COMMAND,id,
+                  case EN_CHANGE:SendMessage16(GetParent16(hwnd),WM_COMMAND,id,
                                          MAKELONG(hwnd, CBN_EDITCHANGE));
                                  break;
-                  case EN_ERRSPACE:SendMessage16(GetParent(hwnd),WM_COMMAND,id,
+                  case EN_ERRSPACE:SendMessage16(GetParent16(hwnd),WM_COMMAND,id,
                                          MAKELONG(hwnd, CBN_ERRSPACE));
                                  break;
                 }
@@ -886,7 +886,7 @@
   
   ListBoxSetCurSel(lphl, newFocused);
   ListBoxSendNotification(lphl, CBN_SELCHANGE);
-  SendMessage16(GetParent(hwnd), WM_COMMAND,ID_CLB,MAKELONG(0,CBN_SELCHANGE));
+  SendMessage16(GetParent16(hwnd), WM_COMMAND,ID_CLB,MAKELONG(0,CBN_SELCHANGE));
   lphl->ItemFocused = newFocused;
   ListBoxScrollToFocus(lphl);
   SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
@@ -1039,7 +1039,7 @@
   else if (lphl->PrevFocused != lphl->ItemFocused) 
           {
       		SendMessage16(CLBoxGetCombo(hwnd),CB_SETCURSEL,lphl->ItemFocused,0);
-      		SendMessage16(GetParent(hwnd), WM_COMMAND,ID_CLB,MAKELONG(0,CBN_SELCHANGE));
+      		SendMessage16(GetParent16(hwnd), WM_COMMAND,ID_CLB,MAKELONG(0,CBN_SELCHANGE));
       		ListBoxSendNotification(lphl, CBN_SELCHANGE);
      	  }
 
diff --git a/controls/listbox.c b/controls/listbox.c
index 7b81dea..8bf7c36 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -888,7 +888,7 @@
   LONG	       dwStyle = GetWindowLong32A(hwnd,GWL_STYLE);
   RECT16 rect;
 
-  CreateListBoxStruct(hwnd, ODT_LISTBOX, dwStyle, GetParent(hwnd));
+  CreateListBoxStruct(hwnd, ODT_LISTBOX, dwStyle, GetParent16(hwnd));
   lphl = ListBoxGetStorageHeader(hwnd);
   dprintf_listbox(stddeb,"ListBox created: lphl = %p dwStyle = %04x:%04x\n", 
 			  lphl, HIWORD(dwStyle), LOWORD(dwStyle));
@@ -2093,37 +2093,37 @@
      case WM_SETFOCUS: return LBSetFocus(hwnd, wParam, lParam);
      case WM_KILLFOCUS: return LBKillFocus(hwnd, wParam, lParam);
      case WM_NCCALCSIZE: return LBNCCalcSize(hwnd, wParam, lParam);
-     case LB_RESETCONTENT: return LBResetContent(hwnd, wParam, lParam);
-     case LB_DIR: return LBDir(hwnd, wParam, lParam);
-     case LB_ADDSTRING: return LBAddString(hwnd, wParam, lParam);
-     case LB_INSERTSTRING: return LBInsertString(hwnd, wParam, lParam);
-     case LB_DELETESTRING: return LBDeleteString(hwnd, wParam, lParam);
-     case LB_FINDSTRING: return LBFindString(hwnd, wParam, lParam);
-     case LB_FINDSTRINGEXACT: return LBFindStringExact(hwnd, wParam, lParam);
-     case LB_GETCARETINDEX: return LBGetCaretIndex(hwnd, wParam, lParam);
-     case LB_GETCOUNT: return LBGetCount(hwnd, wParam, lParam);
-     case LB_GETCURSEL: return LBGetCurSel(hwnd, wParam, lParam);
-     case LB_GETHORIZONTALEXTENT: return LBGetHorizontalExtent(hwnd, wParam, lParam);
-     case LB_GETITEMDATA: return LBGetItemData(hwnd, wParam, lParam);
-     case LB_GETITEMHEIGHT: return LBGetItemHeight(hwnd, wParam, lParam);
-     case LB_GETITEMRECT: return LBGetItemRect(hwnd, wParam, lParam);
-     case LB_GETSEL: return LBGetSel(hwnd, wParam, lParam);
-     case LB_GETSELCOUNT: return LBGetSelCount(hwnd, wParam, lParam);
-     case LB_GETSELITEMS: return LBGetSelItems(hwnd, wParam, lParam);
-     case LB_GETTEXT: return LBGetText(hwnd, wParam, lParam);
-     case LB_GETTEXTLEN: return LBGetTextLen(hwnd, wParam, lParam);
-     case LB_GETTOPINDEX: return LBGetTopIndex(hwnd, wParam, lParam);
-     case LB_SELECTSTRING: return LBSelectString(hwnd, wParam, lParam);
-     case LB_SELITEMRANGE: return LBSelItemRange(hwnd, wParam, lParam);
-     case LB_SETCARETINDEX: return LBSetCaretIndex(hwnd, wParam, lParam);
-     case LB_SETCOLUMNWIDTH: return LBSetColumnWidth(hwnd, wParam, lParam);
-     case LB_SETHORIZONTALEXTENT: return LBSetHorizontalExtent(hwnd, wParam, lParam);
-     case LB_SETITEMDATA: return LBSetItemData(hwnd, wParam, lParam);
-     case LB_SETTABSTOPS: return LBSetTabStops(hwnd, wParam, lParam);
-     case LB_SETCURSEL: return LBSetCurSel(hwnd, wParam, lParam);
-     case LB_SETSEL: return LBSetSel(hwnd, wParam, lParam);
-     case LB_SETTOPINDEX: return LBSetTopIndex(hwnd, wParam, lParam);
-     case LB_SETITEMHEIGHT: return LBSetItemHeight(hwnd, wParam, lParam);
+     case LB_RESETCONTENT16: return LBResetContent(hwnd, wParam, lParam);
+     case LB_DIR16: return LBDir(hwnd, wParam, lParam);
+     case LB_ADDSTRING16: return LBAddString(hwnd, wParam, lParam);
+     case LB_INSERTSTRING16: return LBInsertString(hwnd, wParam, lParam);
+     case LB_DELETESTRING16: return LBDeleteString(hwnd, wParam, lParam);
+     case LB_FINDSTRING16: return LBFindString(hwnd, wParam, lParam);
+     case LB_FINDSTRINGEXACT16: return LBFindStringExact(hwnd, wParam, lParam);
+     case LB_GETCARETINDEX16: return LBGetCaretIndex(hwnd, wParam, lParam);
+     case LB_GETCOUNT16: return LBGetCount(hwnd, wParam, lParam);
+     case LB_GETCURSEL16: return LBGetCurSel(hwnd, wParam, lParam);
+     case LB_GETHORIZONTALEXTENT16: return LBGetHorizontalExtent(hwnd, wParam, lParam);
+     case LB_GETITEMDATA16: return LBGetItemData(hwnd, wParam, lParam);
+     case LB_GETITEMHEIGHT16: return LBGetItemHeight(hwnd, wParam, lParam);
+     case LB_GETITEMRECT16: return LBGetItemRect(hwnd, wParam, lParam);
+     case LB_GETSEL16: return LBGetSel(hwnd, wParam, lParam);
+     case LB_GETSELCOUNT16: return LBGetSelCount(hwnd, wParam, lParam);
+     case LB_GETSELITEMS16: return LBGetSelItems(hwnd, wParam, lParam);
+     case LB_GETTEXT16: return LBGetText(hwnd, wParam, lParam);
+     case LB_GETTEXTLEN16: return LBGetTextLen(hwnd, wParam, lParam);
+     case LB_GETTOPINDEX16: return LBGetTopIndex(hwnd, wParam, lParam);
+     case LB_SELECTSTRING16: return LBSelectString(hwnd, wParam, lParam);
+     case LB_SELITEMRANGE16: return LBSelItemRange(hwnd, wParam, lParam);
+     case LB_SETCARETINDEX16: return LBSetCaretIndex(hwnd, wParam, lParam);
+     case LB_SETCOLUMNWIDTH16: return LBSetColumnWidth(hwnd, wParam, lParam);
+     case LB_SETHORIZONTALEXTENT16: return LBSetHorizontalExtent(hwnd, wParam, lParam);
+     case LB_SETITEMDATA16: return LBSetItemData(hwnd, wParam, lParam);
+     case LB_SETTABSTOPS16: return LBSetTabStops(hwnd, wParam, lParam);
+     case LB_SETCURSEL16: return LBSetCurSel(hwnd, wParam, lParam);
+     case LB_SETSEL16: return LBSetSel(hwnd, wParam, lParam);
+     case LB_SETTOPINDEX16: return LBSetTopIndex(hwnd, wParam, lParam);
+     case LB_SETITEMHEIGHT16: return LBSetItemHeight(hwnd, wParam, lParam);
 
      case WM_DROPFILES: return LBPassToParent(hwnd, message, wParam, lParam);
 
@@ -2133,8 +2133,8 @@
       * range of currently selected items when listbox is in the extended 
       * selection mode.
       */
-     case LB_SETANCHORINDEX: return LB_SETANCHORINDEX; /* that's what Windows returns */
-     case LB_GETANCHORINDEX: return 0;
+     case LB_SETANCHORINDEX16: return LB_SETANCHORINDEX16; /* that's what Windows returns */
+     case LB_GETANCHORINDEX16: return 0;
 
 	case WM_DROPOBJECT:
 	case WM_QUERYDROPOBJECT:
@@ -2164,10 +2164,10 @@
     INT i;
 
     dprintf_listbox( stddeb, "DlgDirSelect: %04x '%s' %d\n", hDlg, lpStr, id );
-    if ((i = SendDlgItemMessage16( hDlg, id, LB_GETCURSEL, 0, 0 )) == LB_ERR)
+    if ((i = SendDlgItemMessage16( hDlg, id, LB_GETCURSEL16, 0, 0 )) == LB_ERR)
         return FALSE;
     if (!(buffer = SEGPTR_ALLOC( 20 * sizeof(char) ))) return FALSE;
-    SendDlgItemMessage16(hDlg, id, LB_GETTEXT, i, (LPARAM)SEGPTR_GET(buffer) );
+    SendDlgItemMessage16(hDlg, id, LB_GETTEXT16, i, (LPARAM)SEGPTR_GET(buffer) );
     if (buffer[0] == '[')  /* drive or directory */
     {
         if (buffer[1] == '-')  /* drive */
@@ -2246,17 +2246,17 @@
         dprintf_listbox(stddeb, "ListBoxDirectory: path=%c:\\%s mask=%s\n",
                         'A' + drive, DRIVE_GetDosCwd(drive), mask);
         
-        SENDMSG( LB_RESETCONTENT, 0, 0 );
+        SENDMSG( LB_RESETCONTENT16, 0, 0 );
         if ((attrib & DDL_DIRECTORY) && !(attrib & DDL_EXCLUSIVE))
         {
             char *temp;
-            if (SENDMSG( LB_DIR, attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
+            if (SENDMSG( LB_DIR16, attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
                          (LPARAM)spec ) == LB_ERR) return FALSE;
             if (!(temp = SEGPTR_ALLOC( 4*sizeof(char) ))) return FALSE;
             strcpy( temp, "*.*" );
             /* FIXME: this won't work with PostMessage(), as temp will */
             /* have been freed by the time we do a DispatchMessage().  */
-            if (SENDMSG( LB_DIR, (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
+            if (SENDMSG( LB_DIR16, (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
                          (LPARAM)SEGPTR_GET(temp) ) == LB_ERR)
             {
                 SEGPTR_FREE(temp);
@@ -2266,7 +2266,7 @@
         }
         else
         {
-            if (SENDMSG( LB_DIR, attrib, (LPARAM)spec) == LB_ERR) return FALSE;
+            if (SENDMSG( LB_DIR16, attrib, (LPARAM)spec) == LB_ERR) return FALSE;
         }
     }
 
diff --git a/controls/scroll.c b/controls/scroll.c
index 4bc72d6..d198bbb 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -364,7 +364,7 @@
     {
         if (nBar == SB_CTL)  /* Only scrollbar controls send WM_CTLCOLOR */
         {
-            HBRUSH hbrush = SendMessage32A( GetParent(hwnd),
+            HBRUSH hbrush = SendMessage32A( GetParent32(hwnd),
                                             WM_CTLCOLORSCROLLBAR, hdc, hwnd );
             SelectObject( hdc, hbrush );
         }
@@ -519,7 +519,7 @@
     default:
         return;
     }
-    SendMessage32A( GetParent(hwnd),
+    SendMessage32A( GetParent32(hwnd),
                     (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
                     msg, hwnd );
 }
@@ -559,7 +559,7 @@
     hdc = (nBar == SB_CTL) ? GetDC(hwnd) : GetWindowDC(hwnd);
     vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
                                         &arrowSize, &thumbPos );
-    hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
+    hwndOwner = (nBar == SB_CTL) ? GetParent32(hwnd) : hwnd;
     hwndCtl   = (nBar == SB_CTL) ? hwnd : 0;
 
     switch(msg)
diff --git a/controls/static.c b/controls/static.c
index 7763ce2..8f91c6f 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -221,7 +221,7 @@
 	wFormat |= DT_NOPREFIX;
 
     if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
-    hBrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
+    hBrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
                              hdc, wndPtr->hwndSelf );
     if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
     FillRect16(hdc, &rc, hBrush);
@@ -275,7 +275,7 @@
     STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra;
 
     GetClientRect16( wndPtr->hwndSelf, &rc);
-    hbrush = SendMessage32A( GetParent(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
+    hbrush = SendMessage32A( GetParent32(wndPtr->hwndSelf), WM_CTLCOLORSTATIC,
                              hdc, wndPtr->hwndSelf );
     FillRect16( hdc, &rc, hbrush );
     if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
diff --git a/controls/status.c b/controls/status.c
index 0b6eb80..3217b2b 100644
--- a/controls/status.c
+++ b/controls/status.c
@@ -279,7 +279,7 @@
 	ReleaseDC(0, hdc);
     }
 
-    parent = GetParent(hwnd);
+    parent = GetParent32(hwnd);
     GetClientRect32(parent, &rect);
     width = rect.right - rect.left;
     height = (self->textHeight * 3)/2;
@@ -393,7 +393,7 @@
 
     if (flags == SIZE_RESTORED) {
 	/* width and height don't apply */
-	parent = GetParent(hwnd);
+	parent = GetParent32(hwnd);
 	GetClientRect32(parent, &parent_rect);
 	height = (self->textHeight * 3)/2;
 	width = parent_rect.right - parent_rect.left;
diff --git a/files/drive.c b/files/drive.c
index d6350c6..8695320 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -586,7 +586,7 @@
     {
     case TYPE_FLOPPY:  return DRIVE_REMOVABLE;
     case TYPE_HD:      return DRIVE_FIXED;
-    case TYPE_CDROM:   return DRIVE_REMOVABLE;
+    case TYPE_CDROM:   return DRIVE_REMOTE;
     case TYPE_NETWORK: return DRIVE_REMOTE;
     case TYPE_INVALID:
     default:           return DRIVE_CANNOTDETERMINE;
diff --git a/files/profile.c b/files/profile.c
index 63a3028..b7c0595 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -429,7 +429,10 @@
         fclose( file );
     }
     else
+    {
+        /* Does not exist yet, we will create it in PROFILE_FlushFile */
         fprintf( stderr, "Warning: profile file %s not found\n", newdos_name );
+    }
     dprintf_profile( stddeb, "PROFILE_Open(%s): successful\n", filename );
     return TRUE;
 }
diff --git a/if1632/commdlg.spec b/if1632/commdlg.spec
index 7f85c1d..5eb6181 100644
--- a/if1632/commdlg.spec
+++ b/if1632/commdlg.spec
@@ -1,22 +1,22 @@
 name	commdlg
 type	win16
 
-1   pascal16 GetOpenFileName(ptr) GetOpenFileName
-2   pascal16 GetSaveFileName(ptr) GetSaveFileName
+1   pascal16 GetOpenFileName(segptr) GetOpenFileName
+2   pascal16 GetSaveFileName(segptr) GetSaveFileName
 5   pascal16 ChooseColor(ptr) ChooseColor
 6   pascal   FileOpenDlgProc(word word word long) FileOpenDlgProc
 7   pascal   FileSaveDlgProc(word word word long) FileSaveDlgProc
 8   pascal   ColorDlgProc(word word word long) ColorDlgProc
 #9   pascal  LOADALTERBITMAP exported, shared data
-11  pascal16 FindText(ptr) FindText
-12  pascal16 ReplaceText(ptr) ReplaceText
+11  pascal16 FindText(segptr) FindText
+12  pascal16 ReplaceText(segptr) ReplaceText
 13  pascal   FindTextDlgProc(word word word long) FindTextDlgProc
 14  pascal   ReplaceTextDlgProc(word word word long) ReplaceTextDlgProc
 15  pascal16 ChooseFont(ptr) ChooseFont
 16  pascal16 FormatCharDlgProc(word word word long) FormatCharDlgProc
 18  pascal16 FontStyleEnumProc(ptr ptr word long)   FontStyleEnumProc
 19  pascal16 FontFamilyEnumProc(ptr ptr word long)  FontFamilyEnumProc
-20  pascal16 PrintDlg(ptr) PrintDlg
+20  pascal16 PrintDlg(segptr) PrintDlg
 21  pascal   PrintDlgProc(word word word long) PrintDlgProc
 22  pascal   PrintSetupDlgProc(word word word long) PrintSetupDlgProc
 #23  pascal  EDITINTEGERONLY exported, shared data
diff --git a/if1632/crtdll.spec b/if1632/crtdll.spec
index 733d405..b290cb0 100644
--- a/if1632/crtdll.spec
+++ b/if1632/crtdll.spec
@@ -284,12 +284,12 @@
 279 stub _splitpath
 280 stub _stat
 281 stub _statusfp
-282 stub _strcmpi
+282 cdecl _strcmpi(ptr ptr) lstrcmpi32A
 283 stub _strdate
 284 stub _strdec
 285 stub _strdup
 286 stub _strerror
-287 stub _stricmp
+287 cdecl _stricmp(ptr ptr) lstrcmpi32A
 288 stub _stricoll
 289 stub _strinc
 290 stub _strlwr
@@ -302,7 +302,7 @@
 297 stub _strset
 298 stub _strspnp
 299 stub _strtime
-300 stub _strupr
+300 cdecl _strupr(ptr) CRTDLL__strupr
 301 stub _swab
 302 stub _sys_errlist
 303 stub _sys_nerr_dll
@@ -341,29 +341,29 @@
 336 stub _y1
 337 stub _yn
 338 stub abort
-339 stub abs
-340 stub acos
+339 cdecl abs(long) CRTDLL_abs
+340 cdecl acos(long) CRTDLL_acos
 341 stub asctime
-342 stub asin
-343 stub atan
-344 stub atan2
+342 cdecl asin(long) CRTDLL_asin
+343 cdecl atan(long) CRTDLL_atan
+344 cdecl atan2(long long) CRTDLL_atan2
 345 stub atexit
-346 stub atof
-347 stub atoi
-348 stub atol
+346 cdecl atof(ptr) CRTDLL_atof
+347 cdecl atoi(ptr) CRTDLL_atoi
+348 cdecl atol(ptr) CRTDLL_atol
 349 stub bsearch
 350 stub calloc
 351 stub ceil
 352 stub clearerr
 353 stub clock
-354 stub cos
-355 stub cosh
+354 cdecl cos(long) CRTDLL_cos
+355 cdecl cosh(long) CRTDLL_cosh
 356 stub ctime
 357 stub difftime
 358 stub div
 359 cdecl exit(long) CRTDLL_exit
-360 stub exp
-361 stub fabs
+360 cdecl exp(long) CRTDLL_exp
+361 cdecl fabs(long) CRTDLL_fabs
 362 stub fclose
 363 stub feof
 364 stub ferror
@@ -380,7 +380,7 @@
 375 stub fputs
 376 stub fputwc
 377 stub fread
-378 stub free
+378 cdecl free(ptr) CRTDLL_free
 379 stub freopen
 380 stub frexp
 381 stub fscanf
@@ -420,16 +420,16 @@
 415 stub iswspace
 416 stub iswupper
 417 stub iswxdigit
-418 stub isxdigit
-419 stub labs
+418 cdecl isxdigit(long) CRTDLL_isxdigit
+419 cdecl labs(long) CRTDLL_labs
 420 stub ldexp
 421 stub ldiv
 422 stub localeconv
 423 stub localtime
-424 stub log
-425 stub log10
+424 cdecl log(long) CRTDLL_log
+425 cdecl log10(long) CRTDLL_log10
 426 stub longjmp
-427 stub malloc
+427 cdecl malloc(ptr) CRTDLL_malloc
 428 stub mblen
 429 stub mbstowcs
 430 stub mbtowc
@@ -441,14 +441,14 @@
 436 stub mktime
 437 stub modf
 438 stub perror
-439 stub pow
+439 cdecl pow(long long) CRTDLL_pow
 440 cdecl printf() CRTDLL_printf
 441 stub putc
 442 cdecl putchar(long) CRTDLL_putchar
 443 stub puts
 444 stub qsort
 445 stub raise
-446 stub rand
+446 cdecl rand() CRTDLL_rand
 447 stub realloc
 448 stub remove
 449 stub rename
@@ -458,10 +458,10 @@
 453 stub setlocale
 454 stub setvbuf
 455 stub signal
-456 stub sin
-457 stub sinh
+456 cdecl sin(long) CRTDLL_sin
+457 cdecl sinh(long) CRTDLL_sinh
 458 stub sprintf
-459 stub sqrt
+459 cdecl sqrt(long) CRTDLL_sqrt
 460 cdecl srand(long) CRTDLL_srand
 461 stub sscanf
 462 cdecl strcat(ptr ptr) lstrcat32A
@@ -488,8 +488,8 @@
 483 stub swprintf
 484 stub swscanf
 485 stub system
-486 stub tan
-487 stub tanh
+486 cdecl tan(long) CRTDLL_tan
+487 cdecl tanh(long) CRTDLL_tanh
 488 cdecl time(ptr) CRTDLL_time
 489 stub tmpfile
 490 stub tmpnam
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index bc5e616..e6f943a 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -145,8 +145,8 @@
 144 pascal16 CreateDirectory(ptr ptr) CreateDirectory16
 145 pascal16 RemoveDirectory(ptr) RemoveDirectory16
 146 pascal16 DeleteFile(ptr) DeleteFile16
-147 stub SetLastError
-148 stub GetLastError
+147 pascal16 SetLastError(long) SetLastError
+148 pascal16 GetLastError() GetLastError
 149 stub GetVersionEx
 150 pascal16 DirectedYield(word) DirectedYield
 151 stub WinOldApCall
diff --git a/if1632/user.spec b/if1632/user.spec
index 4819c68..a74189b 100644
--- a/if1632/user.spec
+++ b/if1632/user.spec
@@ -46,7 +46,7 @@
 43  pascal16 CloseWindow(word) CloseWindow
 44  pascal16 OpenIcon(word) OpenIcon
 45  pascal16 BringWindowToTop(word) BringWindowToTop
-46  pascal16 GetParent(word) GetParent
+46  pascal16 GetParent(word) GetParent16
 47  pascal16 IsWindow(word) IsWindow
 48  pascal16 IsChild(word word) IsChild
 49  pascal16 IsWindowVisible(word) IsWindowVisible
diff --git a/if1632/user32.spec b/if1632/user32.spec
index faff16a..a55b91f 100644
--- a/if1632/user32.spec
+++ b/if1632/user32.spec
@@ -281,7 +281,7 @@
 0274 stub GetNextDlgGroupItem
 0275 stub GetNextDlgTabItem
 0276 stub GetOpenClipboardWindow
-0277 stdcall GetParent(long) GetParent
+0277 stdcall GetParent(long) GetParent32
 0278 stub GetPriorityClipboardFormat
 0279 stub GetProcessWindowStation
 0280 stdcall GetPropA(long ptr) GetProp32A
@@ -292,7 +292,7 @@
 0285 stub GetScrollRange
 0286 stub GetShellWindow
 0287 stdcall GetSubMenu(long long) GetSubMenu
-0288 	stdcall GetSysColor(long) GetSysColor
+0288 stdcall GetSysColor(long) GetSysColor
 0289 stdcall GetSysColorBrush(long) GetSysColorBrush
 0290 stdcall GetSystemMenu(long long) GetSystemMenu
 0291 stdcall GetSystemMetrics(long) GetSystemMetrics
diff --git a/if1632/wsock32.spec b/if1632/wsock32.spec
index 67c7908..7d5a520 100644
--- a/if1632/wsock32.spec
+++ b/if1632/wsock32.spec
@@ -9,14 +9,14 @@
 005 stub getpeername
 006 stub getsockname
 007 stub getsockopt
-008 stub htonl
-009 stub htons
+008 stdcall htonl(long) htonl
+009 stdcall htons(long) htons
 010 stdcall inet_addr(ptr) inet_addr
 011 stdcall inet_ntoa(ptr) inet_ntoa
 012 stub ioctlsocket
 013 stub listen
 014 stub ntohl
-015 stub ntohs
+015 stdcall ntohs(long) ntohs
 016 stub recv
 017 stub recvfrom
 018 stub select
@@ -53,8 +53,9 @@
 # applications *should* 'degrade gracefully if these are not present
 # ... as it is, they don't
 #1000 stub WSApSetPostRoutine
-1100 stub inet_network
-1101 stub getnetbyname
+1001 stdcall WsControl(long long long long long long) WsControl
+1100 stdcall inet_network(ptr) inet_network
+1101 stdcall getnetbyname(ptr) getnetbyname
 #1102 stub rcmd
 #1103 stub rexec
 #1104 stub rresvport
diff --git a/include/commdlg.h b/include/commdlg.h
index 1a01a7c..83f794e 100644
--- a/include/commdlg.h
+++ b/include/commdlg.h
@@ -277,12 +277,12 @@
 
 BOOL  ChooseColor(LPCHOOSECOLOR lpChCol);
 DWORD CommDlgExtendedError(void);
-BOOL  FindText(LPFINDREPLACE lpFind);
+BOOL  FindText( SEGPTR find);
 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf);
-BOOL  GetOpenFileName(LPOPENFILENAME lpofn);
-BOOL  GetSaveFileName(LPOPENFILENAME lpofn);
-BOOL  PrintDlg(LPPRINTDLG lpPrint);
-BOOL  ReplaceText(LPFINDREPLACE lpFind);
+BOOL  GetOpenFileName(SEGPTR ofn);
+BOOL  GetSaveFileName(SEGPTR ofn);
+BOOL  PrintDlg( SEGPTR print);
+BOOL  ReplaceText( SEGPTR find);
 BOOL  ChooseFont(LPCHOOSEFONT lpChFont);
 
 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
diff --git a/include/dc.h b/include/dc.h
index 6356a6b..8f98b9c 100644
--- a/include/dc.h
+++ b/include/dc.h
@@ -10,6 +10,10 @@
 
 #include "gdi.h"
 
+#define CLIP_INTERSECT	0x0001
+#define CLIP_EXCLUDE	0x0002
+#define CLIP_KEEPRGN	0x0004
+
 extern void DC_InitDC( DC* dc );
 extern BOOL DC_SetupGCForPatBlt( DC * dc, GC gc, BOOL fMapColors );
 extern BOOL DC_SetupGCForBrush( DC * dc );
diff --git a/include/windows.h b/include/windows.h
index 988d8d7..96798f2 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -2572,39 +2572,117 @@
 #define LBS_STANDARD          (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER)
 
 /* Listbox messages */
-#define LB_ADDSTRING           (WM_USER+1)
-#define LB_INSERTSTRING        (WM_USER+2)
-#define LB_DELETESTRING        (WM_USER+3)
-#define LB_RESETCONTENT        (WM_USER+5)
-#define LB_SETSEL              (WM_USER+6)
-#define LB_SETCURSEL           (WM_USER+7)
-#define LB_GETSEL              (WM_USER+8)
-#define LB_GETCURSEL           (WM_USER+9)
-#define LB_GETTEXT             (WM_USER+10)
-#define LB_GETTEXTLEN          (WM_USER+11)
-#define LB_GETCOUNT            (WM_USER+12)
-#define LB_SELECTSTRING        (WM_USER+13)
-#define LB_DIR                 (WM_USER+14)
-#define LB_GETTOPINDEX         (WM_USER+15)
-#define LB_FINDSTRING          (WM_USER+16)
-#define LB_GETSELCOUNT         (WM_USER+17)
-#define LB_GETSELITEMS         (WM_USER+18)
-#define LB_SETTABSTOPS         (WM_USER+19)
-#define LB_GETHORIZONTALEXTENT (WM_USER+20)
-#define LB_SETHORIZONTALEXTENT (WM_USER+21)
-#define LB_SETCOLUMNWIDTH      (WM_USER+22)
-#define LB_SETTOPINDEX         (WM_USER+24)
-#define LB_GETITEMRECT         (WM_USER+25)
-#define LB_GETITEMDATA         (WM_USER+26)
-#define LB_SETITEMDATA         (WM_USER+27)
-#define LB_SELITEMRANGE        (WM_USER+28)
-#define LB_SETANCHORINDEX      (WM_USER+29) /* undoc. - for LBS_EXTENDEDSEL */
-#define LB_GETANCHORINDEX      (WM_USER+30) /* - * - */
-#define LB_SETCARETINDEX       (WM_USER+31)
-#define LB_GETCARETINDEX       (WM_USER+32)
-#define LB_SETITEMHEIGHT       (WM_USER+33)
-#define LB_GETITEMHEIGHT       (WM_USER+34)
-#define LB_FINDSTRINGEXACT     (WM_USER+35)
+#define LB_ADDSTRING16           (WM_USER+1)
+#define LB_ADDSTRING32           0x0180
+#define LB_ADDSTRING             WINELIB_NAME(LB_ADDSTRING)
+#define LB_INSERTSTRING16        (WM_USER+2)
+#define LB_INSERTSTRING32        0x0181
+#define LB_INSERTSTRING          WINELIB_NAME(LB_INSERTSTRING)
+#define LB_DELETESTRING16        (WM_USER+3)
+#define LB_DELETESTRING32        0x0182
+#define LB_DELETESTRING          WINELIB_NAME(LB_DELETESTRING)
+#define LB_SELITEMRANGEEX16      (WM_USER+4)
+#define LB_SELITEMRANGEEX32      0x0183
+#define LB_SELITEMRANGEEX        WINELIB_NAME(LB_SELITEMRANGEEX)
+#define LB_RESETCONTENT16        (WM_USER+5)
+#define LB_RESETCONTENT32        0x0184
+#define LB_RESETCONTENT          WINELIB_NAME(LB_RESETCONTENT)
+#define LB_SETSEL16              (WM_USER+6)
+#define LB_SETSEL32              0x0185
+#define LB_SETSEL                WINELIB_NAME(LB_SETSEL)
+#define LB_SETCURSEL16           (WM_USER+7)
+#define LB_SETCURSEL32           0x0186
+#define LB_SETCURSEL             WINELIB_NAME(LB_SETCURSEL)
+#define LB_GETSEL16              (WM_USER+8)
+#define LB_GETSEL32              0x0187
+#define LB_GETSEL                WINELIB_NAME(LB_GETSEL)
+#define LB_GETCURSEL16           (WM_USER+9)
+#define LB_GETCURSEL32           0x0188
+#define LB_GETCURSEL             WINELIB_NAME(LB_GETCURSEL)
+#define LB_GETTEXT16             (WM_USER+10)
+#define LB_GETTEXT32             0x0189
+#define LB_GETTEXT               WINELIB_NAME(LB_GETTEXT)
+#define LB_GETTEXTLEN16          (WM_USER+11)
+#define LB_GETTEXTLEN32          0x018a
+#define LB_GETTEXTLEN            WINELIB_NAME(LB_GETTEXTLEN)
+#define LB_GETCOUNT16            (WM_USER+12)
+#define LB_GETCOUNT32            0x018b
+#define LB_GETCOUNT              WINELIB_NAME(LB_GETCOUNT)
+#define LB_SELECTSTRING16        (WM_USER+13)
+#define LB_SELECTSTRING32        0x018c
+#define LB_SELECTSTRING          WINELIB_NAME(LB_SELECTSTRING)
+#define LB_DIR16                 (WM_USER+14)
+#define LB_DIR32                 0x018d
+#define LB_DIR                   WINELIB_NAME(LB_DIR)
+#define LB_GETTOPINDEX16         (WM_USER+15)
+#define LB_GETTOPINDEX32         0x018e
+#define LB_GETTOPINDEX           WINELIB_NAME(LB_GETTOPINDEX)
+#define LB_FINDSTRING16          (WM_USER+16)
+#define LB_FINDSTRING32          0x018f
+#define LB_FINDSTRING            WINELIB_NAME(LB_FINDSTRING)
+#define LB_GETSELCOUNT16         (WM_USER+17)
+#define LB_GETSELCOUNT32         0x0190
+#define LB_GETSELCOUNT           WINELIB_NAME(LB_GETSELCOUNT)
+#define LB_GETSELITEMS16         (WM_USER+18)
+#define LB_GETSELITEMS32         0x0191
+#define LB_GETSELITEMS           WINELIB_NAME(LB_GETSELITEMS)
+#define LB_SETTABSTOPS16         (WM_USER+19)
+#define LB_SETTABSTOPS32         0x0192
+#define LB_SETTABSTOPS           WINELIB_NAME(LB_SETTABSTOPS)
+#define LB_GETHORIZONTALEXTENT16 (WM_USER+20)
+#define LB_GETHORIZONTALEXTENT32 0x0193
+#define LB_GETHORIZONTALEXTENT   WINELIB_NAME(LB_GETHORIZONTALEXTENT)
+#define LB_SETHORIZONTALEXTENT16 (WM_USER+21)
+#define LB_SETHORIZONTALEXTENT32 0x0194
+#define LB_SETHORIZONTALEXTENT   WINELIB_NAME(LB_SETHORIZONTALEXTENT)
+#define LB_SETCOLUMNWIDTH16      (WM_USER+22)
+#define LB_SETCOLUMNWIDTH32      0x0195
+#define LB_SETCOLUMNWIDTH        WINELIB_NAME(LB_SETCOLUMNWIDTH)
+#define LB_ADDFILE16             (WM_USER+23)
+#define LB_ADDFILE32             0x0196
+#define LB_ADDFILE               WINELIB_NAME(LB_ADDFILE)
+#define LB_SETTOPINDEX16         (WM_USER+24)
+#define LB_SETTOPINDEX32         0x0197
+#define LB_SETTOPINDEX           WINELIB_NAME(LB_SETTOPINDEX)
+#define LB_GETITEMRECT16         (WM_USER+25)
+#define LB_GETITEMRECT32         0x0198
+#define LB_GETITEMRECT           WINELIB_NAME(LB_GETITEMRECT)
+#define LB_GETITEMDATA16         (WM_USER+26)
+#define LB_GETITEMDATA32         0x0199
+#define LB_GETITEMDATA           WINELIB_NAME(LB_GETITEMDATA)
+#define LB_SETITEMDATA16         (WM_USER+27)
+#define LB_SETITEMDATA32         0x019a
+#define LB_SETITEMDATA           WINELIB_NAME(LB_SETITEMDATA)
+#define LB_SELITEMRANGE16        (WM_USER+28)
+#define LB_SELITEMRANGE32        0x019b
+#define LB_SELITEMRANGE          WINELIB_NAME(LB_SELITEMRANGE)
+#define LB_SETANCHORINDEX16      (WM_USER+29)
+#define LB_SETANCHORINDEX32      0x019c
+#define LB_SETANCHORINDEX        WINELIB_NAME(LB_SETANCHORINDEX)
+#define LB_GETANCHORINDEX16      (WM_USER+30)
+#define LB_GETANCHORINDEX32      0x019d
+#define LB_GETANCHORINDEX        WINELIB_NAME(LB_GETANCHORINDEX)
+#define LB_SETCARETINDEX16       (WM_USER+31)
+#define LB_SETCARETINDEX32       0x019e
+#define LB_SETCARETINDEX         WINELIB_NAME(LB_SETCARETINDEX)
+#define LB_GETCARETINDEX16       (WM_USER+32)
+#define LB_GETCARETINDEX32       0x019f
+#define LB_GETCARETINDEX         WINELIB_NAME(LB_GETCARETINDEX)
+#define LB_SETITEMHEIGHT16       (WM_USER+33)
+#define LB_SETITEMHEIGHT32       0x01a0
+#define LB_SETITEMHEIGHT         WINELIB_NAME(LB_SETITEMHEIGHT)
+#define LB_GETITEMHEIGHT16       (WM_USER+34)
+#define LB_GETITEMHEIGHT32       0x01a1
+#define LB_GETITEMHEIGHT         WINELIB_NAME(LB_GETITEMHEIGHT)
+#define LB_FINDSTRINGEXACT16     (WM_USER+35)
+#define LB_FINDSTRINGEXACT32     0x01a2
+#define LB_FINDSTRINGEXACT       WINELIB_NAME(LB_FINDSTRINGEXACT)
+
+#define LB_SETLOCALE32           0x01a5
+#define LB_GETLOCALE32           0x01a6
+#define LB_SETCOUNT32            0x01a7
+#define LB_INITSTORAGE32         0x01a8
+#define LB_ITEMFROMPOINT32       0x01a9
 
 /* Listbox notification codes */
 #define LBN_ERRSPACE        (-2)
@@ -3587,6 +3665,8 @@
 LONG       GetBitmapBits(HBITMAP32,LONG,LPVOID);
 WORD       GetClassWord(HWND32,INT32);
 INT16      GetDlgCtrlID(HWND32);
+DWORD      GetLastError(void);
+COLORREF   GetSysColor(INT32);
 DWORD      GetTickCount(void);
 INT16      GetUpdateRgn(HWND32,HRGN32,BOOL32);
 WORD       GetWindowWord(HWND32,INT32);
@@ -3605,14 +3685,16 @@
 DWORD      RegCloseKey(HKEY);
 DWORD      RegFlushKey(HKEY);
 LONG       SetBitmapBits(HBITMAP32,LONG,LPCVOID);
+COLORREF   SetBkColor(HDC32,COLORREF);
 BOOL16     SetCaretBlinkTime(UINT32);
 BOOL16     SetCaretPos(INT32,INT32);
 WORD       SetClassWord(HWND32,INT32,WORD);
 INT16      SetDIBits(HDC32,HBITMAP32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
 INT16      SetDIBitsToDevice(HDC32,INT32,INT32,DWORD,DWORD,INT32,INT32,UINT32,UINT32,LPCVOID,const BITMAPINFO*,UINT32);
-VOID       SetLastError(DWORD); /* FIXME: not 100% sure it's only in win32 */
+VOID       SetLastError(DWORD);
 VOID       SetLastErrorEx(DWORD,DWORD);
 VOID       SetRectRgn(HRGN32,INT32,INT32,INT32,INT32);
+COLORREF   SetTextColor(HDC32,COLORREF);
 WORD       SetWindowWord(HWND32,INT32,WORD);
 BOOL16     ShowCaret(HWND32);
 HWND16     WindowFromDC(HDC32);
@@ -3970,6 +4052,9 @@
 INT32      GetObject32A(HANDLE32,INT32,LPVOID);
 INT32      GetObject32W(HANDLE32,INT32,LPVOID);
 #define    GetObject WINELIB_NAME_AW(GetObject)
+HWND16     GetParent16(HWND16);
+HWND32     GetParent32(HWND32);
+#define    GetParent WINELIB_NAME(GetParent)
 FARPROC16  GetProcAddress16(HMODULE16,SEGPTR);
 FARPROC32  GetProcAddress32(HMODULE32,LPCSTR);
 #define    GetProcAddress WINELIB_NAME(GetProcAddress)
@@ -4741,7 +4826,6 @@
 WORD       GetNumTasks(void);
 HWND       GetOpenClipboardWindow(void);
 WORD       GetPaletteEntries(HPALETTE16,WORD,WORD,LPPALETTEENTRY);
-HWND       GetParent(HWND);
 DWORD      GetPixel(HDC,short,short);
 WORD       GetPolyFillMode(HDC);
 int        GetPriorityClipboardFormat(WORD*,short);
@@ -4760,7 +4844,6 @@
 HANDLE     GetStockObject(int);
 WORD       GetStretchBltMode(HDC);
 HMENU      GetSubMenu(HMENU,short);
-COLORREF   GetSysColor(short);
 HMENU      GetSystemMenu(HWND,BOOL);
 int        GetSystemMetrics(WORD);
 WORD       GetSystemPaletteEntries(HDC,WORD,WORD,LPPALETTEENTRY);
@@ -4891,7 +4974,6 @@
 int        SelectVisRgn(HDC,HRGN);
 WORD       SelectorAccessRights(WORD,WORD,WORD);
 HWND       SetActiveWindow(HWND);
-COLORREF   SetBkColor(HDC,COLORREF);
 WORD       SetBkMode(HDC,WORD);
 HWND       SetCapture(HWND);
 HANDLE     SetClipboardData(WORD,HANDLE);
@@ -4939,7 +5021,6 @@
 HQUEUE16   SetTaskQueue(HTASK16,HQUEUE16);
 WORD       SetTextAlign(HDC,WORD);
 short      SetTextCharacterExtra(HDC,short);
-DWORD      SetTextColor(HDC,DWORD);
 short      SetTextJustification(HDC,short,short);
 int        SetVoiceAccent(int,int,int,int,int);
 int        SetVoiceEnvelope(int,int,int);
diff --git a/ipc/dde_proc.c b/ipc/dde_proc.c
index 36ca350..b78482d 100644
--- a/ipc/dde_proc.c
+++ b/ipc/dde_proc.c
@@ -521,14 +521,18 @@
  */
 void DDE_TestDDE(HWND hwnd)	   
 {
-
-  if (main_block != NULL)
+  static in_test = 0;
+  if (in_test++) return;
+  if (main_block != NULL) {
+     in_test--;
      return;
+  }
   dprintf_msg(stddeb,"DDE_TestDDE(0x%04x)\n", hwnd);
   if (hwnd==0)
       hwnd=-1;
   /* just send a message to see how things are going */
   SendMessage16( hwnd, WM_DDE_INITIATE, 0, 0);
+  in_test--;
 }
 
 void dde_proc_delete(int proc_idx)
diff --git a/loader/ne_image.c b/loader/ne_image.c
index a900e83..720ba89 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -524,7 +524,7 @@
     if (!(pModule = MODULE_GetPtr( hModule ))) return;
     if (pModule->flags & NE_FFLAGS_WIN32)
     {
-        PE_InitializeDLLs(hModule);
+/*        PE_InitializeDLLs(hModule); */
         return;
     }
     if (pModule->dlls_to_init)
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 87fc649..d4b4f13 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -547,16 +547,10 @@
 
     if (!(pModule->pe_module->pe_header->coff.Characteristics & IMAGE_FILE_DLL))
     {
-        int fs;
         TASK_CreateTask( hModule, hInstance, 0,
                          params->hEnvironment,
                          (LPSTR)PTR_SEG_TO_LIN( params->cmdLine ),
                          *((WORD*)PTR_SEG_TO_LIN(params->showCmd) + 1) );
-        fs=(int)GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, 0x10000 );
-        PE_InitTEB(fs);
-        /* FIXME: this should be done in the context of the new task */
-        __asm__ __volatile__("movw %w0,%%fs"::"r" (fs));
-        PE_InitializeDLLs( hModule );
     }
     return hInstance;
 }
@@ -566,6 +560,7 @@
 
 void PE_Win32CallToStart( SIGCONTEXT *context )
 {
+    int fs;
     HMODULE16 hModule;
     NE_MODULE *pModule;
 
@@ -574,6 +569,10 @@
     hModule = GetExePtr( GetCurrentTask() );
     pModule = MODULE_GetPtr( hModule );
     USER_InitApp( hModule );
+    fs=(int)GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, 0x10000 );
+    PE_InitTEB(fs);
+    __asm__ __volatile__("movw %w0,%%fs"::"r" (fs));
+    PE_InitializeDLLs( hModule );
     CallTaskStart32( (FARPROC32)(pModule->pe_module->load_addr + 
                                pModule->pe_module->pe_header->opt_coff.AddressOfEntryPoint) );
 }
diff --git a/memory/string.c b/memory/string.c
index 8dd57a2..8d49223 100644
--- a/memory/string.c
+++ b/memory/string.c
@@ -291,11 +291,8 @@
 
     if (!n) return 0;
     while ((--n > 0) && *str1)
-    {
-        if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
-        str1++;
-        str2++;
-    }
+      if ( (res = toupper(*str1++) - toupper(*str2++)) ) return res;
+
     return toupper(*str1) - toupper(*str2);
 }
 
diff --git a/misc/commdlg.c b/misc/commdlg.c
index d35ec48..84432c0 100644
--- a/misc/commdlg.c
+++ b/misc/commdlg.c
@@ -56,12 +56,13 @@
 /***********************************************************************
  *           GetOpenFileName   (COMMDLG.1)
  */
-BOOL GetOpenFileName(LPOPENFILENAME lpofn)
+BOOL GetOpenFileName( SEGPTR ofn )
 {
     HINSTANCE hInst;
     HANDLE hDlgTmpl, hResInfo;
     BOOL bRet;
-  
+    LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
+
     if (!lpofn || !FileDlg_Init()) return FALSE;
 
     if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
@@ -85,7 +86,7 @@
     hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
                         (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
-                        (DWORD)lpofn );
+                        ofn );
 
     if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
     {
@@ -102,11 +103,12 @@
 /***********************************************************************
  *           GetSaveFileName   (COMMDLG.2)
  */
-BOOL GetSaveFileName(LPOPENFILENAME lpofn)
+BOOL GetSaveFileName( SEGPTR ofn)
 {
     HINSTANCE hInst;
     HANDLE hDlgTmpl, hResInfo;
     BOOL bRet;
+    LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
   
     if (!lpofn || !FileDlg_Init()) return FALSE;
 
@@ -127,7 +129,7 @@
     hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
                         (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
-                        (DWORD)lpofn); 
+                        ofn );
     if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
     {
         if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
@@ -227,7 +229,7 @@
 	hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
 	SelectObject(lpdis->hDC, hBrush);
 	FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
-	SendMessage16(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
+	SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID, 
                       (LPARAM)SEGPTR_GET(str));
 
 	if (savedlg)       /* use _gray_ text in FileSaveDlg */
@@ -252,7 +254,7 @@
 	hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
 	SelectObject(lpdis->hDC, hBrush);
 	FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
-	SendMessage16(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
+	SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID, 
                       (LPARAM)SEGPTR_GET(str));
 
 	hBitmap = hFolder;
@@ -338,7 +340,7 @@
   char tmpstr[512];
   LPSTR pstr;
   SetWindowLong32A(hWnd, DWL_USER, lParam);
-  lpofn = (LPOPENFILENAME)lParam;
+  lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(lParam);
   if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
   /* read custom filter information */
   if (lpofn->lpstrCustomFilter)
@@ -440,11 +442,11 @@
       FILEDLG_StripEditControl(hWnd);
       if (notification == LBN_DBLCLK)
 	goto almost_ok;
-      lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
+      lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
       if (lRet == LB_ERR) return TRUE;
       if ((pstr = SEGPTR_ALLOC(512)))
       {
-          SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
+          SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
                                (LPARAM)SEGPTR_GET(pstr));
           SetDlgItemText32A( hWnd, edt1, pstr );
           SEGPTR_FREE(pstr);
@@ -459,10 +461,10 @@
       FILEDLG_StripEditControl(hWnd);
       if (notification == LBN_DBLCLK)
 	{
-	  lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL, 0, 0);
+	  lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
 	  if (lRet == LB_ERR) return TRUE;
           pstr = SEGPTR_ALLOC(512);
-	  SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT, lRet,
+	  SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
 			     (LPARAM)SEGPTR_GET(pstr));
           strcpy( tmpstr, pstr );
           SEGPTR_FREE(pstr);
@@ -582,8 +584,8 @@
 	lpofn->nFileExtension++;
       if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) 
 	{
-	  lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
-	  SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
+	  lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
+	  SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
                                lpofn->lpstrFileTitle );
 	}
       if (FILEDLG_HookCallChk(lpofn))
@@ -702,11 +704,12 @@
 /***********************************************************************
  *           FindTextDlg   (COMMDLG.11)
  */
-BOOL FindText(LPFINDREPLACE lpFind)
+BOOL FindText( SEGPTR find )
 {
     HANDLE hInst, hDlgTmpl;
     BOOL bRet;
     LPCVOID ptr;
+    LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
 
     /*
      * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
@@ -721,7 +724,7 @@
     if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
     bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
                         (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
-                        (DWORD)lpFind );
+                        find );
     GlobalUnlock16( hDlgTmpl );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
@@ -731,11 +734,12 @@
 /***********************************************************************
  *           ReplaceTextDlg   (COMMDLG.12)
  */
-BOOL ReplaceText(LPFINDREPLACE lpFind)
+BOOL ReplaceText( SEGPTR find )
 {
     HANDLE hInst, hDlgTmpl;
     BOOL bRet;
     LPCVOID ptr;
+    LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
 
     /*
      * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
@@ -750,7 +754,7 @@
     if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
     bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
                      (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
-                     (DWORD)lpFind );
+                     find );
     GlobalUnlock16( hDlgTmpl );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
@@ -765,7 +769,7 @@
     LPFINDREPLACE lpfr;
 
     SetWindowLong32A(hWnd, DWL_USER, lParam);
-    lpfr = (LPFINDREPLACE)lParam;
+    lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
     lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
     /*
      * FIXME : If the initial FindWhat string is empty, we should disable the
@@ -868,7 +872,7 @@
     LPFINDREPLACE lpfr;
 
     SetWindowLong32A(hWnd, DWL_USER, lParam);
-    lpfr = (LPFINDREPLACE)lParam;
+    lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
     lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
     /*
      * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
@@ -983,10 +987,11 @@
 /***********************************************************************
  *           PrintDlg   (COMMDLG.20)
  */
-BOOL PrintDlg(LPPRINTDLG lpPrint)
+BOOL PrintDlg( SEGPTR printdlg )
 {
     HANDLE hInst, hDlgTmpl;
     BOOL bRet;
+    LPPRINTDLG lpPrint = (LPPRINTDLG)PTR_SEG_TO_LIN(printdlg);
 
     dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
 
@@ -1004,7 +1009,7 @@
                                (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
                                 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
                                 MODULE_GetWndProcEntry16("PrintDlgProc")),
-                               (DWORD)lpPrint );
+                                printdlg );
     SYSRES_FreeResource( hDlgTmpl );
     return bRet;
 }
@@ -1139,7 +1144,7 @@
     hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChCol->hwndOwner,
                            (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
-                           (DWORD)lpChCol );
+                           (DWORD)lpChCol);
     if (!(lpChCol->Flags & CC_ENABLETEMPLATEHANDLE))
     {
         if (lpChCol->Flags & CC_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
@@ -2220,7 +2225,7 @@
     hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
     bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChFont->hwndOwner,
                       (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
-                      (DWORD)lpChFont );
+                      (DWORD)lpChFont);
     if (!(lpChFont->Flags & CF_ENABLETEMPLATEHANDLE))
     {
         if (lpChFont->Flags & CF_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
@@ -2263,7 +2268,7 @@
   int i;
   WORD w;
   HWND hwnd=LOWORD(lParam);
-  HWND hDlg=GetParent(hwnd);
+  HWND hDlg=GetParent16(hwnd);
   LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER); 
   LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
 
@@ -2380,7 +2385,7 @@
 {
   HWND hcmb2=LOWORD(lParam);
   HWND hcmb3=HIWORD(lParam);
-  HWND hDlg=GetParent(hcmb3);
+  HWND hDlg=GetParent16(hcmb3);
   LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER); 
   LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
   TEXTMETRIC16 *lptm = (TEXTMETRIC16 *)PTR_SEG_TO_LIN(metrics);
diff --git a/misc/crtdll.c b/misc/crtdll.c
index c87b28d..1b04915 100644
--- a/misc/crtdll.c
+++ b/misc/crtdll.c
@@ -4,6 +4,7 @@
  * Implements C run-time functionality as known from UNIX.
  *
  * Copyright 1996 Marcus Meissner
+ * Copyright 1996 Jukka Iivonen
  */
 
 #include <stdio.h>
@@ -12,6 +13,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <ctype.h>
+#include <math.h>
 #include "win.h"
 #include "windows.h"
 #include "stddebug.h"
@@ -35,6 +37,10 @@
 UINT32 CRTDLL_winminor_dll;     /* CRTDLL.330 */
 UINT32 CRTDLL_winver_dll;       /* CRTDLL.331 */
 
+
+/*********************************************************************
+ *                  _GetMainArgs  (CRTDLL.022)
+ */
 DWORD
 CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv,LPSTR *environ,DWORD flag)
 {
@@ -60,7 +66,6 @@
 	CRTDLL_osminor_dll     = version & 0xFF;
 	CRTDLL_osmajor_dll     = (version>>8) & 0xFF;
 
-	/* missing heapinit */
 	/* missing threading init */
 
 	i=0;xargv=NULL;xargc=0;afterlastspace=0;
@@ -93,8 +98,11 @@
 }
 
 typedef void (*_INITTERMFUN)();
-DWORD
-CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
+
+/*********************************************************************
+ *                  _initterm     (CRTDLL.135)
+ */
+DWORD CRTDLL__initterm(_INITTERMFUN *start,_INITTERMFUN *end)
 {
 	_INITTERMFUN	*current;
 
@@ -108,25 +116,37 @@
 	return 0;
 }
 
-void
-CRTDLL_srand(DWORD seed) {
+/*********************************************************************
+ *                  srand         (CRTDLL.460)
+ */
+void CRTDLL_srand(DWORD seed)
+{
 	/* FIXME: should of course be thread? process? local */
 	srand(seed);
 }
 
-int
-CRTDLL_fprintf(DWORD *args) {
+/*********************************************************************
+ *                  fprintf       (CRTDLL.373)
+ */
+int CRTDLL_fprintf(DWORD *args)
+{
 	/* FIXME: use args[0] */
 	return vfprintf(stderr,(LPSTR)(args[1]),args+2);
 }
 
-int
-CRTDLL_printf(DWORD *args) {
+/*********************************************************************
+ *                  printf        (CRTDLL.440)
+ */
+int CRTDLL_printf(DWORD *args)
+{
 	return vfprintf(stdout,(LPSTR)(args[0]),args+1);
 }
 
-time_t
-CRTDLL_time(time_t *timeptr) {
+/*********************************************************************
+ *                  time          (CRTDLL.488)
+ */
+time_t CRTDLL_time(time_t *timeptr)
+{
 	time_t	curtime = time(NULL);
 
 	if (timeptr)
@@ -134,14 +154,20 @@
 	return curtime;
 }
 
-BOOL32
-CRTDLL__isatty(DWORD x) {
+/*********************************************************************
+ *                  _isatty       (CRTDLL.137)
+ */
+BOOL32 CRTDLL__isatty(DWORD x)
+{
 	dprintf_crtdll(stderr,"CRTDLL__isatty(%ld)\n",x);
 	return TRUE;
 }
 
-INT32
-CRTDLL__write(DWORD x,LPVOID buf,DWORD len) {
+/*********************************************************************
+ *                  _write        (CRTDLL.332)
+ */
+INT32 CRTDLL__write(DWORD x,LPVOID buf,DWORD len)
+{
 	if (x<=2)
 		return write(x,buf,len);
 	/* hmm ... */
@@ -149,23 +175,143 @@
 	return len;
 }
 
-void
-CRTDLL_exit(DWORD ret) {
-	dprintf_crtdll(stderr,"CRTDLL_exit(%ld)\n",ret);
+
+/*********************************************************************
+ *                  exit          (CRTDLL.359)
+ */
+void CRTDLL_exit(DWORD ret)
+{
+        dprintf_crtdll(stderr,"CRTDLL_exit(%ld)\n",ret);
 	ExitProcess(ret);
 }
 
-void
-CRTDLL_fflush(DWORD x) {
-	dprintf_crtdll(stderr,"CRTDLL_fflush(%ld)\n",x);
+
+/*********************************************************************
+ *                  fflush        (CRTDLL.365)
+ */
+void CRTDLL_fflush(DWORD x)
+{
+    dprintf_crtdll(stderr,"CRTDLL_fflush(%ld)\n",x);
 }
 
-/* BAD, for the whole WINE process blocks... just done this way to test
- * windows95's ftp.exe.
+
+/*********************************************************************
+ *                  gets          (CRTDLL.391)
  */
-LPSTR 
-CRTDLL_gets(LPSTR buf) {
-	return gets(buf);
+LPSTR CRTDLL_gets(LPSTR buf)
+{
+  /* BAD, for the whole WINE process blocks... just done this way to test
+   * windows95's ftp.exe.
+   */
+    return gets(buf);
+}
+
+
+/*********************************************************************
+ *                  abs           (CRTDLL.339)
+ */
+INT32 CRTDLL_abs(INT32 x)
+{
+    return abs(x);
+}
+
+
+/*********************************************************************
+ *                  acos          (CRTDLL.340)
+ */
+float CRTDLL_acos(float x)
+{
+    return acos(x);
+}
+
+
+/*********************************************************************
+ *                  asin          (CRTDLL.342)
+ */
+float CRTDLL_asin(float x)
+{
+    return asin(x);
+}
+
+
+/*********************************************************************
+ *                  atan          (CRTDLL.343)
+ */
+float CRTDLL_atan(float x)
+{
+    return atan(x);
+}
+
+
+/*********************************************************************
+ *                  atan2         (CRTDLL.344)
+ */
+float CRTDLL_atan2(float x, float y)
+{
+    return atan2(x,y);
+}
+
+
+/*********************************************************************
+ *                  atof          (CRTDLL.346)
+ */
+float CRTDLL_atof(LPCSTR x)
+{
+    return atof(x);
+}
+
+
+/*********************************************************************
+ *                  atoi          (CRTDLL.347)
+ */
+INT32 CRTDLL_atoi(LPCSTR x)
+{
+    return atoi(x);
+}
+
+
+/*********************************************************************
+ *                  atol          (CRTDLL.348)
+ */
+LONG CRTDLL_atol(LPCSTR x)
+{
+    return atol(x);
+}
+
+
+/*********************************************************************
+ *                  cos           (CRTDLL.354)
+ */
+float CRTDLL_cos(float x)
+{
+    return cos(x);
+}
+
+
+/*********************************************************************
+ *                  cosh          (CRTDLL.355)
+ */
+float CRTDLL_cosh(float x)
+{
+    return cosh(x);
+}
+
+
+/*********************************************************************
+ *                  exp           (CRTDLL.360)
+ */
+float CRTDLL_exp(float x)
+{
+    return exp(x);
+}
+
+
+/*********************************************************************
+ *                  fabs          (CRTDLL.361)
+ */
+float CRTDLL_fabs(float x)
+{
+    return fabs(x);
 }
 
 
@@ -260,6 +406,105 @@
 
 
 /*********************************************************************
+ *                  isxdigit      (CRTDLL.418)
+ */
+CHAR CRTDLL_isxdigit(CHAR x)
+{
+    return isxdigit(x);
+}
+
+
+/*********************************************************************
+ *                  labs          (CRTDLL.419)
+ */
+LONG CRTDLL_labs(LONG x)
+{
+    return labs(x);
+}
+
+
+/*********************************************************************
+ *                  log           (CRTDLL.424)
+ */
+float CRTDLL_log(float x)
+{
+    return log(x);
+}
+
+
+/*********************************************************************
+ *                  log10         (CRTDLL.425)
+ */
+float CRTDLL_log10(float x)
+{
+    return log10(x);
+}
+
+
+/*********************************************************************
+ *                  pow           (CRTDLL.439)
+ */
+float CRTDLL_pow(float x, float y)
+{
+    return pow(x,y);
+}
+
+
+/*********************************************************************
+ *                  rand          (CRTDLL.446)
+ */
+INT32 CRTDLL_rand()
+{
+    return rand();
+}
+
+
+/*********************************************************************
+ *                  sin           (CRTDLL.456)
+ */
+float CRTDLL_sin(float x)
+{
+    return sin(x);
+}
+
+
+/*********************************************************************
+ *                  sinh          (CRTDLL.457)
+ */
+float CRTDLL_sinh(float x)
+{
+    return sinh(x);
+}
+
+
+/*********************************************************************
+ *                  sqrt          (CRTDLL.459)
+ */
+float CRTDLL_sqrt(float x)
+{
+    return sqrt(x);
+}
+
+
+/*********************************************************************
+ *                  tan           (CRTDLL.486)
+ */
+float CRTDLL_tan(float x)
+{
+    return tan(x);
+}
+
+
+/*********************************************************************
+ *                  tanh          (CRTDLL.487)
+ */
+float CRTDLL_tanh(float x)
+{
+    return tanh(x);
+}
+
+
+/*********************************************************************
  *                  tolower       (CRTDLL.491)
  */
 CHAR CRTDLL_tolower(CHAR x)
@@ -271,53 +516,102 @@
 /*********************************************************************
  *                  toupper       (CRTDLL.492)
  */
-CHAR CRTDLL_toupper(CHAR x) {
-	return toupper(x);
-}
-
-
-void
-CRTDLL_putchar(INT32 x) {
-	putchar(x);
-}
-
-int
-CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
+CHAR CRTDLL_toupper(CHAR x)
 {
-	do {
-		if (!*x)
-			return !!*y;
-		if (!*y)
-			return !!*x;
-		/* FIXME: MBCS handling... */
-		if (*x!=*y)
-			return 1;
-                x++;
-                y++;
-	} while (1);
+    return toupper(x);
 }
 
-unsigned char*
-CRTDLL__mbsinc(unsigned char *x)
+
+/*********************************************************************
+ *                  putchar       (CRTDLL.442)
+ */
+void CRTDLL_putchar(INT32 x)
+{
+    putchar(x);
+}
+
+
+/*********************************************************************
+ *                  _mbsicmp      (CRTDLL.204)
+ */
+int CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
+{
+    do {
+	if (!*x)
+	    return !!*y;
+	if (!*y)
+	    return !!*x;
+	/* FIXME: MBCS handling... */
+	if (*x!=*y)
+	    return 1;
+        x++;
+        y++;
+    } while (1);
+}
+
+
+/*********************************************************************
+ *                  _mbsinc       (CRTDLL.205)
+ */
+unsigned char* CRTDLL__mbsinc(unsigned char *x)
 {
     /* FIXME: mbcs */
     return x++;
 }
 
-int
-CRTDLL_vsprintf(DWORD *args)
+
+/*********************************************************************
+ *                  vsprintf      (CRTDLL.500)
+ */
+int CRTDLL_vsprintf(DWORD *args)
 {
     return vsprintf((char *)args[0],(char *)args[1],args+2);
 }
 
-unsigned char*
-CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
+
+/*********************************************************************
+ *                  _mbscpy       (CRTDLL.200)
+ */
+unsigned char* CRTDLL__mbscpy(unsigned char *x,unsigned char *y)
 {
     return strcpy(x,y);
 }
 
-unsigned char*
-CRTDLL__mbscat(unsigned char *x,unsigned char *y)
+
+/*********************************************************************
+ *                  _mbscat       (CRTDLL.197)
+ */
+unsigned char* CRTDLL__mbscat(unsigned char *x,unsigned char *y)
 {
     return strcat(x,y);
 }
+
+/*********************************************************************
+ *                  _strupr       (CRTDLL.300)
+ */
+CHAR* CRTDLL__strupr(CHAR *x)
+{
+	CHAR	*y=x;
+
+	while (*y) {
+		*y=toupper(*y);
+		y++;
+	}
+	return x;
+}
+
+/*********************************************************************
+ *                  malloc        (CRTDLL.427)
+ */
+VOID* CRTDLL_malloc(DWORD size)
+{
+    return HeapAlloc(GetProcessHeap(),0,size);
+}
+
+/*********************************************************************
+ *                  free          (CRTDLL.427)
+ */
+VOID CRTDLL_free(LPVOID ptr)
+{
+    HeapFree(GetProcessHeap(),0,ptr);
+}
diff --git a/misc/ole2nls.c b/misc/ole2nls.c
index 297ca18..5690ec9 100644
--- a/misc/ole2nls.c
+++ b/misc/ole2nls.c
@@ -23,19 +23,36 @@
 /* Default sorting, neutral sublanguage */
     switch(Options.language)
     {
-    case LANG_En: return 0x09;
-    case LANG_Es: return 0x0a;
-    case LANG_De: return 0x07;
-    case LANG_No: return 0x14;
-    case LANG_Fr: return 0x0c;
-    case LANG_Fi: return 0x0b;
-    case LANG_Da: return 0x06;
-    case LANG_Cz: return 0x05;
-    case LANG_Eo: return 0x25; /* not official */
-    case LANG_It: return 0x10;
-    case LANG_Ko: return 0x12;
+ /* case LANG_Bu: return 0x02; */      /* Bulgarian */
+ /* case LANG_Ch: return 0x04; */      /* Chinese */
+    case LANG_Cz: return 0x05;         /* Czech */
+    case LANG_Da: return 0x06;         /* Danish */
+    case LANG_De: return 0x07;         /* German */
+ /* case LANG_Gr: return 0x08; */      /* Greek */
+    case LANG_En: return 0x09;         /* English */
+    case LANG_Es: return 0x0a;         /* Spanish */
+    case LANG_Fi: return 0x0b;         /* Finnish */
+    case LANG_Fr: return 0x0c;         /* French */
+ /* case LANG_Hu: return 0x0e; */      /* Hungarian */
+ /* case LANG_Ic: return 0x0f; */      /* Icelandic */
+    case LANG_It: return 0x10;         /* Italian */
+ /* case LANG_Jp: return 0x11; */      /* Japanese */
+    case LANG_Ko: return 0x12;         /* Korean */
+ /* case LANG_Du: return 0x13; */      /* Dutch */
+    case LANG_No: return 0x14;         /* Norwegian */
+ /* case LANG_Pl: return 0x15; */      /* Polish */
+ /* case LANG_Po: return 0x16; */      /* Portuguese */
+ /* case LANG_Ro: return 0x18; */      /* Romanian */
+ /* case LANG_Ru: return 0x19; */      /* Russian */
+ /* case LANG_Cr: return 0x1a; */      /* Croatian */
+ /* case LANG_Sl: return 0x1b; */      /* Slovak */
+ /* case LANG_Sw: return 0x1d; */      /* Swedish */
+ /* case LANG_Tu: return 0x1f; */      /* Turkish */
+ /* case LANG_Sv: return 0x24; */      /* Slovenian */
+    case LANG_Eo: return 0x25;         /* Esperanto (not official) */
+
     default:
-	return 0;  /* Neutral language */
+	return 0x00;                   /* Neutral language */
     }
 }
 
diff --git a/misc/spy.c b/misc/spy.c
index 1a58dd4..5b13fd7 100644
--- a/misc/spy.c
+++ b/misc/spy.c
@@ -221,16 +221,50 @@
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x0180 - Win32 Listboxes */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "LB_ADDSTRING32",           /* 0x0180 */
+    "LB_INSERTSTRING32",        /* 0x0181 */
+    "LB_DELETESTRING32",        /* 0x0182 */
+    "LB_SELITEMRANGEEX32",      /* 0x0183 */
+    "LB_RESETCONTENT32",        /* 0x0184 */
+    "LB_SETSEL32",              /* 0x0185 */
+    "LB_SETCURSEL32",           /* 0x0186 */
+    "LB_GETSEL32",              /* 0x0187 */
+    "LB_GETCURSEL32",           /* 0x0188 */
+    "LB_GETTEXT32",             /* 0x0189 */
+    "LB_GETTEXTLEN32",          /* 0x018a */
+    "LB_GETCOUNT32",            /* 0x018b */
+    "LB_SELECTSTRING32",        /* 0x018c */
+    "LB_DIR32",                 /* 0x018d */
+    "LB_GETTOPINDEX32",         /* 0x018e */
+    "LB_FINDSTRING32",          /* 0x018f */
 
-    /* 0x0190 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "LB_GETSELCOUNT32",         /* 0x0190 */
+    "LB_GETSELITEMS32",         /* 0x0191 */
+    "LB_SETTABSTOPS32",         /* 0x0192 */
+    "LB_GETHORIZONTALEXTENT32", /* 0x0193 */
+    "LB_SETHORIZONTALEXTENT32", /* 0x0194 */
+    "LB_SETCOLUMNWIDTH32",      /* 0x0195 */
+    "LB_ADDFILE32",             /* 0x0196 */
+    "LB_SETTOPINDEX32",         /* 0x0197 */
+    "LB_GETITEMRECT32",         /* 0x0198 */
+    "LB_GETITEMDATA32",         /* 0x0199 */
+    "LB_SETITEMDATA32",         /* 0x019a */
+    "LB_SELITEMRANGE32",        /* 0x019b */
+    "LB_SETANCHORINDEX32",      /* 0x019c */
+    "LB_GETANCHORINDEX32",      /* 0x019d */
+    "LB_SETCARETINDEX32",       /* 0x019e */
+    "LB_GETCARETINDEX32",       /* 0x019f */
 
-    /* 0x01A0 */
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "LB_SETITEMHEIGHT32",       /* 0x01a0 */
+    "LB_GETITEMHEIGHT32",       /* 0x01a1 */
+    "LB_FINDSTRINGEXACT32",     /* 0x01a2 */
+    NULL, NULL,
+    "LB_SETLOCALE32",           /* 0x01a5 */
+    "LB_GETLOCALE32",           /* 0x01a6 */
+    "LB_SETCOUNT32",            /* 0x01a7 */
+    "LB_INITSTORAGE32",         /* 0x01a8 */
+    "LB_ITEMFROMPOINT32",       /* 0x01a9 */
+    NULL, NULL, NULL, NULL, NULL, NULL,
 
     /* 0x01B0 */
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -429,7 +463,7 @@
 /***********************************************************************
  *           SPY_GetMsgName
  */
-static const char *SPY_GetMsgName( UINT msg )
+const char *SPY_GetMsgName( UINT msg )
 {
     static char buffer[20];
 
diff --git a/misc/winsocket.c b/misc/winsocket.c
index d90ff82..15bc731 100644
--- a/misc/winsocket.c
+++ b/misc/winsocket.c
@@ -1559,3 +1559,14 @@
 	}
 	return 0;
 }
+
+VOID
+WsControl(DWORD x1,DWORD x2,LPDWORD x3,LPDWORD x4,LPDWORD x5,LPDWORD x6) {
+	fprintf(stdnimp,"WsControl(%lx,%lx,%lx,%lx,%lx,%lx)\n",
+		x1,x2,x3,x4,x5,x6
+	);
+	fprintf(stdnimp,"WsControl(x,x,%lx,%lx,%lx,%lx)\n",
+		x3?*x3:0,x4?*x4:0,x5?*x5:0,x6?*x6:0
+	);
+	return;
+}
diff --git a/multimedia/audio.c b/multimedia/audio.c
index 196356f..4b4cbef 100644
--- a/multimedia/audio.c
+++ b/multimedia/audio.c
@@ -25,12 +25,14 @@
 
 #ifdef linux
 #include <linux/soundcard.h>
+#elif __FreeBSD__
+#include <machine/soundcard.h>
 #endif
 
 #include "stddebug.h"
 #include "debug.h"
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 #define SOUND_DEV "/dev/dsp"
 
 #ifdef SOUND_VERSION
@@ -774,7 +776,7 @@
 		return MMSYSERR_NOTENABLED;
 		}
 	IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size);
-	if (abuf_size < 4096 || abuf_size > 65536) {
+	if (abuf_size < 1024 || abuf_size > 65536) {
 		if (abuf_size == -1)
 			dprintf_mciwave(stddeb,"Linux 'wodOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
 		else
@@ -1073,7 +1075,7 @@
 	return MMSYSERR_NOERROR;
 }
 
-#endif /* linux */
+#endif /* linux || __FreeBSD__*/
 
 /**************************************************************************
 * 				wodMessage			[sample driver]
@@ -1083,7 +1085,7 @@
 {
 	dprintf_mciwave(stddeb,"wodMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
         switch(wMsg) {
 		case WODM_OPEN:
 			return wodOpen(wDevID, (LPWAVEOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
@@ -1133,7 +1135,7 @@
 
 /*-----------------------------------------------------------------------*/
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 
 /**************************************************************************
 * 				widGetDevCaps				[internal]
@@ -1223,7 +1225,7 @@
 		return MMSYSERR_NOTENABLED;
 		}
 	IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, abuf_size);
-	if (abuf_size < 4096 || abuf_size > 65536) {
+	if (abuf_size < 1024 || abuf_size > 65536) {
 		if (abuf_size == -1)
 			dprintf_mciwave(stddeb,"Linux 'widOpen' // IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
 		else
@@ -1532,7 +1534,7 @@
 	return MMSYSERR_NOERROR;
 }
 
-#endif /* linux */
+#endif /* linux || __FreeBSD__ */
 
 /**************************************************************************
 * 				widMessage			[sample driver]
@@ -1542,7 +1544,7 @@
 {
 	dprintf_mciwave(stddeb,"widMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
 			wDevID, wMsg, dwUser, dwParam1, dwParam2);
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	switch(wMsg) {
 		case WIDM_OPEN:
 			return widOpen(wDevID, (LPWAVEOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
@@ -1582,7 +1584,7 @@
 LONG WAVE_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mciwave(stddeb,"WAVE_DriverProc(%08lX, %04X, %04X, %08lX, %08lX)\n", 
 		dwDevID, hDriv, wMsg, dwParam1, dwParam2);
 	switch(wMsg) {
diff --git a/multimedia/mcianim.c b/multimedia/mcianim.c
index abfd6b0..ac22ac1 100644
--- a/multimedia/mcianim.c
+++ b/multimedia/mcianim.c
@@ -29,7 +29,7 @@
 #define ANIMFRAMES_PERMIN 	1800
 #define SECONDS_PERMIN	 	60
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 typedef struct {
     int     nUseCount;          /* Incremented for each shared open */
     BOOL    fShareable;         /* TRUE if first open was shareable */
@@ -57,7 +57,7 @@
 */
 static DWORD ANIM_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	LPSTR		lpstrElementName;
 	char		str[128];
 	dprintf_mcianim(stddeb,"ANIM_mciOpen(%04X, %08lX, %p);\n", 
@@ -115,7 +115,7 @@
 */
 static DWORD ANIM_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciClose(%u, %08lX, %p);\n", 
 				wDevID, dwParam, lpParms);
 	if (AnimDev[wDevID].lpdwTrackLen != NULL) free(AnimDev[wDevID].lpdwTrackLen);
@@ -130,7 +130,7 @@
 static DWORD ANIM_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciGetDevCaps(%u, %08lX, %p);\n", 
 				wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -186,7 +186,7 @@
 static DWORD ANIM_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
 {
 	DWORD	dwTime = 0;
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	UINT	wTrack;
 	UINT	wMinutes;
 	UINT	wSeconds;
@@ -240,7 +240,7 @@
 static DWORD ANIM_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
 {
 	DWORD	dwFrame = 0;
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	UINT	wTrack;
 	dprintf_mcianim(stddeb,"ANIM_CalcFrame(%u, %08lX, %lu);\n", 
 			wDevID, dwFormatType, dwTime);
@@ -288,7 +288,7 @@
 */
 static DWORD ANIM_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciInfo(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -322,7 +322,7 @@
 */
 static DWORD ANIM_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciStatus(%u, %08lX, %p);\n", 
 			wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -411,7 +411,7 @@
 */
 static DWORD ANIM_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int 	start, end;
 	dprintf_mcianim(stddeb,"ANIM_mciPlay(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
@@ -450,7 +450,7 @@
 */
 static DWORD ANIM_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciStop(%u, %08lX, %p);\n", 
 			wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -473,7 +473,7 @@
 */
 static DWORD ANIM_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciPause(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -496,7 +496,7 @@
 */
 static DWORD ANIM_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciResume(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -519,7 +519,7 @@
 */
 static DWORD ANIM_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	DWORD	dwRet;
 	MCI_PLAY_PARMS PlayParms;
 	dprintf_mcianim(stddeb,"ANIM_mciSeek(%u, %08lX, %p);\n", 
@@ -559,7 +559,7 @@
 */
 static DWORD ANIM_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_mcianim(stddeb,"ANIM_mciSet(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -608,7 +608,7 @@
 LONG ANIM_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	switch(wMsg) {
 		case DRV_LOAD:
 			return 1;
diff --git a/multimedia/mcicda.c b/multimedia/mcicda.c
index ed7a7f4..f654573 100644
--- a/multimedia/mcicda.c
+++ b/multimedia/mcicda.c
@@ -26,10 +26,17 @@
 #ifdef linux
 #include <linux/soundcard.h>
 #include <linux/cdrom.h>
+#elif __FreeBSD__
+#include <machine/soundcard.h>
+#include <sys/cdio.h>
 #endif
 
 #define SOUND_DEV "/dev/dsp"
+#ifdef __FreeBSD__
+#define CDAUDIO_DEV "/dev/rcd0c"
+#else
 #define CDAUDIO_DEV "/dev/cdrom"
+#endif
 
 #ifdef SOUND_VERSION
 #define IOCTL(a,b,c)		ioctl(a,b,&c)
@@ -44,7 +51,7 @@
 #define CDFRAMES_PERMIN 	4500
 #define SECONDS_PERMIN	 	60
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 typedef struct {
     int     nUseCount;          /* Incremented for each shared open */
     BOOL    fShareable;         /* TRUE if first open was shareable */
@@ -53,7 +60,11 @@
 	MCI_OPEN_PARMS openParms;
 	DWORD	dwTimeFormat;
 	int		unixdev;
+#ifdef linux
 	struct cdrom_subchnl	sc;
+#elif __FreeBSD__
+	struct cd_sub_channel_info	sc;
+#endif
 	int		mode;
 	UINT	nCurTrack;
 	DWORD	dwCurFrame;
@@ -76,16 +87,30 @@
 */
 static UINT CDAUDIO_GetNumberOfTracks(UINT wDevID)
 {
+#if defined(linux) || defined(__FreeBSD__)
 #ifdef linux
 	struct cdrom_tochdr	hdr;
+#elif __FreeBSD__
+	struct ioc_toc_header	hdr;
+#endif
 	if (CDADev[wDevID].nTracks == 0) {
-		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCHDR, &hdr)) {
+		if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+			  CDROMREADTOCHDR
+#elif __FreeBSD__
+			  CDIOREADTOCHEADER
+#endif
+			  , &hdr)) {
             		dprintf_cdaudio(stddeb,
 				"GetNumberOfTracks(%u) // Error occured !\n", 
 				wDevID);
 			return (WORD)-1;
 			}
+#ifdef linux
 		CDADev[wDevID].nTracks = hdr.cdth_trk1;
+#elif __FreeBSD__
+		CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1;
+#endif
 		}
 	return CDADev[wDevID].nTracks;
 #else
@@ -99,11 +124,16 @@
 */
 static BOOL CDAUDIO_GetTracksInfo(UINT wDevID)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int		i, length;
 	int		start, last_start = 0;
 	int		total_length = 0;
+#ifdef linux
 	struct cdrom_tocentry	entry;
+#elif __FreeBSD__
+	struct ioc_read_toc_entry	entry;
+	struct cd_toc_entry             toc_buffer;
+#endif
 	if (CDADev[wDevID].nTracks == 0) {
 		if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
 		}
@@ -129,18 +159,46 @@
 		(CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
 	for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
 		if (i == CDADev[wDevID].nTracks)
+#ifdef linux
 			entry.cdte_track = CDROM_LEADOUT;
+#elif __FreeBSD__
+#define LEADOUT 0xaa
+			entry.starting_track = LEADOUT; /* XXX */
+#endif
 		else
+#ifdef linux
 			entry.cdte_track = i + 1;
+#elif __FreeBSD__
+			entry.starting_track = i + 1;
+#endif
+#ifdef linux
 		entry.cdte_format = CDROM_MSF;
-		if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCENTRY, &entry)) {
+#elif __FreeBSD__
+		bzero((char *)&toc_buffer, sizeof(toc_buffer));
+		entry.address_format = CD_MSF_FORMAT;
+		entry.data_len = sizeof(toc_buffer);
+	        entry.data = &toc_buffer;
+#endif
+		if (ioctl(CDADev[wDevID].unixdev, 
+#ifdef linux
+			  CDROMREADTOCENTRY
+#elif __FreeBSD__
+			  CDIOREADTOCENTRYS
+#endif
+			  , &entry)) {
             		dprintf_cdaudio(stddeb,
 				"CDAUDIO_GetTracksInfo // error read entry\n");
 			return FALSE;
 			}
+#ifdef linux
 		start = CDFRAMES_PERSEC * (SECONDS_PERMIN * 
 			entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) + 
 			entry.cdte_addr.msf.frame;
+#elif __FreeBSD__
+		start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
+			toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) +
+        	        toc_buffer.addr.msf.frame;
+#endif
 		if (i == 0) {
 			last_start = start;
 			CDADev[wDevID].dwFirstOffset = start;
@@ -176,7 +234,7 @@
 */
 static DWORD CDAUDIO_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%04X, %08lX, %p);\n", 
 					wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -235,7 +293,7 @@
 */
 static DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %08lX, %p);\n", 
 		wDevID, dwParam, lpParms);
 	if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen);
@@ -251,7 +309,7 @@
 static DWORD CDAUDIO_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 						LPMCI_GETDEVCAPS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -305,7 +363,7 @@
 */
 static DWORD CDAUDIO_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -334,7 +392,7 @@
 static DWORD CDAUDIO_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
 {
 	DWORD	dwFrame = 0;
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	UINT	wTrack;
     
     	dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %08lX, %lu);\n", 
@@ -384,45 +442,108 @@
 */
 static BOOL CDAUDIO_GetCDStatus(UINT wDevID)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int		oldmode = CDADev[wDevID].mode;
+#ifdef __FreeBSD__
+	struct ioc_read_subchannel	read_sc;
+
+	read_sc.address_format = CD_MSF_FORMAT;
+	read_sc.data_format    = CD_CURRENT_POSITION;
+	read_sc.track          = 0;
+	read_sc.data_len       = sizeof(CDADev[wDevID].sc);
+	read_sc.data	       = (struct cd_sub_channel_info *)&CDADev[wDevID].sc;
+#elif linux
 	CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMSUBCHNL, &CDADev[wDevID].sc)) {
+#endif
+	if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+		  CDROMSUBCHNL, &CDADev[wDevID].sc
+#elif __FreeBSD__
+		  CDIOCREADSUBCHANNEL, &read_sc
+#endif
+		  )) {
         	dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // opened or no_media !\n");
 		CDADev[wDevID].mode = MCI_MODE_NOT_READY;
 		return TRUE;
 		}
-	switch (CDADev[wDevID].sc.cdsc_audiostatus) {
+	switch (
+#ifdef linux
+		CDADev[wDevID].sc.cdsc_audiostatus
+#elif __FreeBSD__
+		CDADev[wDevID].sc.header.audio_status
+#endif
+		) {
+#ifdef linux
 		case CDROM_AUDIO_INVALID:
+#elif __FreeBSD__
+		case CD_AS_AUDIO_INVALID:
+#endif
             		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // device doesn't support status, returning NOT_READY.\n");
+#ifdef linux
 			CDADev[wDevID].mode = MCI_MODE_NOT_READY;
+#elif __FreeBSD__
+			CDADev[wDevID].mode = MCI_MODE_STOP;
+#endif
 			break;
+#ifdef linux
 		case CDROM_AUDIO_NO_STATUS: 
+#elif __FreeBSD__
+		case CD_AS_NO_STATUS:
+#endif
 			CDADev[wDevID].mode = MCI_MODE_STOP;
             		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
 			break;
+#ifdef linux
 		case CDROM_AUDIO_PLAY: 
+#elif __FreeBSD__
+		case CD_AS_PLAY_IN_PROGRESS:
+#endif
 			CDADev[wDevID].mode = MCI_MODE_PLAY;
             		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
 			break;
+#ifdef linux
 		case CDROM_AUDIO_PAUSED:
+#elif __FreeBSD__
+		case CD_AS_PLAY_PAUSED:
+#endif
 			CDADev[wDevID].mode = MCI_MODE_PAUSE;
             		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
 			break;
 		default:
             		dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // status=%02X !\n",
-					CDADev[wDevID].sc.cdsc_audiostatus);
+#ifdef linux
+					CDADev[wDevID].sc.cdsc_audiostatus
+#elif __FreeBSD__
+					CDADev[wDevID].sc.header.audio_status
+#endif
+					);
 		}
+#ifdef linux
 	CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
 	CDADev[wDevID].dwCurFrame = 
 		CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
 		CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
 		CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
+#elif __FreeBSD__
+	CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.what.position.track_number;
+	CDADev[wDevID].dwCurFrame = 
+		CDFRAMES_PERMIN * CDADev[wDevID].sc.what.position.absaddr.msf.minute +
+		CDFRAMES_PERSEC * CDADev[wDevID].sc.what.position.absaddr.msf.second +
+		CDADev[wDevID].sc.what.position.absaddr.msf.frame;
+#endif
     	dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
+#ifdef linux
 		CDADev[wDevID].sc.cdsc_trk,
 		CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
 		CDADev[wDevID].sc.cdsc_absaddr.msf.second,
-		CDADev[wDevID].sc.cdsc_absaddr.msf.frame);
+		CDADev[wDevID].sc.cdsc_absaddr.msf.frame
+#elif __FreeBSD__
+		CDADev[wDevID].sc.what.position.track_number,
+		CDADev[wDevID].sc.what.position.absaddr.msf.minute,
+		CDADev[wDevID].sc.what.position.absaddr.msf.second,
+		CDADev[wDevID].sc.what.position.absaddr.msf.frame
+#endif
+			);
 	if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
 		if (!CDAUDIO_GetTracksInfo(wDevID)) {
             dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
@@ -442,7 +563,7 @@
 static DWORD CDAUDIO_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
 {
 	DWORD	dwTime = 0;
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	UINT	wTrack;
 	UINT	wMinutes;
 	UINT	wSeconds;
@@ -496,7 +617,7 @@
 */
 static DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -598,9 +719,13 @@
 */
 static DWORD CDAUDIO_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int 	start, end;
+#ifdef linux
 	struct 	cdrom_msf	msf;
+#elif __FreeBSD__
+	struct	ioc_play_msf	msf;
+#endif
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -622,23 +747,50 @@
 		}
 	start += CDADev[wDevID].dwFirstOffset;	
 	end += CDADev[wDevID].dwFirstOffset;
+#ifdef linux
 	msf.cdmsf_min0 = start / CDFRAMES_PERMIN;
 	msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
 	msf.cdmsf_frame0 = start % CDFRAMES_PERSEC;
 	msf.cdmsf_min1 = end / CDFRAMES_PERMIN;
 	msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
 	msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMSTART)) {
+#elif __FreeBSD__
+        msf.start_m     = start / CDFRAMES_PERMIN;
+        msf.start_s     = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
+        msf.start_f     = start % CDFRAMES_PERSEC;
+        msf.end_m       = end / CDFRAMES_PERMIN;
+        msf.end_s       = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
+        msf.end_f       = end % CDFRAMES_PERSEC;
+#endif
+	if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+		  CDROMSTART
+#elif __FreeBSD__
+		  CDIOCSTART
+#endif
+		  )) {
         	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // motor doesn't start !\n");
 		return MCIERR_HARDWARE;
 		}
-	if (ioctl(CDADev[wDevID].unixdev, CDROMPLAYMSF, &msf)) {
+	if (ioctl(CDADev[wDevID].unixdev, 
+#ifdef linux
+		  CDROMPLAYMSF
+#elif __FreeBSD__
+		  CDIOCPLAYMSF
+#endif
+		  , &msf)) {
         	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // device doesn't play !\n");
 		return MCIERR_HARDWARE;
 		}
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
+#ifdef linux
 		msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
-		msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
+		msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1
+#elif __FreeBSD__
+		msf.start_m, msf.start_s, msf.start_f,
+		msf.end_m,   msf.end_s,   msf.end_f
+#endif
+			);
 	CDADev[wDevID].mode = MCI_MODE_PLAY;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
@@ -660,11 +812,17 @@
 */
 static DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMSTOP)) return MCIERR_HARDWARE;
+	if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+		  CDROMSTOP
+#elif __FreeBSD__
+		  CDIOCSTOP
+#endif
+		  )) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
@@ -684,11 +842,17 @@
 */
 static DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMPAUSE)) return MCIERR_HARDWARE;
+	if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+		  CDROMPAUSE
+#elif __FreeBSD__
+		  CDIOCPAUSE
+#endif
+		  )) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_PAUSE;
 	if (dwFlags & MCI_NOTIFY) {
         dprintf_cdaudio(stddeb,
@@ -708,11 +872,17 @@
 */
 static DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) return MCIERR_HARDWARE;
+	if (ioctl(CDADev[wDevID].unixdev, 
+#ifdef linux
+		  CDROMRESUME
+#elif __FreeBSD__
+		  CDIOCRESUME
+#endif
+		  )) return MCIERR_HARDWARE;
 	CDADev[wDevID].mode = MCI_MODE_STOP;
 	if (dwFlags & MCI_NOTIFY) {
         	dprintf_cdaudio(stddeb,
@@ -732,13 +902,19 @@
 */
 static DWORD CDAUDIO_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	DWORD	dwRet;
 	MCI_PLAY_PARMS PlayParms;
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
-	if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) {
+	if (ioctl(CDADev[wDevID].unixdev,
+#ifdef linux
+		  CDROMRESUME
+#elif __FreeBSD__
+		  CDIOCRESUME
+#endif
+		  )) {
 		perror("ioctl CDROMRESUME");
 		return MCIERR_HARDWARE;
 	}
@@ -776,7 +952,7 @@
 */
 static DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
     	dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08lX, %p);\n", 
 		wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
@@ -805,13 +981,26 @@
 	if (dwFlags & MCI_SET_DOOR_OPEN) {
         	dprintf_cdaudio(stddeb,
 			"CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
+#ifdef __FreeBSD__
+		if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
+		if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
+		if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
+#elif linux
 		if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
+#endif
 		CDADev[wDevID].nTracks = 0;
 		}
 	if (dwFlags & MCI_SET_DOOR_CLOSED) {
         	dprintf_cdaudio(stddeb,
 			"CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
+#ifdef __FreeBSD__
+                if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
+                if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
+                if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
+#elif linux
 		if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
+			  /* XXX should it be ",1" ??? */
+#endif
 		CDADev[wDevID].nTracks = 0;
 		}
 	if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
@@ -837,7 +1026,7 @@
 LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 							DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	switch(wMsg) {
 		case DRV_LOAD:
 			return 1;
@@ -895,12 +1084,24 @@
 		case MCI_SET_DOOR_OPEN:
             		dprintf_cdaudio(stddeb,
 				"CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
+#ifdef __FreeBSD__
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
+#elif linux
 			if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
+#endif
 			CDADev[dwDevID].nTracks = 0;
 			return 0;
 		case MCI_SET_DOOR_CLOSED:
             		dprintf_cdaudio(stddeb,"CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
+#ifdef __FreeBSD__
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
+			if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
+#elif linux
 			if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
+#endif
 			CDADev[dwDevID].nTracks = 0;
 			return 0;
 		default:
diff --git a/multimedia/mcistring.c b/multimedia/mcistring.c
index 514f843..7959c8c 100644
--- a/multimedia/mcistring.c
+++ b/multimedia/mcistring.c
@@ -89,16 +89,6 @@
 		res=MCIERR_INVALID_DEVICE_NAME;\
 		break;\
 	}
-/* we need to have strings in 16 bit space for some things 
- * FIXME: this is bad.
- */
-#define	_MCI_STRDUP_TO_SEG(dest,source) {\
-	HANDLE	x;\
-	x=USER_HEAP_ALLOC(strlen(source));\
-	dest=(LPSTR)MAKELONG(x,USER_HeapSel);\
-	strcpy(PTR_SEG_TO_LIN(dest),source);\
-}
-
 /* print a DWORD in the specified timeformat */
 static void
 _MCISTR_printtf(char *buf,UINT uDevType,DWORD timef,DWORD val) {
@@ -315,7 +305,7 @@
 	s=strchr(dev,'!');
 	if (s!=NULL) {
 		*s++='\0';
-		_MCI_STRDUP_TO_SEG(pU->openParams.lpstrElementName,s);
+		pU->openParams.lpstrElementName=SEGPTR_GET(SEGPTR_STRDUP(s));
 	}
 	if (!STRCMP(dev,"cdaudio")) {
 		uDevTyp=MCI_DEVTYPE_CD_AUDIO;
@@ -328,37 +318,40 @@
 	} else if (!STRCMP(dev,"avivideo")) {
 		uDevTyp=MCI_DEVTYPE_DIGITAL_VIDEO;
 	} else {
+		SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName));
+		SEGPTR_FREE(pU);
 		return MCIERR_INVALID_DEVICE_NAME;
 	}
 	wDevID=0;
 	while(mciDrv[wDevID].wType) {
 		if (++wDevID>=MAXMCIDRIVERS) {
 			dprintf_mci(stddeb, __FILE__":MCISTR_Open:MAXMCIDRIVERS reached!\n");
+			SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName));
+			SEGPTR_FREE(pU);
 			return MCIERR_INTERNAL;
 		}
 	}
 	mciDrv[wDevID].wType		= uDevTyp;
 	mciDrv[wDevID].wDeviceID	= wDevID;
-	pU->openParams.dwCallback		= 0;
-	pU->openParams.wDeviceID		= wDevID;
+	pU->openParams.dwCallback	= 0;
+	pU->openParams.wDeviceID	= wDevID;
 	pU->ovlyopenParams.dwStyle	= 0; 
 	pU->animopenParams.dwStyle	= 0; 
-
-	_MCI_STRDUP_TO_SEG(pU->openParams.lpstrDeviceType,dev);
-	pU->openParams.lpstrAlias		= NULL;
+	pU->openParams.lpstrDeviceType	= SEGPTR_GET(SEGPTR_STRDUP(dev));
+	pU->openParams.lpstrAlias	= NULL;
 	dwFlags |= MCI_OPEN_TYPE;
 	i=0;
 	while (i<nrofkeywords) {
 		FLAG1("shareable",MCI_OPEN_SHAREABLE);
 		if (!strcmp(keywords[i],"alias") && (i+1<nrofkeywords)) {
 			dwFlags |= MCI_OPEN_ALIAS;
-			_MCI_STRDUP_TO_SEG(pU->openParams.lpstrAlias,keywords[i]);
+			pU->openParams.lpstrAlias=SEGPTR_GET(SEGPTR_STRDUP(keywords[i]));
 			i+=2;
 			continue;
 		}
 		if (!strcmp(keywords[i],"element") && (i+1<nrofkeywords)) {
 			dwFlags |= MCI_OPEN_ELEMENT;
-			_MCI_STRDUP_TO_SEG(pU->openParams.lpstrElementName,keywords[i]);
+			pU->openParams.lpstrElementName=SEGPTR_GET(SEGPTR_STRDUP(keywords[i]));
 			i+=2;
 			continue;
 		}
@@ -429,7 +422,12 @@
 	_MCI_CALL_DRIVER( MCI_OPEN, SEGPTR_GET(pU) );
 	if (res==0)
 		memcpy(&mciOpenDrv[wDevID],&pU->openParams,sizeof(MCI_OPEN_PARMS));
-        SEGPTR_FREE(pU);
+	else {
+		SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrElementName));
+		SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrDeviceType));
+		SEGPTR_FREE(PTR_SEG_TO_LIN(pU->openParams.lpstrAlias));
+	}
+	SEGPTR_FREE(pU);
 	return res;
 }
 
diff --git a/multimedia/midi.c b/multimedia/midi.c
index 2d9e67f..6c38c30 100644
--- a/multimedia/midi.c
+++ b/multimedia/midi.c
@@ -26,9 +26,11 @@
 
 #ifdef linux
 #include <linux/soundcard.h>
+#elif __FreeBSD__
+#include <machine/soundcard.h>
 #endif
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 #define MIDI_DEV "/dev/sequencer"
 
 #ifdef SOUND_VERSION
@@ -89,7 +91,7 @@
 static DWORD MIDI_NotifyClient(UINT wDevID, WORD wMsg, 
 				DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	if (MidiInDev[wDevID].wFlags != DCB_NULL && !DriverCallback(
 		MidiInDev[wDevID].midiDesc.dwCallback, MidiInDev[wDevID].wFlags, 
 		MidiInDev[wDevID].midiDesc.hMidi, wMsg, 
@@ -109,7 +111,7 @@
 */
 static DWORD MIDI_ReadByte(UINT wDevID, BYTE *lpbyt)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	if (lpbyt != NULL) {
 		if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)lpbyt,
 			(long) sizeof(BYTE)) == (long) sizeof(BYTE)) {
@@ -196,7 +198,7 @@
 */
 static DWORD MIDI_ReadMThd(UINT wDevID, DWORD dwOffset)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	DWORD	toberead;
 	FOURCC	fourcc;
 	dprintf_midi(stddeb, "MIDI_ReadMThd(%04X, %08lX);\n", wDevID, dwOffset);
@@ -239,7 +241,7 @@
 
 static DWORD MIDI_ReadMTrk(UINT wDevID, DWORD dwOffset)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	DWORD	toberead;
 	FOURCC	fourcc;
 	if (mmioSeek(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) {
@@ -267,7 +269,7 @@
 */
 static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	MIDIOPENDESC 	MidiDesc;
 	DWORD		dwRet;
 	DWORD		dwOffset;
@@ -362,7 +364,7 @@
 */
 static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciStop(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
@@ -380,7 +382,7 @@
 */
 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	DWORD		dwRet;
 	dprintf_midi(stddeb, "MIDI_mciClose(%u, %08lX, %p);\n", wDevID, dwParam, lpParms);
 	if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
@@ -411,7 +413,7 @@
 */
 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int			count;
 	int			start, end;
 	LPMIDIHDR	lpMidiHdr;
@@ -501,7 +503,7 @@
 */
 static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int			start, end;
 	LPMIDIHDR	lpMidiHdr;
 	DWORD		dwRet;
@@ -563,7 +565,7 @@
 */
 static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciPause(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
@@ -578,7 +580,7 @@
 */
 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciResume(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	return 0;
@@ -593,7 +595,7 @@
 */
 static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciSet(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	dprintf_midi(stddeb, "MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
@@ -659,7 +661,7 @@
 */
 static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciStatus(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_STATUS_ITEM) {
@@ -748,7 +750,7 @@
 static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags, 
 					LPMCI_GETDEVCAPS_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciGetDevCaps(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	if (dwFlags & MCI_GETDEVCAPS_ITEM) {
@@ -795,7 +797,7 @@
 */
 static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "MIDI_mciInfo(%u, %08lX, %p);\n", wDevID, dwFlags, lpParms);
 	if (lpParms == NULL) return MCIERR_INTERNAL;
 	lpParms->lpstrReturn = NULL;
@@ -837,7 +839,7 @@
 */
 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int		midi;
 	dprintf_midi(stddeb,
 		"midOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
@@ -892,7 +894,7 @@
 */
 static DWORD midClose(WORD wDevID)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "midClose(%u);\n", wDevID);
 	if (MidiInDev[wDevID].unixdev == 0) {
 		dprintf_midi(stddeb,"Linux 'midClose' // can't close !\n");
@@ -1021,7 +1023,7 @@
 */
 static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
 {								 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int		midi;
 	dprintf_midi(stddeb,
 		"modOpen(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
@@ -1079,7 +1081,7 @@
 */
 static DWORD modClose(WORD wDevID)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb, "modClose(%u);\n", wDevID);
 	if (MidiOutDev[wDevID].unixdev == 0) {
 		dprintf_midi(stddeb,"Linux 'modClose' // can't close !\n");
@@ -1103,7 +1105,7 @@
 */
 static DWORD modData(WORD wDevID, DWORD dwParam)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	WORD	event;
 	dprintf_midi(stddeb,	
 		"modData(%u, %08lX);\n", wDevID, dwParam);
@@ -1128,7 +1130,7 @@
 */
 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	int		count;
 	LPWORD	ptr;
 	dprintf_midi(stddeb,	
@@ -1178,7 +1180,7 @@
 */
 static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb,
 		  "modPrepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
@@ -1205,7 +1207,7 @@
 */
 static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	dprintf_midi(stddeb,
 		"modUnprepare(%u, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
 	if (MidiOutDev[wDevID].unixdev == 0) {
@@ -1270,7 +1272,7 @@
 LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg, 
 						DWORD dwParam1, DWORD dwParam2)
 {
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD__)
 	switch(wMsg) {
 		case DRV_LOAD:
 			return 1;
diff --git a/objects/bitmap.c b/objects/bitmap.c
index b836e20..5b060b0 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -403,11 +403,16 @@
     HBITMAP prevHandle = dc->w.hBitmap;
     
     if (!(dc->w.flags & DC_MEMORY)) return 0;
-    hrgn = CreateRectRgn( 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
-    if (!hrgn) return 0;
 
-    DeleteObject( dc->w.hVisRgn );
-    dc->w.hVisRgn    = hrgn;
+    if (dc->w.hVisRgn)
+       SetRectRgn(dc->w.hVisRgn, 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
+    else
+    { 
+       hrgn = CreateRectRgn( 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
+       if (!hrgn) return 0;
+       dc->w.hVisRgn    = hrgn;
+    }
+
     dc->u.x.drawable = bmp->pixmap;
     dc->w.hBitmap    = hbitmap;
 
diff --git a/objects/clipping.c b/objects/clipping.c
index 8339a42..29a5cb4 100644
--- a/objects/clipping.c
+++ b/objects/clipping.c
@@ -159,32 +159,32 @@
 /***********************************************************************
  *           CLIPPING_IntersectClipRect
  *
- * Helper function for {Intersect,Exclude}ClipRect
+ * Helper function for {Intersect,Exclude}ClipRect, can be called from
+ * elsewhere (like ExtTextOut()) to skip redundant metafile update and
+ * coordinate conversion.
  */
-static int CLIPPING_IntersectClipRect( DC * dc, short left, short top,
-                                       short right, short bottom, BOOL exclude)
+int CLIPPING_IntersectClipRect( DC * dc, short left, short top,
+                                         short right, short bottom, UINT16 flags)
 {
-    HRGN tempRgn, newRgn;
-    int ret;
+    HRGN	newRgn;
+    int 	ret;
 
-    left   = XLPTODP( dc, left );
-    right  = XLPTODP( dc, right );
-    top    = YLPTODP( dc, top );
-    bottom = YLPTODP( dc, bottom );
-
-    if (!(newRgn = CreateRectRgn( 0, 0, 0, 0 ))) return ERROR;
-    if (!(tempRgn = CreateRectRgn( left, top, right, bottom )))
+    if ( !(newRgn = CreateRectRgn( left, top, right, bottom )) ) return ERROR;
+    if ( !dc->w.hClipRgn )
     {
-        DeleteObject( newRgn );
-        return ERROR;
+       if( flags & CLIP_INTERSECT )
+       {
+	   dc->w.hClipRgn = newRgn;
+	   CLIPPING_UpdateGCRegion( dc );
+       }
+       return SIMPLEREGION;
     }
-    ret = CombineRgn( newRgn, dc->w.hClipRgn ? dc->w.hClipRgn : dc->w.hVisRgn,
-                      tempRgn, exclude ? RGN_DIFF : RGN_AND);
-    DeleteObject( tempRgn );
 
+    ret = CombineRgn( newRgn, dc->w.hClipRgn, newRgn, 
+			     (flags & CLIP_EXCLUDE)? RGN_DIFF : RGN_AND);
     if (ret != ERROR)
     {
-        if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
+        if ( !(flags & CLIP_KEEPRGN) ) DeleteObject( dc->w.hClipRgn );
         dc->w.hClipRgn = newRgn;    
         CLIPPING_UpdateGCRegion( dc );
     }
@@ -208,9 +208,14 @@
 	return NULLREGION;   /* ?? */
     }
 
+    left   = XLPTODP( dc, left );
+    right  = XLPTODP( dc, right );
+    top    = YLPTODP( dc, top );
+    bottom = YLPTODP( dc, bottom );
+
     dprintf_clipping(stddeb, "ExcludeClipRect: %04x %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, TRUE );
+    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_EXCLUDE );
 }
 
 
@@ -229,9 +234,14 @@
 	return NULLREGION;   /* ?? */
     }
 
+    left   = XLPTODP( dc, left );
+    right  = XLPTODP( dc, right );
+    top    = YLPTODP( dc, top );
+    bottom = YLPTODP( dc, bottom );
+
     dprintf_clipping(stddeb, "IntersectClipRect: %04x %dx%d,%dx%d\n",
 	    hdc, left, top, right, bottom );
-    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, FALSE );
+    return CLIPPING_IntersectClipRect( dc, left, top, right, bottom, CLIP_INTERSECT );
 }
 
 
diff --git a/objects/dc.c b/objects/dc.c
index f8d552f..db20ea8 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -582,6 +582,8 @@
         return 0;
     }
 
+    DC_InitDC( dc );
+
     return handle;
 }
 
@@ -650,9 +652,9 @@
 
 
 /***********************************************************************
- *           SetBkColor    (GDI.1)
+ *           SetBkColor    (GDI.1) (GDI32.305)
  */
-COLORREF SetBkColor( HDC hdc, COLORREF color )
+COLORREF SetBkColor( HDC32 hdc, COLORREF color )
 {
     COLORREF oldColor;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
@@ -672,9 +674,9 @@
 
 
 /***********************************************************************
- *           SetTextColor    (GDI.9)
+ *           SetTextColor    (GDI.9) (GDI32.338)
  */
-COLORREF SetTextColor( HDC hdc, COLORREF color )
+COLORREF SetTextColor( HDC32 hdc, COLORREF color )
 {
     COLORREF oldColor;
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
diff --git a/objects/font.c b/objects/font.c
index 615569f..a632754 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -287,8 +287,9 @@
     metrics->tmHeight  = xfont->ascent + xfont->descent;
 
     metrics->tmInternalLeading  = 0;
-    if (XGetFontProperty( xfont, XA_X_HEIGHT, &prop ))
-	metrics->tmInternalLeading = xfont->ascent - (short)prop;
+    if (XGetFontProperty( xfont, XA_CAP_HEIGHT, &prop ))
+	metrics->tmInternalLeading = xfont->ascent+xfont->descent-(INT16)prop;
+
     metrics->tmExternalLeading  = 0;
     metrics->tmMaxCharWidth     = xfont->max_bounds.width;
     metrics->tmWeight           = logfont->lfWeight;
diff --git a/objects/metafile.c b/objects/metafile.c
index b273a54..5efb700 100644
--- a/objects/metafile.c
+++ b/objects/metafile.c
@@ -668,13 +668,22 @@
     case META_EXTTEXTOUT:
       {
         LPINT16 dxx;
-        s1=mr->rdParam[2];                              /* String length */
-        if (mr->rdSize-(s1+1))
-         dxx=&mr->rdParam[8+(s1+1)/2];                  /* start of array */
-        else
-         dxx=NULL;                                      /* NO array present */
-          
-	ExtTextOut16( hdc, mr->rdParam[1],              /* X position */
+        DWORD len;
+
+        s1 = mr->rdParam[2];                              /* String length */
+        len = sizeof(METARECORD) + (((s1 + 1) >> 1) * 2) + 2 * sizeof(short)
+         + sizeof(UINT16) + sizeof(RECT16);
+        if (mr->rdSize == len / 2)
+          dxx = NULL;                                    /* No array present */
+        else if (mr->rdSize == (len + s1 * sizeof(INT16)) / 2)
+          dxx = &mr->rdParam[8+(s1+1)/2];                /* start of array */
+        else {
+          fprintf(stderr,
+           "PlayMetaFileRecord ExtTextOut mr->rdSize = %08lx, count = %x\n",
+           mr->rdSize, s1);
+          dxx = NULL;
+        }
+        ExtTextOut16( hdc, mr->rdParam[1],              /* X position */
 	                   mr->rdParam[0],              /* Y position */
 	                   mr->rdParam[3],              /* options */
 	                   (LPRECT16) &mr->rdParam[4],  /* rectangle */
@@ -1247,7 +1256,8 @@
     HANDLE hmr;
     METARECORD *mr;
 
-    len = sizeof(METARECORD) + (((count + 1) >> 1) * 2) + 4 + sizeof(RECT16);
+    len = sizeof(METARECORD) + (((count + 1) >> 1) * 2) + 2 * sizeof(short)
+	    + sizeof(UINT16) + sizeof(RECT16);
     if (lpDx)
      len+=count*sizeof(INT16);
     if (!(hmr = GlobalAlloc16(GMEM_MOVEABLE, len)))
diff --git a/objects/text.c b/objects/text.c
index bbfb6d5..fbe88bc 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -31,6 +31,8 @@
 static int spacewidth;
 static int prefix_offset;
 
+extern int CLIPPING_IntersectClipRect( DC * dc, short left, short top,
+                                         short right, short bottom, UINT16 flags);
 
 static const char *TEXT_NextLine( HDC hdc, const char *str, int *count,
                                   char *dest, int *len, int width, WORD format)
@@ -321,10 +323,11 @@
                      const RECT16 *lprect, LPCSTR str, UINT16 count,
                      const INT16 *lpDx )
 {
-    int dir, ascent, descent, i;
+    HRGN	hRgnClip = 0;
+    int 	dir, ascent, descent, i;
     XCharStruct info;
     XFontStruct *font;
-    RECT16 rect;
+    RECT16 	rect;
 
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) 
@@ -442,8 +445,17 @@
 
     if (flags & ETO_CLIPPED)
     {
-        SaveVisRgn( hdc );
-        IntersectVisRect( hdc, rect.left, rect.top, rect.right, rect.bottom );
+       if (dc->w.flags & DC_MEMORY)
+       {
+	  hRgnClip = dc->w.hClipRgn;
+	  CLIPPING_IntersectClipRect(dc, rect.left, rect.top, rect.right, rect.bottom,
+					 CLIP_INTERSECT | CLIP_KEEPRGN);
+       }
+       else
+       { 
+          SaveVisRgn( hdc );
+          IntersectVisRect( hdc, rect.left, rect.top, rect.right, rect.bottom );
+       }
     }
 
       /* Draw the text background if necessary */
@@ -550,7 +562,13 @@
 		   dc->w.DCOrgX + x, dc->w.DCOrgY + y - lineAscent,
 		   dc->w.DCOrgX + x + info.width, dc->w.DCOrgY + y - lineAscent );
     }
-    if (flags & ETO_CLIPPED) RestoreVisRgn( hdc );
+
+    if (flags & ETO_CLIPPED) 
+    {
+	if( dc->w.flags & DC_MEMORY )
+	     SelectClipRgn( hdc, hRgnClip );
+	else RestoreVisRgn( hdc );
+    }
     return TRUE;
 }
 
diff --git a/win32/error.c b/win32/error.c
index 8f66793..5e8bdb8 100644
--- a/win32/error.c
+++ b/win32/error.c
@@ -99,7 +99,7 @@
 };
 
 /**********************************************************************
- *              GetLastError            (KERNEL32.227)
+ *              GetLastError   (KERNEL.148) (KERNEL32.227)
  */
 DWORD GetLastError(void)
 {
@@ -107,7 +107,7 @@
 }
 
 /**********************************************************************
- *              SetLastError            (KERNEL32.497)
+ *              SetLastError   (KERNEL.147) (KERNEL32.497)
  *
  * This is probably not used by apps too much, but it's useful for
  * our own internal use.
diff --git a/windows/defwnd.c b/windows/defwnd.c
index f67c44c..b79fa4b 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -186,7 +186,7 @@
 	    {
 		 if( wndPtr->flags & WIN_NCACTIVATED )
 		 {
-		   FillWindow( GetParent(wndPtr->hwndSelf), wndPtr->hwndSelf,
+		   FillWindow( GetParent16(wndPtr->hwndSelf), wndPtr->hwndSelf,
                                (HDC)wParam, sysColorObjects.hbrushActiveCaption );
 		   return 1;
 		 }
@@ -199,11 +199,11 @@
             {
                 HBRUSH hbrush = CreateSolidBrush( 
 			        GetSysColor(((DWORD)wndPtr->class->hbrBackground)-1));
-                 FillWindow( GetParent(wndPtr->hwndSelf), wndPtr->hwndSelf,
+                 FillWindow( GetParent16(wndPtr->hwndSelf), wndPtr->hwndSelf,
                              (HDC)wParam, hbrush);
                  DeleteObject (hbrush);
             }
-            else FillWindow( GetParent(wndPtr->hwndSelf), wndPtr->hwndSelf,
+            else FillWindow( GetParent16(wndPtr->hwndSelf), wndPtr->hwndSelf,
                                   (HDC)wParam, wndPtr->class->hbrBackground );
 	    return 1;
 	}
diff --git a/windows/event.c b/windows/event.c
index c59b378..fb32363 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -174,15 +174,18 @@
     {
     case KeyPress:
     case KeyRelease:
-	EVENT_key( (XKeyEvent*)event );
+        if (!HOOK_GetHook(WH_JOURNALPLAYBACK, 0) )
+            EVENT_key( (XKeyEvent*)event );
 	break;
 	
     case ButtonPress:
-	EVENT_ButtonPress( (XButtonEvent*)event );
+        if (!HOOK_GetHook(WH_JOURNALPLAYBACK, 0) )
+            EVENT_ButtonPress( (XButtonEvent*)event );
 	break;
 
     case ButtonRelease:
-	EVENT_ButtonRelease( (XButtonEvent*)event );
+        if (!HOOK_GetHook(WH_JOURNALPLAYBACK, 0) )
+            EVENT_ButtonRelease( (XButtonEvent*)event );
 	break;
 
     case MotionNotify:
@@ -194,9 +197,12 @@
 	   problems if the event order is important. I'm not yet seen
 	   of any problems. Jon 7/6/96.
 	 */
-        while (XCheckTypedWindowEvent(display, ((XAnyEvent *)event)->window,
-			  MotionNotify, event));    
-	EVENT_MotionNotify( (XMotionEvent*)event );
+	if (!HOOK_GetHook(WH_JOURNALPLAYBACK, 0) )
+	{
+            while (XCheckTypedWindowEvent(display,((XAnyEvent *)event)->window,
+                                          MotionNotify, event));    
+            EVENT_MotionNotify( (XMotionEvent*)event );
+	}
 	break;
 
     case FocusIn:
diff --git a/windows/mdi.c b/windows/mdi.c
index 96307bf..9dc0890 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -227,7 +227,7 @@
 
     if (!fRefresh) 
        {
-	HWND hwndFrame = GetParent(hwnd);
+	HWND hwndFrame = GetParent16(hwnd);
 	HMENU oldFrameMenu = GetMenu(hwndFrame);
         
 	if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
@@ -504,7 +504,7 @@
 
         if (flagDestroy)
 	   {
-	     MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
+	     MDI_PostUpdate(GetParent16(child), ci, SB_BOTH+1);
             DestroyWindow(child);
 	   }
     }
@@ -1329,7 +1329,7 @@
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
 
-    clientWnd  = WIN_FindWndPtr(GetParent(hwnd));
+    clientWnd  = WIN_FindWndPtr(GetParent16(hwnd));
     ci         = (MDICLIENTINFO *) clientWnd->wExtra;
 
     switch (message)
@@ -1471,7 +1471,7 @@
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
 
-    clientWnd  = WIN_FindWndPtr(GetParent(hwnd));
+    clientWnd  = WIN_FindWndPtr(GetParent16(hwnd));
     ci         = (MDICLIENTINFO *) clientWnd->wExtra;
 
     switch (message)
@@ -1523,7 +1523,7 @@
     MDICLIENTINFO       *ci;
     WND                 *clientWnd;
 
-    clientWnd  = WIN_FindWndPtr(GetParent(hwnd));
+    clientWnd  = WIN_FindWndPtr(GetParent16(hwnd));
     ci         = (MDICLIENTINFO *) clientWnd->wExtra;
 
     switch (message)
diff --git a/windows/message.c b/windows/message.c
index 4624478..b61ecb3 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -6,6 +6,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <sys/time.h>
 #include <sys/types.h>
 
@@ -31,8 +32,13 @@
 #define HWND_BROADCAST16  ((HWND16)0xffff)
 #define HWND_BROADCAST32  ((HWND32)0xffffffff)
 
-extern BYTE* 	KeyStateTable;				 /* event.c */
+#define ASCII_CHAR_HACK 0x0800 
+
 extern WPARAM	lastEventChar;				 /* event.c */
+extern BOOL MouseButtonsStates[3];
+extern BOOL AsyncMouseButtonsStates[3];
+extern BYTE KeyStateTable[256];
+extern BYTE AsyncKeyStateTable[256];
 
 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
 
@@ -263,8 +269,8 @@
         HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0,
                         (LPARAM)SEGPTR_GET(event) );
     }
-    else if ((msg->message >= WM_NCMOUSEMOVE) &&
-             (msg->message <= WM_NCMBUTTONDBLCLK))
+    else if ((msg->message >= WM_NCMOUSEFIRST) &&
+             (msg->message <= WM_NCMOUSELAST))
     {
         event->paramL = LOWORD(msg->lParam);       /* X pos */
         event->paramH = HIWORD(msg->lParam);       /* Y pos */ 
@@ -275,6 +281,108 @@
     SEGPTR_FREE(event);
 }
 
+/*****************************************************************
+ *              MSG_JournalPlayBackIsAscii
+ */
+static BOOL MSG_JournalPlayBackIsAscii(WPARAM wParam)
+{
+ return ((wParam>VK_HELP && wParam<VK_F1) || 
+          wParam == VK_SPACE  ||
+          wParam == VK_ESCAPE ||
+          wParam == VK_RETURN ||
+          wParam == VK_TAB    ||
+          wParam == VK_BACK);   
+}
+
+
+/***********************************************************************
+ *          MSG_JournalPlayBackMsg
+ *
+ * Get an EVENTMSG struct via call JOURNALPAYBACK hook function 
+ */
+static int MSG_JournalPlayBackMsg(void)
+{
+ EVENTMSG16 *tmpMsg;
+ long wtime,lParam;
+ WORD keyDown,i,wParam,result=0;
+
+ if ( HOOK_GetHook(WH_JOURNALPLAYBACK, 0) )
+ {
+  tmpMsg = SEGPTR_NEW(EVENTMSG16);
+  wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)SEGPTR_GET(tmpMsg));
+  /*  dprintf_msg(stddeb,"Playback wait time =%ld\n",wtime); */
+  if (wtime<=0)
+  {
+   wtime=0;
+   if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
+   {
+     wParam=tmpMsg->paramL & 0xFF;
+     lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
+     if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
+     {
+       for (keyDown=i=0; i<256 && !keyDown; i++)
+          if (KeyStateTable[i] & 0x80)
+            keyDown++;
+       if (!keyDown)
+         lParam |= 0x40000000;       
+       AsyncKeyStateTable[wParam]=KeyStateTable[wParam] |= 0x80;
+       if (MSG_JournalPlayBackIsAscii(wParam))
+       {
+         lastEventChar= wParam;         /* control TranslateMessage() */
+         lParam |= (LONG)((LONG)ASCII_CHAR_HACK*0x10000L);
+
+         if (!(KeyStateTable[VK_SHIFT] & 0x80) &&
+             !(KeyStateTable[VK_CAPITAL] & 0x80))
+           lastEventChar= tolower(lastEventChar);
+         if (KeyStateTable[VK_CONTROL] & 0x80)
+           lastEventChar&=0x1f;
+       }  
+     }  
+     else                                       /* WM_KEYUP, WM_SYSKEYUP */
+     {
+       lParam |= 0xC0000000;      
+       AsyncKeyStateTable[wParam]=KeyStateTable[wParam] &= ~0x80;
+     }
+     if (KeyStateTable[VK_MENU] & 0x80)
+       lParam |= 0x20000000;     
+     if (tmpMsg->paramH & 0x8000)              /*special_key bit*/
+       lParam |= 0x01000000;
+     hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );     
+   }
+   else
+   {
+    if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
+    {
+     switch (tmpMsg->message)
+     {
+      case WM_LBUTTONDOWN:MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=1;break;
+      case WM_LBUTTONUP:  MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=0;break;
+      case WM_MBUTTONDOWN:MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=1;break;
+      case WM_MBUTTONUP:  MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=0;break;
+      case WM_RBUTTONDOWN:MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=1;break;
+      case WM_RBUTTONUP:  MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=0;break;      
+     }
+     AsyncKeyStateTable[VK_LBUTTON]= KeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] << 8;
+     AsyncKeyStateTable[VK_MBUTTON]= KeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] << 8;
+     AsyncKeyStateTable[VK_RBUTTON]= KeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] << 8;
+     SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
+     lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
+     wParam=0;             
+     if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
+     if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
+     if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
+     hardware_event( tmpMsg->message, wParam, lParam,  
+                     tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
+    }
+   }
+   HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)SEGPTR_GET(tmpMsg));
+  }
+  else
+    result= QS_MOUSE | QS_KEY;
+  SEGPTR_FREE(tmpMsg);
+ }
+ return result;
+} 
 
 /***********************************************************************
  *           MSG_PeekHardwareMsg
@@ -490,6 +598,8 @@
             break;
         }
 
+        msgQueue->changeBits |= MSG_JournalPlayBackMsg();
+
         /* Now find a hardware event */
 
         if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
@@ -909,7 +1019,6 @@
  * This should call ToAscii but it is currently broken
  */
 
-#define ASCII_CHAR_HACK 0x0800
 
 BOOL TranslateMessage( LPMSG16 msg )
 {
diff --git a/windows/painting.c b/windows/painting.c
index 40f5dff..c1b3d09 100644
--- a/windows/painting.c
+++ b/windows/painting.c
@@ -219,7 +219,7 @@
  */
 HBRUSH GetControlBrush( HWND hwnd, HDC hdc, WORD control )
 {
-    return (HBRUSH)SendMessage32A( GetParent(hwnd), WM_CTLCOLOR+control,
+    return (HBRUSH)SendMessage32A( GetParent32(hwnd), WM_CTLCOLOR+control,
                                    (WPARAM)hdc, (LPARAM)hwnd );
 }
 
diff --git a/windows/syscolor.c b/windows/syscolor.c
index 3c3ddee..11f1ccd 100644
--- a/windows/syscolor.c
+++ b/windows/syscolor.c
@@ -145,10 +145,10 @@
 
 
 /*************************************************************************
- *             GetSysColor           (USER.180)
+ *             GetSysColor   (USER.180) (USER32.288)
  */
 
-COLORREF GetSysColor(short nIndex)
+COLORREF GetSysColor( INT32 nIndex )
 {
     dprintf_syscolor(stddeb,"System Color %d = %8lx\n", 
 		    nIndex, SysColors[nIndex]);
diff --git a/windows/win.c b/windows/win.c
index cbca5aa..626b35f 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -1473,9 +1473,18 @@
 
 
 /*****************************************************************
- *         GetParent              (USER.46)
+ *         GetParent16   (USER.46)
  */
-HWND GetParent(HWND hwnd)
+HWND16 GetParent16( HWND16 hwnd )
+{
+    return (HWND16)GetParent32( hwnd );
+}
+
+
+/*****************************************************************
+ *         GetParent32   (USER32.277)
+ */
+HWND32 GetParent32( HWND32 hwnd )
 {
     WND *wndPtr = WIN_FindWndPtr(hwnd);
     if (!wndPtr) return 0;
diff --git a/windows/winpos.c b/windows/winpos.c
index cfbb72e..ba64e4e 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -1832,7 +1832,7 @@
         }
 
         if ((winpos->hwnd == GetFocus()) || IsChild(winpos->hwnd, GetFocus()))
-            SetFocus( GetParent(winpos->hwnd) );  /* Revert focus to parent */
+            SetFocus( GetParent32(winpos->hwnd) ); /* Revert focus to parent */
 
 	if (winpos->hwnd == hwndActive)
 	{
diff --git a/windows/winproc.c b/windows/winproc.c
index d1c89d7..8f2cc95 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -390,11 +390,8 @@
         }
         return 1;
     case WM_ASKCBFORMATNAME:
-    case WM_COMPAREITEM:
-    case WM_DELETEITEM:
     case WM_DEVMODECHANGE:
     case WM_MDIACTIVATE:
-    case WM_MEASUREITEM:
     case WM_PAINTCLIPBOARD:
     case WM_SIZECLIPBOARD:
     case WM_WININICHANGE:
@@ -497,11 +494,8 @@
         }
         return 1;
     case WM_ASKCBFORMATNAME:
-    case WM_COMPAREITEM:
-    case WM_DELETEITEM:
     case WM_DEVMODECHANGE:
     case WM_MDIACTIVATE:
-    case WM_MEASUREITEM:
     case WM_PAINTCLIPBOARD:
     case WM_SIZECLIPBOARD:
     case WM_WININICHANGE:
@@ -570,17 +564,67 @@
     case WM_ACTIVATE:
     case WM_CHARTOITEM:
     case WM_COMMAND:
-    case WM_HSCROLL:
     case WM_VKEYTOITEM:
-    case WM_VSCROLL:
         *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
         *plparam   = (LPARAM)(HWND32)LOWORD(*plparam);
         return 0;
+    case WM_HSCROLL:
+    case WM_VSCROLL:
+        *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
+        *plparam   = (LPARAM)(HWND32)HIWORD(*plparam);
+        return 0;
     case WM_CTLCOLOR:
         *pmsg32    = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
         *pwparam32 = (WPARAM32)(HDC32)wParam16;
         *plparam   = (LPARAM)(HWND32)LOWORD(*plparam);
         return 0;
+    case WM_COMPAREITEM:
+        {
+            COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
+            COMPAREITEMSTRUCT32 *cis = (COMPAREITEMSTRUCT32 *)
+                                        HeapAlloc(SystemHeap, 0, sizeof(*cis));
+            if (!cis) return -1;
+            cis->CtlType    = cis16->CtlType;
+            cis->CtlID      = cis16->CtlID;
+            cis->hwndItem   = cis16->hwndItem;
+            cis->itemID1    = cis16->itemID1;
+            cis->itemData1  = cis16->itemData1;
+            cis->itemID2    = cis16->itemID2;
+            cis->itemData2  = cis16->itemData2;
+            cis->dwLocaleId = 0;  /* FIXME */
+            *plparam = (LPARAM)cis;
+        }
+        return 1;
+    case WM_DELETEITEM:
+        {
+            DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
+            DELETEITEMSTRUCT32 *dis = (DELETEITEMSTRUCT32 *)
+                                        HeapAlloc(SystemHeap, 0, sizeof(*dis));
+            if (!dis) return -1;
+            dis->CtlType  = dis16->CtlType;
+            dis->CtlID    = dis16->CtlID;
+            dis->hwndItem = dis16->hwndItem;
+            dis->itemData = dis16->itemData;
+            *plparam = (LPARAM)dis;
+        }
+        return 1;
+    case WM_MEASUREITEM:
+        {
+            MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
+            MEASUREITEMSTRUCT32 *mis = (MEASUREITEMSTRUCT32 *)
+                                        HeapAlloc(SystemHeap, 0,
+                                                sizeof(*mis) + sizeof(LPARAM));
+            if (!mis) return -1;
+            mis->CtlType    = mis16->CtlType;
+            mis->CtlID      = mis16->CtlID;
+            mis->itemID     = mis16->itemID;
+            mis->itemWidth  = mis16->itemWidth;
+            mis->itemHeight = mis16->itemHeight;
+            mis->itemData   = mis16->itemData;
+            *(LPARAM *)(mis + 1) = *plparam;  /* Store the previous lParam */
+            *plparam = (LPARAM)mis;
+        }
+        return 1;
     case WM_DRAWITEM:
         {
             DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
@@ -696,11 +740,8 @@
         }
         return 1;
     case WM_ASKCBFORMATNAME:
-    case WM_COMPAREITEM:
-    case WM_DELETEITEM:
     case WM_DEVMODECHANGE:
     case WM_MDIACTIVATE:
-    case WM_MEASUREITEM:
     case WM_PAINTCLIPBOARD:
     case WM_SIZECLIPBOARD:
     case WM_WININICHANGE:
@@ -723,9 +764,22 @@
 {
     switch(msg)
     {
+    case WM_COMPAREITEM:
+    case WM_DELETEITEM:
     case WM_DRAWITEM:
         HeapFree( SystemHeap, 0, (LPVOID)lParam );
         break;
+    case WM_MEASUREITEM:
+        {
+            MEASUREITEMSTRUCT16 *mis16;
+            MEASUREITEMSTRUCT32 *mis = (MEASUREITEMSTRUCT32 *)lParam;
+            lParam = *(LPARAM *)(mis + 1);
+            mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
+            mis16->itemWidth  = (UINT16)mis->itemWidth;
+            mis16->itemHeight = (UINT16)mis->itemHeight;
+            HeapFree( SystemHeap, 0, mis );
+        }
+        break;
     case WM_GETMINMAXINFO:
         {
             MINMAXINFO32 *mmi = (MINMAXINFO32 *)lParam;
@@ -931,6 +985,34 @@
         *plparam = MAKELPARAM( (HWND16)*plparam,
                                (WORD)msg32 - WM_CTLCOLORMSGBOX );
         return 0;
+    case WM_COMPAREITEM:
+        {
+            COMPAREITEMSTRUCT32 *cis32 = (COMPAREITEMSTRUCT32 *)*plparam;
+            COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
+            if (!cis) return -1;
+            cis->CtlType    = (UINT16)cis32->CtlType;
+            cis->CtlID      = (UINT16)cis32->CtlID;
+            cis->hwndItem   = (HWND16)cis32->hwndItem;
+            cis->itemID1    = (UINT16)cis32->itemID1;
+            cis->itemData1  = cis32->itemData1;
+            cis->itemID2    = (UINT16)cis32->itemID2;
+            cis->itemData2  = cis32->itemData2;
+            *plparam = (LPARAM)SEGPTR_GET(cis);
+        }
+        return 1;
+    case WM_DELETEITEM:
+        {
+            DELETEITEMSTRUCT32 *dis32 = (DELETEITEMSTRUCT32 *)*plparam;
+            DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
+            if (!dis) return -1;
+            dis->CtlType  = (UINT16)dis32->CtlType;
+            dis->CtlID    = (UINT16)dis32->CtlID;
+            dis->itemID   = (UINT16)dis32->itemID;
+            dis->hwndItem = (HWND16)dis32->hwndItem;
+            dis->itemData = dis32->itemData;
+            *plparam = (LPARAM)SEGPTR_GET(dis);
+        }
+        return 1;
     case WM_DRAWITEM:
         {
             DRAWITEMSTRUCT32 *dis32 = (DRAWITEMSTRUCT32 *)*plparam;
@@ -948,6 +1030,22 @@
             *plparam = (LPARAM)SEGPTR_GET(dis);
         }
         return 1;
+    case WM_MEASUREITEM:
+        {
+            MEASUREITEMSTRUCT32 *mis32 = (MEASUREITEMSTRUCT32 *)*plparam;
+            MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
+                                     SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
+            if (!mis) return -1;
+            mis->CtlType    = (UINT16)mis32->CtlType;
+            mis->CtlID      = (UINT16)mis32->CtlID;
+            mis->itemID     = (UINT16)mis32->itemID;
+            mis->itemWidth  = (UINT16)mis32->itemWidth;
+            mis->itemHeight = (UINT16)mis32->itemHeight;
+            mis->itemData   = mis32->itemData;
+            *(LPARAM *)(mis + 1) = *plparam;  /* Store the previous lParam */
+            *plparam = (LPARAM)SEGPTR_GET(mis);
+        }
+        return 1;
     case WM_GETMINMAXINFO:
         {
             MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
@@ -1055,11 +1153,8 @@
         }
         return 1;
     case WM_ASKCBFORMATNAME:
-    case WM_COMPAREITEM:
-    case WM_DELETEITEM:
     case WM_DEVMODECHANGE:
     case WM_MDIACTIVATE:
-    case WM_MEASUREITEM:
     case WM_PAINTCLIPBOARD:
     case WM_SIZECLIPBOARD:
     case WM_WININICHANGE:
@@ -1082,9 +1177,20 @@
 {
     switch(msg)
     {
+    case WM_COMPAREITEM:
+    case WM_DELETEITEM:
     case WM_DRAWITEM:
         SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
         break;
+    case WM_MEASUREITEM:
+        {
+            MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
+            MEASUREITEMSTRUCT32 *mis32 = *(MEASUREITEMSTRUCT32 **)(mis + 1);
+            mis32->itemWidth  = mis->itemWidth;
+            mis32->itemHeight = mis->itemHeight;
+            SEGPTR_FREE(mis);
+        }
+        break;
     case WM_GETMINMAXINFO:
         {
             MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam);