Fixed wownt32.h to make it usable from inside Wine, and use it to
avoid some duplication of the handle conversion macros.

diff --git a/controls/listbox.c b/controls/listbox.c
index 3606508..fd22195 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -25,6 +25,7 @@
 #include "wingdi.h"
 #include "wine/winuser16.h"
 #include "wine/winbase16.h"
+#include "wownt32.h"
 #include "wine/unicode.h"
 #include "winuser.h"
 #include "winerror.h"
diff --git a/controls/menu.c b/controls/menu.c
index 52742a5..0470e80 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -39,6 +39,7 @@
 #include "wingdi.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "wine/server.h"
 #include "wine/unicode.h"
 #include "win.h"
diff --git a/controls/static.c b/controls/static.c
index 3c07f0b..50042ba 100644
--- a/controls/static.c
+++ b/controls/static.c
@@ -21,6 +21,7 @@
 #include "windef.h"
 #include "wingdi.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "cursoricon.h"
 #include "controls.h"
 #include "user.h"
diff --git a/dlls/commdlg/cdlg.h b/dlls/commdlg/cdlg.h
index cb2e7af..3f5898c 100644
--- a/dlls/commdlg/cdlg.h
+++ b/dlls/commdlg/cdlg.h
@@ -23,10 +23,7 @@
 
 #include "dlgs.h"
 #include "wine/windef16.h"
-
-/* handle conversions */
-#define HWND_16(h32)		(LOWORD(h32))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
+#include "wownt32.h"
 
 /*---------------- 16-bit ----------------*/
 extern HINSTANCE16	COMMDLG_hInstance;
diff --git a/dlls/gdi/gdi16.c b/dlls/gdi/gdi16.c
index 38d95f3..6f4a234 100644
--- a/dlls/gdi/gdi16.c
+++ b/dlls/gdi/gdi16.c
@@ -20,6 +20,7 @@
 
 #include "winbase.h"
 #include "wingdi.h"
+#include "wownt32.h"
 #include "wine/wingdi16.h"
 #include "gdi.h"
 #include "wine/debug.h"
@@ -29,20 +30,6 @@
 #define HGDIOBJ_32(handle16)    ((HGDIOBJ)(ULONG_PTR)(handle16))
 #define HGDIOBJ_16(handle32)    ((HGDIOBJ16)(ULONG_PTR)(handle32))
 
-#define HDC_32(hdc16)           ((HDC)HGDIOBJ_32(hdc16))
-#define HRGN_32(hrgn16)         ((HRGN)HGDIOBJ_32(hrgn16))
-#define HBRUSH_32(hbrush16)     ((HBRUSH)HGDIOBJ_32(hbrush16))
-#define HBITMAP_32(hbitmap16)   ((HBITMAP)HGDIOBJ_32(hbitmap16))
-#define HPALETTE_32(hpalette16) ((HPALETTE)HGDIOBJ_32(hpalette16))
-
-#define HDC_16(hdc)             ((HDC16)HGDIOBJ_16(hdc))
-#define HPEN_16(hpen)           ((HPEN16)HGDIOBJ_16(hpen))
-#define HRGN_16(hrgn)           ((HRGN16)HGDIOBJ_16(hrgn))
-#define HFONT_16(hfont)         ((HFONT16)HGDIOBJ_16(hfont))
-#define HBRUSH_16(hbrush)       ((HBRUSH16)HGDIOBJ_16(hbrush))
-#define HBITMAP_16(hbitmap)     ((HBITMAP16)HGDIOBJ_16(hbitmap))
-#define HPALETTE_16(hpalette)   ((HPALETTE16)HGDIOBJ_16(hpalette))
-
 
 /* convert a LOGFONT16 to a LOGFONTW */
 static void logfont_16_to_W( const LOGFONT16 *font16, LPLOGFONTW font32 )
diff --git a/dlls/gdi/win16drv/prtdrv.c b/dlls/gdi/win16drv/prtdrv.c
index e2af31d..ab9165c 100644
--- a/dlls/gdi/win16drv/prtdrv.c
+++ b/dlls/gdi/win16drv/prtdrv.c
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include "wine/winbase16.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "win16drv/win16drv.h"
 #include "wine/debug.h"
 #include "bitmap.h"
@@ -63,8 +64,6 @@
 /* ### stop build ### */
 
 
-#define HWND_16(h32)		(LOWORD(h32))
-
 #define MAX_PRINTER_DRIVERS 	16
 static LOADED_PRINTER_DRIVER *gapLoadedPrinterDrivers[MAX_PRINTER_DRIVERS];
 
