Lines 28-30
Link Here
|
28 |
|
28 |
|
29 |
return result; |
29 |
return result; |
30 |
} |
30 |
} |
|
|
31 |
|
32 |
/* |
33 |
* Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) |
34 |
* to the key's array of values, return the name of the indexed value. |
35 |
* The return value is null on any error or when the index is invalid. |
36 |
*/ |
37 |
|
38 |
extern "C" |
39 |
JNIEXPORT jstring Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValueName( |
40 |
JNIEnv * env, jobject obj, jstring subkey, jint index) |
41 |
{ |
42 |
const jchar * csubkey = env->GetStringChars(subkey, NULL); |
43 |
jstring result = NULL; |
44 |
|
45 |
HKEY key; |
46 |
LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key); |
47 |
if (rc != ERROR_SUCCESS) |
48 |
return NULL; |
49 |
|
50 |
wchar_t valueName[256]; |
51 |
DWORD nameSize = sizeof(valueName) + 2; |
52 |
|
53 |
rc = RegEnumValue(key, index, |
54 |
valueName, // UNICODE string |
55 |
&nameSize, |
56 |
NULL, NULL, |
57 |
NULL, // data string |
58 |
NULL); // size in BYTE of data. |
59 |
|
60 |
if (rc == ERROR_SUCCESS) |
61 |
{ |
62 |
result = env->NewString((jchar *)valueName, nameSize); |
63 |
} |
64 |
|
65 |
RegCloseKey(key); |
66 |
|
67 |
env->ReleaseStringChars(subkey, csubkey); |
68 |
|
69 |
return result; |
70 |
} |