REDIRECTSEEK Callback Function
#include "l_bitmap.h"
L_INT32 L_FAR L_EXPORT YourSeek(FD, lnPos, nOrigin, pUserData)
L_INT FD; |
/* file handle */ |
L_INT32 lnPos; |
/* number of bytes to move */ |
L_INT nOrigin; |
/* position to move from */ |
/* pointer to additional parameters */ |
Replaces the normal LEADTOOLS function for repositioning a file pointer.
Parameter |
Description |
|
FD |
Identifies the file, using the file handle returned by the REDIRECTOPEN callback function. |
|
lnPos |
Specifies the number of bytes the pointer is to be moved. |
|
nOrigin |
Specifies the starting position and direction of the pointer. This parameter must be one of the following values: |
|
|
Value |
Meaning |
|
0 |
Move the file pointer lnPos bytes from the beginning of the file. |
|
1 |
Move the file pointer lnPos bytes from its current position. |
|
2 |
Move the file pointer lnPos bytes from the end of the file. |
pUserData |
A void pointer that you can use to access a variable or structure containing data that your callback function needs. This gives you a way to receive data indirectly from the function that uses this callback function. (This is the same pointer that you pass in the pUserData parameter of the calling function.) |
|
|
Keep in mind that this is a void pointer, which must be cast to the appropriate data type within your callback function. |
Returns
>0 |
The number of bytes that the function wrote to the file. |
-1 |
The function failed. |
Comments
For information about using this type of callback, refer to L_RedirectIO.
Example
To see how the following function is defined and called, refer to L_RedirectIO.
/* This procedure is a replacement to the built-in seek procedure.
This emulates the whole seek operation on a memory block, and
adjusts the internal data structures accordingly. */
/************************** Global Declarations **********************************/
typedef struct tagUSERDATA
{
L_INT32 dwSize; /* Size of the buffer. /
L_INT32 dwUsed; / Number of bytes used. */
L_CHAR L_HUGE pData; / Pointer to the buffer. */
L_CHAR L_HUGE pCurData; / Current pointer location. */
} USERDATA, L_FAR * LPUSERDATA;
DATA Data; /* Pointer to DATA structure */
/***************************************************************************************/
L_INT32 L_FAR L_EXPORT WindowsSeek (L_INT FD, L_INT32 lnPos, L_INT nOrigin, LPUSERDATA pUserData)
{
UNREFERENCED_PARAMETER (FD);
switch (nOrigin)
{
case 0: /* SEEK_SET /
pUserData->pCurData = pUserData->pData + lnPos;
pUserData->dwUsed = lnPos;
break;
case 1: / SEEK_CUR /
pUserData->pCurData += lnPos;
pUserData->dwUsed += lnPos;
break;
case 2: / SEEK_END /
if (0 <= lnPos) / Positive value, but at the end, so go to
the end. /
lnPos = 0;
else
lnPos = -(lnPos); / Seek backwards from the end of the buffer. */
pUserData->pCurData = pUserData->pData + pUserData->dwSize – lnPos;
pUserData->dwUsed = pUserData->dwSize – lnPos;
break;
}
return (pUserData->pCurData – pUserData->pData);
}