Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Writing binary values to the Registry

Posted on 2000-04-26
2
Medium Priority
?
312 Views
Last Modified: 2013-11-20
I have to write binary values to the registry, where i store information about my program. Can anyone describe the general procedure of doing this? For example, open the key, write, close it, then read from it, change it.

A link to a good tutorial is cool too.
0
Comment
Question by:Mindo
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2751015
In general, it works like this:

    HANDLE  g_hRegKey;


    // reading...

    DWORD   dwType;
    DWORD   dwSize  =   MAX_PATH;
    BOOL    bRC     =   TRUE;

    g_hRegKey   =   NULL;

    if  (   ERROR_SUCCESS   !=  RegOpenKeyEx    (    HKEY_LOCAL_MACHINE,
                                                     APPLICATION_REGPATH,
                                                     0,
                                                     KEY_ALL_ACCESS,
                                                    &g_hRegKey
                                                )
        )
        {
            DbgReport   (   L"RegOpenKeyEx() failed!!");

            return  (   FALSE);
        }

    dwType  =   REG_BINARY;
    dwSize  =   sizeof  (   g_awcRegUsr);

    if  (   ERROR_SUCCESS   !=  RegQueryValueEx (   g_hRegKey,
                                                    APPLICATION_USRNAME,
                                                    NULL,
                                                    &dwType,
                                                    ( LPBYTE) g_awcRegUsr,
                                                    &dwSize
                                                )
        )  
        {
            DbgReport   (   L"RegQueryValueEx() failed!!");

            bRC =   FALSE;
        }
   
    dwType  =   REG_BINARY;
    dwSize  =   sizeof  (   g_awcRegPwd);

    if  (   ERROR_SUCCESS   !=  RegQueryValueEx (   g_hRegKey,
                                                    APPLICATION_PASSWD,
                                                    NULL,
                                                    &dwType,
                                                    ( LPBYTE) g_awcRegPwd,
                                                    &dwSize
                                                )
        )  
        {
            DbgReport   (   L"RegQueryValueEx() failed!!");

            bRC =   FALSE;
        }


    // writing...

    if  (   ERROR_SUCCESS   !=  RegSetValueEx   (   g_hRegKey,
                                                    APPLICATION_USRNAME,
                                                    NULL,
                                                    REG_BINARY,
                                                    ( LPBYTE) g_awcRegUsr,
                                                    sizeof  (   g_awcRegUsr)
                                                )
        )   bRC =   FALSE;

    if  (   ERROR_SUCCESS   !=  RegSetValueEx   (   g_hRegKey,
                                                    APPLICATION_PASSWD,
                                                    NULL,
                                                    REG_BINARY,
                                                    ( LPBYTE) g_awcRegPwd,
                                                    sizeof  (   g_awcRegPwd)
                                                )
        )   bRC =   FALSE;


Feel free to ask if you need more information!
0
 
LVL 2

Author Comment

by:Mindo
ID: 2781950
Thank you very much!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question