src/java.prefs/windows/native/libprefs/WindowsPreferences.c
author bpb
Thu, 08 Mar 2018 08:17:26 -0800
changeset 49154 28729cf7e4bc
parent 47216 71c04702a3d5
child 50471 f0aeede1b855
permissions -rw-r--r--
8198899: Compilation errors in java.prefs with VS 2017 Summary: Change Java level representation of HKEY from int to long Reviewed-by: alanb, rriggs, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <windows.h>
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    28
#include "jni.h"
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    29
#include "jni_util.h"
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    30
#include "jvm.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    34
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    35
/*
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    36
 * Declare library specific JNI_Onload entry if static build
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    37
 */
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    38
DEF_STATIC_JNI_OnLoad
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    39
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    40
JNIEXPORT jlongArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    41
Java_java_util_prefs_WindowsPreferences_WindowsRegOpenKey(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    42
    jclass this_class, jlong hKey, jbyteArray lpSubKey, jint securityMask) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    43
    char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    44
    CHECK_NULL_RETURN(str, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    45
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    46
    HKEY handle;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    47
    int errorCode = RegOpenKeyEx((HKEY) hKey, str, 0, securityMask, &handle);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    48
    (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    49
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    50
    jlong tmp[2];
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    51
    tmp[0] = (jlong) handle;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    52
    tmp[1] = errorCode;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    53
    jlongArray result = (*env)->NewLongArray(env, 2);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    54
    if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    55
        (*env)->SetLongArrayRegion(env, result, 0, 2, tmp);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    56
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    57
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    58
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    59
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    60
JNIEXPORT jint JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    61
Java_java_util_prefs_WindowsPreferences_WindowsRegCloseKey(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    62
    jclass this_class, jlong hKey) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    63
    return (jint) RegCloseKey((HKEY) hKey);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    64
};
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    65
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    66
JNIEXPORT jlongArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    67
Java_java_util_prefs_WindowsPreferences_WindowsRegCreateKeyEx(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    68
    jclass this_class, jlong hKey, jbyteArray lpSubKey) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    69
    char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    70
    CHECK_NULL_RETURN(str, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    71
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    72
    HKEY handle;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    73
    DWORD lpdwDisposition;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    74
    int errorCode = RegCreateKeyEx((HKEY) hKey, str, 0, NULL,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    75
        REG_OPTION_NON_VOLATILE, KEY_READ,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    76
        NULL, &handle, &lpdwDisposition);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    77
    (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    78
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    79
    jlong tmp[3];
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    80
    tmp[0] = (jlong) handle;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    81
    tmp[1] = errorCode;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    82
    tmp[2] = lpdwDisposition;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    83
    jlongArray result = (*env)->NewLongArray(env, 3);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    84
    if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    85
        (*env)->SetLongArrayRegion(env, result, 0, 3, tmp);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    86
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    87
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    88
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    89
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    90
JNIEXPORT jint JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    91
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteKey(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    92
    jclass this_class, jlong hKey, jbyteArray lpSubKey) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    93
    char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    94
    CHECK_NULL_RETURN(str, -1);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    95
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    96
    int result = RegDeleteKey((HKEY) hKey, str);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    97
    (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    98
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
    99
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   100
};
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   101
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   102
JNIEXPORT jint JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   103
Java_java_util_prefs_WindowsPreferences_WindowsRegFlushKey(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   104
    jclass this_class, jlong hKey) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   105
    return RegFlushKey((HKEY) hKey);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   106
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   107
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   108
JNIEXPORT jbyteArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   109
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   110
    jclass this_class, jlong hKey, jbyteArray valueName) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   111
    char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   112
    CHECK_NULL_RETURN(valueNameStr, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   113
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   114
    DWORD valueType;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   115
    DWORD valueSize;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   116
    if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, NULL,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   117
        &valueSize) != ERROR_SUCCESS) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   118
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   119
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   122
    char* buffer = (char*) malloc(valueSize);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   123
    if (buffer != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   124
        if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, buffer,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   125
            &valueSize) != ERROR_SUCCESS) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   126
            free(buffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   128
            return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   130
    } else {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   131
        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   133
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   136
    jbyteArray result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   137
    if (valueType == REG_SZ) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   138
        result = (*env)->NewByteArray(env, valueSize);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   139
        if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   140
            (*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   141
        }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   142
    } else {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   143
        result = NULL;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   144
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   145
    free(buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   146
    (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   147
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   148
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   149
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   150
JNIEXPORT jint JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   151
Java_java_util_prefs_WindowsPreferences_WindowsRegSetValueEx(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   152
    jclass this_class, jlong hKey, jbyteArray valueName, jbyteArray data) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   153
    if ((valueName == NULL) || (data == NULL)) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   154
        return -1;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   155
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   156
    int size = (*env)->GetArrayLength(env, data);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   157
    char* dataStr = (*env)->GetByteArrayElements(env, data, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   158
    CHECK_NULL_RETURN(dataStr, -1);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   159
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   160
    char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   161
    int error_code = -1;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   162
    if (valueNameStr != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   163
        error_code = RegSetValueEx((HKEY) hKey, valueNameStr, 0,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   164
            REG_SZ, dataStr, size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   166
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   167
    (*env)->ReleaseByteArrayElements(env, data, dataStr, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   168
    return error_code;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   169
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   170
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   171
JNIEXPORT jint JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   172
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteValue(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   173
    jclass this_class, jlong hKey, jbyteArray valueName) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   174
    if (valueName == NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   175
        return -1;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   176
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   177
    char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   178
    CHECK_NULL_RETURN(valueNameStr, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   180
    int error_code = RegDeleteValue((HKEY) hKey, valueNameStr);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   181
    (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   182
    return error_code;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   183
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   184
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   185
JNIEXPORT jlongArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   186
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   187
    jclass this_class, jlong hKey) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   188
    int subKeysNumber;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   189
    int maxSubKeyLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   190
    int valuesNumber;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   191
    int maxValueNameLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   192
    int errorCode = RegQueryInfoKey((HKEY) hKey, NULL, NULL, NULL,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   193
        &subKeysNumber, &maxSubKeyLength, NULL,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   194
        &valuesNumber, &maxValueNameLength,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   195
        NULL, NULL, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   196
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   197
    jlong tmp[5];
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   198
    tmp[0] = subKeysNumber;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   199
    tmp[1] = errorCode;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   200
    tmp[2] = valuesNumber;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   201
    tmp[3] = maxSubKeyLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   202
    tmp[4] = maxValueNameLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   203
    jintArray result = (*env)->NewLongArray(env, 5);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   204
    if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   205
        (*env)->SetLongArrayRegion(env, result, 0, 5, tmp);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   206
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   207
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   208
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   209
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   210
JNIEXPORT jbyteArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   211
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumKeyEx(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   212
    jclass this_class, jlong hKey, jint subKeyIndex, jint maxKeyLength) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   213
    int size = maxKeyLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   214
    char* buffer = (char*) malloc(maxKeyLength);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   215
    if (buffer == NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   216
        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   217
        return NULL;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   218
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   219
    if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   220
        NULL, NULL) != ERROR_SUCCESS) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   221
        free(buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   222
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   225
    jbyteArray result = (*env)->NewByteArray(env, size + 1);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   226
    if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   227
        (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   228
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   229
    free(buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   230
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   231
}
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   232
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   233
JNIEXPORT jbyteArray JNICALL
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   234
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumValue(JNIEnv* env,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   235
    jclass this_class, jlong hKey, jint valueIndex, jint maxValueNameLength) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   236
    int size = maxValueNameLength;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   237
    char* buffer = (char*) malloc(maxValueNameLength);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   238
    if (buffer == NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   239
        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   240
        return NULL;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   241
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   242
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   243
    int error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer,
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   244
        &size, NULL, NULL, NULL, NULL);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   245
    if (error_code != ERROR_SUCCESS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return NULL;
49154
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   248
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   249
    jbyteArray result = (*env)->NewByteArray(env, size + 1);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   250
    if (result != NULL) {
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   251
        (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   252
    }
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   253
    free(buffer);
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   254
    return result;
28729cf7e4bc 8198899: Compilation errors in java.prefs with VS 2017
bpb
parents: 47216
diff changeset
   255
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
#endif