# RegReadString

int RegReadString (unsigned int rootKey, const char subkeyName[], const char valueName[], unsigned char stringBuffer[], unsigned int bufferSize, unsigned int *realStringSize);

## Purpose

This function reads a NUL–terminated ASCII string from the specified Key Value in the Windows Registry. You must specify a Root Key, a Subkey of that Root Key, and the actual Value of that Subkey which you want to read.

If you do not know the size of the string in the Registry, you may pass NULL for the stringBuffer parameter. The function will determine the size of the string and return it through realStringSize. You may then use this value to allocate appropriate space for the string, and call the function again.

Example:

unsigned char *buffer = NULL;
unsigned int size;
RegReadString (REGKEY_HKLM, "Software\\MySubKey", "MyStrValue",
NULL, 0, &size);
buffer = (unsigned char*) malloc(size * sizeof(unsigned char));
if (buffer != NULL) {

RegReadString (REGKEY_HKLM, "Software\\MySubKey",
"MyStrValue", buffer, size, &size);
// Use the data in buffer …
free (buffer);

}

## Parameters

Input
Name | Type | Description
rootKey | unsigned integer | The Root Key under which you wish to access a Subkey and its value. See the Windows Registry functions Class help for more information on Root Keys.
subkeyName | const char [] | The name of the Subkey (relative to the Root Key), from which you wish to read value data. See the Windows Registry functions Class help for more information on Subkeys.
valueName | const char [] | The name of the Value from which you want to read data. You may pass NULL or an empty string to read from to the Key's Default Value. See the Windows Registry functions Class help for more information on Key Values.
bufferSize | unsigned integer | The size of the buffer passed to stringBuffer. This parameter is ignored when you pass NULL in place of an actual buffer.
Output
Name | Type | Description
stringBuffer | unsigned char [] | Returns the ASCII NUL–terminated string contents of the specified Value of the specified Subkey. This buffer must be large enough to receive the entire string. If you are unsure of the size of the string, you may pass NULL. The realStringSize parameter will return the actual size of the string (including the ASCII NUL) in the Registry.
realStringSize | unsigned integer * | Returns the actual size of the ASCII string associated with the specified registry Key. You may pass NULL for the stringBuffer parameter and use this value to allocate adequate memory before calling this function again.

## Return Value

Name | Type | Description
status | integer | The status code that the function returns. 0 indicates success. A negative value indicates an error. This function may return a Programmer's Toolbox or UI Library error code. Call GetGeneralErrorString to obtain a text description of the error.