Index: /trunk/openjdk/jdk/src/windows/javavm/export/jni_md.h
===================================================================
--- /trunk/openjdk/jdk/src/windows/javavm/export/jni_md.h	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/javavm/export/jni_md.h	(revision 195)
@@ -39,3 +39,31 @@
 typedef signed char jbyte;
 
+#ifdef __cplusplus
+
+/* template for safe type casting: the generic version lets the compiler
+ * decide (as if no template was used); specific instantiations deal with
+ * special cases which are guaranteed to be safe */
+template<typename TR, typename TS>
+inline TR jsafe_cast(TS ts) { return ts; }
+
+#ifdef __EMX__
+/* sizeof(jchar) = sizeof(wchar_t) in GCC but the types are not relative
+ * (as opposed to MSVC) so an explicit cast is required */
+typedef unsigned short jchar;
+template<>
+inline jchar *jsafe_cast<jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<jchar*>(ts); }
+template<>
+inline const jchar *jsafe_cast<const jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
+template<>
+inline const jchar *jsafe_cast<const jchar *, const wchar_t *>(const wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
+template<>
+inline wchar_t *jsafe_cast<wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<wchar_t*>(ts); }
+template<>
+inline const wchar_t *jsafe_cast<const wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
+template<>
+inline const wchar_t *jsafe_cast<const wchar_t *, const jchar *>(const jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
+#endif
+
+#endif /* __cplusplus */
+
 #endif /* !_JAVASOFT_JNI_MD_H_ */
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/ShellFolder2.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/ShellFolder2.cpp	(revision 195)
@@ -181,5 +181,5 @@
                                          (CHAR*)pidl + pStrret->uOffset);
         case STRRET_WSTR :
-            return env->NewString(reinterpret_cast<const jchar*>(pStrret->pOleStr),
+            return env->NewString(jsafe_cast<const jchar*>(pStrret->pOleStr),
                 static_cast<jsize>(wcslen(pStrret->pOleStr)));
     }
@@ -188,6 +188,6 @@
 // restoring the original definition
 #define JNU_NewStringPlatform(env, x) \
