Search code examples
windowsdelphiwinapiregistry

RegEnumValue returns different buffer size in Vista compatibility mode


I have a very weird issue when my application is run under "Windows Vista Compatibility mode" (right-click the EXE, enable compatibility mode and select windows vista).

The issue is the return buffer length value from the "RegEnumValue" function returns a different value.

For example, with a registry value of "Zoom Player MAX" (15 characters):

With compatibility mode diabled, RegEnumValue's "lpcbData" field return a value of 16 (including the trailing null termination).

With compatibility mode enabled, RegEnumValue's "lpcbData" field return a value of 15 (doesn't include the trailing null termination).

Is there a work-around/patch for this that doesn't require changing my string conversion code?


Solution

  • It should not matter. When reading from the Registry using low-level classic functions, you must be able to handle strings with and without null-terminators:

    Beware of non-null-terminated registry strings

    The easy way to do this is to secretly allocate one extra character that you don't tell the API about when reading, and then append the '\0' character to the end of however many characters it returns.

    Newer functions like RegGetValue() handle this for you.