diff --git a/dlls/msvideo/msvideo16.c b/dlls/msvideo/msvideo16.c
index fc73570..73782fd 100644
--- a/dlls/msvideo/msvideo16.c
+++ b/dlls/msvideo/msvideo16.c
@@ -29,12 +29,10 @@
 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
 
 /* handle16 --> handle conversions */
-#define HDC_32(h16)		((HDC)(ULONG_PTR)(h16))
 #define HDRAWDIB_32(h16)	((HDRAWDIB)(ULONG_PTR)(h16))
 #define HIC_32(h16)		((HIC)(ULONG_PTR)(h16))
 
 /* handle --> handle16 conversions */
-#define HDC_16(h32)		(LOWORD(h32))
 #define HDRAWDIB_16(h32)	(LOWORD(h32))
 #define HIC_16(h32)		(LOWORD(h32))
 
diff --git a/dlls/msvideo/msvideo_main.c b/dlls/msvideo/msvideo_main.c
index 12fdde7..ee93509 100644
--- a/dlls/msvideo/msvideo_main.c
+++ b/dlls/msvideo/msvideo_main.c
@@ -47,7 +47,6 @@
 LRESULT MSVIDEO_SendMessage(HIC hic, UINT msg, DWORD lParam1, DWORD lParam2, BOOL bFrom32);
 
 #define HDRVR_16(h32)		(LOWORD(h32))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
 
 
 /***********************************************************************
diff --git a/dlls/msvideo/vfw16.h b/dlls/msvideo/vfw16.h
index 7d46da2..4fd4d94 100644
--- a/dlls/msvideo/vfw16.h
+++ b/dlls/msvideo/vfw16.h
@@ -20,6 +20,7 @@
 #define __WINE_VFW16_H
 
 #include "vfw.h"
+#include "wownt32.h"
 #include "wine/windef16.h"
 
 #ifdef __cplusplus
@@ -117,10 +118,6 @@
 HIC16   VFWAPI  ICOpenFunction16(DWORD,DWORD,UINT16,FARPROC16);
 LRESULT VFWAPI  ICSendMessage16(HIC16,UINT16,DWORD,DWORD);
 
-/* handle <-> handle16 conversions */
-#define HPALETTE_32(h16)	((HPALETTE)(ULONG_PTR)(h16))
-#define HPALETTE_16(h32)	(LOWORD(h32))
-
 #ifdef __cplusplus
 }
 #endif  /* __cplusplus */
diff --git a/dlls/ole32/ole2.c b/dlls/ole32/ole2.c
index fb4dc30..282f182 100644
--- a/dlls/ole32/ole2.c
+++ b/dlls/ole32/ole2.c
@@ -36,6 +36,7 @@
 #include "winerror.h"
 #include "winuser.h"
 #include "winreg.h"
+#include "wownt32.h"
 
 #include "wine/obj_clientserver.h"
 #include "wine/winbase16.h"
@@ -48,10 +49,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 WINE_DECLARE_DEBUG_CHANNEL(accel);
 
-#define HACCEL_16(h32)		(LOWORD(h32))
 #define HICON_16(h32)		(LOWORD(h32))
-
-#define HDC_32(h16)		((HDC)(ULONG_PTR)(h16))
 #define HICON_32(h16)		((HICON)(ULONG_PTR)(h16))
 
 /******************************************************************************
diff --git a/dlls/setupapi/setupx_main.c b/dlls/setupapi/setupx_main.c
index 22d7724..6c04068 100644
--- a/dlls/setupapi/setupx_main.c
+++ b/dlls/setupapi/setupx_main.c
@@ -61,6 +61,7 @@
 #include "winreg.h"
 #include "winerror.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "setupapi.h"
 #include "setupx16.h"
 #include "setupapi_private.h"
@@ -69,7 +70,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
 
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
 
 /***********************************************************************
  *		SURegOpenKey (SETUPX.47)
diff --git a/dlls/shell32/shell.c b/dlls/shell32/shell.c
index b7f7022..d431471 100644
--- a/dlls/shell32/shell.c
+++ b/dlls/shell32/shell.c
@@ -32,6 +32,7 @@
 #include "windef.h"
 #include "winerror.h"
 #include "winreg.h"
+#include "wownt32.h"
 #include "dlgs.h"
 #include "shellapi.h"
 #include "shlobj.h"
diff --git a/dlls/shell32/shell32_main.h b/dlls/shell32/shell32_main.h
index 8adde63..8b123bc 100644
--- a/dlls/shell32/shell32_main.h
+++ b/dlls/shell32/shell32_main.h
@@ -200,6 +200,5 @@
 #define HICON_16(h32)		(LOWORD(h32))
 #define HICON_32(h16)		((HICON)(ULONG_PTR)(h16))
 #define HINSTANCE_32(h16)	((HINSTANCE)(ULONG_PTR)(h16))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
 
 #endif
diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c
index cd2a967..6e3ce66 100644
--- a/dlls/shell32/shlexec.c
+++ b/dlls/shell32/shlexec.c
@@ -33,6 +33,7 @@
 #include "windef.h"
 #include "winerror.h"
 #include "winreg.h"
+#include "wownt32.h"
 #include "heap.h"
 #include "shellapi.h"
 #include "shlobj.h"
diff --git a/dlls/user/msg16.c b/dlls/user/msg16.c
index 71763af..29d36ba 100644
--- a/dlls/user/msg16.c
+++ b/dlls/user/msg16.c
@@ -19,6 +19,7 @@
  */
 
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "winerror.h"
 #include "hook.h"
 #include "message.h"
