Option Strict Off
Option Explicit On 
Imports System.Text

Module CTIMERW
	'============================================================-
	' ctimerw.vb
	' Module file for CONTEC API-TIMER(WDM)
	'                                             CONTEC.Co.,Ltd.
	'============================================================-

	'-------------------------------------------------------------
	'Delegate
	'-------------------------------------------------------------
	Public Delegate Sub PTM_INTERVAL_CALLBACK(ByVal TimerId As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

	'-------------------------------------------------------------
	' Function Prototype
	'-------------------------------------------------------------
	Declare Function TimReadTickCount		Lib "CTIMERW.DLL" (ByRef tick_count As Integer) As Integer
	Declare Function TimInit				Lib "CTIMERW.DLL" (ByVal DeviceName As String, ByVal ProductName As String) As Integer
	Declare Function TimExit				Lib "CTIMERW.DLL" () As Integer
	Declare Function TimGetErrorString		Lib "CTIMERW.DLL" (ByVal ErrorCode As Integer, ByVal ErrorString As StringBuilder) As Integer
	Declare Function TimWait				Lib "CTIMERW.DLL" (ByVal Microseconds As Integer) As Integer
	Declare Function TimCountStart			Lib "CTIMERW.DLL" (ByRef CountId As Short) As Integer
	Declare Function TimCountLap			Lib "CTIMERW.DLL" (ByVal CountId As Short, ByRef Microseconds As Integer) As Integer
	Declare Function TimCountStop			Lib "CTIMERW.DLL" (ByVal CountId As Short, ByRef Microseconds As Integer) As Integer
	Declare Function TimCountReset			Lib "CTIMERW.DLL" (ByVal CountId As Short) As Integer
	Declare Function TimStartTimer			Lib "CTIMERW.DLL" (ByRef TimerId As Short, ByVal Microseconds As Integer, ByVal hWnd As Integer) As Integer
	Declare Function TimStopTimer			Lib "CTIMERW.DLL" (ByVal TimerId As Short) As Integer
	Declare Function TimTimerCallBackProc	Lib "CTIMERW.DLL" (ByVal Id As Short, ByVal CallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
	Declare Function TimIsTimer				Lib "CTIMERW.DLL" (ByVal TimerType As Short, ByRef Enabled As Short) As Integer
	Declare Function TimGetTimerType		Lib "CTIMERW.DLL" (ByRef TimerType As Short) As Integer
	Declare Function TimSelectTimerType		Lib "CTIMERW.DLL" (ByVal TimerType As Short) As Integer
	Declare Function TimGetMeasureMode		Lib "CTIMERW.DLL" (ByRef MeasureMode As Short) As Integer
	Declare Function TimSetMeasureMode		Lib "CTIMERW.DLL" (ByVal MeasureMode As Short) As Integer

	'-------------------------------------------------
	' Macro
	'-------------------------------------------------
	Public Const	TIM_USE_NG						As Short = 0			' disable
	Public Const	TIM_USE_OK						As Short = 1			' enable
	Public Const	TIM_TYPE_ONBOARD				As Short = 0			' on board system timer
	Public Const	TIM_TYPE_SYSTEM					As Short = 1			' system timer
	Public Const	TIM_MEASURE_HIGH				As Short = 0			' high accuracy
	Public Const	TIM_MEASURE_NORMAL				As Short = 1			' normal

	Public Const 	TIMM_INTERVAL					As Integer = &H8900I	' windows message number of interval timer

	'-------------------------------------------------
	' Error codes
	'-------------------------------------------------
	Public Const TIM_ERR_SUCCESS 					As Short = 0			' Normality completion
	Public Const TIM_ERR_INI_MEMORY 				As Short = 3			' Failed in the allocation of the memory
	Public Const TIM_ERR_INI_REGISTRY				As Short = 4			' Failed in the access of registry
	Public Const TIM_ERR_SYS_RECOVERED_FROM_STANBY	As Short = 7			' Execute XxxResetDevice function prepared in each API-XXX(WDM) because the device has recovered from standby mode.

	Public Const TIM_ERR_DLL_INVALID_ID				As Short = 10001		' Invalid ID was specified
	Public Const TIM_ERR_DLL_CALL_DRIVER			As Short = 10002		' Driver can't be called
	Public Const TIM_ERR_DLL_CREATE_THREAD			As Short = 10005		' Failed in the creation of the thread
	Public Const TIM_ERR_DLL_NOT_INITIALIZED		As Short = 10010		' It is not initialized. Please confirm whether the initialization function has ended

	Public Const TIM_ERR_DLL_NOT_FIND_DEVICE		As Short = 10051		' The device that can be used is not found.
	Public Const TIM_ERR_DLL_BUFF_ADDRESS			As Short = 10100		' Invalid data buffer address
	Public Const TIM_ERR_DLL_HWND					As Short = 10200		' Window handle is invalid
	Public Const TIM_ERR_DLL_CALLBACK				As Short = 10400		' Invalid callback address
	Public Const TIM_ERR_DLL_INVALID_TIME			As Short = 10550		' It is outside the range where set time can be set.
	Public Const TIM_ERR_DLL_INVALID_TIMER_TYPE		As Short = 10551		' It is outside the range where the timer type can be set.
	Public Const TIM_ERR_DLL_INVALID_MEASURE_MODE	As Short = 10552		' It is outside the range where the measurement mode can be set.
	Public Const TIM_ERR_DLL_OVER_MAX_TIMER			As Short = 10553		' It exceeded the maximum usable number of timers.

	Public Const TIM_ERR_SYS_MEMORY					As Short = 20000		' It failed in memory allocation for the object preparation
	Public Const TIM_ERR_SYS_NOT_SUPPORTED			As Short = 20001		' This function can't be used by this device.
End Module
