#include "windows.h"
#include "oscinterface.h"


// Definition der DLL-Funktion, die verwendet werden soll

typedef void (*OSCOpen_)(void);
OSCOpen_ OSCOpenFunc;

typedef void (*OSCClose_)(void);
OSCClose_ OSCCloseFunc;

typedef int (*OSCMsgCnt_)(void);
OSCMsgCnt_ OSCMsgCntFunc;

typedef int (*OSCMsgParaCnt_)(void);
OSCMsgParaCnt_ OSCMsgParaCntFunc;

typedef int (*OSCAddressSplitCnt_)(void);
OSCAddressSplitCnt_ OSCAddressSplitCntFunc;

typedef char* (*OSCAddress_)(void);
OSCAddress_ OSCAddressFunc;

typedef char* (*OSCAddressSplit_)(int n);
OSCAddressSplit_ OSCAddressSplitFunc;

typedef void (*OSCNext_)(void);
OSCNext_ OSCNextFunc;

typedef int (*OSCParaAsInt_)(int n);
OSCParaAsInt_ OSCParaAsIntFunc;

typedef float (*OSCParaAsSingle_)(int n);
OSCParaAsSingle_ OSCParaAsSingleFunc;

typedef char* (*OSCParaAsString_)(int n);
OSCParaAsString_ OSCParaAsStringFunc;

HINSTANCE hinstLib; 
#define OUTPUT_BUFFER_SIZE 1024


int OSCLinkDLL(void)
{
	hinstLib = LoadLibrary("OSCDll.dll");
	if (hinstLib) {
		// Die Einsprungadresse abfragen
        OSCOpenFunc = (OSCOpen_) GetProcAddress(hinstLib, "OSCOpen");
        OSCCloseFunc = (OSCClose_) GetProcAddress(hinstLib, "OSCClose");
        OSCMsgCntFunc = (OSCMsgCnt_) GetProcAddress(hinstLib, "OSCMsgCnt");
        OSCMsgParaCntFunc = (OSCMsgParaCnt_) GetProcAddress(hinstLib, "OSCMsgParaCnt");
        OSCAddressSplitCntFunc = (OSCAddressSplitCnt_) GetProcAddress(hinstLib, "OSCAddressSplitCnt");
        OSCAddressFunc = (OSCAddress_) GetProcAddress(hinstLib, "OSCAddress");
        OSCAddressSplitFunc = (OSCAddressSplit_) GetProcAddress(hinstLib, "OSCAddressSplit");
		OSCNextFunc = (OSCNext_) GetProcAddress(hinstLib, "OSCNext");
		OSCParaAsIntFunc = (OSCParaAsInt_) GetProcAddress(hinstLib, "OSCParaAsInt");
		OSCParaAsSingleFunc = (OSCParaAsSingle_) GetProcAddress(hinstLib, "OSCParaAsSingle");
		OSCParaAsStringFunc = (OSCParaAsString_) GetProcAddress(hinstLib, "OSCParaAsString");
		return 0;
		//FreeLibrary(hinstLib);
	}
	else	
		return 1;
}
int OSCMsgCnt(void)
{
	return OSCMsgCntFunc();
	//return 5;
};

int OSCMsgParaCnt(void)
{
	return OSCMsgParaCntFunc();
	//return 5;
};

int OSCAddressSplitCnt(void)
{
	return OSCAddressSplitCntFunc();
};

void OSCOpen(void)
{
	OSCOpenFunc();
}

void OSCClose(void)
{
	OSCCloseFunc();
}

char* OSCAddress(void)
{
	return OSCAddressFunc();
}

char* OSCAddressSplit(int n)
{
	return OSCAddressSplitFunc(n);
}

void OSCNext(void)
{
	OSCNextFunc();
}

int OSCParaAsInt(int n)
{
	return OSCParaAsIntFunc(n);
}

float OSCParaAsSingle(int n)
{
	return OSCParaAsSingleFunc(n);
}

char* OSCParaAsString(int n)
{
	return OSCParaAsStringFunc(n);
}
