🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #4877

Re: Registry Subkeys

#4877
From: Remy Lebeau (TeamB)
Date: Mon, 21 Nov 2005 18:45
44 lines
2267 bytes
"Richard Bradbrook" <dont@spamme.com> wrote in message
news:437f42a4@newsgroups.borland.com...

> if(Registry->OpenKey("Software\Company\Product\Key1", false))

Don't forget that you need to double up on backslashes:

    if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )

>   somestring = Registry->ReadString("somevalue");
>   Registry->WriteString("somevalue", somestring);

Also, do note that reading and writing to the same key can fail on NT-based
systems that have security turned on.  You should never open a key for
read/write access.  Open the key for read-only and write-only access
instead, ie:

    TRegistry *Registry = new TRegistry;
    try
    {
        Registry->RootKey = HKEY_CURRENT_USER;
        AnsiString somestring;

        Registry->Access = KEY_QUERY_VALUE;
        if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )
        {
            somestring = Registry->ReadString("somevalue");
            Registry->CloseKey();
        }

        Register->Access = KEY_SET_VALUE;
        if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )
        {
            Registry->WriteString("somevalue", somestring);
            Register->CloseKey();
        }
    }
    __finally {
        delete Registry;
    }


Gambit
Technical Details
Message-ID: <438215b3$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <437f284c$1@newsgroups.borland.com> <437f42a4@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e0d6234a30d9c63
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <437f284c$1@newsgroups.borland.com> <437f42a4@newsgroups.borland.com>
Subject: Re: Registry Subkeys
Date: Mon, 21 Nov 2005 10:45:51 -0800
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <438215b3$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1132598707 68.69.17.41 (21 Nov 2005 10:45:07 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail