Solved

Registry String Array in CString how do I parse it?

Posted on 2000-03-09
1
416 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 46
sumNumber challenge 16 140
My project did see openJDK that I installed. What could be the problem 7 160
Sed question 2 121
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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