Binary Registrykey

This is a discussion on Binary Registrykey within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have the problem that I want to create a binary registrykey. I have a textbox where I put ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Binary Registrykey

    Hello,

    I have the problem that I want to create a binary registrykey.

    I have a textbox where I put in the hex values like 1234ABC

    After this a registrykey REG_BINARY should be created

    Anyone have an idea ??

    Would be really great

    btw. I use VS 2005 with the Framework2
    Last edited by Gerudom; 06-01-2006 at 02:40 AM.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    #include <windows.h> 
    #include <stdio.h>
    
    int main(void)
    {
        DWORD dwType, dwSize, dwRet;
        DWORD dwDisposition, dwIndex, dwResult;
        HKEY hKey;
        unsigned char input[] = {0x0a, 0x4f, 0x5c, 0x3a};
    
        RegCreateKeyEx(HKEY_LOCAL_MACHINE,
            "System\\BinaryData", 0, NULL,
            REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
            &hKey, &dwDisposition);
    
        RegSetValueEx(hKey, "TestData", 0,
            REG_BINARY, (BYTE *)&input,
            sizeof(input));
        RegCloseKey(hKey);
        dwRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
            "System\\BinaryData",
            0, KEY_QUERY_VALUE, &hKey );
        if( dwRet != ERROR_SUCCESS )
        {
            printf("RegOpenKeyEx failed\n");
            return -1;
        }   
        dwResult = RegQueryValueEx(hKey, "TestData",
            0, &dwType, NULL, &dwSize);
        if((dwResult == ERROR_SUCCESS) && (dwType == REG_BINARY))
        {
            char *dataout = new char[dwSize];
            dwResult = RegQueryValueEx(hKey, "TestData", 0,
                &dwType, (BYTE *)dataout, &dwSize);
            if (dwResult == ERROR_SUCCESS)
            {
                for(dwIndex = 0; dwIndex < dwSize; dwIndex++)
                    printf("%02x ", dataout[dwIndex]);
            }
            delete[] dataout;
        }
        else
        {
            printf("RegQueryValueEx failed\n");
            return -1;
        }
        return 0;    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 01:02 PM
  2. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21