473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Char* to registry, then retrieve it?

83 New Member
Hi, I have been doing some work involving the registry.
I can write and read numbers fine, but im stuck writing and reading strings.

I've been googling for a while, and found mostly references to vc.

So basicly, can someone explain to me how to write a char* to a registry key, and then retrieve it again, into char* form.
Dec 21 '08 #1
16 2334
JosAH
11,448 Recognized Expert MVP
Maybe this link helps?

kind regards,

Jos
Dec 21 '08 #2
Adam01
83 New Member
Ah, I was using regQueryValueEx, thanks for the link, I looked around and found:
"To ensure that any string values (REG_SZ, REG_MULTI_SZ, and REG_EXPAND_SZ) returned are null-terminated, use the RegGetValue function."

I had a go at using RegGetValue, but including windows.h, and winreg.h, the compiler says it has not been defined. Any ideas?
Dec 21 '08 #3
Li2Ti
9 New Member
@Adam01
RegGetValue is a relatively new function. You'll need to set _WIN32_WINNT to >= 0x600 in order to use it.
Dec 21 '08 #4
Adam01
83 New Member
Thanks, but still no luck...
Dec 21 '08 #5
Li2Ti
9 New Member
@Adam01
You are defining it before you include the Windows header, right?
Dec 21 '08 #6
Adam01
83 New Member
Yes, as well, the compiler says it is redefined.
Dec 21 '08 #7
Li2Ti
9 New Member
@Adam01
And what version of Windows are you compiling this under?
Dec 21 '08 #8
Adam01
83 New Member
Windows xp media center, with sp3.
Dec 21 '08 #9
Li2Ti
9 New Member
@Adam01
There's your problem. That function isn't supported on your OS.

Anyway, what's wrong with RegQueryValueEx? IIRC, it's been supported since Win2k.

Just be careful with string termination and you should be alright.
Dec 21 '08 #10
Adam01
83 New Member
I am using it with wxWidgets,
this is the current code...

Expand|Select|Wrap|Line Numbers
  1. DWORD StrSize = sizeof(char*);
  2. DWORD SZTHING = REG_SZ;
  3. char* tempusername;
  4. RegQueryValueEx(hKey, TEXT("UsernameValue"), NULL, &SZTHING, (BYTE*)&tempusername, &StrSize );
  5. ConnectSettings->Username = wxString(tempusername, wxConvUTF8);
  6. wxMessageBox( ConnectSettings->Username , _("Note"));
This would cause the program to crash.
Yes, I am not familiar to registry functions.
Dec 21 '08 #11
Li2Ti
9 New Member
@Adam01
Not surprising.

1. Don't ignore API return codes.
2. Look at where RegQueryValueEx is trying to write to.
3. MSDN is your friend.
Dec 21 '08 #12
Adam01
83 New Member
Thanks, I found out that it was the value, written by:

const char *Username = ConnectSettings->Username.mb_str();
RegSetValueEx (hKey, TEXT("UsernameValue"), 0L, REG_SZ,(CONST BYTE*) &Username, sizeof(REG_SZ));

Which writes incorrect value.

I'l have a look at the return codes.
Dec 21 '08 #13
Adam01
83 New Member
Both return success (0),
If I set the key to "hello", the program does not crash, but displays nothing.
Dec 21 '08 #14
Li2Ti
9 New Member
@Adam01
Re-read post No. 12.

Where do you think the RegQueryValueEx function is attempting to write to?

Also, there are countless examples of this sort of thing on the Internet.
Dec 21 '08 #15
Adam01
83 New Member
1. RegQueryValueEx is not writing, it is reading.

And I have now solved it, using TCHAR instead of char.
Dec 21 '08 #16
Li2Ti
9 New Member
@Adam01
It writes to the buffer that you pass. That's the whole point...
Dec 21 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8365
by: Omer Ahmad | last post by:
Hi All, I've been working with python for about 6 months now, and have been very impressed with the size and scope of the libraries. I have, however, run into a bit of a problem. I...
7
16486
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...
6
7561
by: mphanke | last post by:
Hi, how can I retrieve the icon for a registered file extension from the registry and show it in my ListView? Any hints appreciated, Martin
2
1641
by: ABC | last post by:
Which function can retrieve the registry string from HKEY_Current_User\Control Panel\International\sShortDate?
3
3037
by: Slimo | last post by:
Hello, I'm searching some example of code (VB) for reading remote registry subkeys and keys. Thanks
4
9075
by: Kevin L | last post by:
I store some application settings in the registry under HKEY_LOCAL_MACHINE\Software\MyApplication I want to allow full access to this key and subkeys. Currently, I manually change the...
0
3992
by: tmsprowl | last post by:
Greetings! I was wondering if someone could help me with a problem I'm having. My department is just one of many within my organization. My organization has control over the network domain,...
11
12730
by: hamishd | last post by:
Is this possible? Sorry if this question isn't relevant here. actually, I'm really trying to convert a unsigned char * to an int
1
1391
by: JLC | last post by:
Hi, I am trying to write a small windows application that you enter a domain\username and a key and hit enter. When you do this, the program will retrieve the password (which was encrypted, but...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
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...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.