// lkf5glob.cpp : Implementation of Clkf5glob
#include "stdafx.h"
#include "Lkfkdoc.h"
#include "lkf5glob.h"

extern "C" {
#include "..\..\c\lkf5defs.h"
}
#include "AcHelper.h"



/////////////////////////////////////////////////////////////////////////////
// Clkf5glob

static void* __stdcall create_semaphore ()
{
	HANDLE sem;

	sem = CreateSemaphore (0,1,1,0);
	return (void *) sem;
}

static void __stdcall enter_semaphore (void *sem)
{
	HANDLE handle = (HANDLE) sem;
	WaitForSingleObject (handle, INFINITE);
}

static void __stdcall leave_semaphore (void *sem)
{
	HANDLE handle = (HANDLE) sem;
	ReleaseSemaphore (handle, 1, 0);
}

static void __stdcall close_semaphore (void *sem)
{
	HANDLE handle = (HANDLE) sem;
	CloseHandle (handle);
}

static int initialize_semaphores = 1;

Clkf5glob::Clkf5glob()
{

	if (initialize_semaphores) {
	
		lkf_semaphore_callbacks (create_semaphore, enter_semaphore, leave_semaphore, close_semaphore);
		initialize_semaphores = 0;
	}

}

Clkf5glob::~Clkf5glob ()
{
}

STDMETHODIMP Clkf5glob::lkf_set_global_inputpath(BSTR path, long *retval)
{


	// TODO: Add your implementation code here

	char *p = AcHelper::AllocCString (path);
	*retval = 0;
	::lkf_set_global_inputpath (p);
	delete p;

	return S_OK;
}

STDMETHODIMP Clkf5glob::lkf_unload_stamm(long *retcode)
{


	*retcode = ::lkf_unloadStamm ();

	return S_OK;
}

STDMETHODIMP Clkf5glob::get_Version(BSTR* pVal)
{


	if (*pVal) SysFreeString (*pVal);
	*pVal = AcHelper::AllocBString (LKF_VERSION);

	return S_OK;
}

STDMETHODIMP Clkf5glob::get_YearFirst(LONG* pVal)
{


	*pVal = LKF_YEAR_FIRST;

	return S_OK;
}

STDMETHODIMP Clkf5glob::get_YearLatest(LONG* pVal)
{


	*pVal = LKF_YEAR_LATEST;

	return S_OK;
}
