Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zomart

Win32 Registry Strings

This topic is 5869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey- I''ve been trying to store string values in the Windows registry and then load them in different applications. I''ve got them stored, but then when it comes to reading them into a different program I get stuck. The RegQueryValueEx() function sets a *BYTE to the value of the registry key. This is good I think, but I also need to have the string from registry as a string in the program. Is there any way to convert from BYTE to char * with c++ and win32 API? I''ve tried this: BYTE BaseDLLName; char *BaseDLLString = (char *)BaseDLLName; But no luck... maybe I''m reading the registry wrong in the first place becase I''ve tested and seen that BaseDLLName ends up null after passing it into RegQueryValueEx(...). If anybody actually understands this mess of a question and could help it would be greatly appreciated. Thanks...

Share this post


Link to post
Share on other sites
Advertisement
How about this


BYTE BaseDLLName;
unsigned char *BaseDLLString = BaseDLLName;


A LPBYTE is just a pointer to an unsigned char.


[edited by - aNonamuss on May 30, 2002 9:20:29 PM]

Share this post


Link to post
Share on other sites
I guess I was a little unclear on my problem. The conversion it self works, or at least compiles. The problem is when I try to output the string. I''ve tried:

BYTE BaseDLLName;
MessageBox(0, (LPCTSTR)BaseDLLName, "Test", MB_OK);

and that compiles fine. It''s just that no message box pops up... I''m thinking now more along the lines of incorrectly reading the registry value into the BYTE in the first place. The prototype for RegQueryValueEx(...) is:

RegQueryValueEx(HKEY hKey, // handle to registry key
LPTSTR lpValueName, // Name of registry value to read
LPDWORD Reserved, // Must be zero
LPDWORD lpType, // Sets a DWORD* to type of value read
LPBYTE lpData, // The actuall value
LPDWORD lpcbData); // Pointer to buffer size of data

I''m pretty sure that I''m just reading the value wrong. Do you know if lpcbData has to be set to the length of the Data when you pass it to the function? Any help would be great. Thanks...

Share this post


Link to post
Share on other sites
quote:

Zomart I guess I was a little unclear on my problem. The conversion it self works, or at least compiles. The problem is when I try to output the string. I've tried:

BYTE BaseDLLName;
MessageBox(0, (LPCTSTR)BaseDLLName, "Test", MB_OK);

and that compiles fine. It's just that no message box pops up... I'm thinking now more along the lines of incorrectly reading the registry value into the BYTE in the first place. The prototype for RegQueryValueEx(...) is:

RegQueryValueEx(HKEY hKey, // handle to registry key
LPTSTR lpValueName, // Name of registry value to read
LPDWORD Reserved, // Must be zero
LPDWORD lpType, // Sets a DWORD* to type of value read
LPBYTE lpData, // The actuall value
LPDWORD lpcbData); // Pointer to buffer size of data

I'm pretty sure that I'm just reading the value wrong. Do you know if lpcbData has to be set to the length of the Data when you pass it to the function? Any help would be great. Thanks...


Yes, lpcbData points to a variable that contains the buffer size of the character array that is pointed to by lpData. And when the function returns, the variable pointed to by lpcdData will contain the updated size of the data copied into lpData. lpData is a pointer to the character string that you wish to be updated with the string/value retrieved.


[edited by - aNonamuss on May 30, 2002 9:34:47 PM]

Share this post


Link to post
Share on other sites
lpData HAS to be the size of lpcbData.

call the read function twice, once to get the size, create lpData to be the correct size, then call read again ..

it should work. BYTE * and char * is interchangable..

Its my duty, to please that booty ! - John Shaft

Share this post


Link to post
Share on other sites
Sweet, thanks guys.

Oh yeah, one more thing. Does opening a registry key have to be so tedious? Right now I'm opening each subkey seperately, one at a time. I'm sure this can't be the best way of opening keys...

thanks...

[edited by - Zomart on May 31, 2002 1:27:53 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Zomart
Does opening a registry key have to be so tedious? Right now I''m opening each subkey seperately, one at a time. I''m sure this can''t be the best way of opening keys...

Dig around. I''m sure there''s a function that grabs the key-value pairs for an entire section at once. There was for .ini files.

Share this post


Link to post
Share on other sites
Don''t. You can use a full path, like this:


  
HKEY hkey;
RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\MyCompany\\MyProg", 0, 0, &hkey);


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!