1 /* 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "awt.h" 27 #include <jni.h> 28 #include <shellapi.h> 29 #include <float.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * Class: sun_awt_windows_WDesktopPeer 37 * Method: ShellExecute 38 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; 39 */ 40 JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute 41 (JNIEnv *env, jclass cls, jstring uri_j, jstring verb_j) 42 { 43 LPCWSTR uri_c = JNU_GetStringPlatformChars(env, uri_j, JNI_FALSE); 44 LPCWSTR verb_c = JNU_GetStringPlatformChars(env, verb_j, JNI_FALSE); 45 46 // 6457572: ShellExecute possibly changes FPU control word - saving it here 47 unsigned oldcontrol87 = _control87(0, 0); 48 HINSTANCE retval = ::ShellExecute(NULL, verb_c, uri_c, NULL, NULL, SW_SHOWNORMAL); 49 _control87(oldcontrol87, 0xffffffff); 50 51 JNU_ReleaseStringPlatformChars(env, uri_j, uri_c); 52 JNU_ReleaseStringPlatformChars(env, verb_j, verb_c); 53 54 if ((int)retval <= 32) { 55 // ShellExecute failed. 56 LPTSTR buffer = NULL; 57 int len = ::FormatMessage( 58 FORMAT_MESSAGE_ALLOCATE_BUFFER | 59 FORMAT_MESSAGE_FROM_SYSTEM | 60 FORMAT_MESSAGE_IGNORE_INSERTS, 61 NULL, 62 (int)retval, 63 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 64 (LPTSTR)&buffer, 65 0, 66 NULL ); 67 68 if (buffer) { 69 jstring errmsg = JNU_NewStringPlatform(env, buffer); 70 LocalFree(buffer); 71 return errmsg; 72 } 73 } 74 75 return NULL; 76 } 77 78 #ifdef __cplusplus 79 } 80 #endif