Update ooo320-m1
[ooovba.git] / odk / source / unowinreg / win / unowinreg.cxx
blobbe781baf1d327727c5f04f9f0bb38affadaf3350
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unowinreg.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_odk.hxx"
34 #if defined _MSC_VER
35 #pragma warning(push, 1)
36 #endif
37 #include <windows.h>
38 #if defined _MSC_VER
39 #pragma warning(pop)
40 #endif
42 #include <jni.h>
44 extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID)
46 return TRUE;
49 extern "C" JNIEXPORT jboolean JNICALL
50 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot(
51 JNIEnv *env, jclass, jlongArray hkresult)
53 jboolean ret = JNI_FALSE;
54 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
55 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, 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_1RegOpenCurrentConfig(
64 JNIEnv *env, jclass, jlongArray hkresult)
66 jboolean ret = JNI_FALSE;
67 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
68 if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, 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_1RegOpenCurrentUser(
77 JNIEnv *env, jclass, jlongArray hkresult)
79 jboolean ret = JNI_FALSE;
80 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
81 if (RegOpenKeyEx(HKEY_CURRENT_USER, 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_1RegOpenLocalMachine(
90 JNIEnv *env, jclass, jlongArray hkresult)
92 jboolean ret = JNI_FALSE;
93 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
94 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ, phkey)
95 == ERROR_SUCCESS)
96 ret = JNI_TRUE;
97 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
98 return ret;
101 extern "C" JNIEXPORT jboolean JNICALL
102 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers(
103 JNIEnv *env, jclass, jlongArray hkresult)
105 jboolean ret = JNI_FALSE;
106 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
107 if (RegOpenKeyEx(HKEY_USERS, NULL, 0, KEY_READ, phkey) == ERROR_SUCCESS)
108 ret = JNI_TRUE;
109 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
110 return ret;
113 extern "C" JNIEXPORT jboolean JNICALL
114 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx(
115 JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult)
117 jboolean ret = JNI_FALSE;
118 const char *namestr = env->GetStringUTFChars(name, 0);
119 PHKEY phkey = (PHKEY)env->GetLongArrayElements(hkresult, 0);
120 if (RegOpenKeyEx((HKEY)parent, namestr, 0, KEY_READ, phkey)
121 == ERROR_SUCCESS)
122 ret = JNI_TRUE;
123 env->ReleaseStringUTFChars(name, namestr);
124 env->ReleaseLongArrayElements(hkresult, (jlong *)phkey, 0);
125 return ret;
129 extern "C" JNIEXPORT jboolean JNICALL
130 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey(
131 JNIEnv *, jclass, jlong hkey)
133 jboolean ret = JNI_FALSE;
134 if (RegCloseKey((HKEY)hkey) == ERROR_SUCCESS)
135 ret = JNI_TRUE;
136 return ret;
139 extern "C" JNIEXPORT jboolean
140 JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx(
141 JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type,
142 jbyteArray data, jlongArray size)
144 jboolean ret = JNI_FALSE;
145 const char* valuestr = env->GetStringUTFChars(value, 0);
146 LPDWORD ptype = (LPDWORD)env->GetLongArrayElements(type, 0);
147 LPBYTE pdata = (LPBYTE)env->GetByteArrayElements(data, 0);
148 LPDWORD psize = (LPDWORD)env->GetLongArrayElements(size, 0);
149 if (RegQueryValueEx((HKEY)hkey, valuestr, NULL, ptype, pdata, psize)
150 == ERROR_SUCCESS)
151 ret = JNI_TRUE;
152 env->ReleaseStringUTFChars(value, valuestr);
153 env->ReleaseLongArrayElements(type, (jlong *)ptype, 0);
154 env->ReleaseByteArrayElements(data, (jbyte *)pdata, 0);
155 env->ReleaseLongArrayElements(size, (jlong *)psize, 0);
156 return ret;
159 extern "C" JNIEXPORT jboolean JNICALL
160 Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey(
161 JNIEnv *env, jclass, jlong hkey, jlongArray subkeys,
162 jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen,
163 jlongArray maxValueLen, jlongArray secDescriptor)
165 jboolean ret = JNI_FALSE;
166 LPDWORD psubkeys = (LPDWORD)env->GetLongArrayElements(subkeys, 0);
167 LPDWORD pmaxSubkeyLen =
168 (LPDWORD)env->GetLongArrayElements(maxSubkeyLen, 0);
169 LPDWORD pvalues = (LPDWORD)env->GetLongArrayElements(values, 0);
170 LPDWORD pmaxValueNameLen =
171 (LPDWORD)env->GetLongArrayElements(maxValueNameLen, 0);
172 LPDWORD pmaxValueLen =
173 (LPDWORD)env->GetLongArrayElements(maxValueLen, 0);
174 LPDWORD psecDescriptor =
175 (LPDWORD)env->GetLongArrayElements(secDescriptor, 0);
176 FILETIME ft;
177 if (RegQueryInfoKey((HKEY)hkey, NULL, NULL, NULL, psubkeys, pmaxSubkeyLen,
178 NULL, pvalues, pmaxValueNameLen, pmaxValueLen,
179 psecDescriptor, &ft) == ERROR_SUCCESS)
180 ret = JNI_TRUE;
181 env->ReleaseLongArrayElements(subkeys, (jlong*)psubkeys, 0);
182 env->ReleaseLongArrayElements(maxSubkeyLen, (jlong*)pmaxSubkeyLen, 0);
183 env->ReleaseLongArrayElements(values, (jlong*)pvalues, 0);
184 env->ReleaseLongArrayElements(maxValueNameLen, (jlong*)pmaxValueNameLen, 0);
185 env->ReleaseLongArrayElements(maxValueLen, (jlong*)pmaxValueLen, 0);
186 env->ReleaseLongArrayElements(secDescriptor, (jlong*)psecDescriptor, 0);
187 return ret;