C++ Programming

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
Well, as I've now finished uni, I've decided to start up another project; a graphics engine built without existing libraries etc as I really want to get to grips more with the lower-level aspects of the language.

The thing is, I keep running into silly little problems and short of spamming this forum 24/7, I was wondering if anyone could recommend any free C++ programming forums. I say free because ones out there such as Experts-exchange are all well and good until you look at the price, heh :( That said, I suppose I could just spam up one thread on here...



For the time being however, has anyone come across accessing the registry before? I've got this code currently which accesses any registry point specified by the APPLICATIONREG definition; the only problem is that 'temp', the parameter which reads the value, can only seem to be four characters long, producing 'too many characters in constant' errors if you query it against a string value of 5 characters or more. For its current use it's not really a problem but in the interest of extensibility, this isn't the kind of limitation I'd want to impose on end-users.

HKEY hKey;
bool needToWrite = false;

if( ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER, APPLICATIONREG, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL ) )
{
DWORD dwType;
DWORD temp = NULL;
DWORD dwLength = sizeof(DWORD);

//Whether or not the program is fullscreen
RegQueryValueEx(hKey, TEXT("fullScreen"), 0, &dwType, (LPBYTE)temp, &dwLength);
//This works fine
if(temp == 'true'){}
//This doesn't...too many characters in constant
if(temp == 'false'){}

I'm available at kirennia@hotmail.com on MSN if anyone is interested in aiding with this venture as well by the way... It'd be a way to force me into keeping up my UML documentation if I had more people then just myself :)
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,046
must you use the registry? :(

I've no intel on that, unfortunately.
 

Gahn

Resident Freddy
Joined
Jan 16, 2004
Messages
5,056
Well, as I've now finished uni, I've decided to start up another project; a graphics engine built without existing libraries etc as I really want to get to grips more with the lower-level aspects of the language.

The thing is, I keep running into silly little problems and short of spamming this forum 24/7, I was wondering if anyone could recommend any free C++ programming forums. I say free because ones out there such as Experts-exchange are all well and good until you look at the price, heh :( That said, I suppose I could just spam up one thread on here...



For the time being however, has anyone come across accessing the registry before? I've got this code currently which accesses any registry point specified by the APPLICATIONREG definition; the only problem is that 'temp', the parameter which reads the value, can only seem to be four characters long, producing 'too many characters in constant' errors if you query it against a string value of 5 characters or more. For its current use it's not really a problem but in the interest of extensibility, this isn't the kind of limitation I'd want to impose on end-users.

HKEY hKey;
bool needToWrite = false;

if( ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER, APPLICATIONREG, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL ) )
{
DWORD dwType;
DWORD temp = NULL;
DWORD dwLength = sizeof(DWORD);

//Whether or not the program is fullscreen
RegQueryValueEx(hKey, TEXT("fullScreen"), 0, &dwType, (LPBYTE)temp, &dwLength);
//This works fine
if(temp == 'true'){}
//This doesn't...too many characters in constant
if(temp == 'false'){}

I'm available at kirennia@hotmail.com on MSN if anyone is interested in aiding with this venture as well by the way... It'd be a way to force me into keeping up my UML documentation if I had more people then just myself :)

Uhm got no grip on C++ tbh but you don't need to specify the size of variables and or constants?
Seems kinda unbeliavable that you can only fill 4 bits for a regkey ..

After some dig ... you might want to check against this 2 links also:

http://www.codeproject.com/KB/system/NtRegistry.aspx

http://www.codeguru.com/cpp/w-p/system/registry/article.php/c2843
 

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
must you use the registry? :(

I've no intel on that, unfortunately.

Ideally mate; it's the way most programs seem to function in retaining settings e.g. screen height, width, brightness etc etc. It also hides crucial program information from the user so they can't screw it up quite so easily ;)

Uhm got no grip on C++ tbh but you don't need to specify the size of variables and or constants?
Seems kinda unbeliavable that you can only fill 4 bits for a regkey ..

After some dig ... you might want to check against this 2 links also:

CodeProject: Registry Manipulation Using NT Native APIs. Free source code and programming help

CodeGuru: Registry manipulation class with exception handling

What's really confusing me with regards to the error is that it comes up before the program is run which leads me to believe that no matter what, I cannot directly compare a DWORD to a string value.

Looking through those examples, especially the one with the downlaodable code (thanks by the way :)), it seems as if the user has simplified some of the functions but still, the values supplied are similar to the ones I posted... maybe I should concentrate on doing the writer first rather then reading, then I'll have a little more to play about with :)
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,046
Ideally mate; it's the way most programs seem to function in retaining settings e.g. screen height, width, brightness etc etc. It also hides crucial program information from the user so they can't screw it up quite so easily ;)

I put it to you that a small ASCCI file (or even a binary file containing a serialized configuration object) is far nicer than using the registry. For one it instantly makes your application a bit more portable than it was before and writing to a file is rather easier than to the registry.
 

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
I put it to you that a small ASCCI file (or even a binary file containing a serialized configuration object) is far nicer than using the registry. For one it instantly makes your application a bit more portable than it was before and writing to a file is rather easier than to the registry.

The idea is that when saving to HKEY_CURRENT_USER, when different users are accessing the same application, they can maintain their own settings while profile details can remain unchanged if the app is created with that in mind. It also ensures that should the program folder be moved onto another machine or the system information be modified, it reverts to defaults to ensure that it isn't accessing things which it shouldn't be. e.g. resolutions supported on one machine but not another.

Of course, having a file in the directory can do it to a similar degree although the registry already has a framework in place for reading/writing efficiently without the need for additional #include files within the class. It's a preference thing really and something I'm wanting to learn as I go along :)
 

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
Well, I've figured out how to work some of it at least. Now all I need to be able to do is read and write integers into the REG_SZ values

int resolutionH = 600;
if(ERROR_SUCCESS == RegSetValueEx(hKey, TEXT("resolutionH"), NULL, REG_SZ, resolutionH, 4))

I can at least write something if I reference the memory address of resolutionH instead of the value but then of course it comes up with some weird and wonderful memory address rather then the value itself. This is getting mightily frustrating being that searching for an answer seems very difficult as they all just handle other value types e.g. const BYTE...
 

phlash

Fledgling Freddie
Joined
Dec 24, 2003
Messages
195
Have you read through the Registry section of the MSDN library?

Registry (Windows)

That should provide you with suitable details on how to read/write different types of data (strings, dwords).

As for the 'silly little problems' such as directly comparing different types (DWORD with char[] in your example) and wondering why it fails... it looks like you could do with a refresher on C/C++ variable types and operators - I found hundreds of tutorials online, such as: C++ Language Tutorial which appear to cover this area of the language... have a skim through and see what groks with you :)
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,046
You can use files located in the $USER_HOME$ (or whatever its called) directory to the same effect. I *really* dissaprove of the registry. It's a step backwards and a bad habit to get into. Keep it simple, dont rely on some nasty os specific store to keep your config for you.
 

Users who are viewing this thread

Top Bottom