diff --git a/dlls/user/property.c b/dlls/user/property.c
index 972066e..de4e5d9 100644
--- a/dlls/user/property.c
+++ b/dlls/user/property.c
@@ -22,6 +22,7 @@
 
 #include "windef.h"
 #include "wingdi.h"
+#include "wownt32.h"
 #include "wine/winuser16.h"
 #include "wine/server.h"
 #include "win.h"
diff --git a/dlls/user/resource.c b/dlls/user/resource.c
index 1d75018..990ca9a 100644
--- a/dlls/user/resource.c
+++ b/dlls/user/resource.c
@@ -25,6 +25,7 @@
 #include "winnls.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "user.h"
 #include "wine/debug.h"
 
diff --git a/dlls/user/user16.c b/dlls/user/user16.c
index 8d164c7..9937c80 100644
--- a/dlls/user/user16.c
+++ b/dlls/user/user16.c
@@ -20,19 +20,14 @@
 
 #include "wine/winuser16.h"
 #include "winbase.h"
+#include "wownt32.h"
+#include "user.h"
 
 /* handle to handle 16 conversions */
 #define HANDLE_16(h32)		(LOWORD(h32))
-#define HBITMAP_16(h32)		(LOWORD(h32))
-#define HCURSOR_16(h32)		(LOWORD(h32))
-#define HICON_16(h32)		(LOWORD(h32))
 
 /* handle16 to handle conversions */
 #define HANDLE_32(h16)		((HANDLE)(ULONG_PTR)(h16))
-#define HBRUSH_32(h16)		((HBRUSH)(ULONG_PTR)(h16))
-#define HCURSOR_32(h16)		((HCURSOR)(ULONG_PTR)(h16))
-#define HDC_32(h16)		((HDC)(ULONG_PTR)(h16))
-#define HICON_32(h16)		((HICON)(ULONG_PTR)(h16))
 #define HINSTANCE_32(h16)	((HINSTANCE)(ULONG_PTR)(h16))
 
 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
diff --git a/dlls/user/wnd16.c b/dlls/user/wnd16.c
index 9d2c6a6..163feae 100644
--- a/dlls/user/wnd16.c
+++ b/dlls/user/wnd16.c
@@ -19,6 +19,7 @@
  */
 
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "user.h"
 #include "win.h"
 #include "task.h"
@@ -26,19 +27,6 @@
 
 /* handle --> handle16 conversions */
 #define HANDLE_16(h32)		(LOWORD(h32))
-#define HDC_16(h32)		(LOWORD(h32))
-#define HDWP_16(h32)		(LOWORD(h32))
-#define HMENU_16(h32)		(LOWORD(h32))
-
-/* handle16 --> handle conversions */
-#define HBITMAP_32(h16)		((HBITMAP)(ULONG_PTR)(h16))
-#define HDC_32(h16)		((HDC)(ULONG_PTR)(h16))
-#define HDWP_32(h16)		((HDWP)(ULONG_PTR)(h16))
-#define HFONT_32(h16)		((HFONT)(ULONG_PTR)(h16))
-#define HICON_32(h16)		((HICON)(ULONG_PTR)(h16))
-#define HINSTANCE_32(h16)	((HINSTANCE)(ULONG_PTR)(h16))
-#define HMENU_32(h16)		((HMENU)(ULONG_PTR)(h16))
-#define HRGN_32(h16)		((HRGN)(ULONG_PTR)(h16))
 
 static HWND16 hwndSysModal;
 
@@ -1667,7 +1655,7 @@
 
     msgbox32.cbSize             = msgbox->cbSize;
     msgbox32.hwndOwner          = WIN_Handle32( msgbox->hwndOwner );
