//********************************************************************************************************************************
//*                                                                                                                              *
//*     DTMF Scanner Library 1.0.4.25 © 3delite 2023                                                                             *
//*     See DTMF Scanner Library ReadMe.txt for details.                                                                         *
//*                                                                                                                              *
//* Licenses available for usege of this library:                                                                                *
//* Freeeware License: €15                                                                                                       *
//*     http://www.shareit.com/product.html?productid=301011183                                                                  *
//* Shareware License: €25                                                                                                       *
//*     http://www.shareit.com/product.html?productid=301011182                                                                  *
//* Commercial License: €125                                                                                                     *
//*     http://www.shareit.com/product.html?productid=301011181                                                                  *
//*                                                                                                                              *
//*     https://www.3delite.hu/Object%20Pascal%20Developer%20Resources/DTMFScannerLibrary.html                                   *
//*                                                                                                                              *
//* If you have any questions or enquiries please mail: 3delite@3delite.hu                                                       *
//*                                                                                                                              *
//* Good coding! :)                                                                                                              *
//* 3delite                                                                                                                      *
//********************************************************************************************************************************

#pragma once

#ifdef _WIN32 // Windows
//* .dll file name
#define FILENAME_DLL_DTMF_SCANNER_LIBRARY		"DTMFScanner.dll"
#define DTMFSLIBCALL __stdcall

//* Exported function names (Windows)
#define NAME_DTMFScan			"DTMFScan"

#endif

//*	Error codes
#define DTMFSL_OK                       		= 0
#define DTMFSL_ERROR                    		= 1

#ifdef _WIN32
#include <wtypes.h>
typedef unsigned __int64 QWORD;
#else
#include <stdint.h>
#define WINAPI
#define CALLBACK
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;
typedef void* HANDLE;
#ifndef __OBJC__
typedef int BOOL;
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#endif

typedef enum
{
	dtetStart		= 0,
	dtetContinuing	= 1,
	dtetEnd			= 2
} TDTElementType;

//* Callback
typedef int(DTMFSLIBCALL *TDetectCallback)(int DTMF, TDTElementType Status, float Position, QWORD User);

typedef struct {
	LPWSTR FileName;
	DWORD Channel;
	float Treshold;
	BOOL Thread;
	QWORD User;
	TDetectCallback DetectCallback;
} *PDTMFScannerParameters, TDTMFScannerParameters;

//* Exported functions
typedef int(DTMFSLIBCALL* t_DTMFScan)(TDTMFScannerParameters* Parameters);

#ifdef __cplusplus
extern "C" {
#endif

	static HMODULE DTMFScannerLibraryDLLHandle = NULL;
	BOOL DTMFScannerLibraryDLLLoaded = FALSE;

	t_DTMFScan DTMFScan = NULL;

#ifdef __cplusplus
}
#endif

BOOL InitDTMFScannerLibrary()
{
	DTMFScannerLibraryDLLHandle = LoadLibrary(FILENAME_DLL_DTMF_SCANNER_LIBRARY);
	if (NULL != DTMFScannerLibraryDLLHandle)
	{
		DTMFScan = (t_DTMFScan)GetProcAddress(DTMFScannerLibraryDLLHandle, NAME_DTMFScan);
		if (NULL == DTMFScan)
		{
			DTMFScannerLibraryDLLLoaded = FALSE;
			}
		else
		{
			DTMFScannerLibraryDLLLoaded = TRUE;
		}
	}

	return DTMFScannerLibraryDLLLoaded;
}

BOOL FreeDTMFScannerLibrary()
{
	if (NULL != DTMFScannerLibraryDLLHandle)
	{
		DTMFScannerLibraryDLLLoaded = !FreeLibrary(DTMFScannerLibraryDLLHandle);
	}
	return !DTMFScannerLibraryDLLLoaded;
}

