1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_odk.hxx"
26
27 #if defined _MSC_VER
28 #pragma warning(push, 1)
29 #endif
30 #include <windows.h>
31 #if defined _MSC_VER
32 #pragma warning(pop)
33 #endif
34
35 #include <jni.h>
36
_DllMainCRTStartup(HINSTANCE,DWORD,LPVOID)37 extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID)
38 {
39 return TRUE;
40 }
41
42 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(JNIEnv * env,jclass,jlongArray hkresult)43 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(
44 JNIEnv *env, jclass, jlongArray hkresult)
45 {
46 jboolean ret = JNI_FALSE;
47 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
48 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, phkey)
49 == ERROR_SUCCESS)
50 ret = JNI_TRUE;
51 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
52 return ret;
53 }
54
55 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig(JNIEnv * env,jclass,jlongArray hkresult)56 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig(
57 JNIEnv *env, jclass, jlongArray hkresult)
58 {
59 jboolean ret = JNI_FALSE;
60 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
61 if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, NULL, 0, KEY_READ, phkey)
62 == ERROR_SUCCESS)
63 ret = JNI_TRUE;
64 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
65 return ret;
66 }
67
68 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser(JNIEnv * env,jclass,jlongArray hkresult)69 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser(
70 JNIEnv *env, jclass, jlongArray hkresult)
71 {
72 jboolean ret = JNI_FALSE;
73 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
74 if (RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_READ, phkey)
75 == ERROR_SUCCESS)
76 ret = JNI_TRUE;
77 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
78 return ret;
79 }
80
81 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine(JNIEnv * env,jclass,jlongArray hkresult)82 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine(
83 JNIEnv *env, jclass, jlongArray hkresult)
84 {
85 jboolean ret = JNI_FALSE;
86 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
87 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ, phkey)
88 == ERROR_SUCCESS)
89 ret = JNI_TRUE;
90 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
91 return ret;
92 }
93
94 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(JNIEnv * env,jclass,jlongArray hkresult)95 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(
96 JNIEnv *env, jclass, jlongArray hkresult)
97 {
98 jboolean ret = JNI_FALSE;
99 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
100 if (RegOpenKeyEx(HKEY_USERS, NULL, 0, KEY_READ, phkey) == ERROR_SUCCESS)
101 ret = JNI_TRUE;
102 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
103 return ret;
104 }
105
106 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(JNIEnv * env,jclass,jlong parent,jstring name,jlongArray hkresult)107 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(
108 JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult)
109 {
110 jboolean ret = JNI_FALSE;
111 const char *namestr = env->GetStringUTFChars(name, 0);
112 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
113 if (RegOpenKeyEx((HKEY)parent, namestr, 0, KEY_READ, phkey)
114 == ERROR_SUCCESS)
115 ret = JNI_TRUE;
116 env->ReleaseStringUTFChars(name, namestr);
117 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
118 return ret;
119 }
120
121
122 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(JNIEnv *,jclass,jlong hkey)123 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(
124 JNIEnv *, jclass, jlong hkey)
125 {
126 jboolean ret = JNI_FALSE;
127 if (RegCloseKey((HKEY)hkey) == ERROR_SUCCESS)
128 ret = JNI_TRUE;
129 return ret;
130 }
131
132 extern "C" JNIEXPORT jboolean
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(JNIEnv * env,jclass,jlong hkey,jstring value,jlongArray type,jbyteArray data,jlongArray size)133 JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(
134 JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type,
135 jbyteArray data, jlongArray size)
136 {
137 jboolean ret = JNI_FALSE;
138 const char* valuestr = env->GetStringUTFChars(value, 0);
139 LPDWORD ptype = (LPDWORD)env->GetLongArrayElements(type, 0);
140 LPBYTE pdata = (LPBYTE)env->GetByteArrayElements(data, 0);
141 LPDWORD psize = (LPDWORD)env->GetLongArrayElements(size, 0);
142 if (RegQueryValueEx((HKEY)hkey, valuestr, NULL, ptype, pdata, psize)
143 == ERROR_SUCCESS)
144 ret = JNI_TRUE;
145 env->ReleaseStringUTFChars(value, valuestr);
146 env->ReleaseLongArrayElements(type, (jlong *)ptype, 0);
147 env->ReleaseByteArrayElements(data, (jbyte *)pdata, 0);
148 env->ReleaseLongArrayElements(size, (jlong *)psize, 0);
149 return ret;
150 }
151
152 extern "C" JNIEXPORT jboolean JNICALL
Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(JNIEnv * env,jclass,jlong hkey,jlongArray subkeys,jlongArray maxSubkeyLen,jlongArray values,jlongArray maxValueNameLen,jlongArray maxValueLen,jlongArray secDescriptor)153 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(
154 JNIEnv *env, jclass, jlong hkey, jlongArray subkeys,
155 jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen,
156 jlongArray maxValueLen, jlongArray secDescriptor)
157 {
158 jboolean ret = JNI_FALSE;
159 LPDWORD psubkeys = (LPDWORD)env->GetLongArrayElements(subkeys, 0);
160 LPDWORD pmaxSubkeyLen =
161 (LPDWORD)env->GetLongArrayElements(maxSubkeyLen, 0);
162 LPDWORD pvalues = (LPDWORD)env->GetLongArrayElements(values, 0);
163 LPDWORD pmaxValueNameLen =
164 (LPDWORD)env->GetLongArrayElements(maxValueNameLen, 0);
165 LPDWORD pmaxValueLen =
166 (LPDWORD)env->GetLongArrayElements(maxValueLen, 0);
167 LPDWORD psecDescriptor =
168 (LPDWORD)env->GetLongArrayElements(secDescriptor, 0);
169 FILETIME ft;
170 if (RegQueryInfoKey((HKEY)hkey, NULL, NULL, NULL, psubkeys, pmaxSubkeyLen,
171 NULL, pvalues, pmaxValueNameLen, pmaxValueLen,
172 psecDescriptor, &ft) == ERROR_SUCCESS)
173 ret = JNI_TRUE;
174 env->ReleaseLongArrayElements(subkeys, (jlong*)psubkeys, 0);
175 env->ReleaseLongArrayElements(maxSubkeyLen, (jlong*)pmaxSubkeyLen, 0);
176 env->ReleaseLongArrayElements(values, (jlong*)pvalues, 0);
177 env->ReleaseLongArrayElements(maxValueNameLen, (jlong*)pmaxValueNameLen, 0);
178 env->ReleaseLongArrayElements(maxValueLen, (jlong*)pmaxValueLen, 0);
179 env->ReleaseLongArrayElements(secDescriptor, (jlong*)psecDescriptor, 0);
180 return ret;
181 }
182