-    msgbox32.hInstance          = HINSTANCE_32(msgbox->hInstance);
+    msgbox32.hInstance          = MapHModuleSL(msgbox->hInstance);
     msgbox32.lpszText           = MapSL(msgbox->lpszText);
     msgbox32.lpszCaption        = MapSL(msgbox->lpszCaption);
     msgbox32.dwStyle            = msgbox->dwStyle;
diff --git a/dlls/wineps/driver.c b/dlls/wineps/driver.c
index a488393..76e21e6 100644
--- a/dlls/wineps/driver.c
+++ b/dlls/wineps/driver.c
@@ -26,14 +26,13 @@
 #include "psdrv.h"
 #include "wine/debug.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "winspool.h"
 #include "prsht.h"
 #include "psdlg.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
 
-#define HWND_16(h32)		(LOWORD(h32))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
 
 /************************************************************************
  *
diff --git a/dlls/winmm/mcianim/mcianim.c b/dlls/winmm/mcianim/mcianim.c
index 4145e3c..d439f16 100644
--- a/dlls/winmm/mcianim/mcianim.c
+++ b/dlls/winmm/mcianim/mcianim.c
@@ -24,6 +24,7 @@
 #include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "mmddk.h"
 #include "wine/debug.h"
 
@@ -33,8 +34,6 @@
 #define ANIMFRAMES_PERMIN 	1800
 #define SECONDS_PERMIN	 	60
 
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
-
 typedef struct {
         UINT16		wDevID;
         int     	nUseCount;          /* Incremented for each shared open */
diff --git a/dlls/winmm/mciavi/private_mciavi.h b/dlls/winmm/mciavi/private_mciavi.h
index 7df5931..87000b7 100644
--- a/dlls/winmm/mciavi/private_mciavi.h
+++ b/dlls/winmm/mciavi/private_mciavi.h
@@ -20,6 +20,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef __WINE_PRIVATE_MCIAVI_H
+#define __WINE_PRIVATE_MCIAVI_H
+
 #include "windef.h"
 #include "winbase.h"
 #include "wingdi.h"
@@ -27,6 +30,7 @@
 #include "mmddk.h"
 #include "digitalv.h"
 #include "vfw.h"
+#include "wownt32.h"
 #include "mciavi.h"
 
 struct MMIOPos {
@@ -101,5 +105,4 @@
 DWORD	MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms);
 DWORD	MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSA lpParms);
 
-/* handle conversions */
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
+#endif  /* __WINE_PRIVATE_MCIAVI_H */
diff --git a/dlls/winmm/mcicda/mcicda.c b/dlls/winmm/mcicda/mcicda.c
index f6e1b29..9b5cb88 100644
--- a/dlls/winmm/mcicda/mcicda.c
+++ b/dlls/winmm/mcicda/mcicda.c
@@ -29,6 +29,7 @@
 #include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "mmddk.h"
 #include "winioctl.h"
 #include "ntddstor.h"
