A property's value may have any length. If the length of a property's value is not known, use RegistryPropertyGetSize to determine its size so you can allocate space for it.
OSStatus RegistryPropertyGetSize (
const RegEntryID *entryID,
const RegPropertyName *propertyName,
RegPropertyValueSize *propertySize);
RegistryPropertyGetSize returns in propertySize the length (in bytes) of the property named propertyName and associated with the name entry identified by entryID.
RegistryPropertyGetSize may be called from task level or secondary interrupt level.
noErr
|
0 | No error |
paramErr
|
-50 | Bad parameter |
nrInvalidNodeErr
|
-2538 | RegEntryID value not valid |
nrNotFoundErr
|
-2539 | Search failed to match criteria |
In Listing 10-9, RegistryPropertyGetSize and RegistryPropertyGet are used to obtain the value of a property.
Listing 10-9 Obtaining a property value
OSStatus GetDeviceProperty(
constRegEntryID *deviceEntry,
constRegPropertyName *propertyName,
RegPropertyValue propertyValue,
RegPropertyValueSize *propertySize
)
{
RegPropertyValueSize size;
OSStatus err = noErr;
/*
* Get the size of the value first to see if our buffer is big enough.
*/
err = RegistryPropertyGetSize(deviceEntry, propertyName, &size);
if (err == noErr) {
if (size > *propertySize)
return
kPropBufferTooSmall;
/*
* Note, we return the actual property size.
*/
err = RegistryPropertyGet(deviceEntry, propertyName, propertyValue,
propertySize);
}
return err;
}