Changeset 195


Ignore:
Timestamp:
Dec 7, 2010, 7:57:56 PM (15 years ago)
Author:
dmik
Message:

jdk: Added jsafe_cast<> template intended to safely cast between jchar* and wchar_t* on GCC and provide a straight (compiler-defined) conversion on Windows (where jchar and wchar_t are fully replaceable).

Location:
trunk/openjdk/jdk/src/windows
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/openjdk/jdk/src/windows/javavm/export/jni_md.h

    r66 r195  
    3939typedef signed char jbyte;
    4040
     41#ifdef __cplusplus
     42
     43/* template for safe type casting: the generic version lets the compiler
     44 * decide (as if no template was used); specific instantiations deal with
     45 * special cases which are guaranteed to be safe */
     46template<typename TR, typename TS>
     47inline TR jsafe_cast(TS ts) { return ts; }
     48
     49#ifdef __EMX__
     50/* sizeof(jchar) = sizeof(wchar_t) in GCC but the types are not relative
     51 * (as opposed to MSVC) so an explicit cast is required */
     52typedef unsigned short jchar;
     53template<>
     54inline jchar *jsafe_cast<jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<jchar*>(ts); }
     55template<>
     56inline const jchar *jsafe_cast<const jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
     57template<>
     58inline const jchar *jsafe_cast<const jchar *, const wchar_t *>(const wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
     59template<>
     60inline wchar_t *jsafe_cast<wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<wchar_t*>(ts); }
     61template<>
     62inline const wchar_t *jsafe_cast<const wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
     63template<>
     64inline const wchar_t *jsafe_cast<const wchar_t *, const jchar *>(const jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
     65#endif
     66
     67#endif /* __cplusplus */
     68
    4169#endif /* !_JAVASOFT_JNI_MD_H_ */
  • trunk/openjdk/jdk/src/windows/native/sun/windows/ShellFolder2.cpp

    r193 r195  
    181181                                         (CHAR*)pidl + pStrret->uOffset);
    182182        case STRRET_WSTR :
    183             return env->NewString(reinterpret_cast<const jchar*>(pStrret->pOleStr),
     183            return env->NewString(jsafe_cast<const jchar*>(pStrret->pOleStr),
    184184                static_cast<jsize>(wcslen(pStrret->pOleStr)));
    185185    }
     
    188188// restoring the original definition
    189189#define JNU_NewStringPlatform(env, x) \
    190     env->NewString(reinterpret_cast<const jchar*>(x), \
    191         static_cast<jsize>(_tcslen(reinterpret_cast<const WCHAR*>(x))))
     190    env->NewString(jsafe_cast<const jchar*>(x), \
     191        static_cast<jsize>(_tcslen(jsafe_cast<const WCHAR*>(x))))
    192192
    193193/*
     
    729729    jchar* wszPath = new jchar[nLength + 1];
    730730    const jchar* strPath = env->GetStringChars(jname, NULL);
    731     wcsncpy(reinterpret_cast<wchar_t*>(wszPath), reinterpret_cast<const wchar_t*>(strPath), nLength);
     731    wcsncpy(jsafe_cast<wchar_t*>(wszPath), jsafe_cast<const wchar_t*>(strPath), nLength);
    732732    wszPath[nLength] = 0;
    733733    HRESULT res = pIShellFolder->ParseDisplayName(NULL, NULL,
    734                         reinterpret_cast<WCHAR*>(wszPath), NULL, &pIDL, NULL);
     734                        jsafe_cast<WCHAR*>(wszPath), NULL, &pIDL, NULL);
    735735    if (res != S_OK) {
    736736        JNU_ThrowIOException(env, "Could not parse name");
     
    775775{
    776776    SHFILEINFO fileInfo;
    777     if (fn_SHGetFileInfo((LPCTSTR)pIDL, 0L, &fileInfo, sizeof(fileInfo),
     777    if (fn_SHGetFileInfo(reinterpret_cast<LPCTSTR>(pIDL), 0L, &fileInfo, sizeof(fileInfo),
    778778        SHGFI_TYPENAME | SHGFI_PIDL) == 0) {
    779779        return NULL;
     
    791791{
    792792    TCHAR szBuf[MAX_PATH];
    793     LPCTSTR szPath = (LPCTSTR)JNU_GetStringPlatformChars(env, path, NULL);
     793    LPCTSTR szPath = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, path, NULL));
    794794    if (szPath == NULL) {
    795795        return NULL;
     
    814814    HICON hIcon = NULL;
    815815    SHFILEINFO fileInfo;
    816     LPCTSTR pathStr = (LPCTSTR)JNU_GetStringPlatformChars(env, absolutePath, NULL);
     816    LPCTSTR pathStr = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, absolutePath, NULL));
    817817    if (fn_SHGetFileInfo(pathStr, 0L, &fileInfo, sizeof(fileInfo),
    818818                         SHGFI_ICON | (getLargeIcon ? 0 : SHGFI_SMALLICON)) != 0) {
     
    10181018    if (libShell32 != NULL) {
    10191019        hBitmap = (HBITMAP)LoadImage(libShell32,
    1020                     isVista ? TEXT("IDB_TB_SH_DEF_16") : (LPCTSTR)MAKEINTRESOURCE(216),
     1020                    isVista ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216),
    10211021                    IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
    10221022    }
     
    10241024        libComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
    10251025        if (libComCtl32 != NULL) {
    1026             hBitmap = (HBITMAP)LoadImage(libComCtl32, (LPCTSTR)MAKEINTRESOURCE(124),
     1026            hBitmap = (HBITMAP)LoadImage(libComCtl32, MAKEINTRESOURCE(124),
    10271027                                         IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
    10281028        }
     
    10321032    }
    10331033
    1034     GetObject(hBitmap, sizeof(bm), (LPSTR)&bm);
     1034    GetObject(hBitmap, sizeof(bm), reinterpret_cast<LPSTR>(&bm));
    10351035
    10361036    // Get the screen DC
     
    10881088    (JNIEnv* env, jclass cls, jint iconID)
    10891089{
    1090     return (jlong)LoadIcon(NULL, (LPCTSTR)MAKEINTRESOURCE(iconID));
     1090    return (jlong)LoadIcon(NULL, MAKEINTRESOURCE(iconID));
    10911091}
    10921092
     
    11011101     jint cxDesired, jint cyDesired, jboolean useVGAColors)
    11021102{
    1103     HINSTANCE libHandle = LoadLibrary(reinterpret_cast<const WCHAR*>(env->GetStringChars(libName, NULL)));
     1103    HINSTANCE libHandle = LoadLibrary(jsafe_cast<const WCHAR*>(env->GetStringChars(libName, NULL)));
    11041104    if (libHandle != NULL) {
    11051105        UINT fuLoad = (useVGAColors && !isXP) ? LR_VGACOLOR : 0;
    1106         return ptr_to_jlong(LoadImage(libHandle, (LPCTSTR)MAKEINTRESOURCE(iconID),
     1106        return ptr_to_jlong(LoadImage(libHandle, MAKEINTRESOURCE(iconID),
    11071107                                      IMAGE_ICON, cxDesired, cyDesired,
    11081108                                      fuLoad));
  • trunk/openjdk/jdk/src/windows/native/sun/windows/ThemeReader.cpp

    r2 r195  
    251251                    lastError,
    252252                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    253                     (LPSTR)&msgBuffer,
     253                    reinterpret_cast<LPSTR>(&msgBuffer),
    254254                    // it's an output parameter when allocate buffer is used
    255255                    0,
     
    271271(JNIEnv *env, jclass klass, jstring widget) {
    272272
    273     LPCTSTR str = (LPCTSTR) JNU_GetStringPlatformChars(env, widget, NULL);
     273    LPCTSTR str = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, widget, NULL));
    274274    // We need to open the Theme on a Window that will stick around.
    275275    // The best one for that purpose is the Toolkit window.
     
    289289    LPCTSTR str = NULL;
    290290    if (subAppName != NULL) {
    291         str = (LPCTSTR) JNU_GetStringPlatformChars(env, subAppName, NULL);
     291        str = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, subAppName, NULL));
    292292    }
    293293    // We need to set the Window theme on the same theme that we opened it with.
  • trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.cpp

    r193 r195  
    7878    // initialization.
    7979    HMODULE hmodAWT = GetModuleHandleA("awt");
    80     LPSTR abspath = (LPSTR)safe_Malloc(MAX_PATH);
     80    LPSTR abspath = static_cast<LPSTR>(safe_Malloc(MAX_PATH));
    8181    if (abspath != NULL) {
    8282        GetModuleFileNameA(hmodAWT, abspath, MAX_PATH);
     
    161161    const DWORD num)
    162162{
    163     LPWSTR pwstrbuf = (LPWSTR)(pi1W + num);
     163    LPWSTR pwstrbuf = reinterpret_cast<LPWSTR>(pi1W + num);
    164164    DWORD current;
    165165
     
    223223    const DWORD num)
    224224{
    225     LPWSTR pbuf = (LPWSTR)(pi5W + num);
     225    LPWSTR pbuf = reinterpret_cast<LPWSTR>(pi5W + num);
    226226    DWORD current;
    227227
     
    337337    if (Name != NULL) {
    338338        DWORD len = static_cast<DWORD>(wcslen(Name)) + 1;
    339         pNameA = (LPSTR)safe_Malloc(len);
     339        pNameA = static_cast<LPSTR>(safe_Malloc(len));
    340340        ::WideCharToMultiByte(CP_ACP, 0, Name, -1, pNameA, len, NULL, NULL);
    341341    }
  • trunk/openjdk/jdk/src/windows/native/sun/windows/UnicowsLoader.h

    r187 r195  
    7777// to proper JNI functions.
    7878#ifdef __WIN32OS2__
    79 #define JNU_NewStringPlatform(env, x) env->NewString(reinterpret_cast<const jchar*>(x), static_cast<jsize>(_tcslen(reinterpret_cast<LPCTSTR>(x))))
    80 #define JNU_GetStringPlatformChars(env, x, y) (LPWSTR)env->GetStringChars(x, y)
    81 #define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, reinterpret_cast<const jchar*>(y))
     79#define JNU_NewStringPlatform(env, x) env->NewString(jsafe_cast<const jchar*>(x), static_cast<jsize>(_tcslen(jsafe_cast<LPCWSTR>(x))))
     80#define JNU_GetStringPlatformChars(env, x, y) jsafe_cast<LPCWSTR>(env->GetStringChars(x, y))
     81#define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, jsafe_cast<const jchar*>(y))
    8282#else
    8383#define JNU_NewStringPlatform(env, x) env->NewString(x, static_cast<jsize>(_tcslen(x)))
    84 #define JNU_GetStringPlatformChars(env, x, y) (LPWSTR)env->GetStringChars(x, y)
     84#define JNU_GetStringPlatformChars(env, x, y) jsafe_cast<LPWSTR>(env->GetStringChars(x, y))
    8585#define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, y)
    8686#endif
  • trunk/openjdk/jdk/src/windows/native/sun/windows/WPrinterJob.cpp

    r184 r195  
    141141       }
    142142
    143        pPrinterName = (LPTSTR)GlobalAlloc(GPTR, (index+1)*sizeof(TCHAR));
     143       pPrinterName = static_cast<LPTSTR>(GlobalAlloc(GPTR, (index+1)*sizeof(TCHAR)));
    144144       lstrcpyn(pPrinterName, cBuffer, index+1);
    145145       jPrinterName = JNU_NewStringPlatform(env, pPrinterName);
     
    244244    HANDLE hPrinter;
    245245
    246     LPTSTR printerName = NULL;
     246    LPCTSTR printerName = NULL;
    247247    if (printer != NULL) {
    248         printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
     248        printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
    249249                                                         printer,
    250                                                          NULL);
     250                                                         NULL));
    251251        JNU_ReleaseStringPlatformChars(env, printer, printerName);
    252252    }
     
    254254    // printerName - "Win NT/2K/XP: If NULL, it indicates the local printer
    255255    // server" - MSDN.   Win9x : OpenPrinter returns 0.
    256     BOOL ret = OpenPrinter(printerName, &hPrinter, NULL);
     256    BOOL ret = OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL);
    257257    if (!ret) {
    258258      return (jlong)-1;
     
    304304    TRY;
    305305
    306     LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
    307                                                             printer, NULL);
     306    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     307                                                            printer, NULL));
    308308
    309309    jfloatArray printableArray = NULL;
     
    315315        HANDLE hPrinter;
    316316        /* Start by opening the printer */
    317         if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
     317        if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
    318318            JNU_ReleaseStringPlatformChars(env, printer, printerName);
    319319            return printableArray;
     
    322322        PDEVMODE pDevMode;
    323323
    324         if (!AwtPrintControl::getDevmode(hPrinter, printerName, &pDevMode)) {
     324        if (!AwtPrintControl::getDevmode(hPrinter, const_cast<LPTSTR>(printerName),
     325                                         &pDevMode)) {
    325326            /* if failure, cleanup and return failure */
    326327
     
    384385  TRY;
    385386
    386   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
    387   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     387  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
     388  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    388389  jintArray mediasizeArray = NULL;
    389390
     
    403404    jint *jpcIndices = env->GetIntArrayElements(mediasizeArray,
    404405                                       &isCopy), *saveFormats = jpcIndices;
    405     LPTSTR papersBuf = (LPTSTR)new char[numSizes * sizeof(WORD)];
     406    LPTSTR papersBuf = reinterpret_cast<LPTSTR>(new char[numSizes * sizeof(WORD)]);
    406407    if (::DeviceCapabilities(printerName, printerPort,
    407408                             DC_PAPERS, papersBuf, NULL) != -1) {
     
    432433  TRY;
    433434
    434   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
    435                                                           printer, NULL);
    436   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     435  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     436                                                          printer, NULL));
     437  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    437438
    438439  jintArray mediaTrayArray = NULL;
     
    452453                                           &isCopy), *saveFormats = jpcIndices;
    453454
    454     LPTSTR buf = (LPTSTR)new char[nBins * sizeof(WORD)];
     455    LPTSTR buf = reinterpret_cast<LPTSTR>(new char[nBins * sizeof(WORD)]);
    455456
    456457    if (::DeviceCapabilities(printerName, printerPort,
     
    482483  TRY;
    483484
    484   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
    485                                                           printer, NULL);
    486   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     485  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     486                                                          printer, NULL));
     487  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    487488
    488489  jintArray mediaArray = NULL;
     
    502503                                          &isCopy), *saveFormats = jpcIndices;
    503504
    504     LPTSTR buf = (LPTSTR)new char[nPapers * sizeof(POINT)]; // array of POINTs
     505    LPTSTR buf = reinterpret_cast<LPTSTR>(new char[nPapers * sizeof(POINT)]); // array of POINTs
    505506
    506507    if (::DeviceCapabilities(printerName, printerPort,
     
    531532  TRY;
    532533
    533   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
    534                                                           printer, NULL);
    535   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     534  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     535                                                          printer, NULL));
     536  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    536537
    537538  jstring utf_str;
     
    545546  if (cReturned > 0) {
    546547
    547     buf = (LPTSTR)new char[cReturned * buf_len * sizeof(TCHAR)];
     548    buf = reinterpret_cast<LPTSTR>(new char[cReturned * buf_len * sizeof(TCHAR)]);
    548549    if (buf == NULL) {
    549550      throw std::bad_alloc();
     
    603604                                                    jstring port)
    604605{
    605   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
    606   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     606  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
     607  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    607608
    608609  SAVE_CONTROLWORD
     
    641642  TRY;
    642643
    643   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
    644   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     644  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
     645  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    645646
    646647  jintArray resolutionArray = NULL;
     
    660661                                          &isCopy), *saveFormats = jpcIndices;
    661662
    662     LPTSTR resBuf = (LPTSTR)new char[nResolutions * sizeof(LONG) * 2]; // pairs of long
     663    LPTSTR resBuf = reinterpret_cast<LPTSTR>(new char[nResolutions * sizeof(LONG) * 2]); // pairs of long
    663664
    664665    if (::DeviceCapabilities(printerName, printerPort,
     
    692693    nEscapeCode = POSTSCRIPT_PASSTHROUGH;
    693694    if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
    694                      (LPCSTR)&nEscapeCode, 0, NULL ) > 0 )
     695                     reinterpret_cast<LPCSTR>(&nEscapeCode), 0, NULL ) > 0 )
    695696        return TRUE;
    696697
     
    698699    nEscapeCode = GETTECHNOLOGY;
    699700    if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
    700                      (LPCSTR)&nEscapeCode, 0, NULL ) <= 0 )
     701                     reinterpret_cast<LPCSTR>(&nEscapeCode), 0, NULL ) <= 0 )
    701702        return FALSE;
    702703
    703704    // Get the technology string and check if the word "postscript" is in it.
    704705    if( ::ExtEscape( hDC, GETTECHNOLOGY, 0, NULL, MAX_PATH,
    705                      (LPSTR)szTechnology ) <= 0 )
     706                     reinterpret_cast<LPSTR>(szTechnology) ) <= 0 )
    706707        return FALSE;
    707708    strupr( szTechnology );
     
    756757                                                 jstring port)
    757758{
    758   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
    759   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     759  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
     760  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    760761  // 0x1000 is a flag to indicate that getCapabilities has already been called.
    761762  // 0x0001 is a flag for color support and supported is the default.
     
    829830  TRY;
    830831
    831   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
    832   LPTSTR printerPort = (LPTSTR)JNU_GetStringPlatformChars(env, port, NULL);
     832  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
     833  LPCTSTR printerPort = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, port, NULL));
    833834
    834835  jintArray defaultArray = env->NewIntArray(NDEFAULT);
     
    846847
    847848  /* Start by opening the printer */
    848   if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
     849  if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
    849850      env->ReleaseIntArrayElements(defaultArray, saveFormats, 0);
    850851      JNU_ReleaseStringPlatformChars(env, printer, printerName);
     
    852853  }
    853854
    854   if (!AwtPrintControl::getDevmode(hPrinter, printerName, &pDevMode)) {
     855  if (!AwtPrintControl::getDevmode(hPrinter, const_cast<LPTSTR>(printerName), &pDevMode)) {
    855856      /* if failure, cleanup and return failure */
    856857      if (pDevMode != NULL) {
     
    876877                                          DC_PAPERS, NULL, NULL);
    877878      if (numSizes > 0) {
    878           LPWORD papers = (LPWORD)safe_Malloc(numSizes * sizeof(WORD));
     879          LPWORD papers = static_cast<LPWORD>(safe_Malloc(numSizes * sizeof(WORD)));
    879880          if (papers != NULL &&
    880881              ::DeviceCapabilities(printerName, printerPort,
    881                                    DC_PAPERS, (LPTSTR)papers, NULL) != -1) {
     882                                   DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL) != -1) {
    882883              int present = 0;
    883884              for (int i=0;i<numSizes;i++) {
     
    951952    int ret=0;
    952953
    953     LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
     954    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
    954955
    955956    // Start by opening the printer
    956     if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
     957    if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
    957958        JNU_ReleaseStringPlatformChars(env, printer, printerName);
    958959        return -1;
     
    10391040  HANDLE      hPrinter;
    10401041  DOC_INFO_1  DocInfo;
    1041   LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env, printer, NULL);
     1042  LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, printer, NULL));
    10421043  DASSERT(jobname != NULL);
    1043   LPTSTR lpJobName = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
     1044  LPCTSTR lpJobName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jobname, NULL));
    10441045  LPTSTR jname = _tcsdup(lpJobName);
    10451046  JNU_ReleaseStringPlatformChars(env, jobname, lpJobName);
    10461047
    10471048  // Start by opening the printer
    1048   if (!::OpenPrinter(printerName, &hPrinter, NULL)) {
     1049  if (!::OpenPrinter(const_cast<LPTSTR>(printerName), &hPrinter, NULL)) {
    10491050    JNU_ReleaseStringPlatformChars(env, printer, printerName);
    1050     free((LPTSTR)jname);
     1051    free(jname);
    10511052    return false;
    10521053  }
     
    10621063  if( (::StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)) == 0 ) {
    10631064    ::ClosePrinter( hPrinter );
    1064     free((LPTSTR)jname);
     1065    free(jname);
    10651066    return false;
    10661067  }
    10671068
    1068   free((LPTSTR)jname);
     1069  free(jname);
    10691070
    10701071  // Start a page.
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Button.cpp

    r187 r195  
    107107            labelStr = L"";
    108108        } else {
    109             labelStr = (LPCWSTR)env->GetStringChars(label, JNI_FALSE);
     109            labelStr = jsafe_cast<LPCWSTR>(env->GetStringChars(label, JNI_FALSE));
    110110        }
    111111        style = 0;
     
    129129        c->UpdateBackground(env, target);
    130130        if (label != NULL)
    131             env->ReleaseStringChars(label, (jchar*)labelStr);
     131            env->ReleaseStringChars(label, jsafe_cast<const jchar*>(labelStr));
    132132    } catch (...) {
    133133        env->DeleteLocalRef(target);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Checkbox.cpp

    r187 r195  
    107107            label = (jstring)env->GetObjectField(target, AwtCheckbox::labelID);
    108108            if (label != NULL) {
    109                 labelStr = (LPCWSTR)env->GetStringChars(label, 0);
     109                labelStr = jsafe_cast<LPCWSTR>(env->GetStringChars(label, 0));
    110110            }
    111111            if (labelStr != 0) {
     
    124124
    125125                if (labelStr != defaultLabelStr) {
    126                     env->ReleaseStringChars(label, (jchar*)labelStr);
     126                    env->ReleaseStringChars(label, jsafe_cast<const jchar*>(labelStr));
    127127                }
    128128            } else {
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Component.cpp

    r187 r195  
    553553            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    554554                NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    555                 (LPTSTR)&buf, 0, NULL);
     555                reinterpret_cast<LPTSTR>(&buf), 0, NULL);
    556556            jstring s = JNU_NewStringPlatform(env, buf);
    557557            createError = JNU_NewObjectByName(env, "java/lang/InternalError",
     
    18841884      case WM_SETTINGCHANGE:
    18851885          CheckFontSmoothingSettings(NULL);
    1886           mr = WmSettingChange(static_cast<UINT>(wParam), (LPCTSTR)lParam);
     1886          mr = WmSettingChange(static_cast<UINT>(wParam), reinterpret_cast<LPCTSTR>(lParam));
    18871887          break;
    18881888      case WM_CONTEXTMENU:
     
    36173617        WCHAR unicodeChar[2];
    36183618        VERIFY(::MultiByteToWideChar(GetCodePage(), MB_PRECOMPOSED,
    3619         (LPCSTR)&mbChar, 1, unicodeChar, 1));
     3619        reinterpret_cast<LPCSTR>(&mbChar), 1, unicodeChar, 1));
    36203620
    36213621        translation = unicodeChar[0];
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DataTransferer.cpp

    r190 r195  
    289289
    290290        UINT bufsize = 512; // in characters, not in bytes
    291         buffer = (LPTSTR)safe_Malloc(bufsize*sizeof(TCHAR));
     291        buffer = static_cast<LPTSTR>(safe_Malloc(bufsize*sizeof(TCHAR)));
    292292
    293293        for (UINT i = 0; i < nFilenames; i++) {
     
    295295            if (size > bufsize) {
    296296                bufsize = size;
    297                 buffer = (LPTSTR)safe_Realloc(buffer, bufsize*sizeof(TCHAR));
     297                buffer = static_cast<LPTSTR>(safe_Realloc(buffer, bufsize*sizeof(TCHAR)));
    298298            }
    299299            (*do_drag_query_file)(hdrop, i, buffer, bufsize);
     
    391391        case CF_DIB:
    392392
    393             pSrcBmi = (BITMAPINFO*)((LPSTR)bBytes + uOffset);
     393            pSrcBmi = (BITMAPINFO*)(reinterpret_cast<LPSTR>(bBytes) + uOffset);
    394394            pSrcBmih = &pSrcBmi->bmiHeader;
    395395
     
    429429                }
    430430
    431                 pSrcBits = (LPSTR)pSrcBmi + pSrcBmih->biSize
     431                pSrcBits = reinterpret_cast<LPSTR>(pSrcBmi) + pSrcBmih->biSize
    432432                    + nColorEntries * sizeof(RGBQUAD);
    433433            }
     
    666666    pinfo->bmiHeader.biSizeImage = size + pad;
    667667
    668     jbyte *array = (jbyte*)((LPSTR)pinfo + sizeof(BITMAPINFOHEADER));
     668    jbyte *array = (jbyte*)(reinterpret_cast<LPSTR>(pinfo) + sizeof(BITMAPINFOHEADER));
    669669    env->GetByteArrayRegion(imageData, 0, size, array);
    670670    HRESULT hr = S_OK;
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Debug.cpp

    r2 r195  
    158158                  lastError,
    159159                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    160                   (LPSTR)&msgBuffer, // it's an output parameter when allocate buffer is used
     160                  reinterpret_cast<LPSTR>(&msgBuffer), // it's an output parameter when allocate buffer is used
    161161                  0,
    162162                  NULL);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Desktop.cpp

    r187 r195  
    4141  (JNIEnv *env, jclass cls, jstring uri_j, jstring verb_j)
    4242{
    43     const WCHAR* uri_c = (const WCHAR*)env->GetStringChars(uri_j, JNI_FALSE);
    44     const WCHAR* verb_c = (const WCHAR*)env->GetStringChars(verb_j, JNI_FALSE);
     43    const WCHAR* uri_c = jsafe_cast<const WCHAR*>(env->GetStringChars(uri_j, JNI_FALSE));
     44    const WCHAR* verb_c = jsafe_cast<const WCHAR*>(env->GetStringChars(verb_j, JNI_FALSE));
    4545
    4646    // 6457572: ShellExecute possibly changes FPU control word - saving it here
     
    4949    _control87(oldcontrol87, 0xffffffff);
    5050
    51     env->ReleaseStringChars(uri_j, (jchar*)uri_c);
    52     env->ReleaseStringChars(verb_j, (jchar*)verb_c);
     51    env->ReleaseStringChars(uri_j, jsafe_cast<const jchar*>(uri_c));
     52    env->ReleaseStringChars(verb_j, jsafe_cast<const jchar*>(verb_c));
    5353
    5454    if ((int)retval <= 32) {
    5555        // ShellExecute failed.
    56         LPVOID buffer;
     56        LPWSTR buffer;
    5757        int len = FormatMessageW(
    5858                    FORMAT_MESSAGE_ALLOCATE_BUFFER |
     
    6262                    GetLastError(),
    6363                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    64                     (LPWSTR) &buffer,
     64                    reinterpret_cast<LPWSTR>(&buffer),
    6565                    0,
    6666                    NULL );
    6767
    68         jstring errmsg = env->NewString((jchar*)buffer, len);
     68        jstring errmsg = env->NewString(jsafe_cast<const jchar*>(buffer), len);
    6969        LocalFree(buffer);
    7070        return errmsg;
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp

    r190 r195  
    121121        return NULL;
    122122    }
    123     LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
     123    LPTSTR buffer = static_cast<LPTSTR>(safe_Malloc(valueSize));
    124124    if (RegQueryValueEx((HKEY)handle, fontName, NULL,
    125125                        &valueType, (unsigned char *)buffer, &valueSize) != 0) {
     
    167167        return NULL;
    168168    }
    169     LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
     169    LPTSTR buffer = static_cast<LPTSTR>(safe_Malloc(valueSize));
    170170    if (RegQueryValueEx((HKEY)handle, valueName, NULL,
    171171                        valueType, (unsigned char *)buffer, &valueSize) != 0) {
     
    179179        // Pending: buffer must be null-terminated at this point
    180180        valueChar = ExpandEnvironmentStrings(buffer, NULL, 0);
    181         LPTSTR buffer2 = (LPTSTR)safe_Malloc(valueChar*sizeof(TCHAR));
     181        LPTSTR buffer2 = static_cast<LPTSTR>(safe_Malloc(valueChar*sizeof(TCHAR)));
    182182        ExpandEnvironmentStrings(buffer, buffer2, valueChar);
    183183        free(buffer);
     
    609609
    610610    LPTSTR valueName = TEXT("PlaceN");
    611     LPTSTR valueNameBuf = (LPTSTR)safe_Malloc((lstrlen(valueName) + 1) * sizeof(TCHAR));
     611    LPTSTR valueNameBuf = static_cast<LPTSTR>(safe_Malloc((lstrlen(valueName) + 1) * sizeof(TCHAR)));
    612612    lstrcpy(valueNameBuf, valueName);
    613613
    614614    LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
    615     LPTSTR propKeyBuf = (LPTSTR)safe_Malloc((lstrlen(propKey) + 1) * sizeof(TCHAR));
     615    LPTSTR propKeyBuf = static_cast<LPTSTR>(safe_Malloc((lstrlen(propKey) + 1) * sizeof(TCHAR)));
    616616    lstrcpy(propKeyBuf, propKey);
    617617
     
    672672
    673673void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
    674     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     674    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    675675    GetEnv()->CallVoidMethod(self,
    676676                             AwtDesktopProperties::setStringPropertyID,
     
    680680
    681681void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
    682     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     682    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    683683    GetEnv()->CallVoidMethod(self,
    684684                             AwtDesktopProperties::setIntegerPropertyID,
     
    688688
    689689void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
    690     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     690    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    691691    GetEnv()->CallVoidMethod(self,
    692692                             AwtDesktopProperties::setBooleanPropertyID,
     
    696696
    697697void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
    698     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     698    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    699699    GetEnv()->CallVoidMethod(self,
    700700                             AwtDesktopProperties::setColorPropertyID,
     
    731731                            // fall back to Microsoft Sans Serif
    732732                            fontName = JNU_NewStringPlatform(GetEnv(),
    733                                          (const jchar*)L"Microsoft Sans Serif");
     733                                         jsafe_cast<const jchar*>(L"Microsoft Sans Serif"));
    734734                        }
    735735                    }
     
    748748                    }
    749749
    750                     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     750                    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    751751                    GetEnv()->CallVoidMethod(self,
    752752                              AwtDesktopProperties::setFontPropertyID,
     
    789789    }
    790790
    791     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
     791    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
    792792    GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
    793793                             key, fontName, style, pointSize);
     
    798798
    799799void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) {
    800     jstring key = JNU_NewStringPlatform(GetEnv(), (const jchar*)propName);
    801     jstring event = JNU_NewStringPlatform(GetEnv(), (const jchar*)winEventName);
     800    jstring key = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(propName));
     801    jstring event = JNU_NewStringPlatform(GetEnv(), jsafe_cast<const jchar*>(winEventName));
    802802    GetEnv()->CallVoidMethod(self,
    803803                             AwtDesktopProperties::setSoundPropertyID,
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp

    r190 r195  
    11941194    ::CoFileTimeNow(&now);
    11951195
    1196     m_statstg.pwcsName          = (LPWSTR)NULL;
     1196    m_statstg.pwcsName          = NULL;
    11971197    m_statstg.type              = STGTY_STREAM;
    11981198    m_statstg.cbSize.HighPart   = 0;
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp

    r2 r195  
    556556        }
    557557        case TYMED_FILE: {
    558             jobject local = JNU_NewStringPlatform(env, (LPCTSTR)
    559                                                   stgmedium.lpszFileName);
     558            jobject local = JNU_NewStringPlatform(env, jsafe_cast<LPCTSTR>(
     559                                                  stgmedium.lpszFileName));
    560560            jstring fileName = (jstring)env->NewGlobalRef(local);
    561561            env->DeleteLocalRef(local);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp

    r190 r195  
    6666    int length = env->GetStringLength(filterDescription);
    6767    DASSERT(length + 1 < MAX_FILTER_STRING);
    68     LPCTSTR tmp = (LPTSTR)JNU_GetStringPlatformChars(env, filterDescription, NULL);
     68    LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, filterDescription, NULL));
    6969    _tcscpy(s_fileFilterString, tmp);
    7070    JNU_ReleaseStringPlatformChars(env, filterDescription, tmp);
     
    237237
    238238        if (title == NULL || env->GetStringLength(title)==0) {
    239             title = env->NewString((const jchar*)&unicodeChar, 1);
     239            title = env->NewString(jsafe_cast<const jchar*>(&unicodeChar), 1);
    240240        }
    241241
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Font.cpp

    r190 r195  
    366366          NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
    367367{
    368     if(_tcsstr((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName)) {
    369         _tcscpy((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName);
     368    if(_tcsstr(reinterpret_cast<LPTSTR>(lParam), lpelfe->elfLogFont.lfFaceName)) {
     369        _tcscpy(reinterpret_cast<LPTSTR>(lParam), lpelfe->elfLogFont.lfFaceName);
    370370        return 0;
    371371    } else {
     
    694694                // Start of conversion Code to fix arabic shaping problems
    695695                // with unicode support in win 95
    696                 LPSTR buffer =  (LPSTR) alloca((wcslen(string) + 1) * 2);
     696                LPSTR buffer =  static_cast<LPSTR>(alloca((wcslen(string) + 1) * 2));
    697697                int count = ::WideCharToMultiByte(codePage, 0, string, length,
    698698                                                  buffer,
     
    754754
    755755                if (unicodeUsed) {
    756                     VERIFY(!draw || ::TextOutW(hDC, x, y, (LPCWSTR)offsetBuffer, buflen / 2));
    757                     VERIFY(::GetTextExtentPoint32W(hDC, (LPCWSTR)offsetBuffer, buflen / 2, &temp));
     756                    VERIFY(!draw || ::TextOutW(hDC, x, y, reinterpret_cast<LPCWSTR>(offsetBuffer), buflen / 2));
     757                    VERIFY(::GetTextExtentPoint32W(hDC, reinterpret_cast<LPCWSTR>(offsetBuffer), buflen / 2, &temp));
    758758                }
    759759                else {
     
    17771777    VERIFY(::WideCharToMultiByte(CP_ACP, 0, szFamilyName, -1,
    17781778        szTmpName, sizeof(szTmpName), NULL, NULL));
    1779     LONG lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szTmpName,
     1779    LONG lStatus = ::RegQueryValueExA(hKey, reinterpret_cast<LPCSTR>(szTmpName),
    17801780        NULL, &dwType, szFileName, &dwBytes);
    17811781    BOOL fUseDefault = FALSE;
     
    17881788        }
    17891789        char szDefault[] = "SystemDefaultEUDCFont";
    1790         lStatus = ::RegQueryValueExA(hKey, (LPCSTR) szDefault,
     1790        lStatus = ::RegQueryValueExA(hKey, reinterpret_cast<LPCSTR>(szDefault),
    17911791            NULL, &dwType, szFileName, &dwBytes);
    17921792        fUseDefault = TRUE;
     
    17991799    }
    18001800
    1801     if (strcmp((LPCSTR) szFileName, "userfont.fon") == 0) {
     1801    if (strcmp(reinterpret_cast<char*>(szFileName), "userfont.fon") == 0) {
    18021802        // This font is associated with no EUDC font
    18031803        // and the system default EUDC font is not TrueType
     
    18061806    }
    18071807
    1808     DASSERT(strlen((LPCSTR)szFileName) > 0);
     1808    DASSERT(strlen(reinterpret_cast<char*>(szFileName)) > 0);
    18091809    VERIFY(::MultiByteToWideChar(CP_ACP, 0,
    1810         (LPCSTR)szFileName, -1, lpszFileName, cchFileName) != 0);
     1810        reinterpret_cast<LPCSTR>(szFileName), -1, lpszFileName, cchFileName) != 0);
    18111811    if (fUseDefault)
    18121812        wcscpy(m_szDefaultEUDCFile, lpszFileName);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp

    r2 r195  
    511511
    512512    if ((buffSize = ::ImmGetDescription(hkl, szImmDescription, 0)) > 0) {
    513         szImmDescription = (LPTSTR) safe_Malloc(buffSize * sizeof(TCHAR));
     513        szImmDescription = static_cast<LPTSTR>(safe_Malloc(buffSize * sizeof(TCHAR)));
    514514
    515515        if (szImmDescription != NULL) {
     
    596596        if (ret == ERROR_SUCCESS) {
    597597            hkl = reinterpret_cast<HKL>(static_cast<INT_PTR>(
    598                 _tcstoul((LPCTSTR)szHKL, &end, 16)));
     598                _tcstoul(reinterpret_cast<LPCTSTR>(szHKL), &end, 16)));
    599599        }
    600600
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_InputTextInfor.cpp

    r190 r195  
    109109    // Assign the context data
    110110    m_cStrW = cbData[0]/WCHAR_SZ;
    111     m_lpStrW = (LPWSTR)lpData[0];
     111    m_lpStrW = static_cast<LPWSTR>(lpData[0]);
    112112
    113113    m_cReadStrW = cbData[1]/WCHAR_SZ;
    114     m_lpReadStrW = (LPWSTR)lpData[1];
     114    m_lpReadStrW = static_cast<LPWSTR>(lpData[1]);
    115115
    116116    m_cClauseW = cbData[2]/DWORD_SZ - 1;
     
    188188    if (env == NULL || lpStrW == NULL || cStrW == 0) return NULL;
    189189
    190     return env->NewString((jchar*)lpStrW, cStrW);
     190    return env->NewString(jsafe_cast<const jchar*>(lpStrW), cStrW);
    191191}
    192192
     
    253253        }
    254254        else {
    255             readingClauseW[cls] = MakeJavaString(env, (LPWSTR)NULL, 0);
     255            readingClauseW[cls] = MakeJavaString(env, NULL, 0);
    256256        }
    257257    }
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_List.cpp

    r190 r195  
    688688            for (jsize i=0; i < itemCount; i++)
    689689            {
    690                 LPTSTR itemPtr = NULL;
     690                LPCTSTR itemPtr = NULL;
    691691                jstring item = (jstring)env->GetObjectArrayElement(items, i);
    692692                JNI_CHECK_NULL_GOTO(item, "null item", next_item);
    693                 itemPtr = (LPTSTR)JNU_GetStringPlatformChars(env, item, 0);
     693                itemPtr = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, item, 0));
    694694                if (itemPtr == NULL)
    695695                {
     
    698698                else
    699699                {
    700                     l->InsertString(index+i, itemPtr);
     700                    l->InsertString(index+i, const_cast<LPTSTR>(itemPtr));
    701701                    JNU_ReleaseStringPlatformChars(env, item, itemPtr);
    702702                }
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Menu.cpp

    r2 r195  
    150150        UINT flags = MF_STRING | (enabled ? MF_ENABLED : MF_GRAYED);
    151151        flags |= MF_OWNERDRAW;
    152         LPCTSTR itemInfo = (LPCTSTR) this;
     152        LPCTSTR itemInfo = reinterpret_cast<LPCTSTR>(this);
    153153
    154154        if (_tcscmp(item->GetClassName(), TEXT("SunAwtMenu")) == 0) {
    155155            flags |= MF_POPUP;
    156             itemInfo = (LPCTSTR) item;
     156            itemInfo = reinterpret_cast<LPCTSTR>(item);
    157157        }
    158158
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_MenuItem.cpp

    r190 r195  
    166166            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    167167                NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    168                 (LPTSTR)&buf, 0, NULL);
     168                reinterpret_cast<LPTSTR>(&buf), 0, NULL);
    169169            jstring s = JNU_NewStringPlatform(env, buf);
    170170            createError = JNU_NewObjectByName(env, "java/lang/InternalError",
     
    636636
    637637    mii.fType = MFT_OWNERDRAW;
    638     mii.dwTypeData = (LPTSTR)(*sb);
     638    mii.dwTypeData = reinterpret_cast<LPTSTR>(*sb);
    639639
    640640    // find index by menu item id
     
    700700        case MENUITEM_SETLABEL:
    701701        {
    702             LPCTSTR sb = (LPCTSTR)args->param1;
     702            LPCTSTR sb = reinterpret_cast<LPCTSTR>(args->param1);
    703703            DASSERT(!IsBadStringPtr(sb, 20));
    704704            this->SetLabel(sb);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp

    r190 r195  
    136136
    137137    JavaStringBuffer printerNameBuf(env, printerName);
    138     LPTSTR lpcPrinterName = (LPTSTR)printerNameBuf;
     138    LPTSTR lpcPrinterName = jsafe_cast<LPTSTR>(printerNameBuf);
    139139    DASSERT(lpcPrinterName != NULL);
    140140
     
    436436            (DEVNAMES *)::GlobalLock(ppd->hDevNames);
    437437        DASSERT(!IsBadWritePtr(devnames, devnameSize));
    438         LPTSTR lpcDevnames = (LPTSTR)devnames;
     438        LPTSTR lpcDevnames = reinterpret_cast<LPTSTR>(devnames);
    439439
    440440        // note: all sizes are in characters, not in bytes
     
    512512
    513513        DWORD result1 = DeviceCapabilities(printer, port,
    514                                        DC_PAPERS, (LPTSTR) papers, NULL);
     514                                       DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL);
    515515
    516516        DWORD result2 = DeviceCapabilities(printer, port,
    517                                        DC_PAPERSIZE, (LPTSTR) paperSizes,
     517                                       DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
    518518                                       NULL);
    519519
    520520        // REMIND: cache in papers and paperSizes
    521521        if (result1 == -1 || result2 == -1 ) {
    522             free((LPTSTR) papers);
     522            free(papers);
    523523            papers = NULL;
    524             free((LPTSTR) paperSizes);
     524            free(paperSizes);
    525525            paperSizes = NULL;
    526526        }
     
    578578
    579579    if (papers != NULL) {
    580         free((LPTSTR)papers);
     580        free(papers);
    581581    }
    582582
    583583    if (paperSizes != NULL) {
    584         free((LPTSTR)paperSizes);
     584        free(paperSizes);
    585585    }
    586586
     
    621621        pd.hDevNames = AwtPrintControl::getPrintHDName(env, printCtrl);
    622622
    623         LPTSTR getName = (LPTSTR)JNU_GetStringPlatformChars(env,
    624                                                       printerName, NULL);
     623        LPCTSTR getName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     624                                                      printerName, NULL));
    625625
    626626        BOOL samePrinter = FALSE;
     
    631631            DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(pd.hDevNames);
    632632            if (devnames != NULL) {
    633                 LPTSTR lpdevnames = (LPTSTR)devnames;
     633                LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    634634                printName = lpdevnames+devnames->wDeviceOffset;
    635635
     
    951951        DEVNAMES *devnames = (DEVNAMES*)::GlobalLock(pd.hDevNames);
    952952        DASSERT(!IsBadReadPtr(devnames, sizeof(DEVNAMES)));
    953         LPCTSTR lpcNames = (LPTSTR)devnames;
     953        LPCTSTR lpcNames = reinterpret_cast<LPTSTR>(devnames);
    954954        LPCTSTR pbuf = (_tcslen(lpcNames + devnames->wDeviceOffset) == 0 ?
    955955                        TEXT("") : lpcNames + devnames->wDeviceOffset);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_PrintJob.cpp

    r190 r195  
    438438        int sz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, NULL, 0);
    439439        if (sz > 0) {
    440           LPTSTR str = (LPTSTR)safe_Malloc(sizeof(TCHAR) * sz);
     440          LPTSTR str = static_cast<LPTSTR>(safe_Malloc(sizeof(TCHAR) * sz));
    441441          if (str != NULL) {
    442442            sz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, str, sz);
     
    446446              }
    447447            }
    448             free((LPTSTR)str);
     448            free(str);
    449449          }
    450450        }
     
    484484            DEVNAMES* names = (DEVNAMES*)::GlobalLock(setup.hDevNames);
    485485            if (names != NULL) {
    486                 LPTSTR printer = (LPTSTR)names+names->wDeviceOffset;
     486                LPTSTR printer = reinterpret_cast<LPTSTR>(names)+names->wDeviceOffset;
    487487                SAVE_CONTROLWORD
    488488                HDC newDC = ::CreateDC(TEXT("WINSPOOL"), printer, NULL, NULL);
     
    610610  if (devnames != NULL) {
    611611
    612     LPTSTR lpdevnames = (LPTSTR)devnames;
     612    LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    613613    LPTSTR printerName = _tcsdup(lpdevnames+devnames->wDeviceOffset);
    614614
     
    622622      }
    623623      ::GlobalUnlock(hDevNames);
    624       free ((LPTSTR) printerName);
     624      free (printerName);
    625625      return;
    626626    }
     
    633633        ::ClosePrinter(hPrinter);
    634634        ::GlobalUnlock(hDevNames);
    635         free ((LPTSTR) printerName);
     635        free (printerName);
    636636        return ;
    637637    }
     
    648648                                 LOCALE_IMEASURE, NULL, 0);
    649649          if (sz > 0) {
    650             LPTSTR str = (LPTSTR)safe_Malloc(sizeof(TCHAR) * sz);
     650            LPTSTR str = static_cast<LPTSTR>(safe_Malloc(sizeof(TCHAR) * sz));
    651651            if (str != NULL) {
    652652              sz = GetLocaleInfo(LOCALE_USER_DEFAULT,
     
    657657                }
    658658              }
    659               free((LPTSTR)str);
     659              free(str);
    660660            }
    661661          }
     
    694694    ::GlobalFree(pDevMode);
    695695
    696     free ((LPTSTR) printerName);
     696    free (printerName);
    697697
    698698    ::ClosePrinter(hPrinter);
     
    919919
    920920        if (devnames != NULL) {
    921             LPTSTR lpdevnames = (LPTSTR)devnames;
     921            LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    922922            LPTSTR printername = lpdevnames+devnames->wDeviceOffset;
    923923            LPTSTR port = lpdevnames+devnames->wOutputOffset;
     
    10901090    DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(hDevNames);
    10911091    if (devnames != NULL) {
    1092         LPTSTR lpdevnames = (LPTSTR)devnames;
     1092        LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    10931093        LPTSTR printer = lpdevnames+devnames->wDeviceOffset;
    10941094        LPTSTR port = lpdevnames+devnames->wOutputOffset;
     
    11281128    int err = 0;
    11291129
    1130     LPTSTR destination = NULL;
     1130    LPCTSTR destination = NULL;
    11311131    if (dest != NULL) {
    1132         destination = (LPTSTR)JNU_GetStringPlatformChars(env, dest, NULL);
     1132        destination = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, dest, NULL));
    11331133    } else {
    11341134        destination = VerifyDestination(env, self);
     
    11361136    LPTSTR docname = NULL;
    11371137    if (jobname != NULL) {
    1138         LPTSTR tmp = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
     1138        LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jobname, NULL));
    11391139        docname = _tcsdup(tmp);
    11401140        JNU_ReleaseStringPlatformChars(env, jobname, tmp);
     
    13531353                    if (devnames != NULL) {
    13541354
    1355                       LPTSTR lpdevnames = (LPTSTR)devnames;
     1355                      LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    13561356                      LPTSTR printerName = _tcsdup(lpdevnames+devnames->wDeviceOffset);
    13571357
     
    29842984
    29852985            if (devnames != NULL) {
    2986                 LPTSTR lpdevnames = (LPTSTR)devnames;
     2986                LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    29872987                LPTSTR printer = lpdevnames+devnames->wDeviceOffset;
    29882988                LPTSTR port = lpdevnames+devnames->wOutputOffset;
     
    31303130
    31313131        DWORD result = DeviceCapabilities(deviceName, portName,
    3132                                           DC_PAPERSIZE, (LPTSTR) paperSizes,
     3132                                          DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
    31333133                                          NULL);
    31343134        if (result == -1) {
     
    37593759        DEVNAMES *devnames = (DEVNAMES *)::GlobalLock(hDevNames);
    37603760        if (devnames != NULL) {
    3761             LPTSTR lpdevnames = (LPTSTR)devnames;
     3761            LPTSTR lpdevnames = reinterpret_cast<LPTSTR>(devnames);
    37623762            printer = _tcsdup(lpdevnames+devnames->wDeviceOffset);
    37633763            port = _tcsdup(lpdevnames+devnames->wOutputOffset);
     
    37793779
    37803780        DWORD result1 = DeviceCapabilities(printer, port,
    3781                                            DC_PAPERS, (LPTSTR) papers, NULL);
     3781                                           DC_PAPERS, reinterpret_cast<LPTSTR>(papers), NULL);
    37823782        DWORD result2 = DeviceCapabilities(printer, port,
    3783                                            DC_PAPERSIZE, (LPTSTR) paperSizes,
     3783                                           DC_PAPERSIZE, reinterpret_cast<LPTSTR>(paperSizes),
    37843784                                           NULL);
    37853785
     
    39903990  // Copy the DEVNAMES information from PRINTER_INFO_2 structure.
    39913991  pDevNames->wDriverOffset = sizeof(DEVNAMES)/sizeof(TCHAR);
    3992   memcpy((LPTSTR)pDevNames + pDevNames->wDriverOffset,
     3992  memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wDriverOffset,
    39933993         p2->pDriverName, drvNameLen*sizeof(TCHAR));
    39943994
    39953995   pDevNames->wDeviceOffset = static_cast<WORD>(sizeof(DEVNAMES)/sizeof(TCHAR)) +
    39963996   drvNameLen + 1;
    3997    memcpy((LPTSTR)pDevNames + pDevNames->wDeviceOffset,
     3997   memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wDeviceOffset,
    39983998       p2->pPrinterName, ptrNameLen*sizeof(TCHAR));
    39993999
    40004000   pDevNames->wOutputOffset = static_cast<WORD>(sizeof(DEVNAMES)/sizeof(TCHAR)) +
    40014001     drvNameLen + ptrNameLen + 2;
    4002    memcpy((LPTSTR)pDevNames + pDevNames->wOutputOffset,
     4002   memcpy(reinterpret_cast<LPTSTR>(pDevNames) + pDevNames->wOutputOffset,
    40034003          p2->pPortName, porNameLen*sizeof(TCHAR));
    40044004
     
    40214021{
    40224022    TRY;
    4023     LPTSTR printerName = (LPTSTR)JNU_GetStringPlatformChars(env,
    4024                                                             printer, NULL);
     4023    LPCTSTR printerName = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env,
     4024                                                            printer, NULL));
    40254025    HDC hDC = AwtPrintControl::getPrintDC(env, name);
    40264026    if (hDC != NULL) {
     
    40524052    }
    40534053
    4054     SetPrinterDevice(printerName, &hDevMode, &hDevNames);
     4054    SetPrinterDevice(const_cast<LPTSTR>(printerName), &hDevMode, &hDevNames);
    40554055
    40564056    AwtPrintControl::setPrintHDMode(env, name, hDevMode);
     
    40994099
    41004100    printer = JNU_NewStringPlatform(env,
    4101                                     (LPTSTR)pDevNames+pDevNames->wDeviceOffset);
     4101                                    reinterpret_cast<LPTSTR>(pDevNames)+pDevNames->wDeviceOffset);
    41024102    ::GlobalUnlock(hDevNames);
    41034103    return printer;
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextArea.cpp

    r190 r195  
    252252    WCHAR *string = new WCHAR[length];
    253253    env->GetStringRegion(jStr, 0, static_cast<jsize>(length - 1),
    254                          reinterpret_cast<jchar*>(string));
     254                         jsafe_cast<jchar*>(string));
    255255    string[length-1] = '\0';
    256256    for (size_t i = 0; i < maxlen && i < length - 1; i++) {
     
    995995      // WCHAR* buffer = TO_WSTRING(text);
    996996      WCHAR *buffer = new WCHAR[length];
    997       env->GetStringRegion(text, 0, length-1, reinterpret_cast<jchar*>(buffer));
     997      env->GetStringRegion(text, 0, length-1, jsafe_cast<jchar*>(buffer));
    998998      buffer[length-1] = '\0';
    999999
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp

    r190 r195  
    327327            c->GetText(buf, len + 1);
    328328            c->RemoveCR(buf);
    329             result = env->NewString(reinterpret_cast<jchar*>(buf),
     329            result = env->NewString(jsafe_cast<jchar*>(buf),
    330330                                    static_cast<jsize>(wcslen(buf)));
    331331            delete [] buf;
     
    364364        int length = env->GetStringLength(text);
    365365        WCHAR* buffer = new WCHAR[length + 1];
    366         env->GetStringRegion(text, 0, length, reinterpret_cast<jchar*>(buffer));
     366        env->GetStringRegion(text, 0, length, jsafe_cast<jchar*>(buffer));
    367367        buffer[length] = 0;
    368368        c->CheckLineSeparator(buffer);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp

    r191 r195  
    314314        int length = env->GetStringLength(jstr);
    315315        buffer = new TCHAR[length + 1];
    316         LPCTSTR tmp = (LPCTSTR)JNU_GetStringPlatformChars(env, jstr, NULL);
     316        LPCTSTR tmp = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, jstr, NULL));
    317317        _tcscpy(buffer, tmp);
    318318        JNU_ReleaseStringPlatformChars(env, jstr, tmp);
     
    380380    HWND hwnd = CreateWindow(
    381381        szAwtToolkitClassName,
    382         (LPCTSTR)name,                    /* window name */
     382        name,                             /* window name */
    383383        WS_DISABLED,                      /* window style */
    384384        -1, -1,                           /* position of window */
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp

    r193 r195  
    734734    }
    735735
    736     tooltipStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jtooltip, (jboolean *)NULL));
     736    tooltipStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jtooltip, (jboolean *)NULL));
    737737    trayIcon->SetToolTip(tooltipStr);
    738     env->ReleaseStringChars(jtooltip, reinterpret_cast<const jchar *>(tooltipStr));
     738    env->ReleaseStringChars(jtooltip, jsafe_cast<const jchar *>(tooltipStr));
    739739ret:
    740740    env->DeleteGlobalRef(self);
     
    857857    trayIcon = (AwtTrayIcon *)pData;
    858858
    859     captionStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jcaption, (jboolean *)NULL));
    860     textStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jtext, (jboolean *)NULL));
    861     msgTypeStr = reinterpret_cast<LPCTSTR>(env->GetStringChars(jmsgType, (jboolean *)NULL));
     859    captionStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jcaption, (jboolean *)NULL));
     860    textStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jtext, (jboolean *)NULL));
     861    msgTypeStr = jsafe_cast<LPCTSTR>(env->GetStringChars(jmsgType, (jboolean *)NULL));
    862862
    863863    trayIcon->DisplayMessage(captionStr, textStr, msgTypeStr);
    864864
    865     env->ReleaseStringChars(jcaption, reinterpret_cast<const jchar *>(captionStr));
    866     env->ReleaseStringChars(jtext, reinterpret_cast<const jchar *>(textStr));
    867     env->ReleaseStringChars(jmsgType, reinterpret_cast<const jchar *>(msgTypeStr));
     865    env->ReleaseStringChars(jcaption, jsafe_cast<const jchar *>(captionStr));
     866    env->ReleaseStringChars(jtext, jsafe_cast<const jchar *>(textStr));
     867    env->ReleaseStringChars(jmsgType, jsafe_cast<const jchar *>(msgTypeStr));
    868868ret:
    869869    env->DeleteGlobalRef(self);
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.cpp

    r190 r195  
    3636    int len = env->GetStringLength(jstr);
    3737
    38     env->GetStringRegion(jstr, 0, len, reinterpret_cast<jchar*>(lpwstr));
     38    env->GetStringRegion(jstr, 0, len, jsafe_cast<jchar*>(lpwstr));
    3939    lpwstr[len] = '\0';
    4040
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Unicode.h

    r187 r195  
    4747#define TO_WSTRING(jstr) \
    4848   ((jstr == NULL) ? NULL : \
    49      (JNI_J2WHelper1(env, (LPWSTR) alloca((env->GetStringLength(jstr)+1)*2), \
     49     (JNI_J2WHelper1(env, static_cast<LPWSTR>(alloca((env->GetStringLength(jstr)+1)*2)), \
    5050                     jstr) \
    5151    ))
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp

    r190 r195  
    171171{
    172172    if (getWinVer() >= 5 && procAddFontResourceEx != NULL) {
    173       LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, NULL);
     173      LPCTSTR file = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, fontName, NULL));
    174174      (*procAddFontResourceEx)(file, FR_PRIVATE, NULL);
    175175    }
     
    190190{
    191191    if (getWinVer() >= 5 && procRemoveFontResourceEx != NULL) {
    192       LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, NULL);
     192      LPCTSTR file = jsafe_cast<LPCTSTR>(JNU_GetStringPlatformChars(env, fontName, NULL));
    193193      (*procRemoveFontResourceEx)(file, FR_PRIVATE, NULL);
    194194    }
  • trunk/openjdk/jdk/src/windows/native/sun/windows/awt_Window.cpp

    r190 r195  
    596596                      GetLastError(),
    597597                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    598                       (LPTSTR)&msgBuffer, // it's an output parameter when allocate buffer is used
     598                      reinterpret_cast<LPTSTR>(&msgBuffer), // it's an output parameter when allocate buffer is used
    599599                      0,
    600600                      NULL);
     
    16771677        int length = env->GetStringLength(title);
    16781678        WCHAR *buffer = new WCHAR[length + 1];
    1679         env->GetStringRegion(title, 0, length, reinterpret_cast<jchar*>(buffer));
     1679        env->GetStringRegion(title, 0, length, jsafe_cast<jchar*>(buffer));
    16801680        buffer[length] = L'\0';
    16811681        VERIFY(::SetWindowTextW(w->GetHWnd(), buffer));
Note: See TracChangeset for help on using the changeset viewer.