Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.11.1
LEADTOOLS Raster Imaging C DLL Help

SAVEBUFFERCALLBACK Function

Show in webframe

#include "l_bitmap.h"

L_INT pEXT_CALLBACK YourFunction (uRequiredSize, ppBuffer, pdwBufferSize, pUserData)

L_SIZE_T uRequiredSize;

/* buffer size */

L_UCHAR ** ppBuffer;

/* address of a pointer to the buffer */

L_SIZE_T* pdwBufferSize;

/* pointer to a variable */

L_VOID* pUserData;

/* pointer to additional parameters */

Provides input to the L_SaveFileBuffer or L_SaveBitmapBuffer function.

Parameter

Description

uRequiredSize

Minimum buffer size required to save the bitmap or file.

ppBuffer

Address of a pointer to the buffer to save. The callback function allows the user to reallocate the buffer. When reallocating a buffer, the buffer address can change. This parameter should be updated with the new address of the reallocated buffer.

pdwBuffersize

Pointer to a variable that contains the actual buffer size. For the bitmap or file to be saved, *pdwBufferSize must be greater than or equal to uRequiredSize.

pUserData

A void pointer that can be used to access a variable or structure containing data that the callback function needs. This provides a way to receive data indirectly from the function that uses this callback function. (This is the same pointer passed 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 the callback function.

Returns

SUCCESS

The function was successful.

FAILURE

An error occurred.

Comments

This callback function is optional, but recommended. If the callback is not used, then the user must allocate a buffer that is large enough to hold the memory file. If the buffer is not large enough and the callback is not used, the function will fail.

If the user provides a callback function, it must reallocate the buffer to be at least uRequiredSize bytes. The ppBuffer parameter must be updated with the new buffer. The pdwBufferSize parameter must be updated with the size of the new buffer.

If the callback successfully reallocates the buffer, it should return SUCCESS.

If the callback fails to successfully reallocate the buffer, it should return FAILURE.

Required DLLs and Libraries

LTFIL

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

See Also

Functions:

L_SaveFileBuffer, L_SaveBitmapBuffer

Example

typedef struct _tagMYBUFFER
{
   L_UCHAR   *pBuffer;
   L_SIZE_T  dwBufferSize;
} MYBUFFER,  *pMYBUFFER;

L_INT EXT_CALLBACK ExampleSaveBufferCB(L_SIZE_T    uRequiredSize,
                                       L_UCHAR  ** ppBuffer,
                                       L_SIZE_T *  pdwBufferSize,
                                       L_VOID*     pUserData)
{
   L_UCHAR *pTempBuffer;
   L_INT nRet;
   L_TCHAR szMsg[400];
   pMYBUFFER pMyBuffer = (pMYBUFFER)pUserData;
   
   pTempBuffer = (L_UCHAR*)realloc(pMyBuffer->pBuffer, uRequiredSize);
   if (pTempBuffer)
   {
      wsprintf(szMsg, TEXT("** Reallocate from\n\t[0x%x, %d] to\n\t[0x%x, %d]\n"), 
         pMyBuffer->pBuffer,
         pMyBuffer->dwBufferSize,
         pTempBuffer,
         uRequiredSize);
      
      //MessageBox(NULL, szMsg, TEXT(""), MB_OK);
      OutputDebugString(szMsg);
            
      pMyBuffer->pBuffer = pTempBuffer;
      pMyBuffer->dwBufferSize = uRequiredSize;
      
      *ppBuffer = pMyBuffer->pBuffer;
      *pdwBufferSize = uRequiredSize;
      nRet = SUCCESS;
   }
   else 
   {
      nRet = FAILURE;
   }   
   return nRet;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.