MocrHookFunction()函数

Synopsis

Hook function to an event.

Format

MOCRHOOKFCTPTR MocrHookFunction(FontId, HookType, HookHandlerPtr, UserDataPtr)

MIL_ID FontId; Font identifier
long HookType; Type of event to hook
MOCRHOOKFCTPTR
HookHandlerPtr;
Address of function to call when an event occurs
void *UserDataPtr; User data pointer or M_NULL

Description

This function allows you to attach or detach a user defined function to an event when the specified font is used. A type of event to which a user defined function can be hooked is the string validation during a read or verify operation. When this type of event is hooked, the MocrReadString or MocrVerifyString function will call the hooked function one or many times during the operation to validate the string that was read before writing it in the OCR result buffer. This function allows you to impose global string constraints and can be used to implement custom checksum functions or to reject strings that would have otherwise met the character constraints imposed.

The FontId parameter specifies the identifier of the font.

The HookType parameter specifies the event type. This parameter can be set to:

M_STRING_VALIDATION Specifies to hook a function that will be called to validate the read strings.

The HookHandlerPtr parameter specifies the address of the function that should be called when an event occurs.

The value returned by the hook function must be a long containing the string validity status: either M_TRUE or M_FALSE. Note that MOCRHOOKFCTPTR, MFTYPE, and MPTYPE are reserved MIL predefine types for function and data pointers.

The Hook handler function, pointed to by HookHandlerPtr, must be declared as follows:

long MFTYPE HookHandler(HookType, StringPtr, UserDataPtr);

long HookType; Type of event hooked
void MPTYPE *StringPtr; Pointer to string to validate
void MPTYPE *UserDataPtr; User data pointer passed to MocrHookFunction

The UserDataPtr parameter specifies a pointer to a user defined data structure. This pointer will be passed to the hook handler function when the event occurs. If not used, this parameter should be set to M_NULL.

Returned value

A pointer to the previously hooked function of the same hook type is returned. M_NULL is returned if no previous function was hooked. This allows you to chain hook functions and to restore the old hook functions when unhooking.

See also

MocrReadString, MocrVerifyString, MocrSetConstraint