Solved

Writing binary values to the Registry

Posted on 2000-04-26
2
300 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 50 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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