#include <windows.h>
#include <conio.h>
#include <iostream>
#include "..\..\..\..\pilot_nt.h"
#define FUNC_NAME "_GetMerchantIdTerminalId"
#define DDL_NAME "pilot_nt.dll"
typedef int(*Func)(struct_MerchantID_TeminalId* MerchantID_TeminalId);

struct_MerchantID_TeminalId MerchantID_TeminalId;
#ifndef WINCE
int main(int argc, char** argv)
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
#endif
{
    HMODULE dll = LoadLibrary(DDL_NAME);
    if (!dll)
    {
        std::cerr << "pilot_nt.dll not found";
        return -1;
    }

    try {
        Func func = (Func)GetProcAddress(dll, FUNC_NAME);
        if (func) {
            int result = func(&MerchantID_TeminalId);
            std::cout << FUNC_NAME << "returns " << result << std::endl;
            if (result == 0) {
                std::cout << "MerchantID=" << MerchantID_TeminalId.MerchNum << std::endl;
                std::cout << "TerminalID=" << MerchantID_TeminalId.TermNum << std::endl;
            }
        }
        else
            std::cout << "MerchantID_TeminalId not found";
    }
    catch (...)
    {
        std::cerr << "Unknown error";
    }
    FreeLibrary(dll);
    std::cout << "Press any key";
    _getch();
    return 0;
}
