#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <tchar.h>
#include <stdlib.h>

#include <fcntl.h>
#include <dir.h>


#include <direct.h>
#include <wchar.h>
//#include <locale.h> // wcslen



#include <string.h>


#include "nist_demo.h"


#include "convert_utf8_to_utf16.h"


#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT) {
//INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, INT) {
    g_hInstance = hInstance;
	// Create A Window Class Structure
	WNDCLASSEX wc;
	wc.cbClsExtra = 0;
	wc.cbSize = sizeof(wc);
	wc.cbWndExtra = 0;
	wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
	wc.hCursor = LoadCursor(NULL,(IDC_ARROW));
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	wc.hInstance = GetModuleHandle(NULL);
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = g_szNistClass;
	wc.lpszMenuName = NULL;
	wc.style = CS_VREDRAW|CS_HREDRAW|CS_OWNDC;

	// Register Window Class
	RegisterClassEx(&wc);
	
	RECT rect;
	GetWindowRect(GetDesktopWindow(), &rect);

	// Create a Window
    int top, left;
    int width, height;
    width = 520;
    height = 440;
    left = (rect.right-width)/2; // center Window in screen
    top = (rect.bottom-height)/2; // center Window in screen
	g_hwnd = CreateWindowExW(0, w_g_szNistClass, L"NIST Library Demo", WS_OVERLAPPEDWINDOW, left, top, width, height, (HWND)NULL, (HMENU)NULL, (HINSTANCE)wc.hInstance, 0);
	// Drawing area
	g_bitmapWnd = CreateWindowExW(0, L"Static", L"Static", WS_CHILD|WS_VISIBLE|WS_BORDER|SS_BITMAP, 0,0,330,300, g_hwnd,(HMENU)IMG_BITMAP, (HINSTANCE)wc.hInstance, 0); // SS_BITMAP
	if (!g_bitmapWnd) {
       MessageBoxW(0, L"Not create bitmap area", L"Error", 0);
    }
    
	// Create buttons
	g_hwndCreateAndInsertButton = CreateWindowExW(0, L"BUTTON", L"Create and Insert", WS_CHILD|WS_VISIBLE, 10,317,150,33, g_hwnd,(HMENU)CreateAndInsertButton,NULL,0);
	g_hwndReadAndModifyButton = CreateWindowExW(0, L"BUTTON", L"Read and Modify", WS_CHILD|WS_VISIBLE, 175,317,150,33, g_hwnd,(HMENU)ReadAndModifyButton,NULL,0);
	g_hwndReadAndExportButton = CreateWindowExW(0, L"BUTTON", L"Read and Export", WS_CHILD|WS_VISIBLE, 340,317,150,33, g_hwnd,(HMENU)ReadAndExportButton,NULL,0);
	g_hwndReadSingleFieldButton = CreateWindowExW(0, L"BUTTON", L"Read Single Field", WS_CHILD|WS_VISIBLE, 10,360,150,33, g_hwnd,(HMENU)ReadSingleFieldButton,NULL,0);
	g_hwndDeleteSingleFieldButton = CreateWindowExW(0, L"BUTTON", L"Delete Single Field", WS_CHILD|WS_VISIBLE, 175,360,150,33, g_hwnd,(HMENU)DeleteSingleFieldButton,NULL,0);
	g_hwndRegisterButton = CreateWindowExW(0, L"BUTTON", L"Register", WS_CHILD|WS_VISIBLE, 340,360,150,33, g_hwnd,(HMENU)RegisterButton,NULL,0);
	
	
	ShowWindow(g_hwnd,SW_SHOW);
	
	
	
	w_nist_txt_field = (wchar_t *) malloc(sizeof(wchar_t) * 1024);



	// Message Loop
	MSG msg;
	while(GetMessage(&msg,0,0,0)>0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}

bool LoadNISTLibrary() {
	if (!g_nistLibrary) {
		g_nistLibrary = LoadLibraryW(L"NIST_library.dll");
	}
	if (!g_nistLibrary) {
		MessageBoxW(0, L"Cannot load NIST_library.dll library.", L"Error", 0);
		return false;
	}
	
	
	if (!pRegisterNIST) {
		pRegisterNIST = (RegisterNIST)GetProcAddress(g_nistLibrary, "_RegisterNIST");
	}
	if (!pRegisterNIST) {
		MessageBoxW(0, L"Unable to get address of function _RegisterNIST in NIST_library.dll library.", L"Error", 0);
		return false;
	}	

	if (!pCreateNewNISTFile) {
		pCreateNewNISTFile = (CreateNewNISTFile)GetProcAddress(g_nistLibrary, "_CreateNewNISTFile");
	}
	if (!pCreateNewNISTFile) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _CreateNewNISTFile in NIST_library.dll library.", 0);
		return false;
	}	
	
	if (!pWriteNISTToFile) {
		pWriteNISTToFile = (WriteNISTToFile)GetProcAddress(g_nistLibrary, "_WriteNISTToFile");
	}
	if (!pWriteNISTToFile) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _WriteNISTToFile in NIST_library.dll library.", 0);
		return false;
	}	
	
	
	if (!pReadNISTByteArray) {
		pReadNISTByteArray = (ReadNISTByteArray)GetProcAddress(g_nistLibrary, "_ReadNISTByteArray");
	}
	if (!pReadNISTByteArray) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadNISTByteArray in NIST_library.dll library.", 0);
		return false;
	}	
	
	
	if (!pReadSizeOfNISTByteArray) {
		pReadSizeOfNISTByteArray = (ReadSizeOfNISTByteArray)GetProcAddress(g_nistLibrary, "_ReadSizeOfNISTByteArray");
	}
	if (!pReadSizeOfNISTByteArray) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfNISTByteArray in NIST_library.dll library.", 0);
		return false;
	}			
	
	if (!pReadNISTFromFile) {
		pReadNISTFromFile = (ReadNISTFromFile)GetProcAddress(g_nistLibrary, "_ReadNISTFromFile");
	}
	if (!pReadNISTFromFile) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadNISTFromFile in NIST_library.dll library.", 0);
		return false;
	}
	
	
	if (!pReadNISTFromMemory) {
		pReadNISTFromMemory = (ReadNISTFromMemory)GetProcAddress(g_nistLibrary, "_ReadNISTFromMemory");
	}
	if (!pReadNISTFromMemory) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadNISTFromMemory in NIST_library.dll library.", 0);
		return false;
	}


	if (!pCheckIfRecordTypeExists) {
		pCheckIfRecordTypeExists = (CheckIfRecordTypeExists)GetProcAddress(g_nistLibrary, "_CheckIfRecordTypeExists");
	}
	if (!pCheckIfRecordTypeExists) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _CheckIfRecordTypeExists in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadNumberOfRecords) {
		pReadNumberOfRecords = (ReadNumberOfRecords)GetProcAddress(g_nistLibrary, "_ReadNumberOfRecords");
	}
	if (!pReadNumberOfRecords) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadNumberOfRecords in NIST_library.dll library.", 0);
		return false;
	}
	
	
	if (!pReadIDCofRecord) {
		pReadIDCofRecord = (ReadIDCofRecord)GetProcAddress(g_nistLibrary, "_ReadIDCofRecord");
	}
	if (!pReadIDCofRecord) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadIDCofRecord in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadRecordTxtField) {
		pReadRecordTxtField = (ReadRecordTxtField)GetProcAddress(g_nistLibrary, "_ReadRecordTxtField");
	}
	if (!pReadRecordTxtField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadRecordTxtField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadSizeOfRecordTxtField) {
		pReadSizeOfRecordTxtField = (ReadSizeOfRecordTxtField)GetProcAddress(g_nistLibrary, "_ReadSizeOfRecordTxtField");
	}
	if (!pReadSizeOfRecordTxtField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfRecordTxtField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadRecordTxtFieldName) {
		pReadRecordTxtFieldName = (ReadRecordTxtFieldName)GetProcAddress(g_nistLibrary, "_ReadRecordTxtFieldName");
	}
	if (!pReadRecordTxtFieldName) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadRecordTxtFieldName in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadSizeOfRecordTxtFieldName) {
		pReadSizeOfRecordTxtFieldName = (ReadSizeOfRecordTxtFieldName)GetProcAddress(g_nistLibrary, "_ReadSizeOfRecordTxtFieldName");
	}
	if (!pReadSizeOfRecordTxtFieldName) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfRecordTxtFieldName in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadRecordTxtFieldDescription) {
		pReadRecordTxtFieldDescription = (ReadRecordTxtFieldDescription)GetProcAddress(g_nistLibrary, "_ReadRecordTxtFieldDescription");
	}
	if (!pReadRecordTxtFieldDescription) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadRecordTxtFieldDescription in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadSizeOfRecordTxtFieldDescription) {
		pReadSizeOfRecordTxtFieldDescription = (ReadSizeOfRecordTxtFieldDescription)GetProcAddress(g_nistLibrary, "_ReadSizeOfRecordTxtFieldDescription");
	}
	if (!pReadSizeOfRecordTxtFieldDescription) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfRecordTxtFieldDescription in NIST_library.dll library.", 0);
		return false;
	}
	

	if (!pReadRecordExportedTxtFields) {
		pReadRecordExportedTxtFields = (ReadRecordExportedTxtFields)GetProcAddress(g_nistLibrary, "_ReadRecordExportedTxtFields");
	}
	if (!pReadRecordExportedTxtFields) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadRecordExportedTxtFields in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadSizeOfRecordExportedTxtFields) {
		pReadSizeOfRecordExportedTxtFields = (ReadSizeOfRecordExportedTxtFields)GetProcAddress(g_nistLibrary, "_ReadSizeOfRecordExportedTxtFields");
	}
	if (!pReadSizeOfRecordExportedTxtFields) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfRecordExportedTxtFields in NIST_library.dll library.", 0);
		return false;
	}

	if (!pReadRecordBinaryField) {
		pReadRecordBinaryField = (ReadRecordBinaryField)GetProcAddress(g_nistLibrary, "_ReadRecordBinaryField");
	}
	if (!pReadRecordBinaryField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadRecordBinaryField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pReadSizeOfRecordBinaryField) {
		pReadSizeOfRecordBinaryField = (ReadSizeOfRecordBinaryField)GetProcAddress(g_nistLibrary, "_ReadSizeOfRecordBinaryField");
	}
	if (!pReadSizeOfRecordBinaryField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _ReadSizeOfRecordBinaryField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pCreateHBITMAPfromRecordBinaryField) {
		pCreateHBITMAPfromRecordBinaryField = (CreateHBITMAPfromRecordBinaryField)GetProcAddress(g_nistLibrary, "_CreateHBITMAPfromRecordBinaryField");
	}
	if (!pCreateHBITMAPfromRecordBinaryField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _CreateHBITMAPfromRecordBinaryField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pInsertRecordBinaryFieldFromFile) {
		pInsertRecordBinaryFieldFromFile = (InsertRecordBinaryFieldFromFile)GetProcAddress(g_nistLibrary, "_InsertRecordBinaryFieldFromFile");
	}
	if (!pInsertRecordBinaryFieldFromFile) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _InsertRecordBinaryFieldFromFile in NIST_library.dll library.", 0);
		return false;
	}


	if (!pInsertRecordBinaryFieldFromMemory) {
		pInsertRecordBinaryFieldFromMemory = (InsertRecordBinaryFieldFromMemory)GetProcAddress(g_nistLibrary, "_InsertRecordBinaryFieldFromMemory");
	}
	if (!pInsertRecordBinaryFieldFromMemory) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _InsertRecordBinaryFieldFromMemory in NIST_library.dll library.", 0);
		return false;
	}


	if (!pInsertRecordTxtField) {
		pInsertRecordTxtField = (InsertRecordTxtField)GetProcAddress(g_nistLibrary, "_InsertRecordTxtField");
	}
	if (!pInsertRecordTxtField) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _InsertRecordTxtField in NIST_library.dll library.", 0);
		return false;
	}


	if (!pDeleteRecord) {
		pDeleteRecord = (DeleteRecord)GetProcAddress(g_nistLibrary, "_DeleteRecord");
	}
	if (!pDeleteRecord) {
		MessageBoxW(0, L"Error", L"Unable to get address of function _DeleteRecord in NIST_library.dll library.", 0);
		return false;
	}

