Start using the exported TEB structure from winternl.h where
possible.

diff --git a/dlls/kernel/change.c b/dlls/kernel/change.c
index 601b813..3cb2291 100644
--- a/dlls/kernel/change.c
+++ b/dlls/kernel/change.c
@@ -25,6 +25,7 @@
 
 #include "winbase.h"
 #include "winerror.h"
+#include "wine/windef16.h"
 #include "wine/server.h"
 #include "wine/debug.h"
 
diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c
index 15c9380..b393cfa 100644
--- a/dlls/kernel/process.c
+++ b/dlls/kernel/process.c
@@ -23,6 +23,7 @@
 
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
+#include "thread.h"
 #include "wine/server.h"
 #include "wine/debug.h"
 
diff --git a/dlls/msvcrt/except.c b/dlls/msvcrt/except.c
index 3d2a202..1d7c089 100644
--- a/dlls/msvcrt/except.c
+++ b/dlls/msvcrt/except.c
@@ -30,7 +30,6 @@
 
 #include "winternl.h"
 #include "wine/exception.h"
-#include "thread.h"
 #include "msvcrt.h"
 
 #include "msvcrt/setjmp.h"
diff --git a/dlls/ntdll/exception.c b/dlls/ntdll/exception.c
index c5f1e8e..289bbe3 100644
--- a/dlls/ntdll/exception.c
+++ b/dlls/ntdll/exception.c
@@ -26,6 +26,7 @@
 #include <signal.h>
 
 #include "windef.h"
+#include "thread.h"
 #include "winternl.h"
 #include "wine/exception.h"
 #include "wine/server.h"
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index eea3611..deb909c 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "thread.h"
 #include "winternl.h"
 #include "wine/server.h"
 #include "wine/debug.h"
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index f82eab3..0520b7d 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -40,6 +40,7 @@
 
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
+#include "thread.h"
 #include "winternl.h"
 #include "global.h"
 #include "wine/library.h"
diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h
index ff9fe0b..0d1b71d 100644
--- a/dlls/ole32/compobj_private.h
+++ b/dlls/ole32/compobj_private.h
@@ -28,7 +28,7 @@
 
 #include "wtypes.h"
 #include "dcom.h"
