How do I set a REG_BINARY value with a Hex data

Hi,

I have data in Hex format and I would like to set a REG_BINARY value with this data.

Data is C9D3E900000000003766D3008DA3D500FFFFFF00FFFFFF00000000000C2F7F0000000000FFFFFF0000009900C0C0C000FFFFFF003766D300FFFFFF00C9D3E90080808000BFBFBF0000000000FFFFFF00FFFFFF0000000000FFFFFF0000000000FFFFCC00FFFFFF00000000004F9AF600C0C0C000

C++ code please.  I need to set the pbSysColor to hold the value above
RegSetValueEx(hKeyGWE, _T("SysColor"), 0, REG_BINARY, pbSysColor, cbSize);                   

Thanks
H
LVL 12
gbzhhuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Does this do it?
RegSetValueEx(hKeyGWE, _T("SysColor"), 0, REG_BINARY, (LPBYTE)pbSysColor, (DWORD)cbSize);                  
I assume cbSize is the length of the binary data
0
gbzhhuAuthor Commented:
I am not a C++ programmer.  I don't know how to set the pbSysColor to the hex value.  How do you assign it before you even call the RegSetValueEx function.
0
itsmeandnobodyelseCommented:
>>>> Data is C9D3E900000000003766D3008D...

Do you have the data as string or as binary data?

For REG_BINARY you need it in binary, e. g.

   unsigned char bytearr[] = { 0xC9, 0xD3, 0xE9, 0x00, ... };

Or you convert the string like

#include <string>
#include <sstream>
#include <iostream>
using namespace std;
...

   const int MAX_ARR = 1024;  // you also couls take the exact length if you know
   unsigned char bytearr[MAX_ARR] = { 0 };
   string hex = "C9D3E900000000003766D3008DA3D500FFFFFF";
   for (int i = 0; i < (int)hex.size(); i+=2)
   {
         istringstream iss(hex.substr(i, 2));
         iss >> hex >> bytearr[i/2];
   }
   cbSize = (int)hex.size()/2;
   pbByte = byteArr;

0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

AndyAinscowFreelance programmer / ConsultantCommented:
I'm confused.
What is the question?  How to use RegSetValueEx or how to convert string to binary or ...
0
gbzhhuAuthor Commented:
itsmeandnobo and AndyAinscow,

Let me explain more

I am changing a Pocket PC theme.  Somehow it changes all I need except system colours.  Apparently Pocket PC doesn't support SetSysColors API.  So I am left with setting the value in the registry (device) under HKLM\System\GWE key and the value is called syscolor.  

What I did is set the theme manually on the device then capture the registry value.  The reg viewer gives in Hex format but I know the reg value type is REG_BINARY.  What I would like to do is copy the hex as string and "somehow" write that value as REG_BINARY to syscolor.  

I hope I am making sense now

H




0
itsmeandnobodyelseCommented:
>>>> and "somehow" write that value as REG_BINARY to syscolor.
Any problems with the code I posted?

Both variants of filling a byte array should do what you want.

But if you are not a programmer maybe it is easier for you to use regedit to store the values.

Open regedit (Start -> Run -> regedit), navigate to the key and entry you want to set (if not exist til now take any other key with a binary entry). Then select the key and export it (File menu) to a text file. Use NT4 Reg format. Edit the file with notepad or Visual Studio and change keys and values accordingly (you can remove any entries you don't need to update). Finally open a command window and type

    regedit /s yourfile.reg

which will update (or insert) the entry.
0
gbzhhuAuthor Commented:
itsmeandnobo&

I am a programmer.. and have been for 10 years.. just not C++ programmer.  I am coding with C# but devices need native unmanaged code.

>>Both variants of filling a byte array should do what you want.
Your first approach showed how to fill a byte array but not how to use that byte array in the call to RegSetValueEx
Your second route is too long winded and opens up too much code that I am familiar with

I cannot use regedit.  I am putting this code in a dll file that will be called from a CAB file.  

Please ask anything I can to assist you in helping me
 
0
itsmeandnobodyelseCommented:
The below should do as well if you already got the hKeyGWE  (handle to key above).
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
 
 
const char * szColor[] = "C9D3E900000000003766D3008DA3D500FFFFFF00FFFFFF00000000000C2F7F"
                         "0000000000FFFFFF0000009900C0C0C000FFFFFF003766D300FFFFFF00C9D3"
                         "E90080808000BFBFBF0000000000FFFFFF00FFFFFF0000000000FFFFFF0000"
                         "000000FFFFCC00FFFFFF00000000004F9AF600C0C0C000";
 
unsigned int setSysColor(hKeyGWE)
{
   const int MAX_ARR = 1024;  
   unsigned char bytearr[MAX_ARR] = { 0 };
   string hexstr = szColor;
   for (int i = 0; i < (int)hexstr.size(); i+=2)
   {
      istringstream iss(hexstr.substr(i, 2));
      iss >> hex >> bytearr[i/2]; 
   } 
   unsigned int   cbSize     = (int)hexstr.size()/2;
   unsigned char* pbSysColor = byteArr;
 
   return RegSetValueEx(hKeyGWE, _T("SysColor"), 0, REG_BINARY, pbSysColor, cbSize);  
}

Open in new window

0
itsmeandnobodyelseCommented:
>>>> Your first approach showed how to fill a byte array but not how to use that byte array in the call to RegSetValueEx

 it would be

   RegSetValueEx(hKeyGWE, _T("SysColor"), 0, REG_BINARY, bytearr, (DWORD)sizeof(bytearr));
0
gbzhhuAuthor Commented:
Thanks for that  itsmeandnobo

I will try your code ...
0
itsmeandnobodyelseCommented:
>>>>  (DWORD)sizeof(bytearr);

That only worked with

  unsigned char bytearr[] = { 0xC9, 0xD3, 0xE9, 0x00, ... };

where you let the compiler determine the size.
0
gbzhhuAuthor Commented:
Attempted the first approach

2 errors

Error      1      error C2440: 'initializing' : cannot convert from 'const char [233]' to 'const char *[]'      

Error      2      error C2440: 'initializing' : cannot convert from 'const char *[]' to 'std::basic_string<_Elem,_Traits,_Ax>'
0
itsmeandnobodyelseCommented:
should be

const char * szColor = ...

without the brackets [] or

const char  szColor[] = ...

with brackets
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gbzhhuAuthor Commented:
Thank u.  Build succeeds.  Will try solution on device ........
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.