RegSetValueEx and REG_MULTI_SZ

This is a discussion on RegSetValueEx and REG_MULTI_SZ within the Windows Programming forums, part of the Platform Specific Boards category; Im using RegSetValueEx to write to the registry. Everything works great, but i have a problem when writing to a ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    12

    RegSetValueEx and REG_MULTI_SZ

    Im using RegSetValueEx to write to the registry. Everything works great, but i have a problem when writing to a REG_MULTI_SZ.

    If you are familiar with how a REG_MULTI_SZ works, the value should be like this:
    Code:
    value1
    value2
    value3
    My question is: How can I seperate the values?
    Now i get:
    Code:
    value1 value2 value3
    And this aint working.

    Please explain this to me or post some example code

    Iw searched this forum and google, without getting any smarter.

    I dont have my code here atm(im at work) but if its needed i can post it later.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Each value is terminated with a nul character and the last value is followed by two nul characters. This is explained under registry value types.
    Code:
    TEXT("value1\0value2\0value3\0")
    In this example, we are using a string literal which automatically appends one nul character.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    12
    thank you. That url helped me
    When calculating the length of a REG_MULTI_SZ string, add the length of each of the component strings, as above, and add one for the final terminating null.
    that was my problem.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Writing REG_MULTI_SZ values

    I am trying to write an array of strings into the registry and I tried the method that MSDN advises.

    My registry entry is "security code"
    Ex. I had a hard-coded string for testing purposes "111\0222\0333\0444\0\0"
    So technically the registry should have

    111
    222
    333
    444

    But, I checked and the REG_MULTI_SZ type string entry it only has 111.
    What am I doing wrong here?

    Is there some special method that you used to get it working. You mention that the MSDN webpage helped you, I read the same thing and I can't think of anything I am missing.

    Kindly advise.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    Better to start a new thread then necro a 4 year old one...

    Did you use strlen() or lstrlen() to calc the string length? (as it only counts to the first null terminator)

    Otherwise post some code.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Adding a string with multiple nulls

    I figured that out, as I was using strlen, it was terminating the count upto the first null.

    Now my main question is I have a CStringArray. Now I want each element of that array put in a C-style string that I can write to REG_MULTI_SZ value.
    So for ex. if my CStringArray contains 111, 222, 333, 444, 555, I should ideally have the null terminated string as "111\0222\0333\0444\0555\0\0" to be able to write it in type REG_MULTI_SZ.

    I cannot seem to be able to write multiple nulls into the same C Style string. Can anyone help?

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    For a small constant number of elements in the reg setting, something like...

    Code:
    CStringArray sRegArray;
    
    //fill array
    
    char szBuffer[MAX_PATH]={0};
    
    _snprintf(szBuffer, MAX_PATH-1, "%s\0%s\0%s\0\0", sRegArray[0], sRegArray[1], sRegArray[2]);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21