Ben,
Thanks for the three functions. These are the same as I used to use back in
the VB 6 days.
I wanted to write in a Win32 application with a dialog box
If someone asked this question for VB.NET then I would code them a complete
reply. In this case a re-usable function like so:
Private Sub RemoveSomeValue(ByVal sValue As String)
Dim strKey As String = "Software\MyKey"
Dim reg As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey,
True)
Try
reg.SetValue(sValue, "*")
reg.Close()
reg = Nothing
Catch ex As Exception
End Try
End Sub
I wouldn't say look at 'RegistryKey'. How lame is that & what help is it to
the OP? No help because they probably knew that much already
======================================
I got a registry class from The Code Project, stripped out all the functions
I didn't need & are left with the one function I want. However, I add the
header to the MFC form & when I try to call the function in that class I get
a compiler error (C2352 Illegal Call To Non Static Member). God knows what
it means. Checked MSDN
(
http://msdn2.microsoft.com/en-us/library/2x426hte(vs.71).aspx) & all it
says is to comment it out. What use is that?
So, if you got a total newbie asking the same question as I did & you get a
useless answer like Brian wrote then its absolutely no use whatsoever, is
it? No. Why? Because they don't have a clue to begin with & what I've found
on these programming newsgroups is that if someone answers the thread others
see that its been answered & leave the post alone. Thefore if you get a
useless, no help whatsoever, ridiculous reply like I got originally by Brian
then you have to ask the question again & again & again until it does get
answered correctly.
For C++ I used to ask questions on the GotDotNet website, but its now
closed. Used to get good results... & detailed answers too.
There are so, so, so many MVP's who give out rubbish in order to get another
post listed. Does MVP status mean you can use Google & you cannot write
code? It seems that way to me from what I have seen by using these
newsgroups for a number of years.
So, Ben. Can you see now why I answered Brian like I did?
Header file (RegisterEx.h):
#pragma once
#include "stdafx.h"
class CRegisterEx
{
public:
CRegisterEx(CString path);
~CRegisterEx(void);
public:
void WriteString(CString str, CString subPath = "", CString Key = "");
};
CPP Filr (RegisterEx.cpp)
#include "StdAfx.h"
#include "registerex.h"
#include <stdlib.h>
#pragma warning ( disable : 4267 )
#define MAX_BUFFER 2048
char buffer[MAX_BUFFER];
CString pt;
CRegisterEx::CRegisterEx(CString path)
{
pt = path;
}
CRegisterEx::~CRegisterEx(void)
{
}
// Writing strings to the register.
void CRegisterEx::WriteString(CString str, CString subPath, CString Key)
{
HKEY hk;
TCHAR szBuf[2048];
CString insidePath = pt;
if (Key)
{
insidePath = insidePath + "\\" + subPath;
}
if (RegCreateKey(HKEY_CURRENT_USER, _T(insidePath), &hk))
{
// Woops, you don't have privileges
TRACE0("Could not create the registry key.\n\nDo you have the right
privileges?\n");
}
strcpy(szBuf, str);
if (RegSetValueEx(hk, _T(Key), 0, REG_EXPAND_SZ, (LPBYTE)szBuf, strlen(str)
+ 1))
{
// Hmm, you did something wrong
TRACE0("Could not set the given String.\n\nDo you have the right
privileges?\n");
}
RegCloseKey(hk);
}
--
Newbie Coder
(It's just a name)
Ben Voigt said:
Newbie Coder said:
Answer below. But first I address your statements.
But yours is worse. Someone took the time to try to help you. If you were
paying for the assistance you would have a reason to complain.
If someone asked me how to do it in another language then I'd be the first
one to write the function & paste the code to the user, but that's the
difference between you & I.
There are many so-called MVP who cannot write a line of code if their life
depended on it. Herfried is a perfect example of that.
Asking you to rewrite your project with a different toolkit is not really
much different from demanding that someone else learn the MFC you've chosen.
Except that it's your problem, and anyone helping you is on a volunteer
basis.
Back to my original question:
If I search The Code Project I get many, many classes, but I need one
function. Plus, I am starting out back into C++ since I stopped coding in
it
around 2001/2002.
No, you need three functions:
RegOpenKeyEx
RegSetValueEx
RegCloseKey
All provided by windows itself, with no extra runtime library dependencies.
MFC should already be including windows.h for you, just make sure you link
with Advapi32.lib.