The Registry

if i write this to the registry with:

HKEY hKey;
char fullpath[]="c:\windows\";
RegSetValueEx(hKey, name, 0, REG_SZ, (const BYTE*)fullpath, sizeof(fullpath) + 1);

how do i read it back?
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.

DWORD dwType;
char somepath[20]; //or some other size
DWORD dwSize;
RegQueryValueEx(hKey, name, 0, &dwType, somepath, &dwSize);

On success RegQueryValueEx will return ERROR_SUCCESS

I hope this helps.

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:
Why can't you give an example that will get what i wrote in my question, for a beginner i can't get what you wrote to work, i get :
error C2664: 'RegQueryValueA' : cannot convert parameter 4 from 'unsigned long *' to 'long *'
Well, considering your key value is a string I'd go with the following (to read the stuff you wrote in your program) - RegQueryValue would do just fine for that - no need for RegQueryValueEx:


LONG lSize = sizeof(fullpath);
if(RegQueryValue(hKey, name, fullpath, &lSize) != ERROR_SUCCESS) {
  // we have an error here!


[This is all from memory - but it should work fine]
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.