#include <windows.h>
#include <iostream>

#include "..\..\..\..\pilot_nt.h"
#include "..\..\..\..\deprtmnt.h"
#include "..\..\..\..\cardtype.h"
#include "..\..\..\..\errors.h"

#ifndef WINCE
  #define DLL_NAME "pilot_nt.dll"
#else
  #define DLL_NAME L"pilot_nt.dll"
#endif

extern HMODULE LoadPilotNt(const char* name, const char** nameOfTheUncknownFunction);
extern void    FreePilotNt(HMODULE dll);

#ifndef WINCE
int main (int argc, char** argv)
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
#endif
{
	const char *nameOfTheUncknownFunction = NULL;
	HMODULE dll = LoadPilotNt(DLL_NAME, &nameOfTheUncknownFunction);
	if (!dll)
	{
		if (!nameOfTheUncknownFunction)
		{
			std::cerr << "pilot_nt.dll not found";
			return -1;
		}
		else
		{
			std::cerr << "function " << nameOfTheUncknownFunction << " in " << DLL_NAME << " not found";
			return -2;
		}
	}

	try
	{
		auth_answer14 argument;
		DWORD amount = 40000;
		DWORD result;

		memset(&argument, 0, sizeof(argument));
		argument.ans.TType = OP_CASH_ON_TRADE;
		argument.ans.Amount = amount;

		result = card_authorize15(NULL, &argument, NULL, 0, 0);
		std::cout << "Operation completed with code '" << result << "'!" << std::endl;
	}
	catch (...)
	{
	}

	FreePilotNt(dll);

	return 0;
}
