[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1735
  • Last Modified:

how to use REG_MULTI_SZ data type in registry?

this should be any easy one for u.

i want to store valses in resistry like

value name:fruits
data:"apple banana orange"

i am trying to use REG_MULTI_SZ data type for the purpose,but instead of charcter data the ascii values of the data get saved in the registry, i want character data there, not ascii values.

this is very urgent so i am asking here

regds

a_saleem
0
a_saleem
Asked:
a_saleem
  • 5
  • 4
  • 4
  • +1
1 Solution
 
Kevin_ElrodCommented:
I've found that the registry functions can be tricky.  It may be that one of the parameters you've set is incorrect.  Could you display the function?
0
 
jhanceCommented:
>>i want character data there, not ascii values.

Could you please explain what you mean by this statement.  You seem to be contradicting yourself as in many cases "character data" is "ascii".

Note that a REG_MULTI_SZ is a collection of ONE OR MORE strings that are each NULL terminated and the END OF THE LIST is a double-NULL.  In C/C++ there is no direct support for this kind of string since C/C++ strings are terminated at the first NULL.  So you must build the buffer yourself.  If I have two strings, lpszA and lpszB:

char *lpszA = "This is string A";
char *lpszB = "This is string B";

I need a buffer that will hold both of these + one extra NULL.  So use a BYTE buffer:

DWORD dwSize = strlen(lpszA) + strlen(lpszB) + 1;
BYTE *cBuffer = new BYTE[dwSize];

I usually fill the buffer with NULLs to ensure that the last 2 bytes are NULL NULL:

memset(cBuffer, 0, dwSize);

Now we need to copy the data into the correct place:

memcpy(cBuffer, lpszA, strlen(lpszA) + 1);
memcpy(cBuffer + strlen(lpszA) + 1, lpszB, strlen(lpszB) + 1);

Now you have a REG_MULTI_SZ string that can be used by RegSetValueEx().

Don't forget to delete the buffer when you are done...

delete [] cBuffer;
0
 
a_saleemAuthor Commented:
i am fine with buffering stuff the problem is i want the regitry value to be

"abc"

and it is

61 62 63

the whole code works well with data type REG_SZ(yes with only one string) problem arises when REG_MULTI_SZ comes in



 
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jhanceCommented:
There is no difference.  You are being confused by RegEdit's inability to display REG_MULTI_SZ entries in textual form.

If you don't want this, use REGEDT32 or avoid the use of REG_MULTI_SZ.
0
 
a_saleemAuthor Commented:
but i have seen entries in correct form with REG_MULTI_SZ data type in regedit,

***and i now realize that these entries are not even ascii values, ascii of a is 97 but 61 is stored there at "a" place, but when i read from my program i am getting exactly what i am storing, that is "abc", ***strange***
0
 
jtwine100697Commented:
> DWORD dwSize = strlen(lpszA) + strlen(lpszB) + 1;

As an aside.  If the resulting buffer is to contain a total of three NULs, each of strlen(...) calls should have "+ 1" added to their return value, because strlen(...) does not count the terminating NUL in the value it returns.

    DWORD dwSize = ( ( ::strlen( lpszA ) + strlen( lpszB ) ) + 3 );

-=- James.
0
 
a_saleemAuthor Commented:
ooo expert

i am not following jhance for buffering, i am using CString for the purpose and it is doing fine, do some thing for registry storage, what is 61 doing at place of "a"
0
 
jhanceCommented:
The last time I checked, 0x61 = 'a'.
0
 
jhanceCommented:
>>DWORD dwSize = ( ( ::strlen( lpszA ) + strlen( lpszB ) ) + 3 );

Thanks....  Must be "brain fade"
0
 
jtwine100697Commented:
NP.  Long day here, too! :|

-=- James.
0
 
a_saleemAuthor Commented:
great work jhance, i will give points tommorow after testing the other apps, i mean what i am changing in the registry is  shared data, if other apps go fine with this hex stuff, every thing in the world will be again as beatifull as it was before this project:)

Regds

Saleem
0
 
jtwine100697Commented:
> i am not following jhance for buffering, i am using CString for the purpose and it is doing fine,

The CString object wraps "standard C-style" strings (which is what a REG_SZ string is).  That means, that it wraps a char/wchar_t buffer that looks like this:

   "This Is A String\0"  (where "\0" is the NUL terminator)

A string of registry data-type REG_MULTI_SZ looks like this:

   "This Is A String\0This Is Another String\0\0" (Anyone remember building the "file-type" list in the standard file dialogs? :)

Which is two (or possibly more) strings contained within a single buffer.  The CString object does *not* support this kind of string.  (Now, having said that, I am sure someone will bring up the ability to dick around with CString::GetBuffer(...) to get a multi-string buffer in there.  Yes you CAN do that, but that does not mean that it is CORRECT to do so.)

FWIW, if you want to store compound data in the registry, just build a SINGLE string to do it, and parse it upon reading it.  Change:

    value name:fruits
    data:"apple banana orange"

To:

   value name:fruits;data:"apple banana orange"

What would be the problem with that?

-=- James.
0
 
jtwine100697Commented:
Ahh, your comment came in while I was writing...  That *may* explain why you cannot use a simple string...

-=- James.
0
 
a_saleemAuthor Commented:
well on windows NT/2000 there is no hex stuff its only on win 98:)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now