Query on StorPortRegistryRead

Hi,
I am using StorPortRegistryRead from within my miniport driver to read
the data for a particular ValueName. I see that the behavior of API is
different from what is documented with regards to the return value. As per
the WDK,
“StorPortRegistryRead returns a Boolean value of TRUE if the data pointed to
by ValueName is successfully converted into ASCII and copied into the
buffer. This routine returns FALSE in the event of an error.”

In my case, I see that the API returns TRUE when the ValueName being read
does not exist in the registry with the data returned being 0xFFFFFFFF.

The following is a code snippet of how I am using the API:

**************
PUCHAR ptr;
PUCHAR key = “MyValueName”;
ULONG default_length = 0xA0;
ULONG retSize, val;

ptr = StorPortAllocateRegistryBuffer(devExt, &default_length);
if (ptr == NULL) {
return;
}
retSize = default_length;
do {
status = StorPortRegistryRead(devExt, key, 1, REG_BINARY, ptr, &retSize);
if (!status) {
if (ptr != NULL) {
StorPortFreeRegistryBuffer(devExt, ptr);
}
if (retSize == 0) {
return;
}
ptr = StorPortAllocateRegistryBuffer(devExt, &retSize);
if (ptr == NULL) {
return;
}
}
} while (!status);
val = *ptr;

if (ptr != NULL) {
StorPortFreeRegistryBuffer(devExt, ptr);
}
**************

If I set the value of retSize to zero before invoking the API, I see a
return value of FALSE when the key does not exist (which is the behavior I
expected in the first place). However, if the key exists, the API still
returns FALSE and retSize is set to zero on return.

Am I doing something wrong here? Or is this the expected behavior from the
API?

Also, in general, for APIs which return the required size (through an input
pointer) is it expected to set the value of the variable (which receives the
size) to zero before invoking the API?

Regards,
Girish.