Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / odk / source / unowinreg / win / unowinreg.cxx
blob98934bd2d052b6b4a1e53c2e9923ac79c9a1759b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #if !defined WIN32_LEAN_AND_MEAN
22 # define WIN32_LEAN_AND_MEAN
23 #endif
24 #include <windows.h>
26 #include <jni.h>
28 extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID)
30 return TRUE;
33 extern "C" JNIEXPORT jboolean JNICALL
34 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(
35 JNIEnv *env, jclass, jlongArray hkresult)
37 jboolean ret = JNI_FALSE;
38 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
39 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey))
40 == ERROR_SUCCESS)
41 ret = JNI_TRUE;
42 env->ReleaseLongArrayElements(hkresult, phkey, 0);
43 return ret;
46 extern "C" JNIEXPORT jboolean JNICALL
47 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig(
48 JNIEnv *env, jclass, jlongArray hkresult)
50 jboolean ret = JNI_FALSE;
51 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
52 if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey))
53 == ERROR_SUCCESS)
54 ret = JNI_TRUE;
55 env->ReleaseLongArrayElements(hkresult, phkey, 0);
56 return ret;
59 extern "C" JNIEXPORT jboolean JNICALL
60 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser(
61 JNIEnv *env, jclass, jlongArray hkresult)
63 jboolean ret = JNI_FALSE;
64 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
65 if (RegOpenKeyEx(HKEY_CURRENT_USER, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey))
66 == ERROR_SUCCESS)
67 ret = JNI_TRUE;
68 env->ReleaseLongArrayElements(hkresult, phkey, 0);
69 return ret;
72 extern "C" JNIEXPORT jboolean JNICALL
73 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine(
74 JNIEnv *env, jclass, jlongArray hkresult)
76 jboolean ret = JNI_FALSE;
77 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
78 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey))
79 == ERROR_SUCCESS)
80 ret = JNI_TRUE;
81 env->ReleaseLongArrayElements(hkresult, phkey, 0);
82 return ret;
85 extern "C" JNIEXPORT jboolean JNICALL
86 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(
87 JNIEnv *env, jclass, jlongArray hkresult)
89 jboolean ret = JNI_FALSE;
90 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
91 if (RegOpenKeyEx(HKEY_USERS, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) == ERROR_SUCCESS)
92 ret = JNI_TRUE;
93 env->ReleaseLongArrayElements(hkresult, phkey, 0);
94 return ret;
97 extern "C" JNIEXPORT jboolean JNICALL
98 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(
99 JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult)
101 jboolean ret = JNI_FALSE;
102 const char *namestr = env->GetStringUTFChars(name, nullptr);
103 auto phkey = env->GetLongArrayElements(hkresult, nullptr);
104 if (RegOpenKeyEx(reinterpret_cast<HKEY>(parent), namestr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey))
105 == ERROR_SUCCESS)
106 ret = JNI_TRUE;
107 env->ReleaseStringUTFChars(name, namestr);
108 env->ReleaseLongArrayElements(hkresult, phkey, 0);
109 return ret;
113 extern "C" JNIEXPORT jboolean JNICALL
114 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(
115 JNIEnv *, jclass, jlong hkey)
117 jboolean ret = JNI_FALSE;
118 if (RegCloseKey(reinterpret_cast<HKEY>(hkey)) == ERROR_SUCCESS)
119 ret = JNI_TRUE;
120 return ret;
123 extern "C" JNIEXPORT jboolean
124 JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(
125 JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type,
126 jbyteArray data, jlongArray size)
128 jboolean ret = JNI_FALSE;
129 const char* valuestr = env->GetStringUTFChars(value, nullptr);
130 auto ptype = env->GetLongArrayElements(type, nullptr);
131 auto pdata = env->GetByteArrayElements(data, nullptr);
132 auto psize = env->GetLongArrayElements(size, nullptr);
133 if (RegQueryValueEx(reinterpret_cast<HKEY>(hkey), valuestr, nullptr, reinterpret_cast<LPDWORD>(ptype), reinterpret_cast<LPBYTE>(pdata), reinterpret_cast<LPDWORD>(psize))
134 == ERROR_SUCCESS)
135 ret = JNI_TRUE;
136 env->ReleaseStringUTFChars(value, valuestr);
137 env->ReleaseLongArrayElements(type, ptype, 0);
138 env->ReleaseByteArrayElements(data, pdata, 0);
139 env->ReleaseLongArrayElements(size, psize, 0);
140 return ret;
143 extern "C" JNIEXPORT jboolean JNICALL
144 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(
145 JNIEnv *env, jclass, jlong hkey, jlongArray subkeys,
146 jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen,
147 jlongArray maxValueLen, jlongArray secDescriptor)
149 jboolean ret = JNI_FALSE;
150 auto psubkeys = env->GetLongArrayElements(subkeys, nullptr);
151 auto pmaxSubkeyLen = env->GetLongArrayElements(maxSubkeyLen, nullptr);
152 auto pvalues = env->GetLongArrayElements(values, nullptr);
153 auto pmaxValueNameLen = env->GetLongArrayElements(maxValueNameLen, nullptr);
154 auto pmaxValueLen = env->GetLongArrayElements(maxValueLen, nullptr);
155 auto psecDescriptor = env->GetLongArrayElements(secDescriptor, nullptr);
156 FILETIME ft;
157 if (RegQueryInfoKey(reinterpret_cast<HKEY>(hkey), nullptr, nullptr, nullptr, reinterpret_cast<LPDWORD>(psubkeys), reinterpret_cast<LPDWORD>(pmaxSubkeyLen),
158 nullptr, reinterpret_cast<LPDWORD>(pvalues), reinterpret_cast<LPDWORD>(pmaxValueNameLen), reinterpret_cast<LPDWORD>(pmaxValueLen),
159 reinterpret_cast<LPDWORD>(psecDescriptor), &ft) == ERROR_SUCCESS)
160 ret = JNI_TRUE;
161 env->ReleaseLongArrayElements(subkeys, psubkeys, 0);
162 env->ReleaseLongArrayElements(maxSubkeyLen, pmaxSubkeyLen, 0);
163 env->ReleaseLongArrayElements(values, pvalues, 0);
164 env->ReleaseLongArrayElements(maxValueNameLen, pmaxValueNameLen, 0);
165 env->ReleaseLongArrayElements(maxValueLen, pmaxValueLen, 0);
166 env->ReleaseLongArrayElements(secDescriptor, psecDescriptor, 0);
167 return ret;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */