src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp

Print this page




  35 
  36 /*
  37  * Class:     sun_awt_windows_WDesktopPeer
  38  * Method:    ShellExecute
  39  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
  40  */
  41 JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute
  42   (JNIEnv *env, jclass cls, jstring fileOrUri_j, jstring verb_j)
  43 {
  44     LPCWSTR fileOrUri_c = JNU_GetStringPlatformChars(env, fileOrUri_j, JNI_FALSE);
  45     CHECK_NULL_RETURN(fileOrUri_c, NULL);
  46     LPCWSTR verb_c = JNU_GetStringPlatformChars(env, verb_j, JNI_FALSE);
  47     if (verb_c == NULL) {
  48         JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
  49         return NULL;
  50     }
  51 
  52     // 6457572: ShellExecute possibly changes FPU control word - saving it here
  53     unsigned oldcontrol87 = _control87(0, 0);
  54     HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL, SW_SHOWNORMAL);

  55     _control87(oldcontrol87, 0xffffffff);
  56 
  57     JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
  58     JNU_ReleaseStringPlatformChars(env, verb_j, verb_c);
  59 
  60     if ((int)retval <= 32) {
  61         // ShellExecute failed.
  62         LPTSTR buffer = NULL;
  63         int len = ::FormatMessage(
  64                     FORMAT_MESSAGE_ALLOCATE_BUFFER |
  65                     FORMAT_MESSAGE_FROM_SYSTEM  |
  66                     FORMAT_MESSAGE_IGNORE_INSERTS,
  67                     NULL,
  68                     (int)retval,
  69                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  70                     (LPTSTR)&buffer,
  71                     0,
  72                     NULL );
  73 
  74         if (buffer) {
  75             jstring errmsg = JNU_NewStringPlatform(env, buffer);
  76             LocalFree(buffer);
  77             return errmsg;
  78         }
  79     }
  80 
  81     return NULL;
  82 }
  83 
  84 #ifdef __cplusplus
  85 }
  86 #endif


  35 
  36 /*
  37  * Class:     sun_awt_windows_WDesktopPeer
  38  * Method:    ShellExecute
  39  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
  40  */
  41 JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute
  42   (JNIEnv *env, jclass cls, jstring fileOrUri_j, jstring verb_j)
  43 {
  44     LPCWSTR fileOrUri_c = JNU_GetStringPlatformChars(env, fileOrUri_j, JNI_FALSE);
  45     CHECK_NULL_RETURN(fileOrUri_c, NULL);
  46     LPCWSTR verb_c = JNU_GetStringPlatformChars(env, verb_j, JNI_FALSE);
  47     if (verb_c == NULL) {
  48         JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
  49         return NULL;
  50     }
  51 
  52     // 6457572: ShellExecute possibly changes FPU control word - saving it here
  53     unsigned oldcontrol87 = _control87(0, 0);
  54     HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL, SW_SHOWNORMAL);
  55     DWORD error = ::GetLastError();
  56     _control87(oldcontrol87, 0xffffffff);
  57 
  58     JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
  59     JNU_ReleaseStringPlatformChars(env, verb_j, verb_c);
  60 
  61     if ((int)retval <= 32) {
  62         // ShellExecute failed.
  63         LPTSTR buffer = NULL;
  64         int len = ::FormatMessage(
  65                     FORMAT_MESSAGE_ALLOCATE_BUFFER |
  66                     FORMAT_MESSAGE_FROM_SYSTEM  |
  67                     FORMAT_MESSAGE_IGNORE_INSERTS,
  68                     NULL,
  69                     error,
  70                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  71                     (LPTSTR)&buffer,
  72                     0,
  73                     NULL );
  74 
  75         if (buffer) {
  76             jstring errmsg = JNU_NewStringPlatform(env, buffer);
  77             LocalFree(buffer);
  78             return errmsg;
  79         }
  80     }
  81 
  82     return NULL;
  83 }
  84 
  85 #ifdef __cplusplus
  86 }
  87 #endif