-    env->NewString(reinterpret_cast<const jchar*>(x), \
-        static_cast<jsize>(_tcslen(reinterpret_cast<const WCHAR*>(x))))
+    env->NewString(jsafe_cast<const jchar*>(x), \
+        static_cast<jsize>(_tcslen(jsafe_cast<const WCHAR*>(x))))
 
 /*
@@ -729,8 +729,8 @@
     jchar* wszPath = new jchar[nLength + 1];
     const jchar* strPath = env->GetStringChars(jname, NULL);
-    wcsncpy(reinterpret_cast<wchar_t*>(wszPath), reinterpret_cast<const wchar_t*>(strPath), nLength);
+    wcsncpy(jsafe_cast<wchar_t*>(wszPath), jsafe_cast<const wchar_t*>(strPath), nLength);
     wszPath[nLength] = 0;
     HRESULT res = pIShellFolder->ParseDisplayName(NULL, NULL,
-                        reinterpret_cast<WCHAR*>(wszPath), NULL, &pIDL, NULL);
+                        jsafe_cast<WCHAR*>(wszPath), NULL, &pIDL, NULL);
     if (res != S_OK) {
         JNU_ThrowIOException(env, "Could not parse name");
@@ -775,5 +775,5 @@
 {
     SHFILEINFO fileInfo;
-    if (fn_SHGetFileInfo((LPCTSTR)pIDL, 0L, &fileInfo, sizeof(fileInfo),
+    if (fn_SHGetFileInfo(reinterpret_cast<LPCTSTR>(pIDL), 0L, &fileInfo, sizeof(fileInfo),
         SHGFI_TYPENAME | SHGFI_PIDL) == 0) {
         return NULL;
@@ -791,5 +791,5 @@
 {
     TCHAR szBuf[MAX_PATH];
-    LPCTSTR szPath = (LPCTSTR)JNU_GetStringPlatformChars(env, path, NULL);
+    LPCTSTR szPath = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, path, NULL));
     if (szPath == NULL) {
         return NULL;
@@ -814,5 +814,5 @@
     HICON hIcon = NULL;
     SHFILEINFO fileInfo;
-    LPCTSTR pathStr = (LPCTSTR)JNU_GetStringPlatformChars(env, absolutePath, NULL);
+    LPCTSTR pathStr = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, absolutePath, NULL));
     if (fn_SHGetFileInfo(pathStr, 0L, &fileInfo, sizeof(fileInfo),
                          SHGFI_ICON | (getLargeIcon ? 0 : SHGFI_SMALLICON)) != 0) {
@@ -1018,5 +1018,5 @@
     if (libShell32 != NULL) {
         hBitmap = (HBITMAP)LoadImage(libShell32,
-                    isVista ? TEXT("IDB_TB_SH_DEF_16") : (LPCTSTR)MAKEINTRESOURCE(216),
+                    isVista ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216),
                     IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
     }
@@ -1024,5 +1024,5 @@
         libComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
         if (libComCtl32 != NULL) {
-            hBitmap = (HBITMAP)LoadImage(libComCtl32, (LPCTSTR)MAKEINTRESOURCE(124),
+            hBitmap = (HBITMAP)LoadImage(libComCtl32, MAKEINTRESOURCE(124),
                                          IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
         }
@@ -1032,5 +1032,5 @@
     }
 
-    GetObject(hBitmap, sizeof(bm), (LPSTR)&bm);
+    GetObject(hBitmap, sizeof(bm), reinterpret_cast<LPSTR>(&bm));
 
     // Get the screen DC
@@ -1088,5 +1088,5 @@
     (JNIEnv* env, jclass cls, jint iconID)
 {
-    return (jlong)LoadIcon(NULL, (LPCTSTR)MAKEINTRESOURCE(iconID));
+    return (jlong)LoadIcon(NULL, MAKEINTRESOURCE(iconID));
 }
 
@@ -1101,8 +1101,8 @@
      jint cxDesired, jint cyDesired, jboolean useVGAColors)
 {
-    HINSTANCE libHandle = LoadLibrary(reinterpret_cast<const WCHAR*>(env->GetStringChars(libName, NULL)));
+    HINSTANCE libHandle = LoadLibrary(jsafe_cast<const WCHAR*>(env->GetStringChars(libName, NULL)));
     if (libHandle != NULL) {
         UINT fuLoad = (useVGAColors && !isXP) ? LR_VGACOLOR : 0;
-        return ptr_to_jlong(LoadImage(libHandle, (LPCTSTR)MAKEINTRESOURCE(iconID),
+        return ptr_to_jlong(LoadImage(libHandle, MAKEINTRESOURCE(iconID),
                                       IMAGE_ICON, cxDesired, cyDesired,
                                       fuLoad));
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/ThemeReader.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/ThemeReader.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/ThemeReader.cpp	(revision 195)
@@ -251,5 +251,5 @@
                     lastError,
                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                    (LPSTR)&msgBuffer,
+                    reinterpret_cast<LPSTR>(&msgBuffer),
                     // it's an output parameter when allocate buffer is used
                     0,
@@ -271,5 +271,5 @@
 (JNIEnv *env, jclass klass, jstring widget) {
 
-    LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
+    LPCTSTR str = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, widget, NULL));
     // We need to open the Theme on a Window that will stick around.
     // The best one for that purpose is the Toolkit window.
@@ -289,5 +289,5 @@
     LPCTSTR str = NULL;
     if (subAppName != NULL) {
-        str = (LPCTSTR) JNU_GetStringPlatformChars(env, subAppName, NULL);
+        str = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, subAppName, NULL));
     }
     // We need to set the Window theme on the same theme that we opened it with.
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.cpp	(revision 195)
@@ -78,5 +78,5 @@
     // initialization.
     HMODULE hmodAWT = GetModuleHandleA("awt");
-    LPSTR abspath = (LPSTR)safe_Malloc(MAX_PATH);
+    LPSTR abspath = static_cast<LPSTR>(safe_Malloc(MAX_PATH));
     if (abspath != NULL) {
         GetModuleFileNameA(hmodAWT, abspath, MAX_PATH);
@@ -161,5 +161,5 @@
     const DWORD num)
 {
-    LPWSTR pwstrbuf = (LPWSTR)(pi1W + num);
+    LPWSTR pwstrbuf = reinterpret_cast<LPWSTR>(pi1W + num);
     DWORD current;
 
@@ -223,5 +223,5 @@
     const DWORD num)
 {
-    LPWSTR pbuf = (LPWSTR)(pi5W + num);
+    LPWSTR pbuf = reinterpret_cast<LPWSTR>(pi5W + num);
     DWORD current;
 
@@ -337,5 +337,5 @@
     if (Name != NULL) {
         DWORD len = static_cast<DWORD>(wcslen(Name)) + 1;
-        pNameA = (LPSTR)safe_Malloc(len);
+        pNameA = static_cast<LPSTR>(safe_Malloc(len));
         ::WideCharToMultiByte(CP_ACP, 0, Name, -1, pNameA, len, NULL, NULL);
     }
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.h
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.h	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.h	(revision 195)
@@ -77,10 +77,10 @@
 // to proper JNI functions.
 #ifdef __WIN32OS2__
-#define JNU_NewStringPlatform(env, x) env->NewString(reinterpret_cast<const jchar*>(x), static_cast<jsize>(_tcslen(reinterpret_cast<LPCTSTR>(x))))
-#define JNU_GetStringPlatformChars(env, x, y) (LPWSTR)env->GetStringChars(x, y)
-#define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, reinterpret_cast<const jchar*>(y))
+#define JNU_NewStringPlatform(env, x) env->NewString(jsafe_cast<const jchar*>(x), static_cast<jsize>(_tcslen(jsafe_cast<LPCWSTR>(x))))
+#define JNU_GetStringPlatformChars(env, x, y) jsafe_cast<LPCWSTR>(env->GetStringChars(x, y))
+#define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, jsafe_cast<const jchar*>(y))
 #else
 #define JNU_NewStringPlatform(env, x) env->NewString(x, static_cast<jsize>(_tcslen(x)))
-#define JNU_GetStringPlatformChars(env, x, y) (LPWSTR)env->GetStringChars(x, y)
+#define JNU_GetStringPlatformChars(env, x, y) jsafe_cast<LPWSTR>(env->GetStringChars(x, y))
 #define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, y)
 #endif
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/WPrinterJob.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/WPrinterJob.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/WPrinterJob.cpp	(revision 195)
@@ -141,5 +141,5 @@
        }
 
-       pPrinterName = (LPTSTR)GlobalAlloc(GPTR, (index+1)*sizeof(TCHAR));
+       pPrinterName = static_cast<LPTSTR>(GlobalAlloc(GPTR, (index+1)*sizeof(TCHAR)));
        lstrcpyn(pPrinterName, cBuffer, index+1);
        jPrinterName = JNU_NewStringPlatform(env, pPrinterName);
@@ -244,9 +244,9 @@
     HANDLE hPrinter;
 
-    LPTSTR printerName = NULL;
+    LPCTSTR printerName = NULL;
     if (printer != NULL) {
-        printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
+        printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
                                                          printer,
-                                                         NULL);
+                                                         NULL));
         JNU_ReleaseStringPlatformChars(env, printer, printerName);
     }
@@ -254,5 +254,5 @@
     // printerName - "Win NT/2K/XP: If NULL, it indicates the local printer
     // server" - MSDN.   Win9x : OpenPrinter returns 0.
-    BOOL ret = OpenPrinter(printerName, &hPrinter, NULL);
+    BOOL ret = OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL);
     if (!ret) {
       return (jlong)-1;
@@ -304,6 +304,6 @@
     TRY;
 
-    LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                            printer, NULL);
+    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                            printer, NULL));
 
     jfloatArray printableArray = NULL;
@@ -315,5 +315,5 @@
         HANDLE hPrinter;
         /* Start by opening the printer */
-        if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
+        if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
             JNU_ReleaseStringPlatformChars(env, printer, printerName);
             return printableArray;
@@ -322,5 +322,6 @@
         PDEVMODE pDevMode;
 
