Hey guys,
I'm new here and I'm pretty new to c++ too. I was searching on internet about registry and C++ but I couldn't find anything good. Everything was bad written and got lots of errors and there was nothing explained in there.
I'm trying to figure out how could I make a program which can read binary file registry and store it somewhere in program and show it.
Have you tried plain win32 API? I know is hard to get this to work for the first time, but i'm pretty sure you'll get a best result if you write your own code.
Check the MSDN (or the VS docs if you have them installed) for RegOpenKeyEx, this is your key to the windows registry and there are some samples on these docs. If you need further assistance, please reply.
To check whether you have MSDN installed or not, simply hit F1 from inside the VS IDE, the help system will popup, just go to the Index tab and write RegOpenKeyEx, if the entry is found within the index, then you have access to the MSDN (it may be online or local). That's all you need to get started with Win32 programming.
Now let me explain something about API: If you want to make cool apps that make use of windows-specific technologies (registry, directx, etc) you must learn Win32 API. That is just a bunch of functions that the OS provides to let developers interact with it.
So, when it comes to registry, you must use the OS routines to interact with him.
Please tell me if you want some example code, but first, please tell me how skilled you are in C++, Win32 API and if you are using MFC/ATL or just plain C++.
To check whether you have MSDN installed or not, simply hit F1 from inside the VS IDE, the help system will popup, just go to the Index tab and write RegOpenKeyEx, if the entry is found within the index, then you have access to the MSDN (it may be online or local). That's all you need to get started with Win32 programming.
Now let me explain something about API: If you want to make cool apps that make use of windows-specific technologies (registry, directx, etc) you must learn Win32 API. That is just a bunch of functions that the OS provides to let developers interact with it.
So, when it comes to registry, you must use the OS routines to interact with him.
Please tell me if you want some example code, but first, please tell me how skilled you are in C++, Win32 API and if you are using MFC/ATL or just plain C++.
Well i found this MSDN and I got lot of informations about RegOpenKeyEx, thanks for that.
Well it would be very nice if you could post some example code cause I learn it best from examples.
Im not skilled in C++, I started learning about a week ago and I've been throughout a lot of tutorials, I mean a LOT. I decided to skip a bit to the registry cause I got and idea to work something with it but all basic stuff doesen't have much in common.
And I'm not skilled in Win32 API, I don't know anything about it.
Also can you pelase tell me which header files should i load to get all this working?
As I said, I did but there was like 3 kinds of tutorials and every one had different code and everything was bad explained, they even got errors in their code...
Everytime you want to get something from windows, you should add <windows.h> as it automatically adds all the headers from the sdk folder (installed with the vc++ compiler).
For registry functions to get linked, you must add the Advapi32.lib library in project settings -> linker -> aditional dependencies or by using the #pragma comment directive:
Code:
#pragma comment(lib, "Advapi32.lib.")
The code posted is a good start, just check the documentation and you'll be ready to play with API, if you have more questions, post them :-)
Just an small example, this will retrieve your windows product name from the registry, should work with XP/Vista/7, just check how you must open the key and then read the value you want, i don't know if you're using Unicode, but this should compile without it.
Code:
BOOL bGetBinary = FALSE;
HKEY hKey = NULL;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), NULL, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
DWORD dwType = 0, dwBufferSize = 0;
if (!bGetBinary)
{
dwBufferSize = 260;
TCHAR tData[260];
if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&tData, &dwBufferSize) == ERROR_SUCCESS)
{
MessageBox(tData);
}
else
MessageBox(TEXT("Error!"));
}
else
{
dwBufferSize = 1024;
BYTE bBuffer[1024];
if (RegQueryValueEx(hKey, TEXT("ProductName"), NULL, &dwType, (LPBYTE)&bBuffer, &dwBufferSize) == ERROR_SUCCESS)
{
// Do what you want with the raw data here :-)
}
else
MessageBox(TEXT("Error!"));
}
}
Just paste it inside your main procedure and remember the #include <windows.h> and the #pragma comment(lib, "Advapi32.lib.") line before the include.
Windows has two ways of managing characters, the simple, common form (char type) and another, more 'advanced' that supports foreign-language symbols, that used TWO bytes per character.
Code:
LONG i = RegCreateKeyEx( HKEY_CURRENT_USER,"Folder name", 0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
Here you're using chars, but in order for the compiler to use the WCHAR type (wide-char) you must use a macro:
Code:
LONG i = RegCreateKeyEx( HKEY_CURRENT_USER,TEXT("Folder name"), 0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
That will work in Unicode builds converting your string to WCHAR-string and in normal builds leaving it untouched (just chars).
About the Intellisense thing: LPCWSTR is an long-pointer to constant WIDE string, a type windows uses to pass strings, is the same as *WCHAR, the Unicode equivalent to *char and LPCSTR.
Hope this helps you.
Last edited by bioHzrdmX; July 21st, 2010 at 05:13 PM.
Bookmarks