context: using System;
  using System.Runtime.InteropServices;
  
  namespace EDSDKLib
  {
      public class EDSDK
      {
          /// <summary>
          /// Path to the EDSDK DLL
          /// </summary>
          const string DLLPath = "EDSDK.dll";
  
          #region Callback Functions
  
          public delegate uint EdsProgressCallback( uint inPercent, IntPtr inContext, ref bool outCancel);
          public delegate uint EdsCameraAddedHandler(IntPtr inContext);
          public delegate uint EdsPropertyEventHandler(uint inEvent, uint inPropertyID, uint inParam, IntPtr inContext); 
          public delegate uint EdsObjectEventHandler( uint inEvent, IntPtr inRef, IntPtr inContext); 
          public delegate uint EdsStateEventHandler( uint inEvent, uint inParameter, IntPtr inContext);
  
          #endregion
  
          #region Data Types
  
          public enum EdsDataType : uint
          {       
              Unknown     = 0,      
              Bool        = 1,     
              String      = 2,     
              Int8        = 3,     
              UInt8       = 6,    
              Int16       = 4,      
              UInt16      = 7,      
              Int32       = 8,      
              UInt32      = 9,      
              Int64       = 10,     
              UInt64      = 11,    
              Float       = 12,
              Double      = 13,
              ByteBlock   = 14,    
              Rational    = 20,    
              Point       = 21,   
              Rect        = 22,
              Time        = 23,
  
              Bool_Array   = 30,     
              Int8_Array   = 31,     
              Int16_Array  = 32,     
              Int32_Array  = 33,     
              UInt8_Array  = 34,     
              UInt16_Array     = 35,     
              UInt32_Array     = 36,     
              Rational_Array  = 37,      
  
              FocusInfo        = 101,    
              PictureStyleDesc,
          } 
  
          #endregion
  
  
          #region Property IDs
  
          /*----------------------------------
           Camera Setting Properties
          ----------------------------------*/
          public const uint   PropID_Unknown              = 0x0000ffff;     
      
          public const uint   PropID_ProductName          = 0x00000002;   
          public const uint   PropID_BodyIDEx             = 0x00000015;   
          public const uint   PropID_OwnerName            = 0x00000004;       
          public const uint   PropID_MakerName            = 0x00000005;       
          public const uint   PropID_DateTime             = 0x00000006;   
          public const uint   PropID_FirmwareVersion      = 0x00000007;   
          public const uint   PropID_BatteryLevel         = 0x00000008;   
          public const uint   PropID_CFn                  = 0x00000009;       
          public const uint   PropID_SaveTo               = 0x0000000b;
          public const uint   kEdsPropID_CurrentStorage   = 0x0000000c;
          public const uint   kEdsPropID_CurrentFolder    = 0x0000000d;
          public const uint   kEdsPropID_MyMenu           = 0x0000000e;
  
  		public const uint	PropID_BatteryQuality         = 0x00000010;	
  
  		public const uint	PropID_HDDirectoryStructure   = 0x00000020;
  
          /*----------------------------------
           Image Properties
          ----------------------------------*/
          public const uint   PropID_ImageQuality         = 0x00000100;   
          public const uint   PropID_JpegQuality          = 0x00000101;    
          public const uint   PropID_Orientation          = 0x00000102;   
          public const uint   PropID_ICCProfile           = 0x00000103;   
          public const uint   PropID_FocusInfo            = 0x00000104;   
          public const uint   PropID_DigitalExposure      = 0x00000105;   
          public const uint   PropID_WhiteBalance         = 0x00000106;   
          public const uint   PropID_ColorTemperature     = 0x00000107;   
          public const uint   PropID_WhiteBalanceShift    = 0x00000108;
          public const uint   PropID_Contrast             = 0x00000109;
          public const uint   PropID_ColorSaturation      = 0x0000010a;
          public const uint   PropID_ColorTone            = 0x0000010b;
          public const uint   PropID_Sharpness            = 0x0000010c;
          public const uint   PropID_ColorSpace           = 0x0000010d;
          public const uint   PropID_ToneCurve            = 0x0000010e;
          public const uint   PropID_PhotoEffect          = 0x0000010f;
          public const uint   PropID_FilterEffect         = 0x00000110;
          public const uint   PropID_ToningEffect         = 0x00000111;
          public const uint   PropID_ParameterSet         = 0x00000112;   
          public const uint   PropID_ColorMatrix          = 0x00000113;
          public const uint   PropID_PictureStyle         = 0x00000114;
          public const uint   PropID_PictureStyleDesc     = 0x00000115;
          public const uint   PropID_PictureStyleCaption  = 0x00000200;
  
          /*----------------------------------
           Image Processing Properties
          ----------------------------------*/
          public const uint   PropID_Linear               = 0x00000300;
          public const uint   PropID_ClickWBPoint         = 0x00000301;
          public const uint   PropID_WBCoeffs             = 0x00000302;
  
          /*----------------------------------
           Property Mask
          ----------------------------------*/
          public const uint   PropID_AtCapture_Flag       = 0x80000000;   
  
          /*----------------------------------
           Capture Properties
          ----------------------------------*/
          public const uint   PropID_AEMode               = 0x00000400;
  		public const uint   PropID_AEModeSelect         = 0x00000436;
          public const uint   PropID_DriveMode            = 0x00000401;
          public const uint   PropID_ISOSpeed             = 0x00000402;
          public const uint   PropID_MeteringMode         = 0x00000403;
          public const uint   PropID_AFMode               = 0x00000404;
          public const uint   PropID_Av                   = 0x00000405;
          public const uint   PropID_Tv                   = 0x00000406;
          public const uint   PropID_ExposureCompensation = 0x00000407;
          public const uint   PropID_FlashCompensation    = 0x00000408;
          public const uint   PropID_FocalLength          = 0x00000409;
          public const uint   PropID_AvailableShots       = 0x0000040a;
          public const uint   PropID_Bracket              = 0x0000040b;
          public const uint   PropID_WhiteBalanceBracket  = 0x0000040c;
          public const uint   PropID_LensName             = 0x0000040d;
          public const uint   PropID_AEBracket            = 0x0000040e;
          public const uint   PropID_FEBracket            = 0x0000040f;
          public const uint   PropID_ISOBracket           = 0x00000410;
          public const uint   PropID_NoiseReduction       = 0x00000411;
          public const uint   PropID_FlashOn              = 0x00000412;
          public const uint   PropID_RedEye               = 0x00000413;
          public const uint   PropID_FlashMode            = 0x00000414;
          public const uint   PropID_LensStatus           = 0x00000416;
          
          public const uint   PropID_Artist	            = 0x00000418;
          public const uint   PropID_Copyright	        = 0x00000419;
          public const uint   PropID_DepthOfField	        = 0x0000041b;
          public const uint   PropID_EFCompensation       = 0x0000041e;
  
  		/*----------------------------------
  		 EVF Properties
  		----------------------------------*/
          public const uint   PropID_Evf_OutputDevice        = 0x00000500;
          public const uint   PropID_Evf_Mode                = 0x00000501;
          public const uint   PropID_Evf_WhiteBalance        = 0x00000502;
          public const uint   PropID_Evf_ColorTemperature    = 0x00000503;
          public const uint   PropID_Evf_DepthOfFieldPreview = 0x00000504;
  
  		// EVF IMAGE DATA Properties
          public const uint   PropID_Evf_Zoom                = 0x00000507;
          public const uint   PropID_Evf_ZoomPosition        = 0x00000508;
          public const uint   PropID_Evf_FocusAid            = 0x00000509;
          public const uint   PropID_Evf_Histogram           = 0x0000050A;
          public const uint   PropID_Evf_ImagePosition       = 0x0000050B;
  		public const uint   PropID_Evf_HistogramStatus     = 0x0000050C;
          public const uint   PropID_Evf_AFMode              = 0x0000050E;
          public const uint   PropID_Evf_CoordinateSystem    = 0x00000540;
          public const uint   PropID_Evf_ZoomRect            = 0x00000541;
  
  		public const uint   PropID_Record                  = 0x00000510;
               
          /*----------------------------------
           Image GPS Properties
          ----------------------------------*/
          public const uint   PropID_GPSVersionID			 =  0x00000800; 	
          public const uint   PropID_GPSLatitudeRef		 =  0x00000801; 		
          public const uint   PropID_GPSLatitude			 =  0x00000802; 	
          public const uint   PropID_GPSLongitudeRef		 =  0x00000803; 	
          public const uint   PropID_GPSLongitude			 =  0x00000804; 		
  		public const uint   PropID_GPSAltitudeRef		 =  0x00000805; 		
          public const uint   PropID_GPSAltitude			 =  0x00000806; 		
          public const uint   PropID_GPSTimeStamp			 =  0x00000807; 		
          public const uint   PropID_GPSSatellites		 =  0x00000808; 		
          public const uint   PropID_GPSStatus			 =  0x00000809;
          public const uint   PropID_GPSMapDatum			 =  0x00000812; 		
  		public const uint   PropID_GPSDateStamp			 =  0x0000081D; 		
  		#endregion
  
          #region Camera commands
  
          /*-----------------------------------------------------------------------------
           Send Commands
          -----------------------------------------------------------------------------*/
          public const uint CameraCommand_TakePicture         = 0x00000000;       
          public const uint CameraCommand_ExtendShutDownTimer = 0x00000001;
          public const uint CameraCommand_BulbStart			= 0x00000002; 
          public const uint CameraCommand_BulbEnd				= 0x00000003; 
          public const uint CameraCommand_DoEvfAf             = 0x00000102;
          public const uint CameraCommand_DriveLensEvf        = 0x00000103;
          public const uint CameraCommand_DoClickWBEvf        = 0x00000104;
  
          public const uint CameraCommand_PressShutterButton  = 0x00000004; 
          
          public enum EdsEvfAf : uint
          {
  	        CameraCommand_EvfAf_OFF		= 0,
  	        CameraCommand_EvfAf_ON		= 1,
          }
  
          public enum EdsShutterButton : uint
          {
  	        CameraCommand_ShutterButton_OFF					= 0x00000000,
  	        CameraCommand_ShutterButton_Halfway				= 0x00000001,
  	        CameraCommand_ShutterButton_Completely			= 0x00000003,
  	        CameraCommand_ShutterButton_Halfway_NonAF		= 0x00010001,
  	        CameraCommand_ShutterButton_Completely_NonAF	= 0x00010003,
          } 
          #endregion
  
          #region Camera status command
  
          /*----------------------------------
           Camera Status Commands
          ----------------------------------*/
          public const uint CameraState_UILock                = 0x00000000;           
          public const uint CameraState_UIUnLock              = 0x00000001;       
          public const uint CameraState_EnterDirectTransfer   = 0x00000002;       
          public const uint CameraState_ExitDirectTransfer    = 0x00000003;   
  
           #endregion
  
  
          #region  Enumeration of property value  
  
          /*-----------------------------------------------------------------------------
           Stream Seek Origins
          -----------------------------------------------------------------------------*/
          public enum EdsSeekOrigin : uint
          {
              Cur = 0 ,    
              Begin    ,  
              End  ,   
          }
  
          /*-----------------------------------------------------------------------------
           File and Propaties Access
          -----------------------------------------------------------------------------*/
          public enum EdsAccess : uint
          {
              Read = 0  ,  
              Write    ,   
              ReadWrite ,  
              Error = 0xFFFFFFFF,
          }
  
          /*-----------------------------------------------------------------------------
           File Create Disposition
          -----------------------------------------------------------------------------*/
          public enum EdsFileCreateDisposition : uint
          {
              CreateNew = 0    ,  
              CreateAlways     ,   
              OpenExisting     ,   
              OpenAlways   ,  
              TruncateExsisting, 
          } 
  
  
          /*-----------------------------------------------------------------------------
           Target Image Types
          -----------------------------------------------------------------------------*/
          public enum EdsTargetImageType : uint
          {
              Unknown = 0x00000000,
              Jpeg    = 0x00000001,
              TIFF    = 0x00000007,
              TIFF16  = 0x00000008,
              RGB     = 0x00000009,
              RGB16   = 0x0000000A,
          }
  
  
          /*-----------------------------------------------------------------------------
           Image Source 
          -----------------------------------------------------------------------------*/
          public enum EdsImageSource : uint
          {
              FullView = 0   ,
              Thumbnail,
              Preview,
          }
  
          /*-----------------------------------------------------------------------------
           Progress Option
          -----------------------------------------------------------------------------*/
          public enum EdsProgressOption : uint
          {
              NoReport = 0   ,    
              Done          ,     
              Periodically   ,    
          } 
  
  
          /*-----------------------------------------------------------------------------
           file attribute
          -----------------------------------------------------------------------------*/
          public enum EdsFileAttribute : uint
          {
              Normal     = 0x00000000,
              ReadOnly   = 0x00000001,
              Hidden     = 0x00000002,
              System     = 0x00000004,
              Archive    = 0x00000020,
          }
  
          /*-----------------------------------------------------------------------------
           Save To
          -----------------------------------------------------------------------------*/
          public enum EdsSaveTo : uint 
          {
              Camera  =  1,
              Host    =  2,
              Both    =  3,
          }
  
          /*-----------------------------------------------------------------------------
           StorageTypes
          -----------------------------------------------------------------------------*/
          public enum EdsStorageType : uint 
          {
              Non = 0,
              CF  = 1,
              SD  = 2,
          } 
  
          /*-----------------------------------------------------------------------------
           Transfer Option
          -----------------------------------------------------------------------------*/
          public enum EdsTransferOption : uint
          {
              ByDirectTransfer    = 1,
              ByRelease           = 2,
              ToDesktop           = 0x00000100,
          }
  
  		/*-----------------------------------------------------------------------------
  		 Drive Lens
  		-----------------------------------------------------------------------------*/
          public const uint EvfDriveLens_Near1	= 0x00000001;
          public const uint EvfDriveLens_Near2	= 0x00000002;
          public const uint EvfDriveLens_Near3	= 0x00000003;
          public const uint EvfDriveLens_Far1		= 0x00008001;
          public const uint EvfDriveLens_Far2		= 0x00008002;
          public const uint EvfDriveLens_Far3		= 0x00008003;
  
  		/*-----------------------------------------------------------------------------
  		 Depth of Field Preview
  		-----------------------------------------------------------------------------*/
          public const uint EvfDepthOfFieldPreview_OFF	= 0x00000000;
  		public const uint EvfDepthOfFieldPreview_ON		= 0x00000001;
  
  
          /*-----------------------------------------------------------------------------
           Image Format 
          -----------------------------------------------------------------------------*/
  
          public const int ImageFormat_Unknown = 0x00000000;
          public const int ImageFormat_Jpeg = 0x00000001;
          public const int ImageFormat_CRW = 0x00000002;
          public const int ImageFormat_RAW = 0x00000004;
  
          public const int ImageFormat_CR2 = 0x00000006;
  
  
          public const int ImageSize_Large = 0;
          public const int ImageSize_Middle = 1;
          public const int ImageSize_Small = 2;
          public const int ImageSize_Middle1 = 5;
          public const int ImageSize_Middle2 = 6;
          public const int ImageSize_Unknown = -1;
  
  
  
          public const int CompressQuality_Normal = 2;
  		public const int CompressQuality_Fine = 3;
  		public const int CompressQuality_Lossless = 4;
  		public const int CompressQuality_SuperFine = 5;
  		public const int CompressQuality_Unknown = -1;
  
  
          /*-----------------------------------------------------------------------------
           Battery level
          -----------------------------------------------------------------------------*/
          public const uint   BatteryLevel_Empty    = 1;   
          public const uint   BatteryLevel_Low      = 30;      
          public const uint   BatteryLevel_Half     = 50;      
          public const uint   BatteryLevel_Normal   = 80;
          public const uint   BatteryLevel_AC       = 0xFFFFFFFF;     
  
          /*-----------------------------------------------------------------------------
           White Balance
          -----------------------------------------------------------------------------*/
          public const int WhiteBalance_Click         = -1;
          public const int WhiteBalance_Auto          = 0;
          public const int WhiteBalance_Daylight      = 1;
          public const int WhiteBalance_Cloudy        = 2;
          public const int WhiteBalance_Tangsten      = 3;
          public const int WhiteBalance_Fluorescent   = 4;
          public const int WhiteBalance_Strobe        = 5;
          public const int WhiteBalance_WhitePaper    = 6;
          public const int WhiteBalance_Shade         = 8;
          public const int WhiteBalance_ColorTemp     = 9;
          public const int WhiteBalance_PCSet1        = 10;
          public const int WhiteBalance_PCSet2        = 11;
          public const int WhiteBalance_PCSet3        = 12;   
  
          /*-----------------------------------------------------------------------------
           Photo Effects
          -----------------------------------------------------------------------------*/
          public const int PhotoEffect_Off         = 0;
          public const int PhotoEffect_Monochrome  = 5;
  
          /*-----------------------------------------------------------------------------
           Color Matrix
          -----------------------------------------------------------------------------*/
          public const int ColorMatrix_Custom      = 0;
          public const int ColorMatrix_1           = 1;
          public const int ColorMatrix_2           = 2;
          public const int ColorMatrix_3           = 3;
          public const int ColorMatrix_4           = 4;
          public const int ColorMatrix_5           = 5;
          public const int ColorMatrix_6           = 6;
          public const int ColorMatrix_7           = 7;
  
          /*-----------------------------------------------------------------------------
           Filter Effects
          -----------------------------------------------------------------------------*/
          public const int FilterEffect_None       = 0;
          public const int FilterEffect_Yellow     = 1;
          public const int FilterEffect_Orange     = 2;
          public const int FilterEffect_Red        = 3;
          public const int FilterEffect_Green      = 4;
  
          /*-----------------------------------------------------------------------------
           Toning Effects
          -----------------------------------------------------------------------------*/
          public const int TonigEffect_None       = 0;
          public const int TonigEffect_Sepia      = 1;
          public const int TonigEffect_Blue       = 2;
          public const int TonigEffect_Purple     = 3;
          public const int TonigEffect_Green      = 4;
  
          /*-----------------------------------------------------------------------------
           Color Space
          -----------------------------------------------------------------------------*/
          public const uint   ColorSpace_sRGB       = 1;
          public const uint   ColorSpace_AdobeRGB   = 2;
          public const uint   ColorSpace_Unknown    = 0xffffffff;
  
          /*-----------------------------------------------------------------------------
           PictureStyle
          -----------------------------------------------------------------------------*/
          public const uint PictureStyle_Standard     = 0x0081;
          public const uint PictureStyle_Portrait     = 0x0082;
          public const uint PictureStyle_Landscape    = 0x0083;
          public const uint PictureStyle_Neutral      = 0x0084;
          public const uint PictureStyle_Faithful     = 0x0085;
          public const uint PictureStyle_Monochrome   = 0x0086;
          public const uint PictureStyle_User1        = 0x0021;
          public const uint PictureStyle_User2        = 0x0022;
          public const uint PictureStyle_User3        = 0x0023;
          public const uint PictureStyle_PC1          = 0x0041;
          public const uint PictureStyle_PC2          = 0x0042;
          public const uint PictureStyle_PC3          = 0x0043;
  
  
          /*-----------------------------------------------------------------------------
           AE Mode
          -----------------------------------------------------------------------------*/
          public const uint   AEMode_Program          = 0;
          public const uint   AEMode_Tv               = 1;
          public const uint   AEMode_Av               = 2;
          public const uint   AEMode_Manual           = 3;
          public const uint   AEMode_Bulb             = 4;
          public const uint   AEMode_A_DEP            = 5;
          public const uint   AEMode_DEP              = 6;
          public const uint   AEMode_Custom           = 7;
          public const uint   AEMode_Lock             = 8;
          public const uint   AEMode_Green            = 9;
          public const uint   AEMode_NigntPortrait    = 10;
          public const uint   AEMode_Sports           = 11;
          public const uint   AEMode_Portrait         = 12;
          public const uint   AEMode_Landscape        = 13;
          public const uint   AEMode_Closeup          = 14;
          public const uint   AEMode_FlashOff         = 15;
          public const uint   AEMode_CreativeAuto     = 19;
          public const uint   AEMode_Movie			= 20;
          public const uint   AEMode_PhotoInMovie		= 21;
  		public const uint   AEMode_SceneIntelligentAuto = 22;
  		public const uint   AEMode_SCN              = 25;
          public const uint   AEMode_Unknown          = 0xffffffff;
  
          /*-----------------------------------------------------------------------------
           Bracket
          -----------------------------------------------------------------------------*/
          public const uint   Bracket_AEB             = 0x01;
          public const uint   Bracket_ISOB            = 0x02;
          public const uint   Bracket_WBB             = 0x04;
          public const uint   Bracket_FEB             = 0x08;
          public const uint   Bracket_Unknown         = 0xffffffff;
  
  
  		/*-----------------------------------------------------------------------------
  		 EVF Output Device [Flag]
  		-----------------------------------------------------------------------------*/
          public const uint   EvfOutputDevice_TFT			= 1;
          public const uint   EvfOutputDevice_PC			= 2;
  
  
  		/*-----------------------------------------------------------------------------
  		 EVF Zoom
  		-----------------------------------------------------------------------------*/
          public const int   EvfZoom_Fit			= 1;
          public const int   EvfZoom_x5			= 5;
  		public const int	EvfZoom_x10			= 10;
  
          public enum EdsEvfAFMode : uint
          {
              Evf_AFMode_Quick    = 0,
              Evf_AFMode_Live     = 1,
              Evf_AFMode_LiveFace = 2,
  			Evf_AFMode_LiveMulti = 3,
          }
  
          /*-----------------------------------------------------------------------------
           Strobo Mode
          -----------------------------------------------------------------------------*/
          public enum EdsStroboMode
          {
              kEdsStroboModeInternal = 0,
              kEdsStroboModeExternalETTL = 1,
              kEdsStroboModeExternalATTL = 2,
              kEdsStroboModeExternalTTL = 3,
              kEdsStroboModeExternalAuto = 4,
              kEdsStroboModeExternalManual = 5,
              kEdsStroboModeManual = 6,
          }
  
          public enum EdsETTL2Mode
          {
  	        kEdsETTL2ModeEvaluative		= 0,
  	        kEdsETTL2ModeAverage		= 1,
          }
  
          public enum ImageQuality : uint
          {
  			/* Jpeg Only */
  			EdsImageQuality_LJ = 0x0010ff0f,	/* Jpeg Large */
  			EdsImageQuality_M1J = 0x0510ff0f,	/* Jpeg Middle1 */
  			EdsImageQuality_M2J = 0x0610ff0f,	/* Jpeg Middle2 */
  			EdsImageQuality_SJ = 0x0210ff0f,	/* Jpeg Small */
  			EdsImageQuality_LJF = 0x0013ff0f,	/* Jpeg Large Fine */
  			EdsImageQuality_LJN = 0x0012ff0f,	/* Jpeg Large Normal */
  			EdsImageQuality_MJF = 0x0113ff0f,	/* Jpeg Middle Fine */
  			EdsImageQuality_MJN = 0x0112ff0f,	/* Jpeg Middle Normal */
  			EdsImageQuality_SJF = 0x0213ff0f,	/* Jpeg Small Fine */
  			EdsImageQuality_SJN = 0x0212ff0f,	/* Jpeg Small Normal */
  			EdsImageQuality_S1JF = 0x0E13ff0f,	/* Jpeg Small1 Fine */
  			EdsImageQuality_S1JN = 0x0E12ff0f,	/* Jpeg Small1 Normal */
  			EdsImageQuality_S2JF = 0x0F13ff0f,	/* Jpeg Small2 */
  			EdsImageQuality_S3JF = 0x1013ff0f,	/* Jpeg Small3 */
  
  			/* RAW + Jpeg */
  			EdsImageQuality_LR = 0x0064ff0f,	/* RAW */
  			EdsImageQuality_LRLJF = 0x00640013,	/* RAW + Jpeg Large Fine */
  			EdsImageQuality_LRLJN = 0x00640012,	/* RAW + Jpeg Large Normal */
  
gt: 			EdsImageQuality_LRMJF = 0x00640113,	/* RAW + Jpeg Middle Fine */