// dlltest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>
#include <iostream>

//------------------------------------------------------------------------

extern "C" {
typedef void  INIT(char*,int);
typedef int   REGISTER(char*);
typedef char* GET_BASIC(int);
typedef char* GET_KEYED(int, char*);
typedef char* GET_INDEXED(int, int);
typedef void  STORE(int, char*);
typedef void  GET_BUFFERED(int, char*, int);
};

//------------------------------------------------------------------------

int _tmain(int argc, _TCHAR* argv[])
{
	int idx;

	HMODULE hDLL = LoadLibrary(_T("dcl.dll"));

	if (!hDLL) {
		printf("DLL Load failed\n");
		exit(1);
	}

	//-------------------------------------------------------------------------

	INIT*            p__dsInit        =              (INIT*)GetProcAddress(hDLL, "dsInit");
	REGISTER*        p__dsRegister    =          (REGISTER*)GetProcAddress(hDLL, "dsRegister");
	GET_BASIC*       p__dsGetNext     =         (GET_BASIC*)GetProcAddress(hDLL, "dsGetNext");
	GET_KEYED*       p__dsGetKeyed    =         (GET_KEYED*)GetProcAddress(hDLL, "dsGetKeyed");
	GET_INDEXED*     p__dsGetIndexed  =       (GET_INDEXED*)GetProcAddress(hDLL, "dsGetIndexed");
	STORE*           p__dsStore       =             (STORE*)GetProcAddress(hDLL, "dsStore");

	GET_BUFFERED*    p__get_buffered  =      (GET_BUFFERED*)GetProcAddress(hDLL, "get_buffered");

	//printf("Line: %s\n", (*p__next)(1));

	//-------------------------------------------------------------------------

	(*p__dsInit)("localhost", 9578);

	//-------------------------------------------------------------------------

	idx = (*p__dsRegister)("Sequence");

	for (int i = 0; i < 5; i++) {
		std::cout << "Line: " << (*p__dsGetNext)(idx) << std::endl;
	}

	//-------------------------------------------------------------------------

	idx = (*p__dsRegister)("Address");

	for (int i = 0; i < 5; i++) {
		std::cout << "Line: " << (*p__dsGetNext)(idx) << std::endl;
	}

	(*p__dsStore)(idx, "QQQ,SSS,QQQ,AAA");

	//-------------------------------------------------------------------------

	char buffer[1024];

	(*p__get_buffered)(1, buffer, sizeof(buffer));

	std::cout << "Line2: " << buffer << std::endl;

	return 0;
}  // _tmain

//------------------------------------------------------------------------

