Skip to main content

MocrHookFunction

BoardSupported
Host SystemYes
V4L2Yes
Clarity UHDYes
Concord PoENo
GenTLYes
GevIQYes
GigE VisionYes
IndioNo
Iris GTXYes
Radient eV-CLYes
Rapixo CLYes
Rapixo CoFYes
Rapixo CXPYes
USB3 VisionYes

Hook a function to an event.

Syntax

AIL_OCR_HOOK_FUNCTION_PTR MocrHookFunction(
AIL_ID FontContextOcrId, //in
AIL_INT HookType, //in
AIL_OCR_HOOK_FUNCTION_PTR HookHandlerPtr, //in
void * UserDataPtr //in-out
)

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.

Parameters

FontContextOcrId (in, AIL_ID)

Specifies the identifier of the font.

HookType (in, AIL_INT)

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

For specifying the event type

ValueDescription
M_STRING_VALIDATIONSpecifies the character string to be validated.

For the HookType parameter to unhook the function

ValueDescription
M_UNHOOKUnhooks the specified function if hooked to the specified event. When you use M_UNHOOK, you must provide the same values for all the parameters as when you originally hooked the function.

HookHandlerPtr (in, AIL_OCR_HOOK_FUNCTION_PTR)

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

UserDataPtr *(in-out, void)

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

Type: AIL_OCR_HOOK_FUNCTION_PTR

This function returns a NULL pointer.

Remarks

Note that the prototype of this function is kept for backwards-compatibility.

Copyright © 2026 Zebra Technologies.