//=================









	if (!g_bitmapWnd) {
		MessageBoxW(0, L"Unable to create image display object.", L"Error", 0);
		return false;
	}


   //Gets full filename of the program
   GetModuleFileNameW(0, program_file_path, _MAX_PATH);

   wchar_t *ptr;
   ptr = wcschr(program_file_path, '\0');  //Scans a string for the first occurrence of a given character

   // Extracts file path from full filename
   while(*ptr != '\\')
   {*ptr--;}
   *(ptr+1) = '\0';	
	
	
	return true;
}



void RegisterButtonClick() {

	if (!LoadNISTLibrary()) 
	{return;}

	pRegisterNIST();
}




void CreateAndInsertButtonClick() {

	if (!LoadNISTLibrary()) 
	{return;}


    EnableWindow(g_hwndCreateAndInsertButton, false);
    EnableWindow(g_hwndReadAndModifyButton, false);
    EnableWindow(g_hwndReadAndExportButton, false);
    EnableWindow(g_hwndReadSingleFieldButton, false);
    EnableWindow(g_hwndDeleteSingleFieldButton, false);
    EnableWindow(g_hwndRegisterButton, false);
    hcurSave = SetCursor(LoadCursor(0, IDC_WAIT));



   //Creates new empty NIST file
   pCreateNewNISTFile();

//======================================================
 //======================================================
    MessageBoxW(0, L"Inserting/replacing Type-1 and Type-2 records...", L"NIST library", MB_OK);

   //Type-1 record Logical record length (LEN) field is handled automatically
   //and the value of the "LEN" field cannot be changed manually.
   //(pInsertType1Record)("LEN", "100");

   //You can modify value of Type-1 record Version number (VER) field, however please keep in mind that
   //the entry in "VER" field for ANSI/NIST-ITL 1-2000 approved standard must be "0300".
   //(pInsertType1Record)("VER", "0300");

   //Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
   (pInsertRecordTxtField)(1, -1, -1, "TOT", "IMG");

   //Modifies NIST file, inserts/replaces Type-1 record date (DAT)
   (pInsertRecordTxtField)(1, -1, -1, "DAT", "20081031");

   //Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
   //The length of Priority (PRY) field must be equal to 1 bytes
   (pInsertRecordTxtField)(1, -1, -1, "PRY", "1");

   //Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
   (pInsertRecordTxtField)(1, -1, -1, "DAI", "Central Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
   (pInsertRecordTxtField)(1, -1, -1, "ORI", "Local Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
   (pInsertRecordTxtField)(1, -1, -1, "TCN", "000045321");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
   (pInsertRecordTxtField)(1, -1, -1, "TCR", "0000078901");

   //Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
   //The length of Native scanning resolution(NSR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NSR", "19.69");

   //Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
   //The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NTR", "19.69");

   //Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
   (pInsertRecordTxtField)(1, -1, -1, "DOM", "NORAM");

   //Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
   //The length of Greenwich mean time (GMT) field must be equal to 15 bytes
   (pInsertRecordTxtField)(1, -1, -1, "GMT", "20081031152345Z");


   //Modifies NIST file, inserts three Type-2 records,
   //if these records already exist then they are overwritten and replaced

   //Inserts first Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "James Clerk");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Maxwell");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "Berlin, Germany");

   //Inserts second Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "John Smith");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Watson");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "London, UK");

   //Inserts third Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "Alphonse Gabriel");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Al Capone");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "New York, USA");




   //Sets input directory as "input" subdirectory of the program location
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");


    MessageBoxW(0, L"Inserting/replacing Type-4 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts 14 Type-4 records (inserts 14 fingerprint WSQ images).
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_01.wsq");      
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "10");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_02.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "9");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_03.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "8");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_04.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "7");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_05.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "6");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_06.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "5");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_07.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "4");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_08.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "3");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_09.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "2");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_10.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "1");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_11.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "14");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_12.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "13");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_13.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "12");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_14.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "11");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");





