简体   繁体   中英

Convert C Define Macro to C#

How can I convert this C define macro to C#?

#define CMYK(c,m,y,k)       ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))

I have been searching for a couple of days and have not been able to figure this out. Any help would be appreicated.

C# doesn't support #define macros. Your choices are a conversion function or a COLORREF class with a converting constructor.

public class CMYKConverter
{
    public static int ToCMYK(byte c, byte m, byte y, byte k)
    {
        return k | (y << 8) | (m << 16) | (c << 24);
    }
}

public class COLORREF
{
    int value;
    public COLORREF(byte c, byte m, byte y, byte k)
    {
        this.value = k | (y << 8) | (m << 16) | (c << 24);
    }
}

C# does not support C/C++ like macros. There is no #define equivalent for function like expressions. You'll need to write this as an actual method of an object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM