using System;
using System.Runtime.InteropServices;

namespace PrinterDemo
{
    public enum ConfigSettings : int
    {
        CV_CAL_STOPSCAN = 0,
        CV_CAL_SET_RESO = 4,
        CV_CAL_STARTSCAN = 6,
        CV_CAL_SET_LIGHT = 8,
        CV_CAL_SET_DEV = 10,
        CV_CAL_FORCESCAN = 11,
        CV_CAL_PAPER = 24,
        CV_CAL_WAITSPOOL = 36
    }

    public enum Resolutions : int
    {
        EACRmFULL2 = 2 //Full res in black and white.
    }

    public enum DeviceCode
    {
        EDEV200A4_1728 = 1,
    }

    public struct CyberImg
    {
        public IntPtr pIm;
        public IntPtr pCoef;
        public IntPtr pGamma;
        public IntPtr pTDens;
        public IntPtr pTSwap;
        //public IntPtr WinBITMAP;
        //public IntPtr WinHDC;
        public int lTime;
        public short wWidBy;
        public short wWid;
        public short wHei;
        public short wNoClr;
        public byte bPlanes;
        public byte bType;
        public byte bRet;
    }

    class CyberSC
    {

        
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void ScanDataCallback(ref CyberImg data);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate bool ScanPartDataCallback(ref CyberImg data);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void ErrorReportCallback(int error, int type);

        

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScInit(ScanDataCallback fpFinScanning, 
            ErrorReportCallback fpError);

        [DllImport("CyberSC.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScSetupPartScan([In, Out]int[] steps, 
            int numSteps, ScanPartDataCallback fpPartScan);

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScSCalibrate(ConfigSettings step, int param);

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScRejectPaper();

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScPOn();

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScPOff();

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ScPString(
            [MarshalAs(UnmanagedType.LPStr)] string str
        );

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScPPower(byte Pow);

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ScPEnd(
            [MarshalAs(UnmanagedType.LPStr)] string Code,
            int Cut
        );

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScPSynch();

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ScPImage(
            [MarshalAs(UnmanagedType.LPStr)] string FullFileName
        );


        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ScPBmp(IntPtr pBmp);


        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScPStatus();

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ScPError();
    }
}
