473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Registry Access (Write Access)

MFC Application VC++.NET 2003

I have a certain registry key (HKCU\Software\MyKey) that contains between 30
& 64 string values

I need to write a '*' to all those 30 - 64 string values under that
particular key.

Example:

HKCU\Software\MyKey

Key name Value

MyKey1 http://www.somesite.com
MyKey2 http://www.someothersite.com

Becomes:

MyKey1 *
MyKey2 *
....

Any ideas?

Have searched The Code Project & cannot make head not tail of these classes
as I am just starting back into C++ after many years

TIA
Apr 3 '07 #1
20 3758
CRegKey is your friend.

http://msdn2.microsoft.com/en-us/lib...y4(VS.80).aspx

Brian

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uW*************@TK2MSFTNGP06.phx.gbl...
MFC Application VC++.NET 2003

I have a certain registry key (HKCU\Software\MyKey) that contains between
30
& 64 string values

I need to write a '*' to all those 30 - 64 string values under that
particular key.

Example:

HKCU\Software\MyKey

Key name Value

MyKey1 http://www.somesite.com
MyKey2 http://www.someothersite.com

Becomes:

MyKey1 *
MyKey2 *
...

Any ideas?

Have searched The Code Project & cannot make head not tail of these
classes
as I am just starting back into C++ after many years

TIA


Apr 3 '07 #2
Bian,

First of all thank you for your reply

The page says Framework 2 specific. I don't want to use the framework
whatsoever

Any other suggestions?

"Brian Muth" <bm***@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
CRegKey is your friend.

http://msdn2.microsoft.com/en-us/lib...y4(VS.80).aspx

Brian

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uW*************@TK2MSFTNGP06.phx.gbl...
MFC Application VC++.NET 2003

I have a certain registry key (HKCU\Software\MyKey) that contains
between
30
& 64 string values

I need to write a '*' to all those 30 - 64 string values under that
particular key.

Example:

HKCU\Software\MyKey

Key name Value

MyKey1 http://www.somesite.com
MyKey2 http://www.someothersite.com

Becomes:

MyKey1 *
MyKey2 *
...

Any ideas?

Have searched The Code Project & cannot make head not tail of these
classes
as I am just starting back into C++ after many years

TIA


Apr 3 '07 #3

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eM**************@TK2MSFTNGP02.phx.gbl...
Bian,

First of all thank you for your reply

The page says Framework 2 specific. I don't want to use the framework
whatsoever

Any other suggestions?
Using Visual Studio .NET 2003, create the C++ project of your choice, taking
care to check the "support for ATL" checkbox. You can use CRegKey just fine.
It does not depend on .NET Framework 1.1. or 2.0.

Brian.
Apr 4 '07 #4
Brian,

In my original post it said MFC application

Why should I re-write many thousand lines of code in order to your
suggestion?

I was hoping that someone would write me a function in order to do this

How did you gain your MVP status?

In my original question I asked for MFC C++.NET 2003 app & you gave me a
link to 2005 (Framework 2) when I am using 1.1
Now, you ask me to totally change my project just so your link works - you
are joking of course.

Sorry, but your replies aren't useful at all!!

