// mydll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "mydll.h"

#include <stdlib.h>
#include <stdio.h>

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


// Test buffer used for memory allocation
char *buffer = NULL;

// this function is automatically called by FBA when you call loadlibrary
// and MUST be always exported!
// you can do your initialization code here, if needed
//
MYDLL_API void FBA_initlibrary(void)
{
}

// this function is automatically called by FBA when you call freelibrary (or automatically when you close
// FBA with the library loaded) and MUST be always exported!
// you can do your finalization code here, if needed
//
MYDLL_API void FBA_freelibrary(void)
{
	// free temporary buffer used for test
	free(buffer);
}



// sample function available from FBA program
// note: due to LUA typeless variables definition,
// we always use "char *" as input/output values
// all required conversions have to be done internally by your dll!
//
MYDLL_API char *my_cool_dll_function(char *a, char *b)
{
	free(buffer);
	buffer = (char *)malloc(100);	// not nice, just for test ;)
	sprintf(buffer, "a*b is %ld", atoi(a)*atoi(b));
	return buffer;
}


