Solved

Writing binary values to the Registry

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

630 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