1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unowinreg.cxx,v $
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"
35 #pragma warning(push, 1)
44 extern "C" BOOL __stdcall
_DllMainCRTStartup(HINSTANCE
, DWORD
, LPVOID
)
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
)
58 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
71 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
84 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
97 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
109 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
123 env
->ReleaseStringUTFChars(name
, namestr
);
124 env
->ReleaseLongArrayElements(hkresult
, (jlong
*)phkey
, 0);
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
)
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
)
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);
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);
177 if (RegQueryInfoKey((HKEY
)hkey
, NULL
, NULL
, NULL
, psubkeys
, pmaxSubkeyLen
,
178 NULL
, pvalues
, pmaxValueNameLen
, pmaxValueLen
,
179 psecDescriptor
, &ft
) == ERROR_SUCCESS
)
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);