Const correctness fixes.

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 8a08a5d..d95f42a 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -465,7 +465,7 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9 iface, CONST D3DVIEWPORT9* pViewport) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
+    return IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9 iface, D3DVIEWPORT9* pViewport) {
@@ -477,7 +477,7 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9 iface, CONST D3DMATERIAL9* pMaterial) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
+    return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9 iface, D3DMATERIAL9* pMaterial) {
@@ -489,7 +489,7 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST D3DLIGHT9* pLight) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
+    return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, D3DLIGHT9* pLight) {
@@ -537,7 +537,7 @@
 HRESULT  WINAPI  IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9 iface, CONST D3DCLIPSTATUS9* pClipStatus) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n" , This);
-    return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
+    return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
 }
 
 HRESULT  WINAPI  IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9 iface, D3DCLIPSTATUS9* pClipStatus) {
diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c
index 180acb7..f16dd63 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -480,21 +480,21 @@
 
 static unsigned char dwarf2_parse_byte(dwarf2_parse_context_t* ctx)
 {
-  unsigned char uvalue = *(unsigned char*) ctx->data;
+  unsigned char uvalue = *(const unsigned char*) ctx->data;
   ctx->data += 1;
   return uvalue;
 }
 
 static unsigned short dwarf2_parse_u2(dwarf2_parse_context_t* ctx)
 {
-  unsigned short uvalue = *(unsigned short*) ctx->data;
+  unsigned short uvalue = *(const unsigned short*) ctx->data;
   ctx->data += 2;
   return uvalue;
 }
 
 static unsigned long dwarf2_parse_u4(dwarf2_parse_context_t* ctx)
 {
-  unsigned long uvalue = *(unsigned int*) ctx->data;
+  unsigned long uvalue = *(const unsigned int*) ctx->data;
   ctx->data += 4;
   return uvalue;
 }
@@ -706,7 +706,7 @@
   unsigned long offset = 0;
   switch (ctx->word_size) {
   case 4:
-    offset = *(unsigned int*) ctx->data;
+    offset = *(const unsigned int*) ctx->data;
     break;
   case 8:
   default:
@@ -1941,7 +1941,7 @@
   return func_type;
 }
 
-static void dwarf2_parse_compiland_content(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
+static void dwarf2_parse_compiland_content(struct module* module, const dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
 {
   if (entry->have_child) { /** any interest to not have child ? */
     ++ctx->level;
@@ -2044,7 +2044,7 @@
   }
 }
 
-static struct symt_compiland* dwarf2_parse_compiland(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
+static struct symt_compiland* dwarf2_parse_compiland(struct module* module, const dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
 {
   struct symt_compiland* compiland = NULL;
   const char* name = NULL;
@@ -2086,13 +2086,13 @@
 
   while (comp_unit_cursor < end_debug) {
     dwarf2_abbrev_table_t* abbrev_table;
-    dwarf2_comp_unit_stream_t* comp_unit_stream;
+    const dwarf2_comp_unit_stream_t* comp_unit_stream;
     dwarf2_comp_unit_t comp_unit;
     dwarf2_parse_context_t ctx;
     dwarf2_parse_context_t abbrev_ctx;
     struct symt_compiland* compiland = NULL;
     
-    comp_unit_stream = (dwarf2_comp_unit_stream_t*) comp_unit_cursor;
+    comp_unit_stream = (const dwarf2_comp_unit_stream_t*) comp_unit_cursor;
 
     comp_unit.length = *(unsigned long*)  comp_unit_stream->length;
     comp_unit.version = *(unsigned short*) comp_unit_stream->version;
@@ -2131,7 +2131,7 @@
     ctx.abbrev_table = abbrev_table;
 
     while (ctx.data < ctx.end_data) {
-      dwarf2_abbrev_entry_t* entry = NULL;
+      const dwarf2_abbrev_entry_t* entry = NULL;
       unsigned long entry_code;
       unsigned long entry_ref = 0;
 
diff --git a/dlls/dmstyle/commandtrack.c b/dlls/dmstyle/commandtrack.c
index ee7bb95..dfaf017 100644
--- a/dlls/dmstyle/commandtrack.c
+++ b/dlls/dmstyle/commandtrack.c
@@ -287,7 +287,7 @@
 		int r = 0;
 		DMUS_PRIVATE_COMMAND *tmpEntry;
 		struct list *listEntry;
-		TRACE("*** IDirectMusicCommandTrack (%p) ***\n", (LPDIRECTMUSICTRACK8)This->TrackVtbl);
+		TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This->TrackVtbl);
 		TRACE(" - Commands:\n");
 		LIST_FOR_EACH (listEntry, &This->Commands) {
 			tmpEntry = LIST_ENTRY (listEntry, DMUS_PRIVATE_COMMAND, entry);
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 7747555..62fdbf9 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -858,7 +858,7 @@
   int ret;
 
   if (a && b)
-    ret = ((PMIB_IFROW)a)->dwIndex - ((PMIB_IFROW)b)->dwIndex;
+    ret = ((const MIB_IFROW*)a)->dwIndex - ((const MIB_IFROW*)b)->dwIndex;
   else
     ret = 0;
   return ret;
@@ -1011,7 +1011,7 @@
   int ret;
 
   if (a && b)
-    ret = ((PMIB_IPADDRROW)a)->dwAddr - ((PMIB_IPADDRROW)b)->dwAddr;
+    ret = ((const MIB_IPADDRROW*)a)->dwAddr - ((const MIB_IPADDRROW*)b)->dwAddr;
   else
     ret = 0;
   return ret;
@@ -1110,7 +1110,8 @@
   int ret;
 
   if (a && b) {
-    PMIB_IPFORWARDROW rowA = (PMIB_IPFORWARDROW)a, rowB = (PMIB_IPFORWARDROW)b;
+   const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
+   const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
 
     ret = rowA->dwForwardDest - rowB->dwForwardDest;
     if (ret == 0) {
@@ -1227,7 +1228,7 @@
   int ret;
 
   if (a && b)
-    ret = ((PMIB_IPNETROW)a)->dwAddr - ((PMIB_IPNETROW)b)->dwAddr;
+    ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
   else
     ret = 0;
   return ret;
@@ -1503,7 +1504,8 @@
   int ret;
 
   if (a && b) {
-    PMIB_TCPROW rowA = (PMIB_TCPROW)a, rowB = (PMIB_TCPROW)b;
+    const MIB_TCPROW* rowA = a;
+    const MIB_TCPROW* rowB = b;
 
     ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
     if (ret == 0) {
@@ -1614,7 +1616,8 @@
   int ret;
 
   if (a && b) {
-    PMIB_UDPROW rowA = (PMIB_UDPROW)a, rowB = (PMIB_UDPROW)b;
+    const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
+    const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
 
     ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
     if (ret == 0)
diff --git a/dlls/ole32/stg_prop.c b/dlls/ole32/stg_prop.c
index af25e31..aab99dd 100644
--- a/dlls/ole32/stg_prop.c
+++ b/dlls/ole32/stg_prop.c
@@ -2310,7 +2310,7 @@
             }
             else
             {
-                if (++fmtptr < (BYTE *)rfmtid + sizeof(FMTID))
+                if (++fmtptr < (const BYTE *)rfmtid + sizeof(FMTID))
                     i |= *fmtptr << bitsRemaining;
                 *pstr++ = (WCHAR)(fmtMap[i & CHARMASK]);
                 bitsRemaining += BITS_PER_BYTE - BITS_IN_CHARMASK;
diff --git a/dlls/user/win.c b/dlls/user/win.c
index 4e3f6c1..c05f065 100644
--- a/dlls/user/win.c
+++ b/dlls/user/win.c
@@ -880,8 +880,8 @@
     BOOL unicode = (type == WIN_PROC_32W);
 
     TRACE("%s %s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
-          (type == WIN_PROC_32W) ? debugstr_w((LPWSTR)cs->lpszName) : debugstr_a(cs->lpszName),
-          (type == WIN_PROC_32W) ? debugstr_w((LPWSTR)cs->lpszClass) : debugstr_a(cs->lpszClass),
+          (type == WIN_PROC_32W) ? debugstr_w((LPCWSTR)cs->lpszName) : debugstr_a(cs->lpszName),
+          (type == WIN_PROC_32W) ? debugstr_w((LPCWSTR)cs->lpszClass) : debugstr_a(cs->lpszClass),
           cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
           cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
 
diff --git a/dlls/winsock/socket.c b/dlls/winsock/socket.c
index a89e62e..6d9b778 100644
--- a/dlls/winsock/socket.c
+++ b/dlls/winsock/socket.c
@@ -160,9 +160,9 @@
 {
     if (!a) return "(nil)";
     return wine_dbg_sprintf("{ family %d, address %s, port %d }",
-                            ((struct sockaddr_in *)a)->sin_family,
-                            inet_ntoa(((struct sockaddr_in *)a)->sin_addr),
-                            ntohs(((struct sockaddr_in *)a)->sin_port));
+                            ((const struct sockaddr_in *)a)->sin_family,
+                            inet_ntoa(((const struct sockaddr_in *)a)->sin_addr),
+                            ntohs(((const struct sockaddr_in *)a)->sin_port));
 }
 
 /* HANDLE<->SOCKET conversion (SOCKET is UINT_PTR). */
@@ -783,7 +783,7 @@
 #ifdef HAVE_IPX
     case WS_AF_IPX:
         {
-            struct WS_sockaddr_ipx* wsipx=(struct WS_sockaddr_ipx*)wsaddr;
+            const struct WS_sockaddr_ipx* wsipx=(const struct WS_sockaddr_ipx*)wsaddr;
             struct sockaddr_ipx* uipx;
 
             if (wsaddrlen<sizeof(struct WS_sockaddr_ipx))
@@ -845,7 +845,7 @@
 #ifdef HAVE_IPX
     case AF_IPX:
         {
-            struct sockaddr_ipx* uipx=(struct sockaddr_ipx*)uaddr;
+            const struct sockaddr_ipx* uipx=(const struct sockaddr_ipx*)uaddr;
             struct WS_sockaddr_ipx* wsipx=(struct WS_sockaddr_ipx*)wsaddr;
 
             res=-1;
diff --git a/dlls/x11drv/dib.c b/dlls/x11drv/dib.c
index d93a4e2..7893cb3 100644
--- a/dlls/x11drv/dib.c
+++ b/dlls/x11drv/dib.c
@@ -395,7 +395,7 @@
 
     if (core_info)
     {
-        colors = 1 << ((BITMAPCOREINFO*) info)->bmciHeader.bcBitCount;
+        colors = 1 << ((const BITMAPCOREINFO*) info)->bmciHeader.bcBitCount;
     }
     else
     {
@@ -418,22 +418,22 @@
            /* Convert RGBTRIPLEs to RGBQUADs */
            for (i=0; i < colors; i++)
            {
-               colorTable[i].rgbRed   = ((BITMAPCOREINFO*) info)->bmciColors[i].rgbtRed;
-               colorTable[i].rgbGreen = ((BITMAPCOREINFO*) info)->bmciColors[i].rgbtGreen;
-               colorTable[i].rgbBlue  = ((BITMAPCOREINFO*) info)->bmciColors[i].rgbtBlue;
+               colorTable[i].rgbRed   = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtRed;
+               colorTable[i].rgbGreen = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtGreen;
+               colorTable[i].rgbBlue  = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtBlue;
                colorTable[i].rgbReserved = 0;
            }
         }
         else
         {
-            memcpy(colorTable, (LPBYTE) info + (WORD) info->bmiHeader.biSize, colors * sizeof(RGBQUAD));
+            memcpy(colorTable, (const BYTE*) info + (WORD) info->bmiHeader.biSize, colors * sizeof(RGBQUAD));
         }
     }
     else
     {
         HPALETTE hpal = GetCurrentObject(physDev->hdc, OBJ_PAL);
         PALETTEENTRY * pal_ents;
-        WORD *index = (WORD*) ((LPBYTE) info + (WORD) info->bmiHeader.biSize);
+        const WORD *index = (const WORD*) ((const BYTE*) info + (WORD) info->bmiHeader.biSize);
         int logcolors, entry;
 
         logcolors = GetPaletteEntries( hpal, 0, 0, NULL );
@@ -3761,7 +3761,7 @@
     LONG width, height;
     BOOL top_down;
     POINT pt;
-    void* colorPtr;
+    const void* colorPtr;
 
     if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height,
 			   &descr.infoBpp, &descr.compression ) == -1)
@@ -3817,7 +3817,7 @@
     XSetFunction(gdi_display, physDev->gc, X11DRV_XROPfunction[GetROP2(physDev->hdc) - 1]);
     wine_tsx11_unlock();
 
-    colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize;
+    colorPtr = (const BYTE*) info + (WORD) info->bmiHeader.biSize;
 
     switch (descr.infoBpp)
     {
@@ -3887,7 +3887,7 @@
   BITMAP bitmap;
   LONG height, tmpheight;
   INT result;
-  void* colorPtr;
+  const void* colorPtr;
 
   descr.physDev = physDev;
 
@@ -3906,7 +3906,7 @@
 
   if (startscan + lines > height) lines = height - startscan;
 
-  colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize;
+  colorPtr = (const BYTE*) info + (WORD) info->bmiHeader.biSize;
 
   switch (descr.infoBpp)
   {
diff --git a/libs/unicode/cptable.c b/libs/unicode/cptable.c
index ce5d6cf..58574b2 100644
--- a/libs/unicode/cptable.c
+++ b/libs/unicode/cptable.c
@@ -156,7 +156,7 @@
 
 static int cmp_codepage( const void *codepage, const void *entry )
 {
-    return (unsigned int)codepage - (*(const union cptable **)entry)->info.codepage;
+    return (unsigned int)codepage - (*(const union cptable *const *)entry)->info.codepage;
 }
 
 
diff --git a/tools/wrc/parser.y b/tools/wrc/parser.y
index 6add4b2..b444540 100644
--- a/tools/wrc/parser.y
+++ b/tools/wrc/parser.y
@@ -2562,7 +2562,7 @@
 }
 
 /* qsort sorting function for string table entries */
-#define STE(p)	((stt_entry_t *)(p))
+#define STE(p)	((const stt_entry_t *)(p))
 static int sort_stt_entry(const void *e1, const void *e2)
 {
 	return STE(e1)->id - STE(e2)->id;