Branch libreoffice-5-0-4
[LibreOffice.git] / odk / source / unowinreg / win / unowinreg.cxx
blobe1a7ef80231602721a1322027d7fff0bf2690b17
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 _MSC_VER
22 #pragma warning(push, 1)
23 #endif
24 #include <windows.h>
25 #if defined _MSC_VER
26 #pragma warning(pop)
27 #endif
29 #include <jni.h>
31 extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID)
33 return TRUE;
36 extern "C" JNIEXPORT jboolean JNICALL
37 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(
38 JNIEnv *env, jclass, jlongArray hkresult)
40 jboolean ret = JNI_FALSE;
41 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
42 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, phkey)
43 == ERROR_SUCCESS)
44 ret = JNI_TRUE;
45 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
46 return ret;
49 extern "C" JNIEXPORT jboolean JNICALL
50 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig(
51 JNIEnv *env, jclass, jlongArray hkresult)
53 jboolean ret = JNI_FALSE;
54 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
55 if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, NULL, 0, KEY_READ, phkey)
56 == ERROR_SUCCESS)
57 ret = JNI_TRUE;
58 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
59 return ret;
62 extern "C" JNIEXPORT jboolean JNICALL
63 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser(
64 JNIEnv *env, jclass, jlongArray hkresult)
66 jboolean ret = JNI_FALSE;
67 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
68 if (RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_READ, phkey)
69 == ERROR_SUCCESS)
70 ret = JNI_TRUE;
71 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
72 return ret;
75 extern "C" JNIEXPORT jboolean JNICALL
76 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine(
77 JNIEnv *env, jclass, jlongArray hkresult)
79 jboolean ret = JNI_FALSE;
80 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
81 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ, phkey)
82 == ERROR_SUCCESS)
83 ret = JNI_TRUE;
84 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
85 return ret;
88 extern "C" JNIEXPORT jboolean JNICALL
89 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(
90 JNIEnv *env, jclass, jlongArray hkresult)
92 jboolean ret = JNI_FALSE;
93 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
94 if (RegOpenKeyEx(HKEY_USERS, NULL, 0, KEY_READ, phkey) == ERROR_SUCCESS)
95 ret = JNI_TRUE;
96 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
97 return ret;
100 extern "C" JNIEXPORT jboolean JNICALL
101 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(
102 JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult)
104 jboolean ret = JNI_FALSE;
105 const char *namestr = env->GetStringUTFChars(name, 0);
106 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
107 if (RegOpenKeyEx((HKEY)parent, namestr, 0, KEY_READ, phkey)
108 == ERROR_SUCCESS)
109 ret = JNI_TRUE;
110 env->ReleaseStringUTFChars(name, namestr);
111 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
112 return ret;
116 extern "C" JNIEXPORT jboolean JNICALL
117 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(
118 JNIEnv *, jclass, jlong hkey)
120 jboolean ret = JNI_FALSE;
121 if (RegCloseKey((HKEY)hkey) == ERROR_SUCCESS)
122 ret = JNI_TRUE;
123 return ret;
126 extern "C" JNIEXPORT jboolean
127 JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(
128 JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type,
129 jbyteArray data, jlongArray size)
131 jboolean ret = JNI_FALSE;
132 const char* valuestr = env->GetStringUTFChars(value, 0);
133 LPDWORD ptype = (LPDWORD)env->GetLongArrayElements(type, 0);
134 LPBYTE pdata = (LPBYTE)env->GetByteArrayElements(data, 0);
135 LPDWORD psize = (LPDWORD)env->GetLongArrayElements(size, 0);
136 if (RegQueryValueEx((HKEY)hkey, valuestr, NULL, ptype, pdata, psize)
137 == ERROR_SUCCESS)
138 ret = JNI_TRUE;
139 env->ReleaseStringUTFChars(value, valuestr);
140 env->ReleaseLongArrayElements(type, (jlong *)ptype, 0);
141 env->ReleaseByteArrayElements(data, (jbyte *)pdata, 0);
142 env->ReleaseLongArrayElements(size, (jlong *)psize, 0);
143 return ret;
146 extern "C" JNIEXPORT jboolean JNICALL
147 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(
148 JNIEnv *env, jclass, jlong hkey, jlongArray subkeys,
149 jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen,
150 jlongArray maxValueLen, jlongArray secDescriptor)
152 jboolean ret = JNI_FALSE;
153 LPDWORD psubkeys = (LPDWORD)env->GetLongArrayElements(subkeys, 0);
154 LPDWORD pmaxSubkeyLen =
155 (LPDWORD)env->GetLongArrayElements(maxSubkeyLen, 0);
156 LPDWORD pvalues = (LPDWORD)env->GetLongArrayElements(values, 0);
157 LPDWORD pmaxValueNameLen =
158 (LPDWORD)env->GetLongArrayElements(maxValueNameLen, 0);
159 LPDWORD pmaxValueLen =
160 (LPDWORD)env->GetLongArrayElements(maxValueLen, 0);
161 LPDWORD psecDescriptor =
162 (LPDWORD)env->GetLongArrayElements(secDescriptor, 0);
163 FILETIME ft;
164 if (RegQueryInfoKey((HKEY)hkey, NULL, NULL, NULL, psubkeys, pmaxSubkeyLen,
165 NULL, pvalues, pmaxValueNameLen, pmaxValueLen,
166 psecDescriptor, &ft) == ERROR_SUCCESS)
167 ret = JNI_TRUE;
168 env->ReleaseLongArrayElements(subkeys, (jlong*)psubkeys, 0);
169 env->ReleaseLongArrayElements(maxSubkeyLen, (jlong*)pmaxSubkeyLen, 0);
170 env->ReleaseLongArrayElements(values, (jlong*)pvalues, 0);
171 env->ReleaseLongArrayElements(maxValueNameLen, (jlong*)pmaxValueNameLen, 0);
172 env->ReleaseLongArrayElements(maxValueLen, (jlong*)pmaxValueLen, 0);
173 env->ReleaseLongArrayElements(secDescriptor, (jlong*)psecDescriptor, 0);
174 return ret;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */