COLORREF to registry

I need to write a COLORREF to the registry.
I am thinking of using 3 integers each representing R, G & B.   How do i extract these value from a COLORREF then?

Is the any other better way to do the storing?
Who is Participating?
Andy_KeysConnect With a Mentor Commented:
Why Not just write it as binary data COLORREF is just a unsigned long ie 32bits.  Try something like
            RegKey,      0,NULL,                                          REG_OPTION_NON_VOLATILE,                              KEY_WRITE,NULL,      &RestoreKey,&Disp) )
RegSetValueEx( RestoreKey, <aKey>,0, REG_BINARY, &ColourRef,sizeof(COLORREF) );

nancytanAuthor Commented:
I have a problem with 5th parameter of the function RegSetValueEx

COLORREF crText;      
crText = RGB(0,0,255);
RegSetValueEx( RestoreKey, szKeyColref,0, REG_BINARY, &crText, sizeof(COLORREF) );

: error C2664: 'RegSetValueExA' : cannot convert parameter 5 from 'unsigned long *' to 'const unsigned char *'

How should i code it?
Try (unsigned char*)&crText (Compiled when I tried at least)
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

If you're using MFC and storing application info, use WriteProfileInt .. a COLORREF is just an int. (you may need to cast to int when writing .. on read GetProfileInt returns an unsigned int.

you can convert the value of  COLORREF to string and u can also store it as a string
but it is ALREADY an int .. no conversion needed.  Converting to/from a string would (probably) involve sscanf and .Format etc .. more mess than you need
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.