SREC Recognition Functions

This section takes a brief look at some of SREC's exported recognition functions, including CreateCompatibleHRC, ProcessHRC, and CreatePenDataHRC. The code uses the macro

#define lpHRC ((LPHRCinternal) hrc)

to represent a far pointer to the HRC object.

CreateCompatibleHRC

The CreateCompatibleHRC function allocates an HRCinternal structure in the local heap, creates an HPENDATA block for the pen data, and returns a far pointer to the structure. The LPTR argument forces LocalAlloc to return a far pointer to the allocation instead of a memory handle. This far pointer serves as SREC's HRC handle.

Since the HRC has no configurable elements, SREC ignores any template HRC provided in the first parameter.

HRC WINAPI CreateCompatibleHRC( HRC hrcTemplate, HREC hrec )

{

HRC hrc;

hrc = (HRC) LocalAlloc( LPTR, sizeof( HRCinternal ) );

if (hrc)

{

lpHRC->hrec = hrec;

lpHRC->hpendata = CreatePenData( NULL, 0, PDTS_HIENGLISH, 0 );

if (lpHRC->hpendata)

return (hrc);

}

LocalFree( (HLOCAL) hrc ); // If error, free allocation

return NULL; // and return NULL

}

ProcessHRC

The most interesting feature of SREC's ProcessHRC function is the way it sets a time limit for processing. If called with a limit of PH_MIN or PH_DEFAULT, ProcessHRC passes the address of a callback function to SetTimer. When the specified time-out period elapses, the callback function receives control and sets a global flag called vfOutOfTime.

A recognizer can use this technique to ensure that it does not overrun a specified time limit. Its internal processing functions should check the vfOutOfTime flag regularly and, if it is set, terminate immediately. In this case, ProcessHRC returns a value of HRCR_INCOMPLETE to tell the caller recognition has not yet finished.

int WINAPI ProcessHRC( HRC hrc, DWORD dwTimeMax )

{

UINT idTimer, uTime;

int iRet;

  • fOutOfTime = FALSE; // Initialize time-out flag

if (dwTimeMax != PH_MAX) // If time limit specified ...

{

uTime = (dwTimeMax == PH_MIN) ? 50 : 200;

idTimer = SetTimer( NULL, NULL, uTime, (TIMERPROC) TimerProc );

iRet = GetSYG( hrc ); // Quit if out of time

KillTimer( NULL, idTimer );

}

else

iRet = GetSYG( hrc ); // Don't quit until finished

return (iRet);

}

VOID CALLBACK TimerProc( HWND hwnd, UINT ms, UINT iId, DWORD dwTm )

{

  • fOutOfTime = TRUE;

}

CreatePenDataHRC

SREC keeps an HPENDATA handle in its HRC structure. Because the AddPenInputHRC function has already stored pen input in the internal HPENDATA block, CreatePenDataHRC simply duplicates the block.

HPENDATA WINAPI CreatePenDataHRC( HRC hrc )

{

if (hrc)

return (DuplicatePenData( lpHRC->hpendata, 0 ));

else

return NULL;

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database