-        if (!AwtPrintControl::getDevmode(hPrinter, printerName, &pDevMode)) {
+        if (!AwtPrintControl::getDevmode(hPrinter, const_cast<LPTSTR>(printerName),
+                                         &pDevMode)) {
             /* if failure, cleanup and return failure */
 
@@ -384,6 +385,6 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
   jintArray mediasizeArray = NULL;
 
@@ -403,5 +404,5 @@
     jint *jpcIndices = env->GetIntArrayElements(mediasizeArray,
                                        &isCopy), *saveFormats = jpcIndices;
-    LPTSTR papersBuf = (LPTSTR)new char[numSizes * sizeof(WORD)];
+    LPTSTR papersBuf = reinterpret_cast<LPTSTR>(new char[numSizes * sizeof(WORD)]);
     if (::DeviceCapabilities(printerName, printerPort,
                              DC_PAPERS, papersBuf, NULL) != -1) {
@@ -432,7 +433,7 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                          printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                          printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   jintArray mediaTrayArray = NULL;
@@ -452,5 +453,5 @@
                                            &isCopy), *saveFormats = jpcIndices;
 
-    LPTSTR buf = (LPTSTR)new char[nBins * sizeof(WORD)];
+    LPTSTR buf = reinterpret_cast<LPTSTR>(new char[nBins * sizeof(WORD)]);
 
     if (::DeviceCapabilities(printerName, printerPort,
@@ -482,7 +483,7 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                          printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                          printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   jintArray mediaArray = NULL;
@@ -502,5 +503,5 @@
                                           &isCopy), *saveFormats = jpcIndices;
 
-    LPTSTR buf = (LPTSTR)new char[nPapers * sizeof(POINT)]; // array of POINTs
+    LPTSTR buf = reinterpret_cast<LPTSTR>(new char[nPapers * sizeof(POINT)]); // array of POINTs
 
     if (::DeviceCapabilities(printerName, printerPort,
@@ -531,7 +532,7 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                          printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                          printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   jstring utf_str;
@@ -545,5 +546,5 @@
   if (cReturned > 0) {
 
-    buf = (LPTSTR)new char[cReturned * buf_len * sizeof(TCHAR)];
+    buf = reinterpret_cast<LPTSTR>(new char[cReturned * buf_len * sizeof(TCHAR)]);
     if (buf == NULL) {
       throw std::bad_alloc();
@@ -603,6 +604,6 @@
                                                     jstring port)
 {
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   SAVE_CONTROLWORD
@@ -641,6 +642,6 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   jintArray resolutionArray = NULL;
@@ -660,5 +661,5 @@
                                           &isCopy), *saveFormats = jpcIndices;
 
-    LPTSTR resBuf = (LPTSTR)new char[nResolutions * sizeof(LONG) * 2]; // pairs of long
+    LPTSTR resBuf = reinterpret_cast<LPTSTR>(new char[nResolutions * sizeof(LONG) * 2]); // pairs of long
 
     if (::DeviceCapabilities(printerName, printerPort,
@@ -692,5 +693,5 @@
     nEscapeCode = POSTSCRIPT_PASSTHROUGH;
     if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
-                     (LPCSTR)&nEscapeCode, 0, NULL ) > 0 )
+                     reinterpret_cast<LPCSTR>(&nEscapeCode), 0, NULL ) > 0 )
         return TRUE;
 
@@ -698,10 +699,10 @@
     nEscapeCode = GETTECHNOLOGY;
     if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
-                     (LPCSTR)&nEscapeCode, 0, NULL ) <= 0 )
+                     reinterpret_cast<LPCSTR>(&nEscapeCode), 0, NULL ) <= 0 )
         return FALSE;
 
     // Get the technology string and check if the word "postscript" is in it.
     if( ::ExtEscape( hDC, GETTECHNOLOGY, 0, NULL, MAX_PATH,
-                     (LPSTR)szTechnology ) <= 0 )
+                     reinterpret_cast<LPSTR>(szTechnology) ) <= 0 )
         return FALSE;
     strupr( szTechnology );
@@ -756,6 +757,6 @@
                                                  jstring port)
 {
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
   // 0x1000 is a flag to indicate that getCapabilities has already been called.
   // 0x0001 is a flag for color support and supported is the default.
@@ -829,6 +830,6 @@
   TRY;
 
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
-  LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
+  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
 
   jintArray defaultArray = env->NewIntArray(NDEFAULT);
@@ -846,5 +847,5 @@
 
   /* Start by opening the printer */
-  if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
+  if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
       env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
       JNU_ReleaseStringPlatformChars(env, printer, printerName);
@@ -852,5 +853,5 @@
   }
 
-  if (!AwtPrintControl::getDevmode(hPrinter, printerName, &pDevMode)) {
+  if (!AwtPrintControl::getDevmode(hPrinter, const_cast<LPTSTR>(printerName), &pDevMode)) {
       /* if failure, cleanup and return failure */
       if (pDevMode != NULL) {
@@ -876,8 +877,8 @@
                                           DC_PAPERS, NULL, NULL);
       if (numSizes > 0) {
-          LPWORD papers = (LPWORD)safe_Malloc(numSizes * sizeof(WORD));
+          LPWORD papers = static_cast<LPWORD>(safe_Malloc(numSizes * sizeof(WORD)));
           if (papers != NULL &&
               ::DeviceCapabilities(printerName, printerPort,
-                                   DC_PAPERS, (LPTSTR)papers, NULL) != -1) {
+                                   DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL) != -1) {
               int present = 0;
               for (int i=0;i<numSizes;i++) {
@@ -951,8 +952,8 @@
     int ret=0;
 
-    LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
+    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
 
     // Start by opening the printer
-    if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
+    if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
         JNU_ReleaseStringPlatformChars(env, printer, printerName);
         return -1;
@@ -1039,14 +1040,14 @@
   HANDLE      hPrinter;
   DOC_INFO_1  DocInfo;
-  LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
+  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
   DASSERT(jobname != NULL);
-  LPTSTR lpJobName = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
+  LPCTSTR lpJobName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jobname, NULL));
   LPTSTR jname = _tcsdup(lpJobName);
   JNU_ReleaseStringPlatformChars(env, jobname, lpJobName);
 
   // Start by opening the printer
-  if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
+  if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
     JNU_ReleaseStringPlatformChars(env, printer, printerName);
-    free((LPTSTR)jname);
+    free(jname);
     return false;
   }
@@ -1062,9 +1063,9 @@
   if( (::StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)) == 0 ) {
     ::ClosePrinter( hPrinter );
-    free((LPTSTR)jname);
+    free(jname);
     return false;
   }
 
-  free((LPTSTR)jname);
+  free(jname);
 
   // Start a page.
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Button.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Button.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Button.cpp	(revision 195)
@@ -107,5 +107,5 @@
             labelStr = L"";
         } else {
-            labelStr = (LPCWSTR)env->GetStringChars(label, JNI_FALSE);
+            labelStr = jsafe_cast<LPCWSTR>(env->GetStringChars(label, JNI_FALSE));
         }
         style = 0;
@@ -129,5 +129,5 @@
         c->UpdateBackground(env, target);
         if (label != NULL)
-            env->ReleaseStringChars(label, (jchar*)labelStr);
+            env->ReleaseStringChars(label, jsafe_cast<const jchar*>(labelStr));
     } catch (...) {
         env->DeleteLocalRef(target);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Checkbox.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Checkbox.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Checkbox.cpp	(revision 195)
@@ -107,5 +107,5 @@
             label = (jstring)env->GetObjectField(target, AwtCheckbox::labelID);
             if (label != NULL) {
-                labelStr = (LPCWSTR)env->GetStringChars(label, 0);
+                labelStr = jsafe_cast<LPCWSTR>(env->GetStringChars(label, 0));
             }
             if (labelStr != 0) {
@@ -124,5 +124,5 @@
 
                 if (labelStr != defaultLabelStr) {
-                    env->ReleaseStringChars(label, (jchar*)labelStr);
+                    env->ReleaseStringChars(label, jsafe_cast<const jchar*>(labelStr));
                 }
             } else {
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Component.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Component.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Component.cpp	(revision 195)
@@ -553,5 +553,5 @@
             FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                 NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                (LPTSTR)&buf, 0, NULL);
+                reinterpret_cast<LPTSTR>(&buf), 0, NULL);
             jstring s = JNU_NewStringPlatform(env, buf);
             createError = JNU_NewObjectByName(env, "java/lang/InternalError",
@@ -1884,5 +1884,5 @@
       case WM_SETTINGCHANGE:
           CheckFontSmoothingSettings(NULL);
-          mr = WmSettingChange(static_cast<UINT>(wParam), (LPCTSTR)lParam);
+          mr = WmSettingChange(static_cast<UINT>(wParam), reinterpret_cast<LPCTSTR>(lParam));
           break;
       case WM_CONTEXTMENU:
@@ -3617,5 +3617,5 @@
         WCHAR unicodeChar[2];
         VERIFY(::MultiByteToWideChar(GetCodePage(), MB_PRECOMPOSED,
-        (LPCSTR)&mbChar, 1, unicodeChar, 1));
+        reinterpret_cast<LPCSTR>(&mbChar), 1, unicodeChar, 1));
 
         translation = unicodeChar[0];
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DataTransferer.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DataTransferer.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DataTransferer.cpp	(revision 195)
@@ -289,5 +289,5 @@
 
         UINT bufsize = 512; // in characters, not in bytes
