I have another dialog called Login Dialog.
Basically it has two text boxes. One is Username_Box and another is Password_Box.
this is basically just to login to my main dialog.
however I get an assertion error when I try to read registry values and set it into these two boxes from my main dialog code.
You really should adopt the practice of declaring variables where they're used. For example, szString, dwType and dwSize are only used within the if statement, so they should be declared there.
If you want to read registry values, you don't need KEY_ALL_ACCESS. The request for full access will cause RegOpenKeyEx to fail in a more restricted environment. You should only request the access you need.
You need to set the size or else RegQueryValueEx won't know how much data to return. It's possible szString has been overrun. You need to reset it before each call as it's also an output parameter.
I forgot; you aren't checking the type. The query just returns the binary block of data. The type determines how you handle that data. You can only treat it as a string if the type is REG_SZ.
the assertion gives an error where it checks if username_box and password_box are windows...then i guess this validation fails and returns an assertion....nothing to do with registry query or registry type.
Have you looked at the values to confirm they're correct? As your code stands, if the user name is shorter than your password, it won't read all the password.
You still need to check the type and you still need to reset the size before each call and you ought to change that KEY_ALL_ACCESS to something less restrictive.
it saws debug assertion in visual studio and asks me to refer to documentation..
something to do with
the assertion gives an error where it checks if username_box and password_box are windows...then i guess this validation fails and returns an assertion
That doesn't mean much to me. You have a few layers of code in there. I presume logindlg is a dialog derived from CDialog and Username_Box is a CEdit. Why is Username_Box public?
You can only use Username_Box while logindlg is active.
Where are you using this code? Is it from another dialog or the main app or something like that?
The Username_Box class maps onto a Windows edit control and doesn't do anything of itself. If the Windows edit control does not exist, Username_Box can't actually do anything. I suspect that's the error.
There are a couple of ways of fixing this:
1. You could add a constructor to CLoginDlg to take a userid/passwd. When the dialog starts, it pre-populates the edit control fields for the user. You'd do this in CLoginDlg::InitDialog.
2. You could make the actual login function in CLoginDlg static. So you'd end up with a public static method CLoginDlg::DoLogin. Then you could call that from anywhere in your app without having to instantiate a CLoginDlg class.
LoginDialog::LoginDialog(CString strUser, strPass, CWnd* pParent /*=NULL*/)
: CDialog(pParent),
m_strUser(strUser),
m_strPass(strPass)
{
// You'll need to add any other stuff that appears in the other constructor.
}