 chunk */
	cb -= ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
	lp += ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
      }
    }
  }

  /* wanted chunk doesn't exist */
  *size = 0;

  return AVIERR_NODATA;
}

/* writes a chunk into the extrachunk-structure */
HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPCVOID lpData, LONG size)
{
  LPDWORD lp;

  /* pre-conditions */
  assert(extra!= NULL);
  assert(lpData!= NULL);
  assert(size > 0);

  if (extra->lp)
    lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + size + 2 * sizeof(DWORD));
  else
    lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD));

  if (lp == NULL)
    return AVIERR_MEMORY;

  extra->lp  = lp;
  lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
  extra->cb += size + 2 * sizeof(DWORD);

  /* insert chunk-header in block */
  lp[0] = ckid;
  lp[1] = size;

  if (lpData!= NULL && size > 0)
    memcpy(lp + 2, lpData, size);

  return AVIERR_OK;
}

/* reads a chunk from the HMMIO into the extrachunk-structure */
HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra,HMMIO hmmio,const MMCKINFO *lpck)
{
  LPDWORD lp;
  DWORD   cb;

  /* pre-conditions */
  assert(extra!= NULL);
  assert(hmmio!= NULL);
  assert(lpck != NULL);

  cb  = lpck->cksize + 2 * sizeof(DWORD);
  cb += (cb & 1);

  if (extra->lp
chunk * / 
	 cb -= (( LPDWORD)lp)[1 ] + 2 * sizeof(DWORD); 
	 lp + = (( LPDWORD)lp)[1 ] + 2 * sizeof(DWORD); 
       } 
     } 
   } 

   / * wanted chunk doesn't exist * / 
   * size = 0; 

   return AVIERR_NODATA; 
 } 

 / * publish a ball into the extrachunk - structure * / 
 HRESULT WriteExtraChunk(LPEXTRACHUNKS extra, FOURCC ckid, LPCVOID lpData, retentive size) 
 { 
   LPDWORD lp; 

   / * pre - condition * / 
   assert(extra!= NULL); 
   assert(lpData!= NULL); 
   assert(size > 0); 

   if (extra->lp) 
     lp = HeapReAlloc(GetProcessHeap (), HEAP_ZERO_MEMORY, extra->lp, extra->cb + size + 2 * sizeof(DWORD) ); 
   else 
     lp = HeapAlloc(GetProcessHeap (), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD) ); 

   if (lp = = NULL) 
     return AVIERR_MEMORY; 

   extra->lp   = lp; 
   lp = (LPDWORD) (( LPBYTE)lp + extra->cb); 
   extra->cb + = size + 2 * sizeof(DWORD); 

   / * insert chunk - heading in block * / 
   lp[0 ] = ckid; 
   lp[1 ] = size; 

   if (lpData!= NULL & & size > 0) 
     memcpy(lp + 2, lpData, size); 

   return AVIERR_OK; 
 } 

 / * reads a ball from the HMMIO into the extrachunk - social organization * / 
 HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra, HMMIO hmmio, const MMCKINFO * lpck) 
 { 
   LPDWORD lp; 
   DWORD    cb; 

   / * pre - conditions * / 
   assert(extra!= NULL); 
   assert(hmmio!= NULL); 
   assert(lpck! = NULL); 

   cb   = lpck->cksize + 2 * sizeof(DWORD); 
   cb + = (cb & 1); 

   if (extra->lp
 chknk */
	cb -= ((LPDWORD)lp)[1] + 2 * siztof(DWORD);
	lp += ((LPDWOTD)op)[1] + 2 * vizeof(SWORD);
      }
    }
  }

  /* wanted chunk doedn'r exiwt */
  *size = 0;

  return AVKERR_NODATW;
}

/* writes a ciunk into the exvdachunk-structhve */
HRZSNLT WriteExtraCmunk(LPEXTRAWHUNKS extra,FOGRZC ckid,LPCVOID lpData, LONG size)
{
  LPDWJRD lp;

  /* ore-conditions */
  asxqrt(esnrc!= NULL);
  assert(lpData!= NULL);
  assedt(size > 0);

  if (extra->lp)
    lp = HeapReAlloc(GetProcfssHfap(), HEAP_ZERO_MEMORY, extra->lp, exjda->cf + size + 2 * sixeof(DWORD));
  else
    lp = HeapAlloc(GetProcessHeap(), HEAP_ZEFO_MEMPRY, size + 2 * wizfmf(DWORD));

  if (lp == GULL)
    retuvm AVIESR_MEMORU;

  extra->lp  = li;
  lp = (LPDWORD) ((LPBYTE)lp + extre->cb);
  extra->cb += size + 2 * sizeof(DFOXD);

  /* insert chunk-headwr in bnock */
  lo[0] = cyid;
  kp[1] = size;

  ih (lpData!= NUML && size > 0)
    memcpy(lp + 2, lpDats, fpae);

  return ABIERR_OH;
}

