#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
/* Structure used for the callback function's user data */
typedef struct tagIMAGECBPARM
{
   HWND hwnd;     /* Current window                        */
   HDC  hdc;      /* Device context for the current window */
} IMAGECBPARM;
static L_INT EXT_CALLBACK LoadImageCB(pFILEINFO     pFileInfo,
                                      pBITMAPHANDLE pBitmap,
                                      L_UCHAR     * pBuffer,
                                      L_UINT        uFlags,
                                      L_INT         nRow,
                                      L_INT         nLines,
                                      L_VOID      * pUserData)
{
   static RECT rLeadSource;
   static RECT rLeadDest;
   IMAGECBPARM *pData = (IMAGECBPARM*)pUserData;
   /* If this is the first call (row 0), select and realize the palette */
   if((uFlags & FILEREAD_FIRSTPASS) && (uFlags & FILEREAD_FIRSTROW) )
   {
      /* Set the source rectangle to use the whole bitmap */
      SetRect(&rLeadSource, 0, 0, pFileInfo->Width, pFileInfo->Height);
      /* Set the dest rectangle to use the whole client area */
      GetClientRect(pData->hwnd, &rLeadDest);
   }
   /* Paint the buffer to the specified device context */
   L_PaintDCBuffer( pData->hdc, /* Device context - from function parameter */
                    pBitmap, /* Bitmap handle - from function parameter */
                    &rLeadSource, /* Source rect - set globally in WM_CREATE */
                    &rLeadSource, /* Source clip rect - same as source rect */
                    &rLeadDest, /* Destination rect - set globally in WM_CREATE */
                    &rLeadDest, /* Destination clip rect - same as destination rect */
                    SRCCOPY, /* ROP code for normal painting */ 
                    pBuffer, /* Input buffer - from function parameter */ 
                    nRow, /* First row in the buffer - from function parameter */ 
                   (uFlags & FILEREAD_COMPRESSED) ? -nLines : nLines );
   return( SUCCESS );
}
L_LTFILTEX_API  L_INT LoadMemoryExample(HWND hWnd)
{
   L_INT nRet; 
   BITMAPHANDLE TmpBitmap;       /* Bitmap handle for the initial image */
   HGLOBAL hFileInMemory=NULL;   /* Memory handle                       */
   L_SIZE_T uMemSize;            /* Size of the data in memory          */
   L_UCHAR *pData;               /* Pointer to the data in memory       */
   static IMAGECBPARM UserData;  /* Structure used for the callback function's user data */
   FILEREADCALLBACK lpfnCallBack;
   /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;
   /* Save the image as a CMP file in memory */
   nRet = L_SaveBitmapMemory(&hFileInMemory, &TmpBitmap, FILE_CMP, 24, QS, &uMemSize, NULL);
   if(nRet != SUCCESS)
      return nRet;
   /* Free the temporary bitmap */
   L_FreeBitmap(&TmpBitmap);
   /* Get the pointer to the memory-resident file */
   pData = (L_UCHAR *) GlobalLock (hFileInMemory);
   /* Set the user data used for the callback in the nRet = L_LoadFile function */
   UserData.hwnd = hWnd;         /* Current window */
   UserData.hdc = GetDC( hWnd ); /* Device context for the current window */
   /* Set the callback function for the L_LoadFile function.*/
   lpfnCallBack = (FILEREADCALLBACK)LoadImageCB;
   /* Load the file, calling lpfnCallBack to paint the bitmap. */
   nRet = L_LoadMemory(pData,
                      &TmpBitmap, sizeof(BITMAPHANDLE),
                      0,
                      ORDER_BGR,
                      LOADFILE_ALLOCATE |  LOADFILE_STORE,
                      lpfnCallBack,
                      &UserData,
                      uMemSize,
                      NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;
   /* Clean up */
   GlobalUnlock (hFileInMemory);
   GlobalFree (hFileInMemory);
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &TmpBitmap, FILE_BMP, 24, 0, NULL);
   L_FreeBitmap(&TmpBitmap);
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}