Reputation: 2100
I have a c# Windows .Net UI that calls a C dll. The dll does some calculations on a set of data, and comes up with a color that it needs to pass to the UI.
The colors are not exotic, and there are only about 10 different ones it will pass to the UI (eg, RED, WHITE, GREEN, MAGENTA, YELLOW, etc). Is there some set of standard names that both the C and C# can use, so I can avoid having to write more code?
Upvotes: 0
Views: 232
Reputation: 941317
A color value is an integer in code. It only has a name when you use, say, a designer or a type like the .NET System.Drawing.Color type. When you interop between .NET and C then there is no type you can use that works on both ends, other than int.
Color values are encoded in ARGB format, one byte each for Alpha, Red, Green and Blue. So "red" is the value 0xffff0000, "white" is 0xffffffff, "green" is 0xff00ff00, etcetera. Hopefully you see the pattern. If not then you can get the color values by writing a little C# Winforms program that uses int value = Color.Red.ToArgb();
to get the integer value. Also works in the debugger so you can directly type the expression in the quick watch window.
Upvotes: 4