-        buffer = (LPTSTR)safe_Malloc(bufsize*sizeof(TCHAR));
+        buffer = static_cast<LPTSTR>(safe_Malloc(bufsize*sizeof(TCHAR)));
 
         for (UINT i = 0; i < nFilenames; i++) {
@@ -295,5 +295,5 @@
             if (size > bufsize) {
                 bufsize = size;
-                buffer = (LPTSTR)safe_Realloc(buffer, bufsize*sizeof(TCHAR));
+                buffer = static_cast<LPTSTR>(safe_Realloc(buffer, bufsize*sizeof(TCHAR)));
             }
             (*do_drag_query_file)(hdrop, i, buffer, bufsize);
@@ -391,5 +391,5 @@
         case CF_DIB:
 
-            pSrcBmi = (BITMAPINFO*)((LPSTR)bBytes + uOffset);
+            pSrcBmi = (BITMAPINFO*)(reinterpret_cast<LPSTR>(bBytes) + uOffset);
             pSrcBmih = &pSrcBmi->bmiHeader;
 
@@ -429,5 +429,5 @@
                 }
 
-                pSrcBits = (LPSTR)pSrcBmi + pSrcBmih->biSize
+                pSrcBits = reinterpret_cast<LPSTR>(pSrcBmi) + pSrcBmih->biSize
                     + nColorEntries * sizeof(RGBQUAD);
             }
@@ -666,5 +666,5 @@
     pinfo->bmiHeader.biSizeImage = size + pad;
 
-    jbyte *array = (jbyte*)((LPSTR)pinfo + sizeof(BITMAPINFOHEADER));
+    jbyte *array = (jbyte*)(reinterpret_cast<LPSTR>(pinfo) + sizeof(BITMAPINFOHEADER));
     env->GetByteArrayRegion(imageData, 0, size, array);
     HRESULT hr = S_OK;
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Debug.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Debug.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Debug.cpp	(revision 195)
@@ -158,5 +158,5 @@
                   lastError,
                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                  (LPSTR)&msgBuffer, // it's an output parameter when allocate buffer is used
+                  reinterpret_cast<LPSTR>(&msgBuffer), // it's an output parameter when allocate buffer is used
                   0,
                   NULL);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Desktop.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Desktop.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Desktop.cpp	(revision 195)
@@ -41,6 +41,6 @@
   (JNIEnv *env, jclass cls, jstring uri_j, jstring verb_j)
 {
-    const WCHAR* uri_c = (const WCHAR*)env->GetStringChars(uri_j, JNI_FALSE);
-    const WCHAR* verb_c = (const WCHAR*)env->GetStringChars(verb_j, JNI_FALSE);
+    const WCHAR* uri_c = jsafe_cast<const WCHAR*>(env->GetStringChars(uri_j, JNI_FALSE));
+    const WCHAR* verb_c = jsafe_cast<const WCHAR*>(env->GetStringChars(verb_j, JNI_FALSE));
 
     // 6457572: ShellExecute possibly changes FPU control word - saving it here
@@ -49,10 +49,10 @@
     _control87(oldcontrol87, 0xffffffff);
 
-    env->ReleaseStringChars(uri_j, (jchar*)uri_c);
-    env->ReleaseStringChars(verb_j, (jchar*)verb_c);
+    env->ReleaseStringChars(uri_j, jsafe_cast<const jchar*>(uri_c));
+    env->ReleaseStringChars(verb_j, jsafe_cast<const jchar*>(verb_c));
 
     if ((int)retval <= 32) {
         // ShellExecute failed.
-        LPVOID buffer;
+        LPWSTR buffer;
         int len = FormatMessageW(
                     FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -62,9 +62,9 @@
                     GetLastError(),
                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-                    (LPWSTR) &buffer,
+                    reinterpret_cast<LPWSTR>(&buffer),
                     0,
                     NULL );
 
-        jstring errmsg = env->NewString((jchar*)buffer, len);
+        jstring errmsg = env->NewString(jsafe_cast<const jchar*>(buffer), len);
         LocalFree(buffer);
         return errmsg;
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	(revision 195)
@@ -121,5 +121,5 @@
         return NULL;
     }
-    LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
+    LPTSTR buffer = static_cast<LPTSTR>(safe_Malloc(valueSize));
     if (RegQueryValueEx((HKEY)handle, fontName, NULL,
                         &valueType, (unsigned char *)buffer, &valueSize) != 0) {
@@ -167,5 +167,5 @@
         return NULL;
     }
-    LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
+    LPTSTR buffer = static_cast<LPTSTR>(safe_Malloc(valueSize));
     if (RegQueryValueEx((HKEY)handle, valueName, NULL,
                         valueType, (unsigned char *)buffer, &valueSize) != 0) {
@@ -179,5 +179,5 @@
         // Pending: buffer must be null-terminated at this point
         valueChar = ExpandEnvironmentStrings(buffer, NULL, 0);
-        LPTSTR buffer2 = (LPTSTR)safe_Malloc(valueChar*sizeof(TCHAR));
+        LPTSTR buffer2 = static_cast<LPTSTR>(safe_Malloc(valueChar*sizeof(TCHAR)));
         ExpandEnvironmentStrings(buffer, buffer2, valueChar);
         free(buffer);
@@ -609,9 +609,9 @@
 
     LPTSTR valueName = TEXT("PlaceN");
-    LPTSTR valueNameBuf = (LPTSTR)safe_Malloc((lstrlen(valueName) + 1) * sizeof(TCHAR));
+    LPTSTR valueNameBuf = static_cast<LPTSTR>(safe_Malloc((lstrlen(valueName) + 1) * sizeof(TCHAR)));
     lstrcpy(valueNameBuf, valueName);
 
     LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
-    LPTSTR propKeyBuf = (LPTSTR)safe_Malloc((lstrlen(propKey) + 1) * sizeof(TCHAR));
+    LPTSTR propKeyBuf = static_cast<LPTSTR>(safe_Malloc((lstrlen(propKey) + 1) * sizeof(TCHAR)));
     lstrcpy(propKeyBuf, propKey);
 
@@ -672,5 +672,5 @@
 
 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     GetEnv()->CallVoidMethod(self,
                              AwtDesktopProperties::setStringPropertyID,
@@ -680,5 +680,5 @@
 
 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     GetEnv()->CallVoidMethod(self,
                              AwtDesktopProperties::setIntegerPropertyID,
@@ -688,5 +688,5 @@
 
 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     GetEnv()->CallVoidMethod(self,
                              AwtDesktopProperties::setBooleanPropertyID,
@@ -696,5 +696,5 @@
 
 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     GetEnv()->CallVoidMethod(self,
                              AwtDesktopProperties::setColorPropertyID,
@@ -731,5 +731,5 @@
                             // fall back to Microsoft Sans Serif
                             fontName = JNU_NewStringPlatform(GetEnv(),
-                                         (const jchar*)L"Microsoft Sans Serif");
+                                         jsafe_cast<const jchar*>(L"Microsoft Sans Serif"));
                         }
                     }
@@ -748,5 +748,5 @@
                     }
 
-                    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+                    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
                     GetEnv()->CallVoidMethod(self,
                               AwtDesktopProperties::setFontPropertyID,
@@ -789,5 +789,5 @@
     }
 
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
                              key, fontName, style, pointSize);
@@ -798,6 +798,6 @@
 
 void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) {
-    jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
-    jstring event = JNU_NewStringPlatform(GetEnv(), (const jchar*)winEventName);
+    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
+    jstring event = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(winEventName));
     GetEnv()->CallVoidMethod(self,
                              AwtDesktopProperties::setSoundPropertyID,
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp	(revision 195)
@@ -1194,5 +1194,5 @@
     ::CoFileTimeNow(&now);
 
-    m_statstg.pwcsName          = (LPWSTR)NULL;
+    m_statstg.pwcsName          = NULL;
     m_statstg.type              = STGTY_STREAM;
     m_statstg.cbSize.HighPart   = 0;
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp	(revision 195)
@@ -556,6 +556,6 @@
         }
         case TYMED_FILE: {
-            jobject local = JNU_NewStringPlatform(env, (LPCTSTR)
-                                                  stgmedium.lpszFileName);
+            jobject local = JNU_NewStringPlatform(env, jsafe_cast<LPCTSTR>(
+                                                  stgmedium.lpszFileName));
             jstring fileName = (jstring)env->NewGlobalRef(local);
             env->DeleteLocalRef(local);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp	(revision 195)
@@ -66,5 +66,5 @@
     int length = env->GetStringLength(filterDescription);
     DASSERT(length + 1 < MAX_FILTER_STRING);
-    LPCTSTR tmp = (LPTSTR)JNU_GetStringPlatformChars(env, filterDescription, NULL);
+    LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, filterDescription, NULL));
     _tcscpy(s_fileFilterString, tmp);
     JNU_ReleaseStringPlatformChars(env, filterDescription, tmp);
