Solved

Writing binary values to the Registry

Posted on 2000-04-26
2
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 201
repeateFront java challenge 31 95
how to monitor remote shell execution on linux 9 107
countEvens challenge 2 115
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

696 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