Top |
struct | GWin32RegistrySubkeyIter |
struct | GWin32RegistryValueIter |
struct | GWin32RegistryKey |
enum | GWin32RegistryValueType |
enum | GWin32RegistryKeyWatcherFlags |
GWin32RegistryKey represents a single Windows Registry key.
GWin32RegistryKey is used by a number of helper functions that read Windows Registry. All keys are opened with read-only access, and at the moment there is no API for writing into registry keys or creating new ones.
GWin32RegistryKey implements the GInitable interface, so if it is manually
constructed by e.g. g_object_new()
you must call g_initable_init()
and check
the results before using the object. This is done automatically
in g_win32_registry_key_new()
and g_win32_registry_key_get_child()
, so these
functions can return NULL
.
To increase efficiency, a UTF-16 variant is available for all functions that deal with key or value names in the registry. Use these to perform deep registry queries or other operations that require querying a name of a key or a value and then opening it (or querying its data). The use of UTF-16 functions avoids the overhead of converting names to UTF-8 and back.
All functions operate in current user's context (it is not possible to access registry tree of a different user).
Key paths must use '\' as a separator, '/' is not supported. Key names must not include '\', because it's used as a separator. Value names can include '\'.
Key and value names are not case sensitive.
Full key name (excluding the pre-defined ancestor's name) can't exceed 255 UTF-16 characters, give or take. Value name can't exceed 16383 UTF-16 characters. Tree depth is limited to 512 levels.
GWin32RegistrySubkeyIter *
g_win32_registry_subkey_iter_copy (const GWin32RegistrySubkeyIter *iter
);
Creates a dynamically-allocated copy of an iterator. Dynamically-allocated state of the iterator is duplicated too.
Since: 2.46
void
g_win32_registry_subkey_iter_free (GWin32RegistrySubkeyIter *iter
);
Free an iterator allocated on the heap. For iterators that are allocated
on the stack use g_win32_registry_subkey_iter_clear()
instead.
Since: 2.46
void g_win32_registry_subkey_iter_assign (GWin32RegistrySubkeyIter *iter
,const GWin32RegistrySubkeyIter *other
);
Assigns the value of other
to iter
. This function
is not useful in applications, because iterators can be assigned
with GWin32RegistrySubkeyIter i = j;
. The
function is used by language bindings.
Since: 2.46
GWin32RegistryValueIter *
g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter
);
Creates a dynamically-allocated copy of an iterator. Dynamically-allocated state of the iterator is duplicated too.
Since: 2.46
void
g_win32_registry_value_iter_free (GWin32RegistryValueIter *iter
);
Free an iterator allocated on the heap. For iterators that are allocated
on the stack use g_win32_registry_value_iter_clear()
instead.
Since: 2.46
void g_win32_registry_value_iter_assign (GWin32RegistryValueIter *iter
,const GWin32RegistryValueIter *other
);
Assigns the value of other
to iter
. This function
is not useful in applications, because iterators can be assigned
with GWin32RegistryValueIter i = j;
. The
function is used by language bindings.
Since: 2.46
GWin32RegistryKey * g_win32_registry_key_new (const gchar *path
,GError **error
);
Creates an object that represents a registry key specified by path
.
path
must start with one of the following pre-defined names:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_CURRENT_USER_LOCAL_SETTINGS
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
path
must not end with '\'.
a GWin32RegistryKey or NULL
if can't
be opened. Free with g_object_unref()
.
[nullable][transfer full]
GWin32RegistryKey * g_win32_registry_key_new_w (const gunichar2 *path
,GError **error
);
Creates an object that represents a registry key specified by path
.
path
must start with one of the following pre-defined names:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_CURRENT_USER_LOCAL_SETTINGS
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_PERFORMANCE_NLSTEXT
HKEY_PERFORMANCE_TEXT
HKEY_USERS
path
must not end with L'\'.
a GWin32RegistryKey or NULL
if can't
be opened. Free with g_object_unref()
.
[nullable][transfer full]
GWin32RegistryKey * g_win32_registry_key_get_child (GWin32RegistryKey *key
,const gchar *subkey
,GError **error
);
Opens a subkey
of the key
.
key |
a parent GWin32RegistryKey. |
[in][transfer none] |
subkey |
name of a child key to open (in UTF-8), relative to |
[in][transfer none] |
error |
[inout][optional][nullable] |
GWin32RegistryKey * g_win32_registry_key_get_child_w (GWin32RegistryKey *key
,const gunichar2 *subkey
,GError **error
);
Opens a subkey
of the key
.
key |
a parent GWin32RegistryKey. |
[in][transfer none] |
subkey |
name of a child key to open (in UTF-8), relative to |
[in][transfer none] |
error |
[inout][optional][nullable] |
gboolean g_win32_registry_subkey_iter_init (GWin32RegistrySubkeyIter *iter
,GWin32RegistryKey *key
,GError **error
);
Initialises (without allocating) a GWin32RegistrySubkeyIter. iter
may be
completely uninitialised prior to this call; its old value is
ignored.
The iterator remains valid for as long as key
exists.
Clean up its internal buffers with a call to
g_win32_registry_subkey_iter_clear()
when done.
iter |
a pointer to a GWin32RegistrySubkeyIter. |
[in][transfer none] |
key |
a GWin32RegistryKey to iterate over. |
[in][transfer none] |
error |
[inout][optional][nullable] |
Since: 2.46
void
g_win32_registry_subkey_iter_clear (GWin32RegistrySubkeyIter *iter
);
Frees internal buffers of a GWin32RegistrySubkeyIter.
Since: 2.46
gsize
g_win32_registry_subkey_iter_n_subkeys
(GWin32RegistrySubkeyIter *iter
);
Queries the number of subkeys items in the key that we are iterating over. This is the total number of subkeys -- not the number of items remaining.
This information is accurate at the point of iterator initialization, and may go out of sync with reality even while subkeys are enumerated.
Since: 2.46
gboolean g_win32_registry_subkey_iter_next (GWin32RegistrySubkeyIter *iter
,gboolean skip_errors
,GError **error
);
Moves iterator to the next subkey.
Enumeration errors can be ignored if skip_errors
is TRUE
Here is an example for iterating with g_win32_registry_subkey_iter_next()
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// recursively iterate a key void iterate_key_recursive (GWin32RegistryKey *key) { GWin32RegistrySubkeyIter iter; gchar *name; GWin32RegistryKey *child; if (!g_win32_registry_subkey_iter_init (&iter, key, NULL)) return; while (g_win32_registry_subkey_iter_next (&iter, TRUE, NULL)) { if (!g_win32_registry_subkey_iter_get_name (&iter, &name, NULL, NULL)) continue; g_print ("subkey '%s'\n", name); child = g_win32_registry_key_get_child (key, name, NULL); if (child) iterate_key_recursive (child); } g_win32_registry_subkey_iter_clear (&iter); } |
iter |
[in][transfer none] | |
skip_errors |
|
[in] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_subkey_iter_get_name (GWin32RegistrySubkeyIter *iter
,gchar **subkey_name
,gsize *subkey_name_len
,GError **error
);
Gets the name of the subkey at the iter
potision.
iter |
[in][transfer none] | |
subkey_name |
Pointer to a location
to store the name of a subkey (in UTF-8). Free with |
[out callee-allocates][transfer none] |
subkey_name_len |
Pointer to a location to store the
length of |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_subkey_iter_get_name_w (GWin32RegistrySubkeyIter *iter
,gunichar2 **subkey_name
,gsize *subkey_name_len
,GError **error
);
Same as g_win32_registry_subkey_iter_get_next()
, but outputs UTF-16-encoded
data, without converting it to UTF-8 first.
iter |
[in][transfer none] | |
subkey_name |
Pointer to a location to store the name of a subkey (in UTF-16). |
[out callee-allocates][transfer none] |
subkey_name_len |
Pointer to a location
to store the length of |
[out][optional][transfer none] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_init (GWin32RegistryValueIter *iter
,GWin32RegistryKey *key
,GError **error
);
Initialises (without allocating) a GWin32RegistryValueIter. iter
may be
completely uninitialised prior to this call; its old value is
ignored.
The iterator remains valid for as long as key
exists.
Clean up its internal buffers with a call to
g_win32_registry_value_iter_clear()
when done.
iter |
a pointer to a GWin32RegistryValueIter. |
[in][transfer none] |
key |
a GWin32RegistryKey to iterate over. |
[in][transfer none] |
error |
[nullable] |
Since: 2.46
void
g_win32_registry_value_iter_clear (GWin32RegistryValueIter *iter
);
Frees internal buffers of a GWin32RegistryValueIter.
Since: 2.46
gsize
g_win32_registry_value_iter_n_values (GWin32RegistryValueIter *iter
);
Queries the number of values items in the key that we are iterating over. This is the total number of values -- not the number of items remaining.
This information is accurate at the point of iterator initialization, and may go out of sync with reality even while values are enumerated.
Since: 2.46
gboolean g_win32_registry_value_iter_next (GWin32RegistryValueIter *iter
,gboolean skip_errors
,GError **error
);
Advances iterator to the next value in the key. If no more values remain then
FALSE is returned.
Enumeration errors can be ignored if skip_errors
is TRUE
Here is an example for iterating with g_win32_registry_value_iter_next()
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// iterate values of a key void iterate_values_recursive (GWin32RegistryKey *key) { GWin32RegistryValueIter iter; gchar *name; GWin32RegistryValueType val_type; gchar *val_data; if (!g_win32_registry_value_iter_init (&iter, key, NULL)) return; while (g_win32_registry_value_iter_next (&iter, TRUE, NULL)) { if ((!g_win32_registry_value_iter_get_value_type (&iter, &value)) || ((val_type != G_WIN32_REGISTRY_VALUE_STR) && (val_type != G_WIN32_REGISTRY_VALUE_EXPAND_STR))) continue; if (g_win32_registry_value_iter_get_value (&iter, TRUE, &name, NULL, &val_data, NULL, NULL)) g_print ("value '%s' = '%s'\n", name, val_data); } g_win32_registry_value_iter_clear (&iter); } |
iter |
[in][transfer none] | |
skip_errors |
|
[in] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_get_value_type (GWin32RegistryValueIter *iter
,GWin32RegistryValueType *value_type
,GError **error
);
Stores the type of the value currently being iterated over in value_type
.
iter |
[in][transfer none] | |
value_type |
Pointer to a location to store the type of the value. |
[out] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_get_name (GWin32RegistryValueIter *iter
,gchar **value_name
,gsize *value_name_len
,GError **error
);
Stores the name of the value currently being iterated over in value_name
,
and its length - in value_name_len
(if not NULL
).
iter |
[in][transfer none] | |
value_name |
Pointer to a location to store the name of a value (in UTF-8). |
[out callee-allocates][transfer none] |
value_name_len |
Pointer to a location to store the length
of |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_get_name_w (GWin32RegistryValueIter *iter
,gunichar2 **value_name
,gsize *value_name_len
,GError **error
);
Stores the name of the value currently being iterated over in value_name
,
and its length - in value_name
(if not NULL
).
iter |
[in][transfer none] | |
value_name |
Pointer to a location to store the name of a value (in UTF-16). |
[out callee-allocates][transfer none] |
value_name_len |
Pointer to a location to store the length
of |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_get_data (GWin32RegistryValueIter *iter
,gboolean auto_expand
,gpointer *value_data
,gsize *value_data_size
,GError **error
);
Stores the data of the value currently being iterated over in value_data
,
and its length - in value_data_len
(if not NULL
).
iter |
[in][transfer none] | |
auto_expand |
|
[in] |
value_data |
Pointer to a location to store the data of the value (in UTF-8, if it's a string). |
[out callee-allocates][optional][transfer none] |
value_data_size |
Pointer to a location to store the length
of |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_value_iter_get_data_w (GWin32RegistryValueIter *iter
,gboolean auto_expand
,gpointer *value_data
,gsize *value_data_size
,GError **error
);
Stores the data of the value currently being iterated over in value_data
,
and its length - in value_data_len
(if not NULL
).
iter |
[in][transfer none] | |
auto_expand |
|
[in] |
value_data |
Pointer to a location to store the data of the value (in UTF-16, if it's a string). |
[out callee-allocates][optional][transfer none] |
value_data_size |
Pointer to a location to store the size
of |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_key_get_value (GWin32RegistryKey *key
,gboolean auto_expand
,const gchar *value_name
,GWin32RegistryValueType *value_type
,gpointer *value_data
,gsize *value_data_size
,GError **error
);
Get data from a value of a key. String data is guaranteed to be appropriately terminated and will be in UTF-8.
key |
[in][transfer none] | |
auto_expand |
(in) |
|
value_name |
name of the value to get (in UTF-8). Empty string means the '(Default)' value. |
[in][transfer none] |
value_type |
type of the value retrieved. |
[out][optional] |
value_data |
contents of the value. |
[out callee-allocates][optional] |
value_data_size |
size of the buffer pointed
by |
[out][optional] |
error |
[nullable] |
Since: 2.46
gboolean g_win32_registry_key_get_value_w (GWin32RegistryKey *key
,gboolean auto_expand
,const gunichar2 *value_name
,GWin32RegistryValueType *value_type
,gpointer *value_data
,gsize *value_data_size
,GError **error
);
Get data from a value of a key.
Get data from a value of a key. String data is guaranteed to be appropriately terminated and will be in UTF-16.
When calling with value_data == NULL (to get data size without getting the data itself) remember that returned size corresponds to possibly unterminated string data (if value is some kind of string), because termination cannot be checked and fixed unless the data is retreived too.
key |
[in][transfer none] | |
auto_expand |
(in) |
|
value_name |
name of the value to get (in UTF-16). Empty string means the '(Default)' value. |
[in][transfer none] |
value_type |
type of the value retrieved. |
[out][optional] |
value_data |
contents of the value. |
[out callee-allocates][optional] |
value_data_size |
size of the buffer pointed
by |
[out][optional] |
error |
[nullable] |
Since: 2.46
const gchar *
g_win32_registry_key_get_path (GWin32RegistryKey *key
);
Get full path to the key
a full path to the key (in UTF-8),
or NULL
if it can't be converted to UTF-8.
[transfer none]
Since: 2.46
const gunichar2 *
g_win32_registry_key_get_path_w (GWin32RegistryKey *key
);
Get full path to the key
Since: 2.46
void (*GWin32RegistryKeyWatchCallbackFunc) (GWin32RegistryKey *key
,gpointer user_data
);
The type of the callback passed to g_win32_registry_key_watch()
.
The callback is invoked after a change matching the watch flags and arguments occurs. If the children of the key were watched also, there is no way to know which one of them triggered the callback.
key |
A GWin32RegistryKey that was watched. |
|
user_data |
The |
Since: 2.42
gboolean g_win32_registry_key_watch (GWin32RegistryKey *key
,gboolean watch_children
,GWin32RegistryKeyWatcherFlags watch_flags
,GWin32RegistryKeyWatchCallbackFunc callback
,gpointer user_data
,GError **error
);
Puts key
under a watch.
When the key changes, an APC will be queued in the current thread. The APC
will run when the current thread enters alertable state (GLib main loop
should do that; if you are not using it, see MSDN documentation for W32API
calls that put thread into alertable state). When it runs, it will
atomically switch an indicator in the key
. If a callback was specified,
it is invoked at that point. Subsequent calls to
g_win32_registry_key_has_changed()
will return TRUE
, and the callback (if
it was specified) will not be invoked anymore.
Calling g_win32_registry_key_erase_change_indicator()
will reset the indicator,
and g_win32_registry_key_has_changed()
will start returning FALSE
.
To resume the watch, call g_win32_registry_key_watch_for_changes()
again.
Calling g_win32_registry_key_watch_for_changes()
for a key that is already
being watched is allowed and affects nothing.
The fact that the key is being watched will be used internally to update key path (if it changes).
key |
[in][transfer none] | |
watch_children |
(in) |
|
watch_flags |
specifies the types of changes to watch for. |
[in] |
callback |
a function to invoke when a change occurs. |
[in][nullable] |
user_data |
a pointer to pass to |
[in][nullable] |
error |
[nullable] |
Since: 2.46
gboolean
g_win32_registry_key_has_changed (GWin32RegistryKey *key
);
Check the key
's status indicator.
TRUE
if the key
was put under watch at some point and has changed
since then, FALSE
if it either wasn't changed or wasn't watched at all.
Since: 2.46
void
g_win32_registry_key_erase_change_indicator
(GWin32RegistryKey *key
);
Erases change indicator of the key
.
Subsequent calls to g_win32_registry_key_has_changed()
will return FALSE
until the key is put on watch again by calling
g_win32_registry_key_watch()
again.
Since: 2.46