@@ -237,5 +237,5 @@
 
         if (title == NULL || env->GetStringLength(title)==0) {
-            title = env->NewString((const jchar*)&unicodeChar, 1);
+            title = env->NewString(jsafe_cast<const jchar*>(&unicodeChar), 1);
         }
 
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Font.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Font.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Font.cpp	(revision 195)
@@ -366,6 +366,6 @@
           NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
 {
-    if(_tcsstr((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName)) {
-        _tcscpy((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName);
+    if(_tcsstr(reinterpret_cast<LPTSTR>(lParam), lpelfe->elfLogFont.lfFaceName)) {
+        _tcscpy(reinterpret_cast<LPTSTR>(lParam), lpelfe->elfLogFont.lfFaceName);
         return 0;
     } else {
@@ -694,5 +694,5 @@
                 // Start of conversion Code to fix arabic shaping problems
                 // with unicode support in win 95
-                LPSTR buffer =  (LPSTR) alloca((wcslen(string) + 1) * 2);
+                LPSTR buffer =  static_cast<LPSTR>(alloca((wcslen(string) + 1) * 2));
                 int count = ::WideCharToMultiByte(codePage, 0, string, length,
                                                   buffer,
@@ -754,6 +754,6 @@
 
                 if (unicodeUsed) {
-                    VERIFY(!draw || ::TextOutW(hDC, x, y, (LPCWSTR)offsetBuffer, buflen / 2));
-                    VERIFY(::GetTextExtentPoint32W(hDC, (LPCWSTR)offsetBuffer, buflen / 2, &temp));
+                    VERIFY(!draw || ::TextOutW(hDC, x, y, reinterpret_cast<LPCWSTR>(offsetBuffer), buflen / 2));
+                    VERIFY(::GetTextExtentPoint32W(hDC, reinterpret_cast<LPCWSTR>(offsetBuffer), buflen / 2, &temp));
                 }
                 else {
@@ -1777,5 +1777,5 @@
     VERIFY(::WideCharToMultiByte(CP_ACP, 0, szFamilyName, -1,
         szTmpName, sizeof(szTmpName), NULL, NULL));
-    LONG lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szTmpName,
+    LONG lStatus = ::RegQueryValueExA(hKey, reinterpret_cast<LPCSTR>(szTmpName),
         NULL, &dwType, szFileName, &dwBytes);
     BOOL fUseDefault = FALSE;
@@ -1788,5 +1788,5 @@
         }
         char szDefault[] = "SystemDefaultEUDCFont";
-        lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szDefault,
+        lStatus = ::RegQueryValueExA(hKey, reinterpret_cast<LPCSTR>(szDefault),
             NULL, &dwType, szFileName, &dwBytes);
         fUseDefault = TRUE;
@@ -1799,5 +1799,5 @@
     }
 
-    if (strcmp((LPCSTR) szFileName, "userfont.fon") == 0) {
+    if (strcmp(reinterpret_cast<char*>(szFileName), "userfont.fon") == 0) {
         // This font is associated with no EUDC font
         // and the system default EUDC font is not TrueType
@@ -1806,7 +1806,7 @@
     }
 
-    DASSERT(strlen((LPCSTR)szFileName) > 0);
+    DASSERT(strlen(reinterpret_cast<char*>(szFileName)) > 0);
     VERIFY(::MultiByteToWideChar(CP_ACP, 0,
-        (LPCSTR)szFileName, -1, lpszFileName, cchFileName) != 0);
+        reinterpret_cast<LPCSTR>(szFileName), -1, lpszFileName, cchFileName) != 0);
     if (fUseDefault)
         wcscpy(m_szDefaultEUDCFile, lpszFileName);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp	(revision 195)
@@ -511,5 +511,5 @@
 
     if ((buffSize = ::ImmGetDescription(hkl, szImmDescription, 0)) > 0) {
-        szImmDescription = (LPTSTR) safe_Malloc(buffSize * sizeof(TCHAR));
+        szImmDescription = static_cast<LPTSTR>(safe_Malloc(buffSize * sizeof(TCHAR)));
 
         if (szImmDescription != NULL) {
@@ -596,5 +596,5 @@
         if (ret == ERROR_SUCCESS) {
             hkl = reinterpret_cast<HKL>(static_cast<INT_PTR>(
-                _tcstoul((LPCTSTR)szHKL, &end, 16)));
+                _tcstoul(reinterpret_cast<LPCTSTR>(szHKL), &end, 16)));
         }
 
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputTextInfor.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputTextInfor.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputTextInfor.cpp	(revision 195)
@@ -109,8 +109,8 @@
     // Assign the context data
     m_cStrW = cbData[0]/WCHAR_SZ;
-    m_lpStrW = (LPWSTR)lpData[0];
+    m_lpStrW = static_cast<LPWSTR>(lpData[0]);
 
     m_cReadStrW = cbData[1]/WCHAR_SZ;
-    m_lpReadStrW = (LPWSTR)lpData[1];
+    m_lpReadStrW = static_cast<LPWSTR>(lpData[1]);
 
     m_cClauseW = cbData[2]/DWORD_SZ - 1;
@@ -188,5 +188,5 @@
     if (env == NULL || lpStrW == NULL || cStrW == 0) return NULL;
 
-    return env->NewString((jchar*)lpStrW, cStrW);
+    return env->NewString(jsafe_cast<const jchar*>(lpStrW), cStrW);
 }
 
@@ -253,5 +253,5 @@
         }
         else {
-            readingClauseW[cls] = MakeJavaString(env, (LPWSTR)NULL, 0);
+            readingClauseW[cls] = MakeJavaString(env, NULL, 0);
         }
     }
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_List.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_List.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_List.cpp	(revision 195)
@@ -688,8 +688,8 @@
             for (jsize i=0; i < itemCount; i++)
             {
-                LPTSTR itemPtr = NULL;
+                LPCTSTR itemPtr = NULL;
                 jstring item = (jstring)env->GetObjectArrayElement(items, i);
                 JNI_CHECK_NULL_GOTO(item, "null item", next_item);
-                itemPtr = (LPTSTR)JNU_GetStringPlatformChars(env, item, 0);
+                itemPtr = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, item, 0));
                 if (itemPtr == NULL)
                 {
@@ -698,5 +698,5 @@
                 else
                 {
-                    l->InsertString(index+i, itemPtr);
+                    l->InsertString(index+i, const_cast<LPTSTR>(itemPtr));
                     JNU_ReleaseStringPlatformChars(env, item, itemPtr);
                 }
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Menu.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Menu.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Menu.cpp	(revision 195)
@@ -150,9 +150,9 @@
         UINT flags = MF_STRING | (enabled ? MF_ENABLED : MF_GRAYED);
         flags |= MF_OWNERDRAW;
-        LPCTSTR itemInfo = (LPCTSTR) this;
+        LPCTSTR itemInfo = reinterpret_cast<LPCTSTR>(this);
 
         if (_tcscmp(item->GetClassName(), TEXT("SunAwtMenu")) == 0) {
             flags |= MF_POPUP;
-            itemInfo = (LPCTSTR) item;
+            itemInfo = reinterpret_cast<LPCTSTR>(item);
         }
 
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp	(revision 195)
@@ -166,5 +166,5 @@
             FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                 NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                (LPTSTR)&buf, 0, NULL);
