| Customize Help
| Save Settings


Function Map
Hook a function to an event.
MIL_ID FontContextOcrId, //in
MIL_INT HookType, //in
void *UserDataPtr //in-out

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 which MIL system’s documentation you should use in its place and any possible differences.
This function is not supported on the selected boards.
This function reference has not been updated for the selected MIL system. To show the content of this page, choose a second MIL system; refer to the MIL system's release note to see which MIL system’s documentation to choose and any possible differences.

Specifies the identifier of the font.


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

function map For specifying the event type
Click to summarizeValue Description
Click to summarize M_STRING_VALIDATION +

Specifies the character string to be validated.

You must specify a combination value from the following table:
Combination value 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
Click to summarizeCombination value Description
Click to summarize M_UNHOOK

Unhooks the function that was hooked to the event.


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 HookType,
char *StringPtr,
void *UserDataPtr


Specifies the type of event hooked.


Points to the string to validate.


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.


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.