Search code examples
c#imapi

I get 6 as State result for a blank CD


I don't know why I get 6 as a result when I insert a blank media in my burner. To my understanding there is no 6 in the states of the enumeration of IMAPI_FORMAT2_DATA_MEDIA_STATE.

Here is a link that contain this states and the example that I am based on : MSDN:Checking Media Support.

var state = dataWriter.CurrentMediaStatus;                        
Debug.WriteLine((int)state); // outputs 6

Solution

  • It is a combination of both of them, basically a bitwise operation is calculated on the two (or more values). When you make an enum with the attribute Flags then you can do Bitwise operations on it, even though it should work without the attribute

    IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK
    IMAPI_FORMAT2_DATA_MEDIA_STATE_APPENDABLE
    

    The value of IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK with an 'OR' operation with IMAPI_FORMAT2_DATA_MEDIA_STATE_APPENDABLE will give 6 in C# it would be value = 2 | 4;

    To go further if you want to test if the value contains a certain Option you can go ahead and do something like this

    if ((value & IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK) == IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK)
    {
    //IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK is contained
    }
    

    You can read more about Bitwise operations here