// VSCppDemo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

// Encode library. Link ECC200.lib
#include "ECC200.h"

#define CHECK_RES(a) if(res != 0){ printf("Failed %s: %d\n\n", a, res); goto Exit;}
int main()
{
	const int MODULE_SIZE = 3;
	const int QUIET_ZONE_SIZE = 5;
	const char data[] = "2DTG - Your optimum choice in robust performance";
	int res;
	void* encoder = NULL; // Encoder

	// Create encoder
	encoder = CreateSymbol_ECC200();
	if (encoder == NULL)
	{
		printf("Failed CreateSymbol_ECC200\n");
		goto Exit;
	}
	// Set the scheme of the data encoding 
	res = SetScheme_ECC200(encoder, schAUTO);
	CHECK_RES("SetScheme_ECC200");

	// Set the symbol dimensions 
	res = SetDimension_ECC200(encoder, dim_auto);
	CHECK_RES("SetDimension_ECC200");
	
	// Set data to encode
	res = SetDataToEncoding_ECC200(encoder, data, (int)strlen(data));
	CHECK_RES("SetDataToEncoding_ECC200");

	// Encode not protected DMatrix
	res = WriteEncodedSymbolToBMP_ECC200(encoder, MODULE_SIZE, QUIET_ZONE_SIZE, (char*)"NotProt.bmp");
	CHECK_RES("WriteEncodedSymbolToBMP_ECC200");
	
	printf("Not protected matrix - OK\n\n");

	// Protected with User ID - Data Matrix Authentication
	res = SetSignUser_ECC200(encoder, true);
	CHECK_RES("SetSignUser_ECC200");
	res = WriteEncodedSymbolToBMP_ECC200(encoder, MODULE_SIZE, QUIET_ZONE_SIZE, (char*)"USig.bmp");
	CHECK_RES("WriteEncodedSymbolToBMP_ECC200");
	
	printf("Protected with User ID - OK\n\n");

	// Protected with Product ID - Data Matrix Encryption
	res = SetSignUser_ECC200(encoder, false);
	CHECK_RES("SetSignUser_ECC200");
	res = SetSignProduct_ECC200(encoder, true, "s#123456789");
	CHECK_RES("SetSignProduct_ECC200");
	res = WriteEncodedSymbolToBMP_ECC200(encoder, MODULE_SIZE, QUIET_ZONE_SIZE, (char*)"PSig.bmp");
	CHECK_RES("WriteEncodedSymbolToBMP_ECC200");
	
	printf("Protected with Product ID - OK\n\n");

	// Protected both with User ID and Product ID - combined Data Matrix authentication and encryption
	res = SetSignUser_ECC200(encoder, true);
	CHECK_RES("SetSignUser_ECC200");
	res = SetSignProduct_ECC200(encoder, true, "s#123456789");
	CHECK_RES("SetSignProduct_ECC200");
	res = WriteEncodedSymbolToBMP_ECC200(encoder, MODULE_SIZE, QUIET_ZONE_SIZE, (char*)"USigPSig.bmp");
	CHECK_RES("WriteEncodedSymbolToBMP_ECC200");
	
	printf("Protected both with User ID and Product ID - OK\n\n");

Exit:
	// Delete encoder
	if(encoder)
		DeleteSymbol_ECC200(encoder);

	char str[16];
	printf("Press Enter to exit.\n");
	scanf("%c", str);
   return 0;
}