+                reinterpret_cast<LPTSTR>(&buf), 0, NULL);
             jstring s = JNU_NewStringPlatform(env, buf);
             createError = JNU_NewObjectByName(env, "java/lang/InternalError",
@@ -636,5 +636,5 @@
 
     mii.fType = MFT_OWNERDRAW;
-    mii.dwTypeData = (LPTSTR)(*sb);
+    mii.dwTypeData = reinterpret_cast<LPTSTR>(*sb);
 
     // find index by menu item id
@@ -700,5 +700,5 @@
         case MENUITEM_SETLABEL:
         {
-            LPCTSTR sb = (LPCTSTR)args->param1;
+            LPCTSTR sb = reinterpret_cast<LPCTSTR>(args->param1);
             DASSERT(!IsBadStringPtr(sb, 20));
             this->SetLabel(sb);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp	(revision 195)
@@ -136,5 +136,5 @@
 
     JavaStringBuffer printerNameBuf(env, printerName);
-    LPTSTR lpcPrinterName = (LPTSTR)printerNameBuf;
+    LPTSTR lpcPrinterName = jsafe_cast<LPTSTR>(printerNameBuf);
     DASSERT(lpcPrinterName != NULL);
 
@@ -436,5 +436,5 @@
             (DEVNAMES *)::GlobalLock(ppd->hDevNames);
         DASSERT(!IsBadWritePtr(devnames, devnameSize));
-        LPTSTR lpcDevnames = (LPTSTR)devnames;
+        LPTSTR lpcDevnames = reinterpret_cast<LPTSTR>(devnames);
 
         // note: all sizes are in characters, not in bytes
@@ -512,15 +512,15 @@
 
         DWORD result1 = DeviceCapabilities(printer, port,
-                                       DC_PAPERS, (LPTSTR) papers, NULL);
+                                       DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL);
 
         DWORD result2 = DeviceCapabilities(printer, port,
-                                       DC_PAPERSIZE, (LPTSTR) paperSizes,
+                                       DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
                                        NULL);
 
         // REMIND: cache in papers and paperSizes
         if (result1 == -1 || result2 == -1 ) {
-            free((LPTSTR) papers);
+            free(papers);
             papers = NULL;
-            free((LPTSTR) paperSizes);
+            free(paperSizes);
             paperSizes = NULL;
         }
@@ -578,9 +578,9 @@
 
     if (papers != NULL) {
-        free((LPTSTR)papers);
+        free(papers);
     }
 
     if (paperSizes != NULL) {
-        free((LPTSTR)paperSizes);
+        free(paperSizes);
     }
 
@@ -621,6 +621,6 @@
         pd.hDevNames = AwtPrintControl::getPrintHDName(env, printCtrl);
 
-        LPTSTR getName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                      printerName, NULL);
+        LPCTSTR getName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                      printerName, NULL));
 
         BOOL samePrinter = FALSE;
@@ -631,5 +631,5 @@
             DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(pd.hDevNames);
             if (devnames != NULL) {
-                LPTSTR lpdevnames = (LPTSTR)devnames;
+                LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
                 printName = lpdevnames+devnames->wDeviceOffset;
 
@@ -951,5 +951,5 @@
         DEVNAMES *devnames = (DEVNAMES*)::GlobalLock(pd.hDevNames);
         DASSERT(!IsBadReadPtr(devnames, sizeof(DEVNAMES)));
-        LPCTSTR lpcNames = (LPTSTR)devnames;
+        LPCTSTR lpcNames = reinterpret_cast<LPTSTR>(devnames);
         LPCTSTR pbuf = (_tcslen(lpcNames + devnames->wDeviceOffset) == 0 ?
                         TEXT("") : lpcNames + devnames->wDeviceOffset);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp	(revision 195)
@@ -438,5 +438,5 @@
         int sz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, NULL, 0);
         if (sz > 0) {
-          LPTSTR str = (LPTSTR)safe_Malloc(sizeof(TCHAR) * sz);
+          LPTSTR str = static_cast<LPTSTR>(safe_Malloc(sizeof(TCHAR) * sz));
           if (str != NULL) {
             sz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, str, sz);
@@ -446,5 +446,5 @@
               }
             }
