Solved

Registry String Array in CString how do I parse it?

Posted on 2000-03-09
1
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
repeatEnd java challenge 42 85
child constructor and parent constructor, overriding and overloading 6 96
EvenOdd challenge 10 160
How to convert MFC::CString to UTF8 wchar_t* 10 467
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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