//Fields of the Type-7 logical record are user-defined.
//Individual fields required for a given transaction, such as field description,
//size, and content shall conform to the specifications set forth by the agency
//to whom the transmission is being sent.
//L"NIST library" uses Interpol Implementation of the Type-7 logical record,
//prepared by The Interpol AFIS Expert Group, version No. 4.22b � October 28, 2005
    MessageBoxW(0, L"Inserting/replacing Type-7 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-7 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_01.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "25");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_02.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "26");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_03.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "21");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_04.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "22");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");



    MessageBoxW(0, L"Inserting/replacing Type-8 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-8 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type8_01.bin");
   idc_current = (pInsertRecordBinaryFieldFromFile)(8, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(8, idc_current, -1, "SIG", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "SRT", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "ISR", "1");
//  HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "HLL", "1000");
//  VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "VLL", "500");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type8_02.bin");
   idc_current = (pInsertRecordBinaryFieldFromFile)(8, -1, convert_utf16_to_utf8((char*)filename));

   (pInsertRecordTxtField)(8, idc_current, -1, "SIG", "1");
   (pInsertRecordTxtField)(8, idc_current, -1, "SRT", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "ISR", "1");
//  HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "HLL", "1000");
//  VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "VLL", "500");





    MessageBoxW(0, L"Inserting/replacing Type-10 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-10 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_01.jpg");
//   wcscat(filename, L"type10_01.png");
//   wcscat(filename, L"type10_01.jp2");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");
//   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"SCAR");


   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPEGB");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"F");  //Full Face Frontal




   filename[0] = 0;
   wcscat(filename, filedirectory);
//   wcscat(filename, L"type10_02.jpg");
   wcscat(filename, L"type10_02.png");
//   wcscat(filename, L"type10_02.jp2");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "PNG");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"R");  //Right Profile


   filename[0] = 0;
   wcscat(filename, filedirectory);
//   wcscat(filename, L"type10_03.jpg");
//   wcscat(filename, L"type10_03.png");
   wcscat(filename, L"type10_03.jp2");


   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JP2" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JP2");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"A");  //Angled Pose





    MessageBoxW(0, L"Inserting/replacing Type-13 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-13 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type13_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(13, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Impression type (IMP)
   (pInsertRecordTxtField)(13, idc_current, -1, "IMP" ,"6");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(13, idc_current, -1, "SRC" ,"MDNISTVIP");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Latent capture date (LCD)
   (pInsertRecordTxtField)(13, idc_current, -1, "LCD" ,"19990707");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Scale units (SLC)
   (pInsertRecordTxtField)(13, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(13, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(13, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-13 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(13, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(13, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Finger / palm position (FGP)
   (pInsertRecordTxtField)(13, idc_current, -1, "FGP" ,"8");



    MessageBoxW(0, L"Inserting/replacing Type-14 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-14 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type14_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(14, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
   (pInsertRecordTxtField)(14, idc_current, -1, "IMP" ,"3");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SRC" ,"MDNISTVIP");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
   (pInsertRecordTxtField)(14, idc_current, -1, "TCD" ,"19990707");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-14 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(14, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(14, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
   (pInsertRecordTxtField)(14, idc_current, -1, "FGP" ,"8");



    MessageBoxW(0, L"Inserting/replacing Type-15 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-15 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"24");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_02.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"25");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_03.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"27");



    MessageBoxW(0, L"Inserting/replacing Type-16 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-16 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type16_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(16, -1, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-16 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(16, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "CSP" ,"A01");





   //Sets output file name as "sample_modified.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(_waccess(filedirectory, 0) != 0)
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_new.nist");




   //Saves NIST into the file "sample_new.nist" (in "output" subdirectory)
   //(pWriteNISTToFile)(convert_utf16_to_utf8((char*)filename));

   //Instead function WriteNISTToFile you can use function ReadNISTByteArray and save NIST byte array manually (the code bellow)
//==========================
     byte_array = (pReadNISTByteArray)();
     size_of_byte_array = (pReadSizeOfNISTByteArray)();

	 if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0,  L"Error: open file failed", L"NIST Library Error", MB_OK );}
     if((n = fwrite(byte_array, sizeof(unsigned char), size_of_byte_array, outfp)) != size_of_byte_array)
     {MessageBoxW(0,  L"Error: write to file failed", L"NIST Library Error", MB_OK );}
     fclose(outfp);
//==========================


    MessageBoxW(0, L"New NIST file was created, modified and saved as\n\".\\output\\sample_new.nist\"\nPlease use \"NIST viewer\" to view\n\"sample_new.nist\" file.", L"NIST Library Demo", MB_OK);


   
    EnableWindow(g_hwndCreateAndInsertButton, true);
    EnableWindow(g_hwndReadAndModifyButton, true);
    EnableWindow(g_hwndReadAndExportButton, true);
    EnableWindow(g_hwndReadSingleFieldButton, true);
    EnableWindow(g_hwndDeleteSingleFieldButton, true);
    EnableWindow(g_hwndRegisterButton, true);
	  SetCursor(hcurSave);



}

void ReadAndModifyButtonClick() {

	if (!LoadNISTLibrary()) 
	{return;}


    EnableWindow(g_hwndCreateAndInsertButton, false);
    EnableWindow(g_hwndReadAndModifyButton, false);
    EnableWindow(g_hwndReadAndExportButton, false);
    EnableWindow(g_hwndReadSingleFieldButton, false);
    EnableWindow(g_hwndDeleteSingleFieldButton, false);
    EnableWindow(g_hwndRegisterButton, false);
    hcurSave = SetCursor(LoadCursor(0, IDC_WAIT));  



   //Sets input file name as "sample.nist" which located in "input" subdirectory
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");
   wcscat(filename, filedirectory);
   wcscat(filename, L"sample.nist");


   if(_waccess(filename, 0) != 0)
   {
   MessageBoxW(0, L"Error: file .\\input\\sample.nist does not exist.", L"Error", MB_OK);
   return;
   }


   //Reads NIST file
   (pReadNISTFromFile)(convert_utf16_to_utf8((char*)filename));


   //Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
   (pInsertRecordTxtField)(1, -1, -1, "TOT", "WSQ");

   //Modifies NIST file, inserts/replaces Type-1 record Date (DAT)
   (pInsertRecordTxtField)(1, -1, -1, "DAT", "20080931");

   //Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
   //The length of Priority (PRY) field must be equal to 1 bytes
   (pInsertRecordTxtField)(1, -1, -1, "PRY", "2");

   //Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
   (pInsertRecordTxtField)(1, -1, -1, "DAI", "Central Intelligence Agency");

   //Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
   (pInsertRecordTxtField)(1, -1, -1, "ORI", "Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
   (pInsertRecordTxtField)(1, -1, -1, "TCN", "000000123");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
   (pInsertRecordTxtField)(1, -1, -1, "TCR", "000000987");

   //Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
   //The length of Native scanning resolution(NSR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NSR", "21.33");

   //Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
   //The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NTR", "21.33");

   //Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
   (pInsertRecordTxtField)(1, -1, -1, "DOM", "NORAM");

   //Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
   //The length of Greenwich mean time (GMT) field must be equal to 15 bytes
   (pInsertRecordTxtField)(1, -1, -1, "GMT", "20080931170316Z");


   //Modifies NIST file, inserts two Type-2 records,
   //if these records already exist then they are overwritten and replaced
   idc = 0;
   (pInsertRecordTxtField)(2, idc, 30, "", "William Thompson");
   (pInsertRecordTxtField)(2, idc, 31, "", "Kelvin");



   //Sets input directory as "input" subdirectory of the program location
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");


//Modifies NIST file, inserts Type-4 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_left_thumb.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, 7, convert_utf16_to_utf8((char*)filename));


   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "6");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_right_thumb.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, 12, convert_utf16_to_utf8((char*)filename));
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "1");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



//Modifies NIST file, inserts Type-10 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_Charles_Luciano_frontal.jpg");


   idc_current = (pInsertRecordBinaryFieldFromFile)(10, 23, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
//   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"SCAR");


   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPEGB");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"F");  //Full Face Frontal




   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_Charles_Luciano_profile.jpg");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, 24, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPG");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"R");  //Right Profile


//Modifies NIST file, inserts Type-14 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type14_replace_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(14, 27, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
   (pInsertRecordTxtField)(14, idc_current, -1, "IMP" ,"0");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
   (pInsertRecordTxtField)(14, idc_current, -1, "TCD" ,"19990923");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-13 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(14, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(14, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
   (pInsertRecordTxtField)(14, idc_current, -1, "FGP" ,"14");



/*
//Modifies NIST file, inserts Type-16 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type16_replace_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(16, 29, convert_utf16_to_utf8((char*)filename));

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-16 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(16, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "CSP" ,"A01");
*/





   //Sets output file name as "sample_modified.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(_waccess(filedirectory, 0) != 0)
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_modified.nist");


   //Saves NIST into the file "sample_modified.nist" (in "output" subdirectory)
   (pWriteNISTToFile)(convert_utf16_to_utf8((char*)filename));

    MessageBoxW(0, L"NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_modified.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_modified.nist\" file.", L"NIST Library Demo", MB_OK);

	

    EnableWindow(g_hwndCreateAndInsertButton, true);
    EnableWindow(g_hwndReadAndModifyButton, true);
    EnableWindow(g_hwndReadAndExportButton, true);
    EnableWindow(g_hwndReadSingleFieldButton, true);
    EnableWindow(g_hwndDeleteSingleFieldButton, true);
    EnableWindow(g_hwndRegisterButton, true);
    SetCursor(hcurSave);


}





void ReadAndExportButtonClick() {
	
	if (!LoadNISTLibrary()) 
	{return;}
	
	
    EnableWindow(g_hwndCreateAndInsertButton, false);
    EnableWindow(g_hwndReadAndModifyButton, false);
    EnableWindow(g_hwndReadAndExportButton, false);
    EnableWindow(g_hwndReadSingleFieldButton, false);
    EnableWindow(g_hwndDeleteSingleFieldButton, false);
    EnableWindow(g_hwndRegisterButton, false);
    hcurSave = SetCursor(LoadCursor(0, IDC_WAIT));	
	
	

   //Sets output directory (".\output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(_waccess(filedirectory, 0) != 0)
   {
   // Create output directory
   _wmkdir(filedirectory);
   }



	
	const wchar_t* strFilter = L"NIST files\0*.nist\0All files\0*.*\0\0";


    wchar_t szFileName[MAX_PATH] = { 0 };
    OPENFILENAMEW ofn;
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = 0;
    ofn.hInstance = 0;
    ofn.lpstrFilter = strFilter;
    ofn.nFilterIndex = 1;
    ofn.nMaxFile = MAX_PATH;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = 0;
    ofn.lpstrDefExt= 0;
    ofn.lpstrFile = szFileName;
    ofn.Flags = OFN_FILEMUSTEXIST | OFN_READONLY;

      if (!GetOpenFileNameW(&ofn)) {
         return ; // cancel open file
      }

//=============================
     // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
//    (pReadNISTFromFile)(szFileName);


     //Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
//==========================
     handle = _wopen(szFileName, O_RDONLY);

     if((ret = filelength(handle)) < 0)
     {MessageBoxW(0, L"Error: filelength < 0", L"Error", MB_OK);}
     size_of_byte_array = ret;

     if((infp = _wfopen(szFileName, L"rb")) == (FILE *)NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}

     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}

     byte_array = (unsigned char *)malloc(size_of_byte_array * sizeof(unsigned char));
     if(byte_array == (unsigned char *)NULL)
     {MessageBoxW(0, L"Error: malloc for buffer failed", L"Error", MB_OK);}

     n = fread(byte_array, sizeof(unsigned char), size_of_byte_array, infp);
     if(n != size_of_byte_array)
     {MessageBoxW(0, L"Error: reading file failed", L"Error", MB_OK);}

     fclose(infp);
     close(handle);



     // Loads NIST file contents from memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
     (pReadNISTFromMemory)(byte_array, size_of_byte_array);

     // Here you need to free memory resources.
     // byte_array is no longer needed after it has been read and decoded into usable format.
     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}
//==========================



if(pCheckIfRecordTypeExists(1) == 1)
{
     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(1, 0);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(1, 0);

	 // Sets filename for saving exported data of text field from Type-1 record
	 filename[0] = 0;
	 wcscat(filename, filedirectory);
	 wcscat(filename, L"type1.txt");

     // Writes exported data of text field from Type-1 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     MessageBoxW(0, L"Type-1 record text field was exported to file .\\output\\type1.txt", L"NIST library", MB_OK);

}//if(pCheckIfRecordTypeExists(1) == 1)


if(pCheckIfRecordTypeExists(2) == 1)
{
     type_2_number_of_records = (pReadNumberOfRecords)(2);

     // In Type-2 record there might be up to 12 fingerprint images.
     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_2_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(2, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(2, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(2, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-2 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type2_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 


     // Writes exported data of text field from Type-2 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

	 output_message[0] = 0;
	 wcscat(output_message, L"Type-2 record text field was exported to file .\\output\\type2_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.");
     MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }



     }//for(int i = 1; i <= type_2_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(2) == 1)



if(pCheckIfRecordTypeExists(4) == 1)
{
     type_4_number_of_records = (pReadNumberOfRecords)(4);

     // In Type-4 record there might be up to 14 fingerprint images.
     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(4, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(4, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(4, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-4 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type4_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-4 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(4, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(4, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(4, idc, -1, "GCA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-4 record
     filename[0] = 0;
	 wcscpy(filename, filedirectory);
	 wcscat(filename, L"type4_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	 

	 output_message[0] = 0;
	 wcscat(output_message, L"Type-4 record text field was exported to file .\\output\\type4_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-4 record binary field was exported to file .\\output\\type4_");
	 wcscat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nHigh-resolution grayscale fingerprint image was extracted from Type-4 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");

	 // Writes exported data of binary field from Type-4 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
	 {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

	// Converts NIST file binary field contents into HBITMAP image.
	// Returns image in HBITMAP format if successful, returns NULL otherwise.
	hBitmap = (pCreateHBITMAPfromRecordBinaryField)(4, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)


     }

     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(4) == 1)


if(pCheckIfRecordTypeExists(7) == 1)
{
     type_7_number_of_records = (pReadNumberOfRecords)(7);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(7, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(7, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(7, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-7 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type7_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

	 // Writes exported data of text field from Type-7 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
	 {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

	 }

	 // Returns size of binary NIST field.
	 size = (pReadSizeOfRecordBinaryField)(7, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
	 // returns NULL otherwise.
	 nist_binary_field = (pReadRecordBinaryField)(7, idc);

	 if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(7, idc, -1, "GCA");
	 strcpy(image_compression_code, p_image_compression_code);


	 // Sets filename for saving exported data of binary field from Type-7 record
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-7 record text field was exported to file .\\output\\type7_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-7 record binary field was exported to file .\\output\\type7_");
	 wcscat(output_message, int_converted_to_string);

	 filename[0] = 0;
	 wcscpy(filename, filedirectory);
	 wcscat(filename, L"type7_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);		 

	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nUser-defined image was extracted from Type-7 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-7 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(7, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)

     }

     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(7) == 1)



if(pCheckIfRecordTypeExists(8) == 1)
{
     type_8_number_of_records = (pReadNumberOfRecords)(8);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(8, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(8, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(8, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-8 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type8_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

	 // Writes exported data of text field from Type-8 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
	 {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

	 }

	 // Returns size of binary NIST field.
	 size = (pReadSizeOfRecordBinaryField)(8, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
	 // returns NULL otherwise.
	 nist_binary_field = (pReadRecordBinaryField)(8, idc);

	 if(nist_binary_field)
	 {
	 // Sets filename for saving exported data of binary field from Type-8 record
	 filename[0] = 0;
	 wcscpy(filename, filedirectory);
	 wcscat(filename, L"type8_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	
	 wcscat(filename, L".bin");

	 output_message[0] = 0;
	 wcscat(output_message, L"Type-8 record text field was exported to file .\\output\\type8_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-8 record binary field was exported to file .\\output\\type8_");
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".bin.");

	 wcscat(output_message, L"\n\nSignature image was extracted from Type-8 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");

     // Writes exported data of binary field from Type-8 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(8, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(8) == 1)



if(pCheckIfRecordTypeExists(9) == 1)
{
     type_9_number_of_records = (pReadNumberOfRecords)(9);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(9, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(9, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(9, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-9 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type9_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-9 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(9, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(9, idc);

     if(nist_binary_field)
	 {
	 //p_image_compression_code = (pReadRecordTxtField)(10, idc, -1, "CGA");
	 //strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-9 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type9_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	
     wcscat(filename, L".wsq");


	 output_message[0] = 0;
	 wcscat(output_message, L"Type-9 record text field was exported to file .\\output\\type9_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-9 record binary field was exported to file .\\output\\type9_");
	 wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L".wsq.");


//	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
//	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
//	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
//	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
//	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
//	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
//	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
//	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
//	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
//	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nMinutiae data was extracted from Type-9 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");



     // Writes exported data of binary field from Type-9 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(9, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)




if(pCheckIfRecordTypeExists(10) == 1)
{
     type_10_number_of_records = (pReadNumberOfRecords)(10);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(10, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(10, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(10, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-10 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type10_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-10 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(10, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(10, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(10, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-10 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type10_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	


	 output_message[0] = 0;
	 wcscat(output_message, L"Type-10 record text field was exported to file .\\output\\type10_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-10 record binary field was exported to file .\\output\\type10_");
	 wcscat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nFacial & SMT image was extracted from Type-10 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");



     // Writes exported data of binary field from Type-10 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(10, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(10) == 1)




if(pCheckIfRecordTypeExists(13) == 1)
{
     type_13_number_of_records = (pReadNumberOfRecords)(13);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(13, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(13, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(13, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-13 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type13_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-13 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(13, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(13, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(13, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-13 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type13_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	

	 output_message[0] = 0;
	 wcscat(output_message, L"Type-13 record text field was exported to file .\\output\\type13_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-13 record binary field was exported to file .\\output\\type13_");
	 wcscat(output_message, int_converted_to_string);

	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nVariable-resolution latent image was extracted from Type-13 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-13 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(13, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)



if(pCheckIfRecordTypeExists(14) == 1)
{
     type_14_number_of_records = (pReadNumberOfRecords)(14);


     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(14, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(14, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(14, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-14 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type14_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-14 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(14, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(14, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(14, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-14 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type14_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	


	 output_message[0] = 0;
	 wcscat(output_message, L"Type-14 record text field was exported to file .\\output\\type14_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-14 record binary field was exported to file .\\output\\type14_");
	 wcscat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nVariable-resolution fingerprint image was extracted from Type-14 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-14 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(14, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)


if(pCheckIfRecordTypeExists(15) == 1)
{
     type_15_number_of_records = (pReadNumberOfRecords)(15);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(15, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(15, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(15, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-15 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type15_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-15 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(15, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(15, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(15, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-15 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type15_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);	


	 output_message[0] = 0;
	 wcscat(output_message, L"Type-15 record text field was exported to file .\\output\\type15_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-15 record binary field was exported to file .\\output\\type15_");
	 wcscat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nVariable-resolution palmprint image was extracted from Type-15 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-15 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(15, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)


if(pCheckIfRecordTypeExists(16) == 1)
{
     type_16_number_of_records = (pReadNumberOfRecords)(16);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(16, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(16, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(16, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-16 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type16_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
	 wcscat(filename, L".txt."); 

     // Writes exported data of text field from Type-16 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(16, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(16, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(16, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-16 record
     filename[0] = 0;
     wcscpy(filename, filedirectory);
     wcscat(filename, L"type16_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(filename, int_converted_to_string);
     wcscpy(filename, filename);


	 output_message[0] = 0;
	 wcscat(output_message, L"Type-16 record text field was exported to file .\\output\\type16_");
	 _itow(idc, int_converted_to_string, 10);
	 wcscat(output_message, int_converted_to_string);
	 wcscat(output_message, L".txt.\n\nType-16 record binary field was exported to file .\\output\\type16_");
	 wcscat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); wcscat(output_message, L".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); wcscat(output_message, L".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); wcscat(output_message, L".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); wcscat(output_message, L".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); wcscat(output_message, L".png.");}

	 wcscat(output_message, L"\n\nVariable-resolution user-defined testing image was extracted from Type-16 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-16 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {MessageBoxW(0, L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

    // Converts NIST file binary field contents into HBITMAP image.
    // Returns image in HBITMAP format if successful, returns NULL otherwise.
    hBitmap = (pCreateHBITMAPfromRecordBinaryField)(16, idc);

     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)



     }

     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)






    EnableWindow(g_hwndCreateAndInsertButton, true);
    EnableWindow(g_hwndReadAndModifyButton, true);
    EnableWindow(g_hwndReadAndExportButton, true);
    EnableWindow(g_hwndReadSingleFieldButton, true);
    EnableWindow(g_hwndDeleteSingleFieldButton, true);
    EnableWindow(g_hwndRegisterButton, true);
	  SetCursor(hcurSave);
    



}





void ReadSingleFieldButtonClick() {

	if (!LoadNISTLibrary()) 
	{return;}

	const wchar_t* strFilter = L"NIST files\0*.nist\0All files\0*.*\0\0";


    wchar_t szFileName[MAX_PATH] = { 0 };
    OPENFILENAMEW ofn;
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = 0;
    ofn.hInstance = 0;
    ofn.lpstrFilter = strFilter;
    ofn.nFilterIndex = 1;
    ofn.nMaxFile = MAX_PATH;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = 0;
    ofn.lpstrDefExt= 0;
    ofn.lpstrFile = szFileName;
    ofn.Flags = OFN_FILEMUSTEXIST | OFN_READONLY;

      if (!GetOpenFileNameW(&ofn)) {
         return ; // cancel open file
      }
      

    EnableWindow(g_hwndCreateAndInsertButton, false);
    EnableWindow(g_hwndReadAndModifyButton, false);
    EnableWindow(g_hwndReadAndExportButton, false);
    EnableWindow(g_hwndReadSingleFieldButton, false);
    EnableWindow(g_hwndDeleteSingleFieldButton, false);
    EnableWindow(g_hwndRegisterButton, false);
    hcurSave = SetCursor(LoadCursor(0, IDC_WAIT));



//=============================
     // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
//    (pReadNISTFromFile)(szFileName);


     //Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
//==========================
     handle = _wopen(szFileName, O_RDONLY);

     if((ret = filelength(handle)) < 0)
     {MessageBoxW(0, L"Error: filelength < 0", L"Error", MB_OK);}
     size_of_byte_array = ret;

	 if((infp = _wfopen(szFileName, L"rb")) == (FILE *)NULL)
     {MessageBoxW(0, L"Error: open file failed", L"Error", MB_OK);}

     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}

     byte_array = (unsigned char *)malloc(size_of_byte_array * sizeof(unsigned char));
     if(byte_array == (unsigned char *)NULL)
     {MessageBoxW(0, L"Error: malloc for buffer failed", L"Error", MB_OK);}

     n = fread(byte_array, sizeof(unsigned char), size_of_byte_array, infp);
     if(n != size_of_byte_array)
     {MessageBoxW(0, L"Error: reading file failed", L"Error", MB_OK);}

     fclose(infp);
     close(handle);



     // Loads NIST file contents from memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
     (pReadNISTFromMemory)(byte_array, size_of_byte_array);

     // Here you need to free memory resources.
     // byte_array is no longer needed after it has been read and decoded into usable format.
     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}
//==========================


if(pCheckIfRecordTypeExists(1) == 1)
{

     output_message[0] = 0;

     wcscat(output_message, L"Type-1 record field values were read in cycle using field number\n\n");

     for(int i = 1; i < 16; i++)
     {
     wcscat(output_message, L"Type-1 record ");
     //Reads Type-1 record i Field Description
     nist_txt_field = (pReadRecordTxtFieldDescription)(1, -1, i, "");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
     wcscat(output_message, L" (");
     //Reads Type-1 record i Field Name
     nist_txt_field = (pReadRecordTxtFieldName)(1, -1, i);
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
     wcscat(output_message, L") = ");
     //Reads Type-1 record i Field Value
     nist_txt_field = (pReadRecordTxtField)(1, -1, i, "");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
     wcscat(output_message, L"\n");
     }
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     output_message[0] = 0;

     wcscat(output_message, L"Type-1 record field values were read using field names\n\n");

     //Reads Type-1 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "LEN");
     wcscat(output_message, L"Type-1 record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Version number (VER) of the standard implemented by the software or system creating the file
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "VER");
     wcscat(output_message, L"\nType-1 record Version number (VER) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record File content (CNT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "CNT");
     wcscat(output_message, L"\nType-1 record File content (CNT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Type of transaction (TOT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TOT");
     wcscat(output_message, L"\nType-1 record Type of transaction (TOT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Date (DAT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DAT");
     wcscat(output_message, L"\nType-1 record Date (DAT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Priority (PRY)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "PRY");
     wcscat(output_message, L"\nType-1 record Priority (PRY) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Destination agency identifier (DAI)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DAI");
     wcscat(output_message, L"\nType-1 record Destination agency identifier (DAI) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Originating agency identifier (ORI)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "ORI");
     wcscat(output_message, L"\nType-1 record Originating agency identifier (ORI) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Transaction control number (TCN)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TCN");
     wcscat(output_message, L"\nType-1 record Transaction control number (TCN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Transaction control reference (TCR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TCR");
     wcscat(output_message, L"\nType-1 record Transaction control reference (TCR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Native scanning resolution(NSR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "NSR");
     wcscat(output_message, L"\nType-1 record Native scanning resolution (NSR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Nominal transmitting resolution (NTR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "NTR");
     wcscat(output_message, L"\nType-1 record Nominal transmitting resolution (NTR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Domain name (DOM)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DOM");
     wcscat(output_message, L"\nType-1 record Domain name (DOM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Greenwich mean time (GMT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "GMT");
     wcscat(output_message, L"\nType-1 record Greenwich mean time (GMT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-1 record Directory of character sets (DCS)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DCS");
     wcscat(output_message, L"\nType-1 record Directory of character sets (DCS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


}//if(CheckIfRecordTypeExists(1) == 1)



if(pCheckIfRecordTypeExists(2) == 1)
{

     type_2_number_of_records = (pReadNumberOfRecords)(2);
	 
     _itow(type_2_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-2 number of records = ");
	 wcscat(output_message, int_converted_to_string); 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);

	 
     for(int i = 1; i <= type_2_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(2, i);


     //Reads Type-2 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(2, idc, 1 , "");
     wcscat(output_message, L"Type-2 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);


     //Reads Type-2 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(2, idc, 2, "");
     wcscat(output_message, L"\nType-2 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-2 record User-defined field #30
     nist_txt_field = (pReadRecordTxtField)(2, idc, 30, "");
     wcscat(output_message, L"\nType-2 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") Type-2 record User-defined field #30 = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-2 record User-defined field #31
     nist_txt_field = (pReadRecordTxtField)(2, idc, 31, "");
     wcscat(output_message, L"\nType-2 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") Type-2 record User-defined field #31 = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-2 record User-defined field #32
     nist_txt_field = (pReadRecordTxtField)(2, idc, 32, "");
     wcscat(output_message, L"\nType-2 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") Type-2 record User-defined field #32 = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
     MessageBoxW(0, output_message, L"NIST library", MB_OK);

     }//for(int i = 1; i <= type_2_number_of_records; i++)


}//if(CheckIfRecordTypeExists(2) == 1)




if(pCheckIfRecordTypeExists(4) == 1)
{

     type_4_number_of_records = (pReadNumberOfRecords)(4);
	 
     _itow(type_4_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-4 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // In Type-4 record there might be up to 14 fingerprint images.
     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(4, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-4 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "LEN");
//     nist_txt_field = (pReadRecordTxtField)(4, idc, 1, "");
     wcscat(output_message, L"Type-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "IDC");
//     nist_txt_field = (pReadRecordTxtField)(4, idc, 2, "");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "IMP");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Impression type (IMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Finger position (FGP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Known or most probable Finger position (FGP1)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP1");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Known or most probable Finger position (FGP1) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Second possible Finger position (FGP2)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP2");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Second possible Finger position (FGP2) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Third possible Finger position (FGP3)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP3");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Third possible Finger position (FGP3) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Fourth possible Finger position (FGP4)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP4");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Fourth possible Finger position (FGP4) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Fifth possible Finger position (FGP5)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP5");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Fifth possible Finger position (FGP5) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Sixth possible Finger position (FGP6)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP6");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Sixth possible Finger position (FGP6) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Image scanning resolution (ISR)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "ISR");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image scanning resolution (ISR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "HLL");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "VLL");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-4 record Grayscale compression algorithm (GCA)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "GCA");
     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Grayscale compression algorithm (GCA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);


     // Returns Type-4 record Size of binary field.
     size = (pReadSizeOfRecordBinaryField)(4, idc);

     wcscat(output_message, L"\nType-4 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Size of binary field = ");
     _itow(size, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);


     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     //nist_binary_field = (pReadType4RecordBinaryField)(1, idc);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(4, idc);

     wcscat(output_message, L"\nHigh-resolution grayscale fingerprint image was extracted from Type-4 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)




     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(CheckIfRecordTypeExists(4) == 1)


if(pCheckIfRecordTypeExists(7) == 1)
{

     type_7_number_of_records = (pReadNumberOfRecords)(7);
	 
     _itow(type_7_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-7 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // In Type-7 record there might be up to 17 fingerprint images.
     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(7, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-7 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "LEN");
     wcscat(output_message, L"Type-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IDC");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Image type (IMT)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMT");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image type (IMT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Image description (IMD)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMD");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image description (IMD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Pattern classification (PCN)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "PCN");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Pattern classification (PCN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Image capture resolution (IMR)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMR");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image capture resolution (IMR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "HLL");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Horizontal line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "VLL");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-7 record Gray-scale compression algorithm (GCA)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "GCA");
     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Gray-scale compression algorithm (GCA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);



     // Returns Type-7 record Size of binary field.
     size = (pReadSizeOfRecordBinaryField)(7, idc);

     wcscat(output_message, L"\nType-7 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Size of binary field = ");
     _itow(size, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);


     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     //nist_binary_field = (pReadType7RecordBinaryField)(1, idc);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(7, idc);

     wcscat(output_message, L"\nUser-defined image was extracted from Type-7 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)	  




     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(CheckIfRecordTypeExists(7) == 1)



if(pCheckIfRecordTypeExists(8) == 1)
{
     type_8_number_of_records = (pReadNumberOfRecords)(8);
	 
     _itow(type_8_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-8 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Reads NIST file and shows facial and SMT images on the screen.
     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(8, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-8 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "LEN");
     wcscat(output_message, L"Type-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "IDC");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Signature type (SIG)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "SIG");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Signature type (SIG) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Signature representation type (SRT)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "SRT");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Signature representation type (SRT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Image scanning resolution (ISR)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "ISR");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image scanning resolution (ISR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "HLL");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-8 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "VLL");
     wcscat(output_message, L"\nType-8 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(8, idc);

     wcscat(output_message, L"\nSignature image was extracted from Type-8 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)		 
		 

     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(CheckIfRecordTypeExists(8) == 1)


if(pCheckIfRecordTypeExists(9) == 1)
{

     type_9_number_of_records = (pReadNumberOfRecords)(9);
	 
     _itow(type_9_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-9 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Reads NIST file and shows minutiae data images on the screen.
     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(9, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-9 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "LEN");
     wcscat(output_message, L"Type-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "IDC");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "IMP");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Impression type (IMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Minutiae format (FMT)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FMT");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Minutiae format (FMT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     if(strcmp(nist_txt_field, "S") == 0)
     {

     //Reads Type-9 record Originating fingerprint reading system (OFR)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "OFR");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Originating fingerprint reading system (OFR) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FGP");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Finger position (FGP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Fingerprint pattern classification (FPC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FPC");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Fingerprint pattern classification (FPC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Core position (CRP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "CRP");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Core position (CRP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Delta(s) position (DLT)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "DLT");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Delta(s) position (DLT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Number of minutiae (MIN)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "MIN");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Number of minutiae (MIN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Number of minutiae (RDG)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "RDG");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Minutiae ridge count indicator (RDG) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-9 record Number of minutiae (MRC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "MRC");
     wcscat(output_message, L"\nType-9 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Minutiae and ridge count data (MRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);

     }//if(strcmp(nist_txt_field, "S") == 0)


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(9, idc);
	 
     wcscat(output_message, L"\nMinutiae data was extracted from Type-9 record binary field\nof NIST file.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)
   
  
	 


     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)



if(pCheckIfRecordTypeExists(10) == 1)
{
     type_10_number_of_records = (pReadNumberOfRecords)(10);
	 
     _itow(type_10_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-10 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Reads NIST file and shows facial and SMT images on the screen.
     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(10, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-10 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "LEN");
     wcscat(output_message, L"Type-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "IDC");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Image type (IMT)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "IMT");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image type (IMT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SRC");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Source agency / ORI (SRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Photo date (PHD)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PHD");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Photo date (PHD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "HLL");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "VLL");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SLC");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scale units (SLC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "HPS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal pixel scale (HPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "VPS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical pixel scale (VPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "CGA");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Compression algorithm (CGA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Colorspace (CSP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "CSP");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Colorspace (CSP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject acquisition profile (SAP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SAP");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject acquisition profile (SAP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);


     //Reads Type-10 record Subject pose (POS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "POS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject pose (POS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Pose offset angle (POA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "POA");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Pose offset angle (POA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Photo description (PXS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PXS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Photo description (PXS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Photo acquisition source (PAS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PAS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Photo acquisition source (PAS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject quality score (SQS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SQS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject quality score (SQS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject pose angles (SPA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SPA");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject pose angles (SPA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject facial description (SXS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SXS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject facial description (SXS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject eye color (SEC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SEC");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject eye color (SEC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Subject hair color (SHC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SHC");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Subject hair color (SHC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Facial feature points (FFP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "FFP");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Facial feature points (FFP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "DMM");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Device monitoring mode (DMM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record NCIC designation code (SMT)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMT");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record NCIC designation code (SMT) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record SMT size (SMS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMS");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record SMT size (SMS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record SMT descriptors (SMD)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMD");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record SMT descriptors (SMD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-10 record Color (COL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "COL");
     wcscat(output_message, L"\nType-10 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Color (COL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(10, idc);

     wcscat(output_message, L"\nFacial & SMT image was extracted from Type-10 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)		 
		 


     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(CheckIfRecordTypeExists(10) == 1)



if(pCheckIfRecordTypeExists(13) == 1)
{
     type_13_number_of_records = (pReadNumberOfRecords)(13);
	 
     _itow(type_13_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-13 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);

     // Reads NIST file and shows latent images on the screen.
     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(13, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-13 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "LEN");
     wcscat(output_message, L"Type-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Image Designation Character (IDC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "IDC");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Impression Type (IMP)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "IMP");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (IMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SRC");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Source agency / ORI (SRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Latent capture date (LCD)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "LCD");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Latent capture date (LCD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Latent capture date (HLL)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "HLL");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Latent capture date (VLL)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "VLL");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SLC");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scale units (SLC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "HPS");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal pixel scale (HPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "VPS");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical pixel scale (VPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "CGA");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Compression algorithm (CGA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "BPX");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Bits per pixel (BPX) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Finger / palm position (FGP)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "FGP");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Finger / palm position (FGP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Search position descriptors (SPD)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SPD");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Search position descriptors (SPD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Print position coordinates (PPC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "PPC");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Print position coordinates (PPC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SHPS");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned horizontal pixel scale (SHPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SVPS");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned vertical pixel scale (SVPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-13 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "COM");
     wcscat(output_message, L"\nType-13 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Comment (COM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(13, idc);

     wcscat(output_message, L"\nVariable-resolution latent image was extracted from Type-13 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)
		 
		 
		 

     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)


if(pCheckIfRecordTypeExists(14) == 1)
{
     type_14_number_of_records = (pReadNumberOfRecords)(14);
	 
     _itow(type_14_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-14 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Reads NIST file and shows tenprint images images on the screen.
     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(14, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-14 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "LEN");
     wcscat(output_message, L"Type-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "IDC");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "IMP");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Impression type (IMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SRC");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Source agency / ORI (SRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Tenprint capture date (TCD)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "TCD");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Tenprint capture date (TCD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "HLL");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "VLL");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SLC");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scale units (SLC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "HPS");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal pixel scale (HPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "VPS");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical pixel scale (VPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "CGA");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Compression algorithm (CGA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "BPX");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Bits per pixel (BPX) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "FGP");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Finger position (FGP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Print position descriptors (PPD)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "PPD");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Print position descriptors (PPD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Print position coordinates (PPC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "PPC");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Print position coordinates (PPC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SHPS");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned horizontal pixel scale (SHPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SVPS");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned vertical pixel scale (SVPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Amputated or bandaged (AMP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "AMP");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Amputated or bandaged (AMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "COM");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Comment (COM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Finger segment position(s) (SEG)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SEG");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Finger segment position(s) (SEG) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record NIST quality metric (NQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "NQM");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record NIST quality metric (NQM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Segmentation quality metric (SQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SQM");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Segmentation quality metric (SQM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Fingerprint quality metric (FQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "FQM");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Fingerprint quality metric (FQM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Alternate finger segment position(s) (ASEG)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "ASEG");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Alternate finger segment position(s) (ASEG) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-14 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "DMM");
     wcscat(output_message, L"\nType-14 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Device monitoring mode (DMM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(14, idc);

     wcscat(output_message, L"\nVariable-resolution fingerprint image was extracted from Type-14 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)
		 
		 


     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)



if(pCheckIfRecordTypeExists(15) == 1)
{
     type_15_number_of_records = (pReadNumberOfRecords)(15);
	 
     _itow(type_15_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-15 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);

     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(15, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-15 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "LEN");
     wcscat(output_message, L"Type-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "IDC");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "IMP");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Impression type (IMP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Source agency/ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SRC");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Source agency/ORI (SRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Palmprint capture date (PCD)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PCD");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Palmprint capture date (PCD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "HLL");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal line length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "VLL");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical line length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SLC");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scale units (SLC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "HPS");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal pixel scale (HPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "VPS");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical pixel scale (VPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "CGA");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Compression algorithm (CGA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "BPX");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Bits per pixel (BPX) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Palmprint position (PLP)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PLP");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Palmprint position (PLP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SHPS");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned horizontal pixel scale (SHPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SVPS");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned vertical pixel scale (SVPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "COM");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Comment (COM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Palmprint quality metric (PQM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PQM");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Palmprint quality metric (PQM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-15 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "DMM");
     wcscat(output_message, L"\nType-15 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Device monitoring mode (DMM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);
//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(15, idc);

     wcscat(output_message, L"\nVariable-resolution palmprint image was extracted from Type-15 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)


     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)


if(pCheckIfRecordTypeExists(16) == 1)
{
     type_16_number_of_records = (pReadNumberOfRecords)(16);
	 
     _itow(type_16_number_of_records, int_converted_to_string, 10);
	 output_message[0] = 0;
	 wcscat(output_message, L"Type-16 number of records = ");
	 wcscat(output_message, int_converted_to_string); 	 
     MessageBoxW(0, output_message, L"NIST library", MB_OK);

     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(16, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-16 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "LEN");
     wcscat(output_message, L"Type-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Logical record length (LEN) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "IDC");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Image designation character (IDC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record User-Defined Image (UDI)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UDI");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record User-Defined Image (UDI) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Source Agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SRC");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Source Agency / ORI (SRC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record User-Defined Testing Date (UTD)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UTD");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record User-Defined Testing Date (UTD) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Horizontal Line Length (HLL)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "HLL");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal Line Length (HLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Vertical Line Length (VLL)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "VLL");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical Line Length (VLL) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Scale Units (SLC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SLC");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scale Units (SLC) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Horizontal Pixel Scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "HPS");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Horizontal Pixel Scale (HPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Vertical Pixel Scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "VPS");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Vertical Pixel Scale (VPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Compression Algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "CGA");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Compression Algorithm (CGA) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Bits Per Pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "BPX");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Bits Per Pixel (BPX) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Color Space (CSP)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "CSP");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Color Space (CSP) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Scanned Horizontal Pixel Scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SHPS");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned Horizontal Pixel Scale (SHPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Scanned Vertical Pixel Scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SVPS");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Scanned Vertical Pixel Scale (SVPS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "COM");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Comment (COM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record User-Defined Testing Image Quality Score (UQS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UQS");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record User-Defined Testing Image Quality Score (UQS) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);

     //Reads Type-16 record Device Monitoring Mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "DMM");
     wcscat(output_message, L"\nType-16 (");
     _itow(idc, int_converted_to_string, 10);
     wcscat(output_message, int_converted_to_string);
     wcscat(output_message, L") record Device Monitoring Mode (DMM) = ");
     mbstowcs(w_nist_txt_field, nist_txt_field, strlen(nist_txt_field)+1); wcscat(output_message, w_nist_txt_field);


//     MessageBoxW(0, output_message, L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(16, idc);

     wcscat(output_message, L"\nVariable-resolution user-defined testing image was extracted from Type-16 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
     if(hBitmap)
     {
         SendMessage(g_bitmapWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
         InvalidateRect(0, 0, true);

         MessageBoxW(0, output_message, L"NIST library", MB_OK);
     }//if(hBitmap)


     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)






    EnableWindow(g_hwndCreateAndInsertButton, true);
    EnableWindow(g_hwndReadAndModifyButton, true);
    EnableWindow(g_hwndReadAndExportButton, true);
    EnableWindow(g_hwndReadSingleFieldButton, true);
    EnableWindow(g_hwndDeleteSingleFieldButton, true);
    EnableWindow(g_hwndRegisterButton, true);
    SetCursor(hcurSave);



}



void DeleteSingleFieldButtonClick() {

	if (!LoadNISTLibrary()) 
	{return;}



    EnableWindow(g_hwndCreateAndInsertButton, false);
    EnableWindow(g_hwndReadAndModifyButton, false);
    EnableWindow(g_hwndReadAndExportButton, false);
    EnableWindow(g_hwndReadSingleFieldButton, false);
    EnableWindow(g_hwndDeleteSingleFieldButton, false);
    EnableWindow(g_hwndRegisterButton, false);
    hcurSave = SetCursor(LoadCursor(0, IDC_WAIT));




   //Sets input file name as "sample.nist" which located in "input" subdirectory
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");
   wcscat(filename, filedirectory);
   wcscat(filename, L"sample.nist");



   if(_waccess(filename, 0) != 0)
   {
   MessageBoxW(0, L"Error: file .\\input\\sample.nist does not exist.", L"Error", MB_OK);
   return;
   }


   // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
   // usable format. This function must be called at the beginning (one time only) before
   // any further processing of NIST file.
   (pReadNISTFromFile)(convert_utf16_to_utf8((char*)filename));





if(pCheckIfRecordTypeExists(2) == 1)
{
(pDeleteRecord)(2, 0);
}


if(pCheckIfRecordTypeExists(4) == 1)
{

   //Modifies NIST file, Deletes all Type-4 records
    type_4_number_of_records = (pReadNumberOfRecords)(4);

     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(4, 1); //selects the first Type-4 record
//     idc = (pReadIDCofRecord)(4, (type_4_number_of_records - i + 1)); //selects the last Type-4 record
     (pDeleteRecord)(4, idc);
     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(4) == 1)





if(pCheckIfRecordTypeExists(7) == 1)
{

   //Modifies NIST file, Deletes all Type-7 records
    type_7_number_of_records = (pReadNumberOfRecords)(7);

     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(7, 1); //selects the first Type-7 record
//     idc = (pReadIDCofRecord)(7, (type_7_number_of_records - i + 1)); //selects the last Type-7 record
     (pDeleteRecord)(7, idc);
     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(7) == 1)




if(pCheckIfRecordTypeExists(8) == 1)
{

   //Modifies NIST file, Deletes all Type-8 records
    type_8_number_of_records = (pReadNumberOfRecords)(8);

     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(8, 1); //selects the first Type-8 record
//     idc = (pReadIDCofRecord)(8, (type_8_number_of_records - i + 1)); //selects the last Type-8 record
     (pDeleteRecord)(8, idc);
     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(8) == 1)




if(pCheckIfRecordTypeExists(9) == 1)
{

   //Modifies NIST file, Deletes all Type-9 records
    type_9_number_of_records = (pReadNumberOfRecords)(9);

     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(9, 1); //selects the first Type-9 record
//     ShowMessage(idc);
//     idc = (pReadIDCofRecord)(9, (type_9_number_of_records - i + 1)); //selects the last Type-9 record
     (pDeleteRecord)(9, idc);
     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)




if(pCheckIfRecordTypeExists(10) == 1)
{

   //Modifies NIST file, Deletes all Type-10 records
    type_10_number_of_records = (pReadNumberOfRecords)(10);

     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(10, 1); //selects the first Type-10 record
//     idc = (pReadIDCofRecord)(10, (type_10_number_of_records - i + 1)); //selects the last Type-10 record
     (pDeleteRecord)(10, idc);
     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(10) == 1)



if(pCheckIfRecordTypeExists(13) == 1)
{

   //Modifies NIST file, Deletes all Type-13 records
    type_13_number_of_records = (pReadNumberOfRecords)(13);

     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(13, 1); //selects the first Type-13 record
//     idc = (pReadIDCofRecord)(13, (type_13_number_of_records - i + 1)); //selects the last Type-13 record
     (pDeleteRecord)(13, idc);
     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)



if(pCheckIfRecordTypeExists(14) == 1)
{

   //Modifies NIST file, Deletes all Type-14 records
    type_14_number_of_records = (pReadNumberOfRecords)(14);


     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(14, 1); //selects the first Type-14 record
//     idc = (pReadIDCofRecord)(14, (type_14_number_of_records - i + 1)); //selects the last Type-14 record
     (pDeleteRecord)(14, idc);
     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)




if(pCheckIfRecordTypeExists(15) == 1)
{
   //Modifies NIST file, Deletes all Type-15 records
    type_15_number_of_records = (pReadNumberOfRecords)(15);

     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(15, 1); //selects the first Type-15 record
//     idc = (pReadIDCofRecord)(15, (type_15_number_of_records - i + 1)); //selects the last Type-15 record
     (pDeleteRecord)(15, idc);
     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)





if(pCheckIfRecordTypeExists(16) == 1)
{
   //Modifies NIST file, Deletes all Type-16 records
    type_16_number_of_records = (pReadNumberOfRecords)(16);

     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(16, 1); //selects the first Type-16 record
//     idc = (pReadIDCofRecord)(16, (type_16_number_of_records - i + 1)); //selects the last Type-16 record
     (pDeleteRecord)(16, idc);
     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)




   //Sets output file name as "sample_of_deletion.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(_waccess(filedirectory, 0) != 0)
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_of_deletion.nist");


   //Saves NIST into the file "sample_of_deletion.nist" (in "output" subdirectory)
   (pWriteNISTToFile)(convert_utf16_to_utf8((char*)filename));

    MessageBoxW(0, L"NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_of_deletion.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_of_deletion.nist\" file.", L"NIST Library Demo", MB_OK);

 
 


    EnableWindow(g_hwndCreateAndInsertButton, true);
    EnableWindow(g_hwndReadAndModifyButton, true);
    EnableWindow(g_hwndReadAndExportButton, true);
    EnableWindow(g_hwndReadSingleFieldButton, true);
    EnableWindow(g_hwndDeleteSingleFieldButton, true);
    EnableWindow(g_hwndRegisterButton, true);
    SetCursor(hcurSave);


}









LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	switch (message) {
	case WM_COMMAND:

		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==CreateAndInsertButton) {
			CreateAndInsertButtonClick();
		}
		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==ReadAndModifyButton) {
			ReadAndModifyButtonClick();
		}
		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==ReadAndExportButton) {
			ReadAndExportButtonClick();
		}
		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==ReadSingleFieldButton) {
			ReadSingleFieldButtonClick();
		}
		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==DeleteSingleFieldButton) {
			DeleteSingleFieldButtonClick();
		}
		//--------------------------------------------------------------------------
		if (LOWORD(wParam)==RegisterButton) {
			RegisterButtonClick();
		}										
		//--------------------------------------------------------------------------
		break;
 	case WM_DESTROY:
			PostQuitMessage(0);
			break;	
	}
	return DefWindowProc(hWnd,message,wParam,lParam);
}
