What's wrong with this:

CString newpass = "Hello";
char var2[20];
strcpy(var2, (LPCSTR)newpass); // copies the string

DWORD dwcbData = sizeof(var2);

RegSetValueEx(MyKey, "WinM", 0, REG_SZ, (LPBYTE)&var2, dwcbData);
RegSaveKey(MyKey, "WinM", NULL);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When using RegOpenKeyEx you will open your RootKey, if it does not exist you will get a return value=ERROR_SUCCESS.

To store a key under the RootKey you would use RegSetValueEx.

RegSaveKey will only write the key to specified file, and not to the registry.

Check if your Software\\WinM exist, if not create it, but first get a valid root e.g set to RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software",0,KEY_ALL_ACCESS,&MyKey);


RegCreateKeyEx( hKeyRoot, "WinM", 0L, NULL, REG_OPTION_VOLATILE, KEY_READ, NULL, &m_hKey, &dw);

or use RegSetValueEx which adds the key if not existing.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scooter1Author Commented:
it exist from a previous creation, are you suggesting i dont' need RegSaveKey() ?  and is my conversion of string to char right ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.