-#include "thread.h"
+#include "winternl.h"
 
 /* exported interface */
 typedef struct tagXIF {
diff --git a/dlls/user/msg16.c b/dlls/user/msg16.c
index 0ce2687..0b6156c 100644
--- a/dlls/user/msg16.c
+++ b/dlls/user/msg16.c
@@ -22,7 +22,6 @@
 #include "wownt32.h"
 #include "winerror.h"
 #include "message.h"
-#include "thread.h"
 #include "win.h"
 #include "winproc.h"
 #include "wine/debug.h"
diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c
index 78dc823..7d5583d 100644
--- a/dlls/user/user_main.c
+++ b/dlls/user/user_main.c
@@ -32,7 +32,6 @@
 #include "global.h"
 #include "message.h"
 #include "user.h"
-#include "thread.h"
 #include "win.h"
 #include "wine/debug.h"
 
diff --git a/dlls/winedos/dosvm.c b/dlls/winedos/dosvm.c
index 24dec2f..fe05f5a 100644
--- a/dlls/winedos/dosvm.c
+++ b/dlls/winedos/dosvm.c
@@ -45,12 +45,12 @@
 #include "winnt.h"
 #include "wincon.h"
 
+#include "thread.h"
 #include "msdos.h"
 #include "file.h"
 #include "miscemu.h"
 #include "dosexe.h"
 #include "dosvm.h"
-#include "thread.h"
 #include "wine/debug.h"
 #include "excpt.h"
 
diff --git a/dlls/winsock/socket.c b/dlls/winsock/socket.c
index f97119e..6b7ff03 100644
--- a/dlls/winsock/socket.c
+++ b/dlls/winsock/socket.c
@@ -123,6 +123,7 @@
 #include "winnt.h"
 #include "wownt32.h"
 #include "iphlpapi.h"
+#include "thread.h"
 #include "wine/server.h"
 #include "wine/debug.h"
 
diff --git a/include/async.h b/include/async.h
index a620f72..8422e41 100644
--- a/include/async.h
+++ b/include/async.h
@@ -26,6 +26,7 @@
 #ifndef __WINE_ASYNC_H
 #define __WINE_ASYNC_H
 
+#include "thread.h"
 #include "wine/server.h"
 #include "winternl.h"
 
diff --git a/include/thread.h b/include/thread.h
index 9d7c633..876d121 100644
--- a/include/thread.h
+++ b/include/thread.h
@@ -21,6 +21,7 @@
 #ifndef __WINE_THREAD_H
 #define __WINE_THREAD_H
 
+#define WINE_NO_TEB
 #include "winternl.h"
 #include "wine/windef16.h"
 
@@ -51,6 +52,8 @@
   ie4       0x40
   PESHiELD  0x23/0x30 (win95)
 */
+#ifndef WINE_TEB_DEFINED
+#define WINE_TEB_DEFINED
 typedef struct _TEB
 {
     NT_TIB       Tib;            /* 12-  00 Thread information block */
@@ -126,6 +129,7 @@
     DWORD        pad9[24];                   /* --n f20 */
     PVOID        ReservedForOle;             /* -2- f80 used by ole32 (IErrorInfo*) */
 } TEB;
+#endif /* WINE_TEB_DEFINED */
 
 /* Thread exception flags */
 #define TEBF_WIN32  0x0001
diff --git a/include/wine/server.h b/include/wine/server.h
index acde067..5b47c14 100644
--- a/include/wine/server.h
+++ b/include/wine/server.h
@@ -21,7 +21,7 @@
 #ifndef __WINE_WINE_SERVER_H
 #define __WINE_WINE_SERVER_H
 
-#include "thread.h"
+#include "winternl.h"
 #include "wine/exception.h"
 #include "wine/server_protocol.h"
 
diff --git a/include/winternl.h b/include/winternl.h
index 88b9186..94c64fe 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -30,35 +30,6 @@
 #endif /* defined(__cplusplus) */
 
 
-/***********************************************************************
- * TEB data structure
- */
-#if 0
-typedef struct _TEB
-{
-    NT_TIB          Tib;                        /* 000 */
-    PVOID           EnvironmentPointer;         /* 01c */
-    CLIENT_ID       ClientId;                   /* 020 */
-    PVOID           ActiveRpcHandle;            /* 028 */
-    PVOID           ThreadLocalStoragePointer;  /* 02c */
-    PPEB            Peb;                        /* 030 */
-    ULONG           LastErrorValue;             /* 034 */
-    BYTE            __pad038[140];              /* 038 */
-    ULONG           CurrentLocale;              /* 0c4 */
-    BYTE            __pad0c8[1752];             /* 0c8 */
-    PVOID           Reserved2[278];             /* 7a0 */
-    UNICODE_STRING  StaticUnicodeString;        /* bf8 used by advapi32 */
-    WCHAR           StaticUnicodeBuffer[261];   /* c00 used by advapi32 */
-    PVOID           DeallocationStack;          /* e0c */
-    PVOID           TlsSlots[64];               /* e10 */
-    BYTE            Reserved3[8];               /* f10 */
-    PVOID           Reserved4[26];              /* f18 */
-    PVOID           ReservedForOle;             /* f80 Windows 2000 only */
-    PVOID           Reserved5[4];               /* f84 */
-    PVOID           TlsExpansionSlots;          /* f94 */
-} TEB, *PTEB;
-#endif
-
 /**********************************************************************
  * Fundamental types and data structures
  */
@@ -176,6 +147,42 @@
 
 
 /***********************************************************************
+ * TEB data structure
+ */
+#if defined(_NTSYSTEM_) || defined(_KERNEL32_)  /* hack, should go away */
+# define WINE_NO_TEB
+#endif
+
+#ifndef WINE_NO_TEB  /* don't define TEB if included from thread.h */
+# ifndef WINE_TEB_DEFINED
+# define WINE_TEB_DEFINED
+typedef struct _TEB
+{
+    NT_TIB          Tib;                        /* 000 */
+    PVOID           EnvironmentPointer;         /* 01c */
+    CLIENT_ID       ClientId;                   /* 020 */
+    PVOID           ActiveRpcHandle;            /* 028 */
+    PVOID           ThreadLocalStoragePointer;  /* 02c */
+    PPEB            Peb;                        /* 030 */
+    ULONG           LastErrorValue;             /* 034 */
+    BYTE            __pad038[140];              /* 038 */
+    ULONG           CurrentLocale;              /* 0c4 */
+    BYTE            __pad0c8[1752];             /* 0c8 */
+    PVOID           Reserved2[278];             /* 7a0 */
+    UNICODE_STRING  StaticUnicodeString;        /* bf8 used by advapi32 */
+    WCHAR           StaticUnicodeBuffer[261];   /* c00 used by advapi32 */
+    PVOID           DeallocationStack;          /* e0c */
+    PVOID           TlsSlots[64];               /* e10 */
+    BYTE            Reserved3[8];               /* f10 */
+    PVOID           Reserved4[26];              /* f18 */
+    PVOID           ReservedForOle;             /* f80 Windows 2000 only */
+    PVOID           Reserved5[4];               /* f84 */
+    PVOID           TlsExpansionSlots;          /* f94 */
+} TEB, *PTEB;
+# endif /* WINE_TEB_DEFINED */
+#endif  /* WINE_NO_TEB */
+
+/***********************************************************************
  * Enums
  */
 
diff --git a/loader/module.c b/loader/module.c
index e18db67..c7f92d1 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -34,6 +34,7 @@
 #include "winerror.h"
 #include "winternl.h"
 #include "heap.h"
+#include "thread.h"
 #include "file.h"
 #include "module.h"
 
diff --git a/memory/environ.c b/memory/environ.c
index 4579d42..a80d268 100644
--- a/memory/environ.c
+++ b/memory/environ.c
@@ -27,7 +27,7 @@
 
 #include "windef.h"
 #include "winerror.h"
-
+#include "thread.h"
 #include "wine/winbase16.h"
 #include "wine/server.h"
 #include "wine/library.h"
diff --git a/tools/winebuild/spec16.c b/tools/winebuild/spec16.c
index 948949d..eccff57 100644
--- a/tools/winebuild/spec16.c
+++ b/tools/winebuild/spec16.c
@@ -29,9 +29,9 @@
 #include <ctype.h>
 
 #include "wine/exception.h"
+#include "stackframe.h"
 #include "builtin16.h"
 #include "module.h"
-#include "stackframe.h"
 
 #include "build.h"
 
diff --git a/windows/message.c b/windows/message.c
index 1a003b1..c3e3dbf 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -37,7 +37,6 @@
 #include "controls.h"
 #include "dde.h"
 #include "message.h"
-#include "thread.h"
 #include "user.h"
 #include "win.h"
 #include "winpos.h"