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.
16 2334 JosAH 11,448
Recognized Expert MVP
Maybe this link helps?
kind regards,
Jos
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?
@Adam01 RegGetValue is a relatively new function. You'll need to set _WIN32_WINNT to >= 0x600 in order to use it.
Thanks, but still no luck...
@Adam01
You are defining it before you include the Windows header, right?
Yes, as well, the compiler says it is redefined.
@Adam01
And what version of Windows are you compiling this under?
Windows xp media center, with sp3.
@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.
I am using it with wxWidgets,
this is the current code... - DWORD StrSize = sizeof(char*);
-
DWORD SZTHING = REG_SZ;
-
char* tempusername;
-
RegQueryValueEx(hKey, TEXT("UsernameValue"), NULL, &SZTHING, (BYTE*)&tempusername, &StrSize );
-
ConnectSettings->Username = wxString(tempusername, wxConvUTF8);
-
wxMessageBox( ConnectSettings->Username , _("Note"));
This would cause the program to crash.
Yes, I am not familiar to registry functions.
@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.
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.
Both return success (0),
If I set the key to "hello", the program does not crash, but displays nothing.
@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.
1. RegQueryValueEx is not writing, it is reading.
And I have now solved it, using TCHAR instead of char.
@Adam01
It writes to the buffer that you pass. That's the whole point...
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
by: ABC |
last post by:
Which function can retrieve the registry string from
HKEY_Current_User\Control Panel\International\sShortDate?
|
by: Slimo |
last post by:
Hello,
I'm searching some example of code (VB) for reading remote registry subkeys
and keys.
Thanks
| |
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...
|
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,...
|
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
|
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...
|
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,...
|
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: 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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |