L_RedirectIO

#include "l_bitmap.h"

L_VOID EXT_FUNCTION L_RedirectIO(pfnOpen, pfnRead, pfnWrite, pfnSeek, pfnClose, pUserData)

REDIRECTOPEN pfnOpen;

/* far pointer to an open procedure */

REDIRECTREAD pfnRead;

/* far pointer to a read procedure */

REDIRECTWRITE pfnWrite;

/* far pointer to a write procedure */

REDIRECTSEEK pfnSeek;

/* far pointer to a seek procedure */

REDIRECTCLOSE pfnClose;

/* far pointer to a close procedure */

L_VOID L_FAR *pUserData;

/* pointer to additional parameters */

Lets you replace the LEADTOOLS input/output functions for opening, reading, writing, seeking, and closing files.

Parameter

Description

pfnOpen

Far pointer to an open procedure. Use NULL to reset to the default. For a description of the callback function syntax, refer to REDIRECTOPEN Callback Function.

pfnRead

Far pointer to a read procedure. Use NULL to reset to the default. For a description of the callback function syntax, refer to REDIRECTREAD Callback Function.

pfnWrite

Far pointer to a write procedure. Use NULL to reset to the default For a description of the callback function syntax, refer to REDIRECTWRITE Callback Function.

pfnSeek

Far pointer to a seek procedure. Use NULL to reset to the default. For a description of the callback function syntax, refer to REDIRECTSEEK Callback Function.

pfnClose

Far pointer to a close procedure. Use NULL to reset to the default. For a description of the callback function syntax, refer to REDIRECTCLOSE Callback Function.

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

None.

Comments

For example, you can redirect all of the LEADTOOLS I/O functions by using the multimedia extensions, or you can redirect all the toolkit I/O functions to your own I/O functions.

Use a NULL argument to reset an I/O function to its default setting. The redefinition of the I/O process is left to you to define.

This function cannot be used in combination with L_FeedLoad, L_LoadBitmapMemory, L_LoadMemory, L_StartFeedLoad, L_StopFeedLoad, L_SaveBitmapMemory, and L_SaveFileMemory.

Note:

This function does not support Kodak PhotoCD (PCD), FlashPix (FPX), or Microsoft FAX (AWD) files.

Required DLLs and Libraries

LTKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Topics:

Raster Image Functions: Input and Output

 

Annotation Functions: Input and Output

Example

For complete sample code, refer to the REDIRECT example.

/* This example loads a file using redirected input and output.
Refer to the individual callback function descriptions to see how they are implemented. */

/************************** Global Declarations **********************************/
typedef struct tagDATA
{
HPALETTE hPalette; /* Logical palette for painting. */
L_TCHAR szFilename[128]; /* File name to load. */
FILEINFO FileInfo; /* FILEINFO structure. */
BITMAPHANDLE BitmapHandle; /* BITMAP HANDLE to hold the image. */
} DATA;
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;

/* Proc pointers for callback functions */
REDIRECTREAD lpfnCallBackRead; /* For MakeProcInstance */
REDIRECTOPEN lpfnCallBackOpen; /* For MakeProcInstance */
REDIRECTWRITE lpfnCallBackWrite; /* For MakeProcInstance */
REDIRECTSEEK lpfnCallBackSeek; /* For MakeProcInstance */
REDIRECTCLOSE lpfnCallBackClose; /* For MakeProcInstance */

DATA Data; /* Pointer to DATA structure */
HANDLE hInst; /* Current instance of the application */
HANDLE hBuf; /* Handle for globally allocated memory */
USERDATA UserData; /* User structure for I/O operation */

/* Prototypes for callback functions */
L_INT L_FAR L_EXPORT WindowsClose (L_INT FD, L_VOID L_FAR* pUserData);
L_INT32 L_FAR L_EXPORT WindowsSeek (L_INT FD, L_INT32 lnPos, L_INT nCount, L_VOID L_FAR* pUserData);
L_UINT L_FAR L_EXPORT WindowsWrite (L_INT FD, L_CHAR L_FAR * pBuf, L_UINT uCount, L_VOID L_FAR* pUserData);
L_UINT L_FAR L_EXPORT WindowsRead (L_INT FD, L_CHAR L_FAR * pBuf, L_UINT uCount, L_VOID L_FAR* pUserData);
L_INT L_FAR L_EXPORT WindowsOpen (const L_CHAR L_FAR * pFile, L_INT nMode, L_INT nShare, L_VOID L_FAR* pUserData);

/***************************************************************************************/
BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct)
{
L_INT32 lSizeToRead;
HFILE hFile;
L_INT nRet;
UNREFERENCED_PARAMETER (lpCreateStruct);
/* We will allocate a buffer of the image size and read the image into it,
then all of our I/O operations will be operate on this buffer */
#ifdef UNICODE

hFile = _wopen (Data.szFilename, OF_READ | OF_SHARE_DENY_WRITE);

#else

hFile = _lopen (Data.szFilename, OF_READ | OF_SHARE_DENY_WRITE);

#endif

   UserData.dwSize = _llseek (hFile, 0, FILE_END);
   _llseek (hFile, 0, FILE_BEGIN);
   /* Allocate a buffer to hold the file. */
   hBuf = GlobalAlloc (GMEM_MOVEABLE, UserData.dwSize);
   UserData.pData = (L_CHAR L_FAR *)GlobalLock (hBuf);
   UserData.pCurData = UserData.pData;
   UserData.dwUsed = 0;
   lSizeToRead = 0;
   /* Read the file in a loop, because the file could be larger than a single
      read can request. */
   while (lSizeToRead < UserData.dwSize)
   {
      nRet = _lread (hFile, (L_VOID L_HUGE *) UserData.pCurData,
                     (L_INT) min (UserData.dwSize - lSizeToRead, 32000));
      lSizeToRead += nRet;
      UserData.pCurData += nRet;
   }
   UserData.pCurData = UserData.pData;
   _lclose (hFile);
   /* Create instances of each I/O function*/
   lpfnCallBackOpen = (REDIRECTOPEN) MakeProcInstance ((FARPROC) WindowsOpen, hInst);
   lpfnCallBackRead = (REDIRECTREAD) MakeProcInstance ((FARPROC) WindowsRead, hInst);
   lpfnCallBackWrite = (REDIRECTWRITE) MakeProcInstance ((FARPROC) WindowsWrite, hInst);
   lpfnCallBackSeek = (REDIRECTSEEK) MakeProcInstance ((FARPROC) WindowsSeek, hInst);
   lpfnCallBackClose = (REDIRECTCLOSE) MakeProcInstance ((FARPROC) WindowsClose, hInst);
   /* Initialize the bitmap to the image width, height, and 8 bits per pixel. */
   L_InitBitmap (&Data.BitmapHandle, sizeof(BITMAPHANDLE), Data.FileInfo.Width,
                 Data.FileInfo.Height, 8);
   /* Use our own routines to replace the internal I/O calls */
   L_RedirectIO ((REDIRECTOPEN) lpfnCallBackOpen,
                 (REDIRECTREAD) lpfnCallBackRead,
                 (REDIRECTWRITE) lpfnCallBackWrite,
                 (REDIRECTSEEK) lpfnCallBackSeek,
                 (REDIRECTCLOSE) lpfnCallBackClose, &UserData);
   /* Load the bitmap as an 8 bit */
   nRet = L_LoadBitmap (Data.szFilename, &Data.BitmapHandle, sizeof(BITMAPHANDLE), 8, ORDER_RGB, NULL, NULL);
   /* Reset the I/O routines to the default ones. */
   L_RedirectIO (NULL, NULL, NULL, NULL, NULL, NULL);
   /* Free the function instances */
   FreeProcInstance ((FARPROC) lpfnCallBackOpen);
   FreeProcInstance ((FARPROC) lpfnCallBackRead);
   FreeProcInstance ((FARPROC) lpfnCallBackWrite);
   FreeProcInstance ((FARPROC) lpfnCallBackClose);
   FreeProcInstance ((FARPROC) lpfnCallBackSeek);
   FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage);
   GlobalUnlock (hBuf);
   GlobalFree (hBuf);
   return (nRet);               /* SUCCESS (TRUE) if creation is OK */
}