@@ -42,8 +43,6 @@
 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
 #define FRAME_OF_TOC(toc, idx)  FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
 
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
-
 typedef struct {
     UINT		wDevID;
     int     		nUseCount;          /* Incremented for each shared open */
diff --git a/dlls/winmm/mciseq/mcimidi.c b/dlls/winmm/mciseq/mcimidi.c
index 6196466..f419b78 100644
--- a/dlls/winmm/mciseq/mcimidi.c
+++ b/dlls/winmm/mciseq/mcimidi.c
@@ -37,13 +37,12 @@
 #include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "mmddk.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mcimidi);
 
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
-
 #define MIDI_NOTEOFF             0x80
 #define MIDI_NOTEON              0x90
 
diff --git a/dlls/winmm/mciwave/mciwave.c b/dlls/winmm/mciwave/mciwave.c
index 55ee125..ce97052 100644
--- a/dlls/winmm/mciwave/mciwave.c
+++ b/dlls/winmm/mciwave/mciwave.c
@@ -27,13 +27,12 @@
 #include "wingdi.h"
 #include "winuser.h"
 #include "mmddk.h"
+#include "wownt32.h"
 #include "digitalv.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mciwave);
 
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
-
 typedef struct {
     UINT			wDevID;
     HANDLE			hWave;
diff --git a/dlls/winmm/winemm.h b/dlls/winmm/winemm.h
index 41392f48..4801136 100644
--- a/dlls/winmm/winemm.h
+++ b/dlls/winmm/winemm.h
@@ -23,6 +23,7 @@
  */
 
 #include "mmddk.h"
+#include "wownt32.h"
 
 typedef DWORD (WINAPI *MessageProc16)(UINT16 wDevID, UINT16 wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
 typedef DWORD (WINAPI *MessageProc32)(UINT wDevID, UINT wMsg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2);
@@ -252,7 +253,6 @@
 #define HWAVE_32(h16)		((HWAVE)(ULONG_PTR)(h16))
 #define HWAVEIN_32(h16)		((HWAVEIN)(ULONG_PTR)(h16))
 #define HWAVEOUT_32(h16)	((HWAVEOUT)(ULONG_PTR)(h16))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
 
 /* HANDLE -> HANDLE16 conversions */
 #define HDRVR_16(h32)		(LOWORD(h32))
@@ -266,4 +266,3 @@
 #define HWAVE_16(h32)		(LOWORD(h32))
 #define HWAVEIN_16(h32)		(LOWORD(h32))
 #define HWAVEOUT_16(h32)	(LOWORD(h32))
-#define HWND_16(h32)		(LOWORD(h32))
diff --git a/dlls/winsock/async.c b/dlls/winsock/async.c
index 3f45704..9a341f7 100644
--- a/dlls/winsock/async.c
+++ b/dlls/winsock/async.c
@@ -102,6 +102,7 @@
 #include "winuser.h"
 #include "winsock2.h"
 #include "ws2spi.h"
+#include "wownt32.h"
 #include "wine/winsock16.h"
 #include "winnt.h"
 
diff --git a/dlls/winsock/socket.c b/dlls/winsock/socket.c
index ab9a017..b98d630 100644
--- a/dlls/winsock/socket.c
+++ b/dlls/winsock/socket.c
@@ -114,6 +114,7 @@
 #include "wsipx.h"
 #include "wine/winsock16.h"
 #include "winnt.h"
+#include "wownt32.h"
 #include "wine/server.h"
 #include "wine/debug.h"
 
diff --git a/include/user.h b/include/user.h
index 69f75cf..ccd0a81 100644
--- a/include/user.h
+++ b/include/user.h
@@ -143,13 +143,9 @@
 extern DWORD USER16_AlertableWait;
 
 /* HANDLE16 <-> HANDLE conversions */
-#define HACCEL_16(h32)  (LOWORD(h32))
-#define HBRUSH_16(h32)  (LOWORD(h32))
 #define HCURSOR_16(h32) (LOWORD(h32))
 #define HICON_16(h32)   (LOWORD(h32))
 
-#define HACCEL_32(h16)  ((HACCEL)(ULONG_PTR)(h16))
-#define HBRUSH_32(h16)  ((HBRUSH)(ULONG_PTR)(h16))
 #define HCURSOR_32(h16) ((HCURSOR)(ULONG_PTR)(h16))
 #define HICON_32(h16)   ((HICON)(ULONG_PTR)(h16))
 
diff --git a/include/win.h b/include/win.h
index c682be7..c9fc3d3 100644
--- a/include/win.h
+++ b/include/win.h
@@ -120,9 +120,6 @@
     return hwnd;
 }
 
-#define HWND_16(hwnd32)   (LOWORD(hwnd32))
-#define HWND_32(hwnd16)   ((HWND)(ULONG_PTR)(hwnd16))
-
 inline static WND *WIN_FindWndPtr16( HWND16 hwnd )
 {
     /* don't bother with full conversion */
diff --git a/include/wine/winsock16.h b/include/wine/winsock16.h
index 2ea8a05..ceed17b 100644
--- a/include/wine/winsock16.h
+++ b/include/wine/winsock16.h
@@ -105,7 +105,4 @@
 INT16     WINAPI WSAAsyncSelect16(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, LONG lEvent);
 INT16     WINAPI WSARecvEx16(SOCKET16 s, char *buf, INT16 len, INT16 *flags);
 
-#define HWND_16(h32)		(LOWORD(h32))
-#define HWND_32(h16)		((HWND)(ULONG_PTR)(h16))
-
 #endif /* __WINE_WINE_WINSOCK16_H */
diff --git a/include/wownt32.h b/include/wownt32.h
index 4d27fe5..86a0bbb 100644
--- a/include/wownt32.h
+++ b/include/wownt32.h
@@ -59,6 +59,46 @@
 HANDLE WINAPI WOWHandle32(WORD,WOW_HANDLE_TYPE);
 WORD   WINAPI WOWHandle16(HANDLE,WOW_HANDLE_TYPE);
 
+#ifdef __WINE__
+/* under Wine use the kernel functions directly so we don't have to import wow32 */
+HANDLE WINAPI K32WOWHandle32(WORD,WOW_HANDLE_TYPE);
+WORD   WINAPI K32WOWHandle16(HANDLE,WOW_HANDLE_TYPE);
+#define WOWHandle32 K32WOWHandle32
+#define WOWHandle16 K32WOWHandle16
+#endif
+
+#ifdef __WINE__
+/* under Wine we use optimized versions where we can */
+#define HWND_32(h16)      ((HWND)      (ULONG_PTR)(h16))
+#define HMENU_32(h16)     ((HMENU)     (ULONG_PTR)(h16))
+#define HDWP_32(h16)      ((HDWP)      (ULONG_PTR)(h16))
+#define HDROP_32(h16)     ((HDROP)     (ULONG_PTR)(h16))
+#define HDC_32(h16)       ((HDC)       (ULONG_PTR)(h16))
+#define HFONT_32(h16)     ((HFONT)     (ULONG_PTR)(h16))
+#define HMETAFILE_32(h16) ((HMETAFILE) (ULONG_PTR)(h16))
+#define HRGN_32(h16)      ((HRGN)      (ULONG_PTR)(h16))
+#define HBITMAP_32(h16)   ((HBITMAP)   (ULONG_PTR)(h16))
+#define HBRUSH_32(h16)    ((HBRUSH)    (ULONG_PTR)(h16))
+#define HPALETTE_32(h16)  ((HPALETTE)  (ULONG_PTR)(h16))
+#define HPEN_32(h16)      ((HPEN)      (ULONG_PTR)(h16))
+#define HACCEL_32(h16)    ((HACCEL)    (ULONG_PTR)(h16))
+
+#define HWND_16(h32)      (LOWORD(h32))
+#define HMENU_16(h32)     (LOWORD(h32))
+#define HDWP_16(h32)      (LOWORD(h32))
+#define HDROP_16(h32)     (LOWORD(h32))
+#define HDC_16(h32)       (LOWORD(h32))
+#define HFONT_16(h32)     (LOWORD(h32))
+#define HMETAFILE_16(h32) (LOWORD(h32))
+#define HRGN_16(h32)      (LOWORD(h32))
+#define HBITMAP_16(h32)   (LOWORD(h32))
+#define HBRUSH_16(h32)    (LOWORD(h32))
+#define HPALETTE_16(h32)  (LOWORD(h32))
+#define HPEN_16(h32)      (LOWORD(h32))
+#define HACCEL_16(h32)    (LOWORD(h32))
+
+#else  /* __WINE__ */
+
 #define HWND_32(h16)      ((HWND)      (WOWHandle32(h16, WOW_TYPE_HWND)))
 #define HMENU_32(h16)     ((HMENU)     (WOWHandle32(h16, WOW_TYPE_HMENU)))
 #define HDWP_32(h16)      ((HDWP)      (WOWHandle32(h16, WOW_TYPE_HDWP)))
@@ -72,8 +112,6 @@
 #define HPALETTE_32(h16)  ((HPALETTE)  (WOWHandle32(h16, WOW_TYPE_HPALETTE)))
 #define HPEN_32(h16)      ((HPEN)      (WOWHandle32(h16, WOW_TYPE_HPEN)))
 #define HACCEL_32(h16)    ((HACCEL)    (WOWHandle32(h16, WOW_TYPE_HACCEL)))
-#define HTASK_32(h16)     ((DWORD)     (WOWHandle32(h16, WOW_TYPE_HTASK)))
-#define FULLHWND_32(h16)  ((HWND)      (WOWHandle32(h16, WOW_TYPE_FULLHWND)))
 
 #define HWND_16(h32)      (WOWHandle16(h32, WOW_TYPE_HWND))
 #define HMENU_16(h32)     (WOWHandle16(h32, WOW_TYPE_HMENU))
@@ -88,8 +126,13 @@
 #define HPALETTE_16(h32)  (WOWHandle16(h32, WOW_TYPE_HPALETTE))
 #define HPEN_16(h32)      (WOWHandle16(h32, WOW_TYPE_HPEN))
 #define HACCEL_16(h32)    (WOWHandle16(h32, WOW_TYPE_HACCEL))
-#define HTASK_16(h32)     (WOWHandle16(h32, WOW_TYPE_HTASK))
 
+#endif  /* __WINE__ */
+
+#define FULLHWND_32(h16)  ((HWND) (WOWHandle32(h16, WOW_TYPE_FULLHWND)))
+#define HTASK_32(h16)     ((DWORD)(WOWHandle32(h16, WOW_TYPE_HTASK)))
+
+#define HTASK_16(h32)     (WOWHandle16((HANDLE)(h32), WOW_TYPE_HTASK))
 
 #define WCB16_PASCAL     0
 #define WCB16_CDECL      1
@@ -99,5 +142,3 @@
 BOOL  WINAPI WOWCallback16Ex(DWORD,DWORD,DWORD,LPVOID,LPDWORD);
 
 #endif /* _WOWNT32_H_ */
-
-
diff --git a/windows/class.c b/windows/class.c
index 81e4ec0..3326782 100644
--- a/windows/class.c
+++ b/windows/class.c
@@ -37,6 +37,7 @@
 #include "windef.h"
 #include "wingdi.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "wine/unicode.h"
 #include "win.h"
 #include "user.h"
diff --git a/windows/cursoricon.c b/windows/cursoricon.c
index 73d8668..67d887c 100644
--- a/windows/cursoricon.c
+++ b/windows/cursoricon.c
@@ -48,6 +48,7 @@
 
 #include "windef.h"
 #include "wingdi.h"
+#include "wownt32.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
 #include "wine/exception.h"
@@ -66,16 +67,6 @@
 WINE_DECLARE_DEBUG_CHANNEL(icon);
 WINE_DECLARE_DEBUG_CHANNEL(resource);
 
-/* handle conversions */
-#define HCURSOR_16(h32)		(LOWORD(h32))
-#define HGLOBAL_16(h32)		(LOWORD(h32))
-#define HICON_16(h32)		(LOWORD(h32))
-#define HINSTANCE_16(h32)	(LOWORD(h32))
-
-#define HCURSOR_32(h16)		((HCURSOR)(ULONG_PTR)(h16))
-#define HICON_32(h16)		((HICON)(ULONG_PTR)(h16))
-#define HINSTANCE_32(h16)	((HINSTANCE)(ULONG_PTR)(h16))
-#define HMODULE_32(h16)		((HMODULE)(ULONG_PTR)(h16))
 
 static RECT CURSOR_ClipRect;       /* Cursor clipping rect */
 
@@ -504,14 +495,13 @@
  * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
  *        with cbSize parameter as well.
  */
-static HICON CURSORICON_CreateFromResource( HINSTANCE hInstance, HICON hObject, LPBYTE bits,
+static HICON CURSORICON_CreateFromResource( HMODULE16 hModule, HGLOBAL16 hObj, LPBYTE bits,
 	 					UINT cbSize, BOOL bIcon, DWORD dwVersion,
 						INT width, INT height, UINT loadflags )
 {
     static HDC hdcMem;
     int sizeAnd, sizeXor;
     HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
-    HGLOBAL16 hObj = HGLOBAL_16(hObject);
     BITMAP bmpXor, bmpAnd;
     POINT16 hotspot;
     BITMAPINFO *bmi;
@@ -677,8 +667,8 @@
 	CURSORICONINFO *info;
 
 	/* Make it owned by the module */
-        if (hInstance) hInstance = GetExePtr(hInstance);
-        FarSetOwner16( hObj, hInstance );
+        if (hModule) hModule = GetExePtr(hModule);
+        FarSetOwner16( hObj, hModule );
 
 	info = (CURSORICONINFO *)GlobalLock16( hObj );
 	info->ptHotSpot.x   = hotspot.x;
@@ -825,11 +815,10 @@
  *
  * Make a copy of a cursor or icon.
  */
-static HICON CURSORICON_Copy( HINSTANCE hInst, HICON hIcon )
+static HICON CURSORICON_Copy( HINSTANCE16 hInst16, HICON hIcon )
 {
     char *ptrOld, *ptrNew;
     int size;
-    HINSTANCE16 hInst16 = HINSTANCE_16(hInst);
     HICON16 hOld = HICON_16(hIcon);
     HICON16 hNew;
 
@@ -1008,7 +997,7 @@
     info.bPlanes = 1;
     info.bBitsPerPixel = 1;
 
-    return HICON_32(CreateCursorIconIndirect16(HINSTANCE_16(hInstance), &info,
+    return HICON_32(CreateCursorIconIndirect16(MapHModuleLS(hInstance), &info,
 		    lpANDbits, lpXORbits));
 }
 
@@ -1099,7 +1088,7 @@
         info.bPlanes = bPlanes;
         info.bBitsPerPixel = bBitsPixel;
 
-        hIcon=HICON_32(CreateCursorIconIndirect16(HINSTANCE_16(hInstance), &info,
+        hIcon=HICON_32(CreateCursorIconIndirect16(MapHModuleLS(hInstance), &info,
 						  lpANDbits, lpXORbits));
     } else {
         ICONINFO iinfo;
@@ -1171,7 +1160,7 @@
 HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
 {
     TRACE_(icon)("%04x %04x\n", hInstance, hIcon );
-    return HICON_16(CURSORICON_Copy(HINSTANCE_32(hInstance), HICON_32(hIcon)));
+    return HICON_16(CURSORICON_Copy(hInstance, HICON_32(hIcon)));
 }
 
 
@@ -1191,7 +1180,7 @@
 HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
 {
     TRACE_(cursor)("%04x %04x\n", hInstance, hCursor );
-    return HICON_16(CURSORICON_Copy(HINSTANCE_32(hInstance), HCURSOR_32(hCursor)));
+    return HICON_16(CURSORICON_Copy(hInstance, HCURSOR_32(hCursor)));
 }
 
 /**********************************************************************
@@ -1528,7 +1517,7 @@
      {
 	 LPBYTE bits = (LPBYTE)GlobalLock16( hMemObj );
 	 hMemObj = HICON_16(CURSORICON_CreateFromResource(
-				HMODULE_32(hModule), HICON_32(hMemObj), bits,
+				hModule, hMemObj, bits,
 				SizeofResource16(hModule, hRsrc), TRUE, 0x00030000,
 				GetSystemMetrics(SM_CXICON),
 				GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR));
@@ -1548,7 +1537,7 @@
     {
 	LPBYTE bits = (LPBYTE)GlobalLock16( hMemObj );
 	hMemObj = HICON_16(CURSORICON_CreateFromResource(
-				HMODULE_32(hModule), HICON_32(hMemObj), bits,
+				hModule, hMemObj, bits,
 				SizeofResource16(hModule, hRsrc), FALSE, 0x00030000,
 				GetSystemMetrics(SM_CXCURSOR),
 				GetSystemMetrics(SM_CYCURSOR), LR_MONOCHROME));
diff --git a/windows/dialog.c b/windows/dialog.c
index 58bb38e..2095fad 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -36,6 +36,7 @@
 #include "windowsx.h"
 #include "wine/winuser16.h"
 #include "wine/winbase16.h"
+#include "wownt32.h"
 #include "wine/unicode.h"
 #include "controls.h"
 #include "heap.h"
diff --git a/windows/hook.c b/windows/hook.c
index bc7bd0b..5c8c1f9 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -34,6 +34,7 @@
 #include "winuser.h"
 #include "wine/winuser16.h"
 #include "wine/winbase16.h"
+#include "wownt32.h"
 #include "hook.h"
 #include "win.h"
 #include "queue.h"
diff --git a/windows/mdi.c b/windows/mdi.c
index e5888c0..0241e9a 100644
--- a/windows/mdi.c
+++ b/windows/mdi.c
@@ -89,6 +89,7 @@
 #include "winbase.h"
 #include "wingdi.h"
 #include "winuser.h"
+#include "wownt32.h"
 #include "wine/unicode.h"
 #include "win.h"
 #include "nonclient.h"
diff --git a/windows/spy.c b/windows/spy.c
index 33f0767..d3be284 100644
--- a/windows/spy.c
+++ b/windows/spy.c
@@ -25,6 +25,7 @@
 #include "windef.h"
 #include "wingdi.h"
 #include "winreg.h"
+#include "wownt32.h"
 #include "wine/winuser16.h"
 #include "wine/winbase16.h"
 #include "wine/unicode.h"
diff --git a/windows/struct32.c b/windows/struct32.c
index df3536f..9eed6d4 100644
--- a/windows/struct32.c
+++ b/windows/struct32.c
@@ -19,6 +19,7 @@
  */
 
 #include "struct32.h"
+#include "wownt32.h"
 #include "win.h"
 #include "winerror.h"
 
diff --git a/windows/win.c b/windows/win.c
index a7e0c4e..8225791 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -27,6 +27,7 @@
 #include "windef.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
+#include "wownt32.h"
 #include "wine/server.h"
 #include "wine/unicode.h"
 #include "win.h"
diff --git a/windows/winhelp.c b/windows/winhelp.c
index 42400fa..55b2f15 100644
--- a/windows/winhelp.c
+++ b/windows/winhelp.c
@@ -29,6 +29,7 @@
 #include "wine/debug.h"
 #include "windef.h"
 #include "wingdi.h"
+#include "wownt32.h"
 #include "wine/winuser16.h"
 #include "wine/winbase16.h"
 #include "win.h"
diff --git a/windows/winproc.c b/windows/winproc.c
index e841c0b..774c963 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -27,6 +27,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "wingdi.h"
+#include "wownt32.h"
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
 #include "stackframe.h"