FeedLoad example for C++ Builder

This example uses StartFeedLoad, FeedLoad, and StopFeedLoad and loads a file through a buffer to simulate receiving a transmitted image.

#define BUFFERSIZE 1000
void __fastcall TForm1::Button2Click(TObject *Sender)
{
   LPSTR          lp;   /* pointer to the data */
   ILEADRasterIO *pRasterIO=NULL;
   ILEADRasterVariant* pRasterVar= NULL;

   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL,
                    IID_ILEADRasterIO, (void**)&pRasterIO);
   CoCreateInstance( CLSID_LEADRasterVariant, NULL, CLSCTX_ALL, IID_ILEADRasterVariant,(void**)&pRasterVar);

   pRasterVar->set_Type(VALUE_ARRAY_BYTE);
   pRasterVar->ItemCount= BUFFERSIZE;
   /* Now we have a variant and we can do the real work */
   HFILE    hf;
   int      bytesread;
   OFSTRUCT of;
   if( (hf = OpenFile("v:\\images\\eagle.cmp", &of, OF_READ)) == HFILE_ERROR)
   {
      ShowMessage ( "Error opening file !" );
      return;
   }
   if(pRasterIO->StartFeedLoad(LEADRasterView1->Raster, 0, 0, 1)) /* default bits per pixel and first page */
   {
      _lclose( hf );
      ShowMessage( "Error in StartFeedLoad !" );
      return;
   }
   do
   {
      bytesread = (int)_hread( hf, lp, BUFFERSIZE );
      if(pRasterIO->FeedLoad(pRasterVar, (long)bytesread))
      {
         _lclose( hf );
         ShowMessage( "Error in FeedLoad !" );
         return;
      }
   } while (bytesread > 0);
   if(pRasterIO->StopFeedLoad())
   {
      _lclose( hf );
      ShowMessage( "Error in StopFeedLoad !" );
      return;
   }
   if ( pRasterIO )
      pRasterIO->Release();
   if ( pRasterVar )
      pRasterVar->Release();
}