Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading from and Writing to the Registry???

91 views
Skip to first unread message

PeteOlcott

unread,
Jun 28, 2007, 3:44:57 PM6/28/07
to
I need to save a few values to the registry so that my application can
easily reinitialize itself to the previously stored values. Does
anyone know about any C++ code that makes this very easy?

Scott McPhillips [MVP]

unread,
Jun 28, 2007, 3:57:43 PM6/28/07
to

In an MFC app: WriteProfileString, GetProfilestring
and WriteProfileInt, ...

--
Scott McPhillips [MVP VC++]

Hans-J. Ude

unread,
Jun 28, 2007, 5:22:24 PM6/28/07
to
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> schrieb:

To be exact CWinApp::WriteProfileString wich is different from the API
::WriteProfileString. Just to not confuse the OP.

Hans

Peter Olcott

unread,
Jun 28, 2007, 10:04:40 PM6/28/07
to

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in
message news:R8SdnUKV9IQmjxnb...@comcast.com...

Boy that sure worked great thanks. Do you know where this
data would be stored in the registry?


Tom Serface

unread,
Jun 29, 2007, 2:15:28 AM6/29/07
to
You should see something like this:

// Change the registry key under which our settings are stored.
SetRegistryKey(_T("MyCompany"));

In your InitInstance() routine in the main app .cpp file. This is used for
the main code (under HKCU\Software\MyCompany for example). This gets
appended with the name of the program so it will likely be something like
HKCU\Software\MyCompany\MyApp.

Tom

"Peter Olcott" <NoS...@SeeScreen.com> wrote in message
news:_MZgi.3036$uq2....@newsfe06.phx...

Peter Olcott

unread,
Jun 30, 2007, 9:43:22 AM6/30/07
to
"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:03439FD9-5581-46E6...@microsoft.com...

> You should see something like this:
>
> // Change the registry key under which our settings are
> stored.
> SetRegistryKey(_T("MyCompany"));
>
> In your InitInstance() routine in the main app .cpp file.
> This is used for the main code (under
> HKCU\Software\MyCompany for example). This gets appended
> with the name of the program so it will likely be
> something like HKCU\Software\MyCompany\MyApp.
>
> Tom

BOOL WriteProfileString( LPCTSTR lpszSection, LPCTSTR
lpszEntry, LPCTSTR lpszValue );
Under which registry key could this data be found:
WriteProfileString("MyCompany", "MyFieldName", "MyData");
???
I want to be able to find it using regedit.

David Wilkinson

unread,
Jun 30, 2007, 11:29:56 AM6/30/07
to
Peter Olcott wrote:

> BOOL WriteProfileString( LPCTSTR lpszSection, LPCTSTR
> lpszEntry, LPCTSTR lpszValue );
> Under which registry key could this data be found:
> WriteProfileString("MyCompany", "MyFieldName", "MyData");
> ???
> I want to be able to find it using regedit.

[In this wild land where both bottom and (regrettably) top posting are
tolerated, please try to trim unnecessary quoting.]

You are not doing it right. Do like this:

SetRegistryKey(_T("MyCompany"));

WriteProfileString("MySectionName", "MyFieldName", "MyData");

Then the entry will appear in

HKCU\Software\MyCompany\MyApp\MySectionName\MyFieldName

The MyApp is inserted automatically by MFC.

--
David Wilkinson
Visual C++ MVP

Tom Serface

unread,
Jun 30, 2007, 12:05:40 PM6/30/07
to
One way to find the location in the registry (if you are not sure) would be
to write something unique looking into the registry using your command then
just open RegEdit and do a Find on the string. Then you'll see the whole
path to where it is ending up and you an adjust your program using the MFC
functions to set the registry locations.

Tom

"Peter Olcott" <NoS...@SeeScreen.com> wrote in message

news:16thi.10191$oh3...@newsfe03.phx...

Joseph M. Newcomer

unread,
Jul 1, 2007, 12:30:24 AM7/1/07
to
See my Registry class on my MVP Tips site. I haven't wrriten any registry code in years;
if I need to manipulate the Reigstry, I use this library.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages