#include <windows.h>

#define THIN_CLIENT_OPEN1           16  // Control Code for opening cash drawer 1 of thin client mainboard
#define THIN_CLIENT_STATUS1         17  // Control Code for getting status of cash drawer 1 of thin client mainboard
#define THIN_CLIENT_OPEN2           18  // Control Code for opening cash drawer 2 of thin client  mainboard
#define THIN_CLIENT_STATUS2         19  // Control Code for getting status of cash drawer 2 of thin client mainboard
#define THIN_CLIENT_CASH_DRAWER_IS_OPEN      1
#define THIN_CLIENT_CASH_DRAWER_IS_CLOSED    0 

#define CREATE_FILE_FAILED     -1
#define DEVICE_CONTROL_FAILED  -2

#define CROSSBOW_4710_OPEN1         30  // Control Code for opening cash drawer 1 of IEI 4710 mainboard
#define CROSSBOW_4710_STATUS1       31  // Control Code for getting status of cash drawer 1 of IEI 4710 mainboard
#define CROSSBOW_4710_OPEN2         32  // Control Code for opening cash drawer 2 of IEI 4710 mainboard
#define CROSSBOW_4710_STATUS2       33  // Control Code for getting status of cash drawer 2 of IEI 4710 mainboard
#define CROSSBOW_4710_CASH_DRAWER_IS_OPEN      1
#define CROSSBOW_4710_CASH_DRAWER_IS_CLOSED    0




// szDeviceName ->Device Driver Name
// CTL_ID-> Control Code
__declspec( dllimport ) DWORD WINAPI LoadService(LPSTR szService, LPSTR szImagePath);

__declspec( dllimport ) DWORD WINAPI DeviceControl(LPSTR szDeviceName, DWORD CTL_ID);
__declspec( dllimport ) DWORD WINAPI Crossbow4710GetCashDrawerStatus(LPSTR szDeviceName,DWORD CTL_ID);

__declspec( dllimport ) DWORD WINAPI DeviceControl(LPSTR szDeviceName, DWORD CTL_ID);
__declspec( dllimport ) DWORD WINAPI ThinClientGetCashDrawerStatus(LPSTR szDeviceName,DWORD CTL_ID);

__declspec( dllimport ) DWORD WINAPI UnloadService(LPSTR szService, BOOL bUninstall);

void main()
{
 DWORD ret;

 //ret=0,load driver successfully
 //ret!=0,load driver failed
 ret = LoadService("FEC_cash", "system32\\drivers\\FEC_cash.sys");
 


 //ret=0  -> success
 //ret=-1 -> create file failed
 //ret=-2 -> device io control failed
 ret = DeviceControl("\\\\.\\FEC_cash", THIN_CLIENT_OPEN1+0x280); 

 //THIN_CLIENT_OPEN1+0x280 -> for cash drawer 1 when BIOS setting for DIO is 0x280
 //THIN_CLIENT_OPEN1+0x200 -> for cash drawer 1 when BIOS setting for DIO is 0x200
 //THIN_CLIENT_OPEN1+0x220 -> for cash drawer 1 when BIOS setting for DIO is 0x220
 //THIN_CLIENT_OPEN1+0x240 -> for cash drawer 1 when BIOS setting for DIO is 0x240
 //THIN_CLIENT_OPEN1+0x260 -> for cash drawer 1 when BIOS setting for DIO is 0x260

 
 
  
 //ret=0  -> cash drawer is closed
 //ret=1  -> cash drawer is open
 //ret=-1 -> create file failed
 //ret=-2 -> device io control failed
 ret = ThinClientGetCashDrawerStatus("\\\\.\\FEC_cash", THIN_CLIENT_STATUS1+0x280); 

 //THIN_CLIENT_STATUS1+0x280 -> for cash drawer 1 when BIOS setting for DIO is 0x280
 //THIN_CLIENT_STATUS1+0x200 -> for cash drawer 1 when BIOS setting for DIO is 0x200
 //THIN_CLIENT_STATUS1+0x220 -> for cash drawer 1 when BIOS setting for DIO is 0x220
 //THIN_CLIENT_STATUS1+0x240 -> for cash drawer 1 when BIOS setting for DIO is 0x240
 //THIN_CLIENT_STATUS1+0x260 -> for cash drawer 1 when BIOS setting for DIO is 0x260

	
 //ret=0  -> success
 //ret=-1 -> create file failed
 //ret=-2 -> device io control failed
 ret = DeviceControl("\\\\.\\FEC_cash", CROSSBOW_4710_OPEN1); //for cash drawer 1




 
 //ret=0  -> cash drawer is closed
 //ret=1  -> cash drawer is open
 //ret=-1 -> create file failed
 //ret=-2 -> device io control failed
 ret = Crossbow4710GetCashDrawerStatus("\\\\.\\FEC_cash", CROSSBOW_4710_STATUS1); //for cah drawer 1


 ret = DeviceControl("\\\\.\\FEC_cash", CROSSBOW_4710_OPEN2); //for cash drawer 2

 //ret=0  -> cash drawer is closed
 //ret=1  -> cash drawer is open
 //ret=-1 -> create file failed
 //ret=-2 -> device io control failed
 ret = Crossbow4710GetCashDrawerStatus("\\\\.\\FEC_cash", CROSSBOW_4710_STATUS2); //for cah drawer 2

 //unload driver	 
 ret = UnloadService("FEC_cash", TRUE);





}