#include <windows.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <conio.h>
#include <string>
#include "..\..\..\..\pilot_nt.h"
#define FUNC_NAME "_GetLoyaltyList"
#define DDL_NAME "pilot_nt.dll"
typedef int(*Func)(ListFormat format, char* pDest, unsigned sz, unsigned *length);
#ifndef WINCE
int main(int argc, char** argv)
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
#endif
{
	std::vector < char > data(3, 0);
	int res = 0;
	unsigned Lenght = 0;
	HMODULE dll = LoadLibrary(DDL_NAME);
	if (!dll)
	{
		std::cerr << "pilot_nt.dll not found";
		return -1;
	}

	try {
		Func func = (Func)GetProcAddress(dll, "_GetLoyaltyList");
		if (func) {
			res = func(IdWithComma, &data[0], data.size(), &Lenght);
			if (res == 4384) {
				data.resize(Lenght + 1, '\0');
				res = func(IdWithComma, &data[0], data.size(), &Lenght);
			}
			if (!Lenght && !res)
				std::cout << "Loyalty List unload in tlv:" << std::endl;
			std::string str((char*)&data[0]);

			std::cout << "Loyalty List: " << str << std::endl;
			std::cout << "Func() complited error: " << res << std::endl;


		}
		else std::cout << "GetLoyaltyList not found";
	}
	catch (...)
	{
		
	}
	FreeLibrary(dll);
	return 0;
}
