Re: Working with registry
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.
Re: Working with registry
Quote:
Originally Posted by
bioHzrdmX
Have you tried plain win32 API?
.
I read somewhere about it but I couldn't get it work.
Check the MSDN (or the VS docs if you have them installed) for RegOpenKeyEx, this is your key to
Quote:
Originally Posted by
bioHzrdmX
Check the MSDN (or the VS docs if you have them installed) for RegOpenKeyEx, this is your key to
.
Can you please explain me how can I check if i got this installated?
I have Microsoft Visual C++ 2010 as compiler.
thanks
Re: Working with registry
"Check the MSDN (or the VS docs if you have them installed) for RegOpenKeyEx, this is your key to "
sorry its my mistake while i was copy/pasting, forgot to erase it
Re: Working with registry
This should help you understand
This is for creating a registery key with REG_SZ value.
Code:
HKEY hKey;
DWORD buffersize = 8000;
char* lpData = new char [buffersize];
LPDWORD lpdwDisp = &buffersize;
LONG i = RegCreateKeyEx( HKEY_CURRENT_USER,"Folder Name", 0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
LPCSTR abv = "Value";
if(i == ERROR_SUCCESS)
{
RegSetValueEx(hKey,"Reg Key Name", 0, REG_SZ,LPBYTE (abv),sizeof(abv) );
}
return 0;
}
This is for deleting a reg key
Code:
int _tmain(int argc, _TCHAR* argv[])
{
RegDeleteKey(HKEY_CURRENT_USER,"Folder");//*Deletes entire folder with key in it
return 0;
}
This is for querying a reg key
Code:
HKEY hKey;
DWORD buffersize = 1024;
char* lpData = new char [buffersize];
if(RegOpenKeyEx(HKEY_CURRENT_USER,"Folder",NULL,KEY_READ,&hKey) ==ERROR_SUCCESS)
{
RegQueryValueEx(hKey,"Folder",0,0,(LPBYTE) lpData,&buffersize);
RegCloseKey(hKey);
}
Re: Working with registry
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++.
Re: Working with registry
Quote:
Originally Posted by
bioHzrdmX
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?
Re: Working with registry
You can Search google for tutorials
Re: Working with registry
Re: Working with registry
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...
Re: Working with registry
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 :-)
Regards.
Re: Working with registry
Okay, thanks a lot for making things clear to me!
Cheers.
Re: Working with registry
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.
Re: Working with registry
I tried this code, but I'm getting an error.
Code:
LONG i = RegCreateKeyEx( HKEY_CURRENT_USER,"Folder name", 0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
At this point where i need to put folder name i got this error. I tried to locate my folder multiple times but Im always getting this.
1 IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
Re: Working with registry
It's because you're using Unicode:
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.