// Execute.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "sense4.h"
#include <stdio.h>
#include "AccKey.h"


int main(int argc, char* argv[])
{
	SENSE4_CONTEXT * pCtx = NULL;
	DWORD			dwRet;
	DWORD			dwReturned;
	BYTE			outBuff[9];
	BYTE			inBuff[9];
	BYTE			pPin[8]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};

	//Access key
	pCtx = AccessKey();
	if(pCtx == NULL)
	{
		printf("Access device failed.");
		return 0;
	}

	//Change current directory to root directory
	dwRet = S4ChangeDir(pCtx,"\\");
	
	//Verify user PIN
	dwRet=S4VerifyPin(pCtx,pPin,8,S4_USER_PIN);

	//inBuf points to the parameters passed in for executable file
	memcpy(inBuff,"\x02\x12\x34\x56\x78\x9a\xbc\xde\xf0",0x09);

	//Assume the VM executable file 0101 is existent.
	dwRet=S4Execute(pCtx,"0101",inBuff,0x09,outBuff,0x09,&dwReturned);

	//Invoke S4ExecuteEx to execute VM executable file.
	dwRet = S4ExecuteEx(pCtx, "0101", S4_VM_EXE, inBuff, 0x09, outBuff, 0x09, &dwReturned);

	//Assume the XA executable file 0102 is existent, invoke S4ExecuteEx to execute XA executable file.
	dwRet = S4ExecuteEx(pCtx, "0102",  S4_XA_EXE, inBuff, 0x09, outBuff, 0x09, &dwReturned);




	//.......Add your code here......//

	//Close device
	S4Close(pCtx);

	//Free memory
	free(pCtx);
	pCtx = NULL;

	return 0;
}