-            free((LPTSTR)str);
+            free(str);
           }
         }
@@ -484,5 +484,5 @@
             DEVNAMES* names = (DEVNAMES*)::GlobalLock(setup.hDevNames);
             if (names != NULL) {
-                LPTSTR printer = (LPTSTR)names+names->wDeviceOffset;
+                LPTSTR printer = reinterpret_cast<LPTSTR>(names)+names->wDeviceOffset;
                 SAVE_CONTROLWORD
                 HDC newDC = ::CreateDC(TEXT("WINSPOOL"), printer, NULL, NULL);
@@ -610,5 +610,5 @@
   if (devnames != NULL) {
 
-    LPTSTR lpdevnames = (LPTSTR)devnames;
+    LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
     LPTSTR printerName = _tcsdup(lpdevnames+devnames->wDeviceOffset);
 
@@ -622,5 +622,5 @@
       }
       ::GlobalUnlock(hDevNames);
-      free ((LPTSTR) printerName);
+      free (printerName);
       return;
     }
@@ -633,5 +633,5 @@
         ::ClosePrinter(hPrinter);
         ::GlobalUnlock(hDevNames);
-        free ((LPTSTR) printerName);
+        free (printerName);
         return ;
     }
@@ -648,5 +648,5 @@
                                  LOCALE_IMEASURE, NULL, 0);
           if (sz > 0) {
-            LPTSTR str = (LPTSTR)safe_Malloc(sizeof(TCHAR) * sz);
+            LPTSTR str = static_cast<LPTSTR>(safe_Malloc(sizeof(TCHAR) * sz));
             if (str != NULL) {
               sz = GetLocaleInfo(LOCALE_USER_DEFAULT,
@@ -657,5 +657,5 @@
                 }
               }
-              free((LPTSTR)str);
+              free(str);
             }
           }
@@ -694,5 +694,5 @@
     ::GlobalFree(pDevMode);
 
-    free ((LPTSTR) printerName);
+    free (printerName);
 
     ::ClosePrinter(hPrinter);
@@ -919,5 +919,5 @@
 
         if (devnames != NULL) {
-            LPTSTR lpdevnames = (LPTSTR)devnames;
+            LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
             LPTSTR printername = lpdevnames+devnames->wDeviceOffset;
             LPTSTR port = lpdevnames+devnames->wOutputOffset;
@@ -1090,5 +1090,5 @@
     DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(hDevNames);
     if (devnames != NULL) {
-        LPTSTR lpdevnames = (LPTSTR)devnames;
+        LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
         LPTSTR printer = lpdevnames+devnames->wDeviceOffset;
         LPTSTR port = lpdevnames+devnames->wOutputOffset;
@@ -1128,7 +1128,7 @@
     int err = 0;
 
-    LPTSTR destination = NULL;
+    LPCTSTR destination = NULL;
     if (dest != NULL) {
-        destination = (LPTSTR)JNU_GetStringPlatformChars(env, dest, NULL);
+        destination = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, dest, NULL));
     } else {
         destination = VerifyDestination(env, self);
@@ -1136,5 +1136,5 @@
     LPTSTR docname = NULL;
     if (jobname != NULL) {
-        LPTSTR tmp = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
+        LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jobname, NULL));
         docname = _tcsdup(tmp);
         JNU_ReleaseStringPlatformChars(env, jobname, tmp);
@@ -1353,5 +1353,5 @@
                     if (devnames != NULL) {
 
-                      LPTSTR lpdevnames = (LPTSTR)devnames;
+                      LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
                       LPTSTR printerName = _tcsdup(lpdevnames+devnames->wDeviceOffset);
 
@@ -2984,5 +2984,5 @@
 
             if (devnames != NULL) {
-                LPTSTR lpdevnames = (LPTSTR)devnames;
+                LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
                 LPTSTR printer = lpdevnames+devnames->wDeviceOffset;
                 LPTSTR port = lpdevnames+devnames->wOutputOffset;
@@ -3130,5 +3130,5 @@
 
         DWORD result = DeviceCapabilities(deviceName, portName,
-                                          DC_PAPERSIZE, (LPTSTR) paperSizes,
+                                          DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
                                           NULL);
         if (result == -1) {
@@ -3759,5 +3759,5 @@
         DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(hDevNames);
         if (devnames != NULL) {
-            LPTSTR lpdevnames = (LPTSTR)devnames;
+            LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
             printer = _tcsdup(lpdevnames+devnames->wDeviceOffset);
             port = _tcsdup(lpdevnames+devnames->wOutputOffset);
@@ -3779,7 +3779,7 @@
 
         DWORD result1 = DeviceCapabilities(printer, port,
-                                           DC_PAPERS, (LPTSTR) papers, NULL);
+                                           DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL);
         DWORD result2 = DeviceCapabilities(printer, port,
-                                           DC_PAPERSIZE, (LPTSTR) paperSizes,
+                                           DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
                                            NULL);
 
@@ -3990,15 +3990,15 @@
   // Copy the DEVNAMES information from PRINTER_INFO_2 structure.
   pDevNames->wDriverOffset = sizeof(DEVNAMES)/sizeof(TCHAR);
-  memcpy((LPTSTR)pDevNames + pDevNames->wDriverOffset,
+  memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wDriverOffset,
          p2->pDriverName, drvNameLen*sizeof(TCHAR));
 
    pDevNames->wDeviceOffset = static_cast<WORD>(sizeof(DEVNAMES)/sizeof(TCHAR)) +
    drvNameLen + 1;
-   memcpy((LPTSTR)pDevNames + pDevNames->wDeviceOffset,
+   memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wDeviceOffset,
        p2->pPrinterName, ptrNameLen*sizeof(TCHAR));
 
    pDevNames->wOutputOffset = static_cast<WORD>(sizeof(DEVNAMES)/sizeof(TCHAR)) +
      drvNameLen + ptrNameLen + 2;
-   memcpy((LPTSTR)pDevNames + pDevNames->wOutputOffset,
+   memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wOutputOffset,
           p2->pPortName, porNameLen*sizeof(TCHAR));
 
@@ -4021,6 +4021,6 @@
 {
     TRY;
-    LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
-                                                            printer, NULL);
+    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
+                                                            printer, NULL));
     HDC hDC = AwtPrintControl::getPrintDC(env, name);
     if (hDC != NULL) {
@@ -4052,5 +4052,5 @@
     }
 
-    SetPrinterDevice(printerName, &hDevMode, &hDevNames);
+    SetPrinterDevice(const_cast<LPTSTR>(printerName), &hDevMode, &hDevNames);
 
     AwtPrintControl::setPrintHDMode(env, name, hDevMode);
@@ -4099,5 +4099,5 @@
 
     printer = JNU_NewStringPlatform(env,
-                                    (LPTSTR)pDevNames+pDevNames->wDeviceOffset);
+                                    reinterpret_cast<LPTSTR>(pDevNames)+pDevNames->wDeviceOffset);
     ::GlobalUnlock(hDevNames);
     return printer;
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextArea.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextArea.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextArea.cpp	(revision 195)
@@ -252,5 +252,5 @@
     WCHAR *string = new WCHAR[length];
     env->GetStringRegion(jStr, 0, static_cast<jsize>(length - 1),
-                         reinterpret_cast<jchar*>(string));
+                         jsafe_cast<jchar*>(string));
     string[length-1] = '\0';
     for (size_t i = 0; i < maxlen && i < length - 1; i++) {
@@ -995,5 +995,5 @@
       // WCHAR* buffer = TO_WSTRING(text);
       WCHAR *buffer = new WCHAR[length];
-      env->GetStringRegion(text, 0, length-1, reinterpret_cast<jchar*>(buffer));
+      env->GetStringRegion(text, 0, length-1, jsafe_cast<jchar*>(buffer));
       buffer[length-1] = '\0';
 
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp	(revision 195)
@@ -327,5 +327,5 @@
             c->GetText(buf, len + 1);
             c->RemoveCR(buf);
-            result = env->NewString(reinterpret_cast<jchar*>(buf),
+            result = env->NewString(jsafe_cast<jchar*>(buf),
                                     static_cast<jsize>(wcslen(buf)));
             delete [] buf;
@@ -364,5 +364,5 @@
         int length = env->GetStringLength(text);
         WCHAR* buffer = new WCHAR[length + 1];
-        env->GetStringRegion(text, 0, length, reinterpret_cast<jchar*>(buffer));
+        env->GetStringRegion(text, 0, length, jsafe_cast<jchar*>(buffer));
         buffer[length] = 0;
         c->CheckLineSeparator(buffer);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	(revision 195)
@@ -314,5 +314,5 @@
         int length = env->GetStringLength(jstr);
         buffer = new TCHAR[length + 1];
-        LPCTSTR tmp = (LPCTSTR)JNU_GetStringPlatformChars(env, jstr, NULL);
+        LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jstr, NULL));
         _tcscpy(buffer, tmp);
         JNU_ReleaseStringPlatformChars(env, jstr, tmp);