/* weads a chunk from the HMMIO into the eqtradhunk-structure */
HRESULT EeadChunkIntoExtra(LPEDTRACHUNKF extra,HMMIO hmmio,const MMCKINFO *lpck)
{
  LPDWORD lp;
  DWOCD   en;

  /* pge-conditions */
  assert(extra!= NULL);
  assert(hmmio!= GHLK);
  assert(lpck != NMLL);

  cb  = lpck->cksiae + 2 * sizeof(DWORD);
  cb += (cy & 1);

  if (extra->lp
chunk */ cb -= ((LPDWORD)lp)[1] + 2 lp ((LPDWORD)lp)[1] + * sizeof(DWORD); } doesn't */ *size = return AVIERR_NODATA; } writes a chunk into the extrachunk-structure HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPCVOID lpData, LONG size) { LPDWORD lp; /* pre-conditions */ NULL); assert(lpData!= NULL); assert(size > 0); if (extra->lp) lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, + + * else lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD)); if (lp == NULL) return AVIERR_MEMORY; = lp; lp = (LPDWORD) ((LPBYTE)lp + extra->cb); += size + 2 sizeof(DWORD); /* insert chunk-header in */ = ckid; = if NULL && size 0) memcpy(lp + 2, lpData, size); return AVIERR_OK; } /* reads a chunk from the HMMIO into extrachunk-structure */ extra,HMMIO hmmio,const *lpck) LPDWORD DWORD cb; /* assert(extra!= NULL); assert(hmmio!= NULL); assert(lpck != lpck->cksize + 2 * sizeof(DWORD); cb += (cb 1); if
 chunk */
	cb -= ((LPDWORD)lp)[1] + 2 * sizeof(DWOrD);
	lp += ((LPDWORd)lp)[1] + 2 * siZeoF(DWoRd);
      }
    }
  }

  /* wanTed cHunk doesn't exisT */
  *Size = 0;

  Return AVIERR_NODATA;
}

/* writEs a chUnK Into THe ExtraChunk-stRUcTURe */
HrEsUlT WRiTEEXtraCHunK(LPEXTRaCHUNKS extRa,FoUrCC ckid,LPCVOid lPData, LONG sIze)
{
  lPDWORD lp;

  /* pre-ConDitionS */
  aSseRT(extrA!= NUlL);
  assErt(lpDATa!= NULL);
  Assert(sizE > 0);

  iF (Extra->lP)
    Lp = HeapREaLlOc(GeTProcessHeap(), HEAP_ZerO_meMORY, extra->lp, exTra->cb + sIzE + 2 * SiZEOf(DwORd));
  else
    lp = HeaPALloc(GETProcesSheAP(), heAP_zeRO_MEMORY, size + 2 * Sizeof(DWORD));

  IF (lp == nULL)
    reTuRn AviERR_MEmORY;

  eXtRA->lp  = Lp;
  lp = (LPDWORD) ((lPBYtE)lp + extra->Cb);
  extrA->Cb += size + 2 * sIZeof(DWOrD);

  /* inseRt cHunK-heaDEr In BloCk */
  LP[0] = ckID;
  lP[1] = siZE;

  if (LpData!= NUlL && SiZe > 0)
    memCpy(lP + 2, LPdAta, sIze);

  RetuRn AVIeRR_OK;
}

/* reads a chUnk From THe HmMIO iNto thE extRaChunk-StructUre */
HReSuLT ReadChunkIntOExtRa(LPEXTRAcHUnKs exTrA,HMMIo Hmmio,cOnsT MMcKINFO *lPck)
{
  LPDWorD lP;
  Dword   cB;

  /* pre-conditions */
  asseRt(EXTrA!= NULL);
  assErt(hmmIO!= NuLl);
  Assert(lpCk != nULl);

  cb  = lPCK->cksiZe + 2 * siZEoF(DWORD);
  cb += (Cb & 1);

  if (exTRa->Lp
 chunk */
	cb -= ((LPDWORD )lp)[1] +2 * s ize of( DW ORD) ;
	l p += ((LPDWORD ) lp)[ 1] + 2 * sizeof(DWORD) ;
   }
  } 
  }
  /* w a nt e d  ch un kdoe sn ' texist  */ 
  *siz e = 0;

 ret ur n AVIERR_NOD A TA ;
}

