| MIL 10 Reference
| Customize Help
| Save Settings

MocrHookFunction



See also
Availability
Not available in MIL-Lite
Available in MIL

Available on Windows
Available on Linux

Available on Non-Matrox computer
Available on Matrox 4Sight-X
Available on Matrox 4Sight GP
Available on Matrox Supersight
function map Function map
Examples
None.
Synopsis
Hook a function to an event.
Syntax
MIL_OCR_HOOK_FUNCTION_PTR MocrHookFunction(
MIL_ID FontContextOcrId, //in
MIL_INT HookType, //in
MIL_OCR_HOOK_FUNCTION_PTR HookHandlerPtr, //in
void *UserDataPtr //in
)
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 string validation. This would immediately follow a read or verify operation. When this type of event occurs, the MocrReadString() or MocrVerifyString() function will call the hooked function one or many times during the operation to validate each string after it is read but before being written to 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.

Note that a function hooked to an event executes on a distinct thread. This permits the functions to run asynchronously from the operation that fired the event and from functions hooked to another event.

Hooked functions should not take longer to execute than the period in which two of their associated events can occur. You cannot determine the instance of the event that fired the function, and even if this were possible, this information would generally not be very useful. Typically, a hooked function performs the minimum number of operations required and, if necessary, performs longer processes by launching other threads.

Note that this function reference has not been updated for a MIL system added during a MIL update. Refer to the MIL system's release note to see if there is complementary information.
Parameters
This function is not supported on the selected boards.
Parameters
FontContextOcrId

Specifies the identifier of the font.

HookType

Specifies the event type. This parameter can be set to the following value:

function map For specifying the event type
CollapseValue Description
Collapse M_STRING_VALIDATION +

Specifies the character string to be validated.


You must specify a combination value from the following table:
(summarize)
Combination constant for any of the possible values of the HookType parameter.

You must add the following value to the above-mentioned value to specify to unhook the event that was hooked to the function.

function map For the HookType parameter to unhook the function
CollapseCombination value Description
Collapse M_UNHOOK

Unhooks the function that was hooked to the event.

HookHandlerPtr

Specifies the address of the function that should be called when the event occurs.

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

MIL_INT MFTYPE HookHandler(
MIL_INT HookType,
char *StringPtr,
void *UserDataPtr
)
Parameters
HookType

Specifies the type of event hooked.

StringPtr

Points to the string to validate.

UserDataPtr

Specifies the user data pointer passed to MocrHookFunction().

The value returned by the hook function must contain the validity status: either M_TRUE or M_FALSE. Note that, MFTYPE and MIL_OCR_HOOK_FUNCTION_PTR are reserved MIL predefined types for functions and data pointers.

UserDataPtr

Specifies the address of the user data that you want to make available to the hook-handler function. This address is passed to the hook-handler function, through its UserDataPtr parameter, when the specified event occurs. Set this parameter to M_NULL if the UserDataPtr is not required.

Return value
This function returns a NULL pointer.
Compilation information
Header Include mil.h.
Library Use mil.lib; milocr.lib.
DLL Requires mil.dll; milocr.dll.
STRING VALIDATION UNHOOK