Advertisement

how to write a reg-key

Started by April 16, 2003 05:43 AM
4 comments, last by biotech 21 years, 10 months ago
does anybody know how to write a reg-key from program? belgrade-yu
belgrade-yu
Code is on the NeHe CD ... plug plug

email me and I will send you an example.
Advertisement
Hope the code helped...?
LONG RegCreateKeyEx(  HKEY hKey,                // handle to an open key  LPCTSTR lpSubKey,         // address of subkey name  DWORD Reserved,           // reserved  LPTSTR lpClass,           // address of class string  DWORD dwOptions,          // special options flag  REGSAM samDesired,        // desired security access  LPSECURITY_ATTRIBUTES lpSecurityAttributes,                            // address of key security structure  PHKEY phkResult,          // address of buffer for opened handle  LPDWORD lpdwDisposition   // address of disposition value buffer);LONG RegSetValueEx(  HKEY hKey,           // handle to key to set value for  LPCTSTR lpValueName, // name of the value to set  DWORD Reserved,      // reserved  DWORD dwType,        // flag for value type  CONST BYTE *lpData,  // address of value data  DWORD cbData         // size of value data);LONG RegQueryValueEx(  HKEY hKey,           // handle to key to query  LPTSTR lpValueName,  // address of name of value to query  LPDWORD lpReserved,  // reserved  LPDWORD lpType,      // address of buffer for value type  LPBYTE lpData,       // address of data buffer  LPDWORD lpcbData     // address of data buffer size); 


Typically you''d use it something like this:
HKEY myKey;CString szMyKey = "SomeName";DWORD dwDisposition;RegCreateKeyEx(HKEY_CURRENT_USER, szMyKey, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &myKey, &dwDisposition);// Now the key is created or opened, and you can talk to it.CString myBobKey = "BobKey";CString myValue = "Bob";RegSetValueEx(myKey, szBobKey, NULL, REG_SZ, (BYTE*const)((LPCTSTR)myValue), (lstrlen((LPCTSTR)myValue)+1)*(sizeof(TCHAR));// Now we have our main key, and a sub key with a vlue in it.CString currentValue;LPTSTR lpsz = currentValue.GetBuffer(256);DWORD dwType;DWORD dwLength;RegQueryValueEx(myKey, szBobKey, NULL, &dwType, (BYTE*)lpsz, &dwLength);currentValue.ReleaseBuffer();// Clean it all up.RegCloseKey(myKey); 


Ok, I think I''ve got it all there. I''m not really sure though, and it''s all sort of pseudo code, though should be pretty close. You can actually do a:
RegQueryValueEx(myKey, szBobKey, NULL, &dwType, NULL, &dwLength); 

Prior to actually getting the key, and you could then do .GetBufferSetLength(dwLength) instead of the one I''ve got with a hard-coded buffer min-size in it.

Soo....hope that helps, hope I didn''t do too much crazy stuff.

- sighuh?
- sighuh?
i think this will help,
thanx

belgrade-yu
belgrade-yu
I wrote a CRegKey class at one time...don''t know if people use Reg-Key''s often enough to find something like that useful...

Anyone?



- sighuh?
- sighuh?

This topic is closed to new replies.

Advertisement