--
Newbie Coder
(It's just a name)

"Brian Muth" <bm***@mvps.orgwrote in message
news:e2**************@TK2MSFTNGP03.phx.gbl...
>
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eM**************@TK2MSFTNGP02.phx.gbl...
Bian,

First of all thank you for your reply

The page says Framework 2 specific. I don't want to use the framework
whatsoever

Any other suggestions?

Using Visual Studio .NET 2003, create the C++ project of your choice,
taking
care to check the "support for ATL" checkbox. You can use CRegKey just
fine.
It does not depend on .NET Framework 1.1. or 2.0.

Brian.


Apr 4 '07 #5
Newbie Coder wrote:
Brian,

In my original post it said MFC application

Why should I re-write many thousand lines of code in order to your
suggestion?

I was hoping that someone would write me a function in order to do this

How did you gain your MVP status?

In my original question I asked for MFC C++.NET 2003 app & you gave me a
link to 2005 (Framework 2) when I am using 1.1
Now, you ask me to totally change my project just so your link works - you
are joking of course.

Sorry, but your replies aren't useful at all!!
Newbie:

What is your problem? Brian told you about CRegKey. You have VS2003.
Look it up in the help. It's there. It's in VC6 also.

David Wilkinson
Apr 4 '07 #6
David,

You have an attitude

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.

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.

--
Newbie Coder
(It's just a name)
"David Wilkinson" <no******@effisols.comwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
Newbie Coder wrote:
Brian,

In my original post it said MFC application

Why should I re-write many thousand lines of code in order to your
suggestion?

I was hoping that someone would write me a function in order to do this

How did you gain your MVP status?

In my original question I asked for MFC C++.NET 2003 app & you gave me a
link to 2005 (Framework 2) when I am using 1.1
Now, you ask me to totally change my project just so your link works -
you
are joking of course.

Sorry, but your replies aren't useful at all!!

Newbie:

What is your problem? Brian told you about CRegKey. You have VS2003.
Look it up in the help. It's there. It's in VC6 also.

David Wilkinson


Apr 4 '07 #7
>
In my original post it said MFC application
My solution applies to MFC applications.
>
Why should I re-write many thousand lines of code in order to your
suggestion?
Why do you believe you need to rewrite any code at all?
>
I was hoping that someone would write me a function in order to do this

How did you gain your MVP status?

In my original question I asked for MFC C++.NET 2003 app & you gave me a
link to 2005 (Framework 2) when I am using 1.1
On the reference I gave you, there is a link to the Microsoft Visual Studio
2003/.NET Framework 1.1 version of the document. So save you from the extra
effort on clicking on that link, here it is for you:

http://msdn2.microsoft.com/en-us/lib...y4(vs.71).aspx

You will find that the information is the same for both environments.

The information on this page is valuable and gives clear instructions on how
to use CRegKey. If you don't want to experiment with the fresh solution I
suggested in my previous post, go directly to your MFC project and insert

#include "atlbase.h"

at the top of your code after any other #include statements. You can now use
CRegKey to your heart's delight.
Now, you ask me to totally change my project just so your link works - you
are joking of course.
The changes to your code are minimal and trivial.
Sorry, but your replies aren't useful at all!!
Then please re-post your questions if you are confused. What has not been
answered?.

Brian

Apr 4 '07 #8

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
David,
Answer below. But first I address your statements.
>
You have an attitude
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.
>
--
Newbie Coder
(It's just a name)

Apr 5 '07 #9
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/lib...te(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" <rb*@nospam.nospamwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
>
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
David,

Answer below. But first I address your statements.

You have an attitude

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.

--
Newbie Coder
(It's just a name)


Apr 5 '07 #10

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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
Plenty of help. It tells you what to look for on MSDN, which has lots of
examples
http://msdn2.microsoft.com/en-us/lib...gistrykey.aspx
If you can't understand the example on MSDN, you should say that, not that
you want to do this and don't know where to start.

Here is the documentation for RegSetValueEx:
http://msdn2.microsoft.com/en-us/library/ms724923.aspx

On that page you will find a section called "Example Code" with a link.
That link is a complete example including error handling. Were you not able
to find it?

Sure, saying look at RegistryKey.CurrentUser.OpenSubKey and
RegistryKey.SetValue would be better than just RegistryKey, but that is an
appropriate level of detail, since you can type that into your Visual Studio
help and get an answer.
>
======================================

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/lib...te(vs.71).aspx) & all it
says is to comment it out. What use is that?
Why don't you just use RegOpenKeyEx, RegSetValueEx, and RegCloseKey like I
suggested? They work perfectly well and come with good documentation,
unlike some functions in Windows.
>
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
I don't agree with Brian's answer, because it's an ATL-specific solution
when a very good generic Win32 API exists. But you have been quite
insulting to everyone.
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?
No. I cannot understand why you lash out at people who try to help you, and
except that it will make others willing to help.

The correct thing to reply to Brian would have been:

"Thanks for your suggestion, but my project doesn't use ATL. I'm looking
for a Win32/MFC solution."
>
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);

}

The code you provided looks perfectly ok, except for warning disable pragma,
fixed buffer sizes, magic numbers, and plenty of other code smell. However,
I suspect that you tried to call it like this:

CRegisterEx::WriteString(....);

It's not a static member function, so you can't call it without an instance.
Since you claim to know .NET, you should already know what that means and
how to fix it. A little humility would be very much in order the next time
you ask a question, after all, you are the one who can't figure it out
without help.
Apr 5 '07 #11
>
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
The equivalent C++ code is:

#include "stdafx.h"
#include "stdio.h"
#include "atlbase.h"

void RemoveSomeValue (_TCHAR *sValue)
{
CRegKey r;

LONG lRes = r.Open (HKEY_CURRENT_USER, _T("SOFTWARE\\MyKey"), KEY_READ |
KEY_WRITE);
if (lRes != ERROR_SUCCESS)
{
// error handling here
_tprintf_s (_T("Error %d can be found in WinError.h"), lRes);
return;
}

lRes = r.SetStringValue (sValue, _T("*"));
if (lRes != ERROR_SUCCESS)
{
// error handling here
_tprintf_s (_T("Error %d can be found in WinError.h"), lRes);
return;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
RemoveSomeValue (_T("MySpecialKey"));
return 0;
}

Brian


Apr 5 '07 #12
I don't agree with Brian's answer, because it's an ATL-specific solution
when a very good generic Win32 API exists.
This is directed more at Newbie Coder than Ben:

Although the CRegKey class is defined in atlbase.h, there is really nothing
ATL-specific about it. It's basically just a thin wrapper around the Win32
API's you are struggling with. Feel free to bypass and go directly to
RegOpenKeyEx, RegSetKeyValue, and sibling Win32 API calls if you prefer.

Part of the purpose of classes in C++ is to provide a cleaner more
object-oriented approach to access OS services. It's my personal preference
to use such classes when they are available. Since the source code comes
with CRegKey, one can even single-step into the code to see what is
happening under the hood. In the full program that I posted, I suggest you
try that out with the debugger. The exercise will pay off in dividends in
future projects.
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/lib...te(vs.71).aspx) & all it
says is to comment it out. What use is that?
I'd venture to say that the MSDN Library is a superb resource and is getting
better all the time. Because I'm familiar with C++ I can instantly recognize
the issue when looking at that reference. Your problem is your unfamiliarity
with the C++ language. Instead of blaming me and other MVP's for weak
replies, buckle down and learn the language. Get a good C++ reference book.
And feel free to post lots of questions. Remember, questions without the
vitriol will deliver better responses.

Brian

Apr 5 '07 #13
>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/lib...te(vs.71).aspx) & all it
says is to comment it out. What use is that?
By the way, the line that is commented shows the correct implementation. The
intention is for you to uncomment the:

// MyClass::MyFunc2();

and comment the

MyClass::MyFunc(); // C2352

to see how to correct the error.

Brian
Apr 6 '07 #14
Brian,

I have been away from C++ for 5-6 years concentrating more on VB.NET.
Getting bored with it so I decided to change back & prefer not to write .NET
Framework managed applications but application that don't need it because so
many people I help around the world don't have the .NET Framework installed
& why get them to download a 23.1 MB file just so they can run a few apps
that I have created for them?

My call which produced the compiler error was a call I wanted in that
specific class to delete the value in that registry key & the MSDN document
I sent the link about said to comment it out. So, if I comment the call out
that calls that function then it won't work. What is my way around it? How
do I call that function in CRegisterEx when I am in the cpp dialog of the
main app.. In VB.NET:

Dim regSetValue As New RegisterEx
regSetValue.SetValue("", "", "")

--
Newbie Coder
(It's just a name)
"Brian Muth" <bm***@mvps.orgwrote in message
news:ej****************@TK2MSFTNGP02.phx.gbl...
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/lib...te(vs.71).aspx) & all
it
says is to comment it out. What use is that?

By the way, the line that is commented shows the correct implementation.
The
intention is for you to uncomment the:

// MyClass::MyFunc2();

and comment the

MyClass::MyFunc(); // C2352

to see how to correct the error.

Brian


Apr 6 '07 #15
Brian,

Thank you for the code, but how do I call it from a MFC form on a button
click (btnRemove) when the code is in another header/cpp file?

I inclucde the line in the MFC form:

#include "RegisterEx.h"

But the function is still invisible

===========================

I have ordered a C++ MSPRESS book & have an old C++.NET Managed Extension
one here, but I want to write most apps without needing the .NET Framework
because no everyone has them.

--
Newbie Coder
(It's just a name)

"Brian Muth" <bm***@mvps.orgwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...

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

The equivalent C++ code is:

#include "stdafx.h"
#include "stdio.h"
#include "atlbase.h"

void RemoveSomeValue (_TCHAR *sValue)
{
CRegKey r;

LONG lRes = r.Open (HKEY_CURRENT_USER, _T("SOFTWARE\\MyKey"), KEY_READ
|
KEY_WRITE);
if (lRes != ERROR_SUCCESS)
{
// error handling here
_tprintf_s (_T("Error %d can be found in WinError.h"), lRes);
return;
}

lRes = r.SetStringValue (sValue, _T("*"));
if (lRes != ERROR_SUCCESS)
{
// error handling here
_tprintf_s (_T("Error %d can be found in WinError.h"), lRes);
return;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
RemoveSomeValue (_T("MySpecialKey"));
return 0;
}

Brian


Apr 6 '07 #16
Newbie Coder wrote:
Brian,

Thank you for the code, but how do I call it from a MFC form on a button
click (btnRemove) when the code is in another header/cpp file?

I inclucde the line in the MFC form:

#include "RegisterEx.h"

But the function is still invisible
Newbie:

Invisible? Won't compile? Won't link?
What is in "RegisterEx.h" ?

Problems of this kind have nothing to do with MFC, ATL, or Windows
programming, but rather with the basic C/C++ compilation model.

David Wilkinson
Apr 6 '07 #17
David,

The headers & the cpp files are in a previous post of mine in this thread

--
Newbie Coder
(It's just a name)

"David Wilkinson" <no******@effisols.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
Newbie Coder wrote:
Brian,

Thank you for the code, but how do I call it from a MFC form on a button
click (btnRemove) when the code is in another header/cpp file?

I inclucde the line in the MFC form:

#include "RegisterEx.h"

But the function is still invisible

Newbie:

Invisible? Won't compile? Won't link?
What is in "RegisterEx.h" ?

Problems of this kind have nothing to do with MFC, ATL, or Windows
programming, but rather with the basic C/C++ compilation model.

David Wilkinson

Apr 7 '07 #18

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uH*************@TK2MSFTNGP04.phx.gbl...
Brian,

Thank you for the code, but how do I call it from a MFC form on a button
click (btnRemove) when the code is in another header/cpp file?
You need to insert a "function prototype" somewhere in either your source
code or header file. In this case, it would be:

void RemoveSomeValue (_TCHAR *sValue);

A function prototype basically looks like the function definition but
without the body. Some programmers add the "extern" modifier to clear
indicate that this has scope outside the translation unit, as in:

extern void RemoveSomeValue (_TCHAR *sValue);

http://msdn2.microsoft.com/en-us/library/061kwye0.aspx

The link above describes a variable with the extern modifer, but it can be
applied to a subroutine as well.

HTH

Brian

Apr 8 '07 #19
Brian,

The function prototype is already defined in the RegisterEx.h file which if
you see a few of my posts back the full header/cpp files I am using

I just want to be able to use that class in my MFC application like I wrote
before in VB.NET:

Dim clsReg As New RegisterEx
clsReg.SetSomeValue("bla", "bla", "bla")

Cheers,

--
Newbie Coder
(It's just a name)

"Brian Muth" <bm***@mvps.orgwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
>
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:uH*************@TK2MSFTNGP04.phx.gbl...
Brian,

Thank you for the code, but how do I call it from a MFC form on a button
click (btnRemove) when the code is in another header/cpp file?

You need to insert a "function prototype" somewhere in either your source
code or header file. In this case, it would be:

void RemoveSomeValue (_TCHAR *sValue);

A function prototype basically looks like the function definition but
without the body. Some programmers add the "extern" modifier to clear
indicate that this has scope outside the translation unit, as in:

extern void RemoveSomeValue (_TCHAR *sValue);

http://msdn2.microsoft.com/en-us/library/061kwye0.aspx

The link above describes a variable with the extern modifer, but it can be
applied to a subroutine as well.

HTH

Brian

Apr 9 '07 #20

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:OY**************@TK2MSFTNGP06.phx.gbl...
Brian,

The function prototype is already defined in the RegisterEx.h file which
if
you see a few of my posts back the full header/cpp files I am using

I just want to be able to use that class in my MFC application like I
wrote
before in VB.NET:

Dim clsReg As New RegisterEx
clsReg.SetSomeValue("bla", "bla", "bla")

Cheers,

--
Newbie Coder
(It's just a name)
I might be getting lost here. If your class is defined as:

class CRegisterEx
{
public:
CRegisterEx(CString path);
~CRegisterEx(void);

void WriteString(CString str, CString subPath = "", CString Key = "");
};

Simply add the new function as a member function of the class, as in:

class CRegisterEx
{
public:
CRegisterEx(CString path);
~CRegisterEx(void);

void WriteString(CString str, CString subPath = "", CString Key = "");
void RemoveSomeValue (_TCHAR *sValue);
};

The client code calling this function might look like:

CRegisterEx r ("F:\Mypath");
r.RemoveSomeValue (_T("MyKey"));

Brian

Apr 9 '07 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim Blizard | last post by:
I know this topic has been discussed before but I couldn't find any thread more recent than about 18 months and was interested in what conclusions people had come to recently. Invariably 3...
2
by: Dan Sikorsky | last post by:
Should application data be read and written to the Registry to persist state, or should the App.config file be used? If the Registry should be used, what .NET class reads and writes the...
7
by: Dennis C. Drumm | last post by:
Can my program access the HKEY_LOCAL_MACHINE/Software section of the registry when being used by a user with restricted rights (not with admin rights)? If so, how? I have a program that...
3
by: Martin | last post by:
Hi I am attempting to write a small application that will allow users to manage the AddressBar entries within Internet Explorer. The typed URLs in the AddressBar can be found at...
1
by: Yoshitha | last post by:
Hi I am developing web application through which i've to write and read the values from the registry. When i set impersonate property to "false" it is displaying exception " Requested Registry...
8
by: Al Kaufman | last post by:
I have a simple console app that uses: regSubKey = <some registry key> Dim reg As RegistryKey = Registry.ClassesRoot.OpenSubKey(regSubKey) Dim path As String path = CStr(reg.GetValue(""))
3
by: Nikolay Petrov | last post by:
Why I always get 'Requested registry access is not allowed' when i try to Read/Write to Windows Registry from ASP service. I use ASP NET account? Also granted full permissions to required Registry...
3
by: Dylan Parry | last post by:
Hi folks, I've just got a new machine at work, so I've spent all day copying across all of my work from my old machine. Now I've come across a problem that I've never seen before. I now get...
4
by: Colin Priest | last post by:
I am trying to write a program to switch off serial port enumerations via the associated registry key. My code is: RegistryPermission permission = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.