Solved

Registry String Array in CString how do I parse it?

Posted on 2000-03-09
1
392 Views
Last Modified: 2013-11-20
Hi out there,
as usually I've got a problem :)
I want to put a string array to the registry and read it back. For writing I use the function RegSetValueEx with parameter REG_MULTI_SZ.
The data that I pass to this function is created like this:

CString s;
s += _T("test");
s += _T("\n");
s += _T("string2");
s += _T("\n");

Now my first question ist the "\n" the correct separation character or should I use _T((char)0)); ?

Lets go on with reading.
The RegQueryValueEx function fills my CString but when I run IsEmpty() it always returns true. :(
Why?

Help

Tobias
0
Comment
Question by:SirSmokeALot
1 Comment
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 50 total points
ID: 2600383
the RegSetValueEx type is a double NULL terminated list adn will not be possible to make using a CString.

By double NULL terminated list I mean the following

"test\0string2\0\0"

so what you need to do is create a char array that is big enough for all you strings and the null seperators in this case it is strlen("test")+strlen("string2")+3 (1 for each NULL '\0')

then copy them into your buffer putting the nulls in he correct places.

to extract is a bit easier

use RegQueryValueEx(...) to determine the size of the string and create you receiving buffer and then call RegQueryValueEx(...) again.

you then have to parse your string (pseudo code)

to get test out (char *buffer)

char *p=buffer;
CString szTest=p;
p+=szTest.GetLength()+1; // the plus one is to step past the NULL
CString szSecondString=p;

etc repeat until there are no more strings left ie p==NULL;

Or alternatively you can get a registry handling class from http://www.codeguru.com/system/index.shtml
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now