SAVEBUFFERCALLBACK

#include "l_bitmap.h"

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

Provides input to the L_SaveFileBuffer or L_SaveBitmapBuffer function.

Parameters

L_SIZE_T 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.

L_VOID* 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.)

L_UCHAR ** ppBuffer

Keep in mind that this is a void pointer, which must be cast to the appropriate data type within the callback function.

Returns

Value Meaning
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

See Also

Functions

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; 
} 
Help Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.