@@ -380,5 +380,5 @@
     HWND hwnd = CreateWindow(
         szAwtToolkitClassName,
-        (LPCTSTR)name,                    /* window name */
+        name,                             /* window name */
         WS_DISABLED,                      /* window style */
         -1, -1,                           /* position of window */
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	(revision 195)
@@ -734,7 +734,7 @@
     }
 
-    tooltipStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jtooltip, (jboolean *)NULL));
+    tooltipStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jtooltip, (jboolean *)NULL));
     trayIcon->SetToolTip(tooltipStr);
-    env->ReleaseStringChars(jtooltip, reinterpret_cast<const jchar *>(tooltipStr));
+    env->ReleaseStringChars(jtooltip, jsafe_cast<const jchar *>(tooltipStr));
 ret:
     env->DeleteGlobalRef(self);
@@ -857,13 +857,13 @@
     trayIcon = (AwtTrayIcon *)pData;
 
-    captionStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jcaption, (jboolean *)NULL));
-    textStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jtext, (jboolean *)NULL));
-    msgTypeStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jmsgType, (jboolean *)NULL));
+    captionStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jcaption, (jboolean *)NULL));
+    textStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jtext, (jboolean *)NULL));
+    msgTypeStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jmsgType, (jboolean *)NULL));
 
     trayIcon->DisplayMessage(captionStr, textStr, msgTypeStr);
 
-    env->ReleaseStringChars(jcaption, reinterpret_cast<const jchar *>(captionStr));
-    env->ReleaseStringChars(jtext, reinterpret_cast<const jchar *>(textStr));
-    env->ReleaseStringChars(jmsgType, reinterpret_cast<const jchar *>(msgTypeStr));
+    env->ReleaseStringChars(jcaption, jsafe_cast<const jchar *>(captionStr));
+    env->ReleaseStringChars(jtext, jsafe_cast<const jchar *>(textStr));
+    env->ReleaseStringChars(jmsgType, jsafe_cast<const jchar *>(msgTypeStr));
 ret:
     env->DeleteGlobalRef(self);
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.cpp	(revision 195)
@@ -36,5 +36,5 @@
     int len = env->GetStringLength(jstr);
 
-    env->GetStringRegion(jstr, 0, len, reinterpret_cast<jchar*>(lpwstr));
+    env->GetStringRegion(jstr, 0, len, jsafe_cast<jchar*>(lpwstr));
     lpwstr[len] = '\0';
 
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.h
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.h	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.h	(revision 195)
@@ -47,5 +47,5 @@
 #define TO_WSTRING(jstr) \
    ((jstr == NULL) ? NULL : \
-     (JNI_J2WHelper1(env, (LPWSTR) alloca((env->GetStringLength(jstr)+1)*2), \
+     (JNI_J2WHelper1(env, static_cast<LPWSTR>(alloca((env->GetStringLength(jstr)+1)*2)), \
                      jstr) \
     ))
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp	(revision 195)
@@ -171,5 +171,5 @@
 {
     if (getWinVer() >= 5 && procAddFontResourceEx != NULL) {
-      LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, NULL);
+      LPCTSTR file = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, fontName, NULL));
       (*procAddFontResourceEx)(file, FR_PRIVATE, NULL);
     }
@@ -190,5 +190,5 @@
 {
     if (getWinVer() >= 5 && procRemoveFontResourceEx != NULL) {
-      LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, NULL);
+      LPCTSTR file = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, fontName, NULL));
       (*procRemoveFontResourceEx)(file, FR_PRIVATE, NULL);
     }
Index: /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Window.cpp
===================================================================
--- /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Window.cpp	(revision 194)
+++ /trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Window.cpp	(revision 195)
@@ -596,5 +596,5 @@
                       GetLastError(),
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                      (LPTSTR)&msgBuffer, // it's an output parameter when allocate buffer is used
+                      reinterpret_cast<LPTSTR>(&msgBuffer), // it's an output parameter when allocate buffer is used
                       0,
                       NULL);
@@ -1677,5 +1677,5 @@
         int length = env->GetStringLength(title);
         WCHAR *buffer = new WCHAR[length + 1];
-        env->GetStringRegion(title, 0, length, reinterpret_cast<jchar*>(buffer));
+        env->GetStringRegion(title, 0, length, jsafe_cast<jchar*>(buffer));
         buffer[length] = L'\0';
         VERIFY(::SetWindowTextW(w->GetHWnd(), buffer));