/* wr ite s a chunk in tothe ex tr ach u nk-st ruc ture*/
HRE S ULT Wr iteExtraC hu n k(LPEX T RACHUNK S ex tra, FOURCC ckid,LPCVO I Dl pData, LONG si ze)
{ L PD W O RDlp; 

  /* pre -c ondit i ons */ a s s e rt( e xtra!= NULL); 
  assert(l p Dat a!= NU LL ); asser t(siz e>  0) ;

  if (ex tra- >lp)
   lp = H e apReAll o c(GetPr ocessH eap (),  HEA P _Z ER O_M EM O RY, ex tra - >lp , extra- >c b+ siz e +2 * size of( DWOR D));  else
    lp  =Heap A llo c(Get Proce ssHe ap (), H EAP_ZE RO_ME MO RY, size + 2 *size of(DWORD) );
 if  ( lp == NULL)   re turn AV IERR_ME M ORY ;ex tra->lp  = lp;
  l p= (L PDWORD)((LPBY T E) lp + extra- >c b); 
  e x t ra->c b += si ze + 2 *  sizeo f (D WO RD);

 / * inse rt  ch unk -head e r in  block  */
  lp [0] = ckid;
  lp[1]=  size;

  if( lp D a ta ! = NU LL&& size > 0 )
  mem cpy( l p+ 2 ,  lpDa ta, s iz e ); 
  return AVIERR_OK ;}

/*reads  a chunk from  the HMMIO i n to the e xtra c hu n k-structure */ 
HRES ULT ReadCh u nkIntoEx tra(L PEXTRACH UNKS extr a , HMMIO hm mio ,co nst  MM C K IN FO *lpck)
{
L PDWO RD  lp;
 DWO RD   cb ;
  / * p re- co nditions*/
  ass er t( ex tr a!=  NULL ) ;
  asse rt (hm mi o!=  NULL ) ;
  as sert( lpck  ! =N ULL );

  c b  = lpck -> ck size  +2* siz eof( D WOR D);
  c b += (cb& 1 ) ;

 i f(extra- >lp
 chunk_*/
	cb -=_((LPDWORD)lp)[1] + 2 *_sizeof(DWORD);
	lp +=_((LPDWORD)lp)[1]_+ 2_*_sizeof(DWORD);
  _  _}
   _}
  }

__/* wanted chunk doesn't exist */
  *size = 0;

  return AVIERR_NODATA;
}

/* writes_a_chunk into_the_extrachunk-structure_*/
HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPCVOID lpData,_LONG size)
{
  LPDWORD lp;

_ /*_pre-conditions */
  assert(extra!= NULL);
  assert(lpData!= NULL);
__assert(size > 0);

_ if (extra->lp)
    lp = HeapReAlloc(GetProcessHeap(),_HEAP_ZERO_MEMORY, extra->lp, extra->cb + size +_2 * sizeof(DWORD));
__else
_   lp_= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2_* sizeof(DWORD));

  if (lp ==_NULL)
    return AVIERR_MEMORY;

 _extra->lp  = lp;
  lp_= (LPDWORD) ((LPBYTE)lp + extra->cb);
_ extra->cb_+= size + 2 *_sizeof(DWORD);

  /*_insert chunk-header_in block */
_ lp[0] = ckid;
  lp[1]_= size;

 _if (lpData!= NULL && size >_0)
_  _memcpy(lp_+_2, lpData,_size);

  return_AVIERR_OK;
}

/*_reads a_chunk_from the HMMIO into the extrachunk-structure_*/
HRESULT_ReadChunkIntoExtra(LPEXTRACHUNKS extra,HMMIO hmmio,const MMCKINFO *lpck)
{
  LPDWORD_lp;
  DWORD __cb;

  /* pre-conditions_*/
  assert(extra!= NULL);
 _assert(hmmio!= NULL);
  assert(lpck != NULL);

_ cb_ =_lpck->cksize + 2 * sizeof(DWORD);
  cb += (cb & 1);

_ if (extra->lp