EncodeABIC2 Example for C++ 5.0 and later

void CDemo::OnEncodeABIC()
{
   int nRet;
   CString strFileName;
   int i;
   unsigned char * pBmpData = NULL;
   long uBound;

   VARIANT vInputData,vOutputData;

   ILEADRaster * pRaster = NULL;
   CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pRaster);

   ILEADRasterIO * pRasterIO = NULL;
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);

   m_RasterView.GetRaster().UnlockSupport(L_SUPPORT_ABIC_READ, L_KEY_ABIC_READ);

   nRet = pRasterIO->Load (pRaster, "c:\\Abic.bmp", 0, 0, 1);
   pRasterIO->SaveMemory2 (pRaster, (RasterFileConstants)FILE_RAW, 0, (QFactorConstants)0, SAVE_OVERWRITE);

   if (pRasterIO->GetSaveMemory2Handle())
   {
      unsigned char *pMem;
      pMem = (unsigned char *)GlobalLock((HANDLE)pRasterIO->GetSaveMemory2Handle());
      pBmpData = (unsigned char *)malloc(pRasterIO->SaveMemory2Size - 1);
      memcpy(pBmpData, pMem, pRasterIO->SaveMemory2Size - 1);
      GlobalUnlock ((HANDLE)pRasterIO->SaveMemory2Handle);
      GlobalFree ((HANDLE)pRasterIO->SaveMemory2Handle);
   }

   SAFEARRAYBOUND sabFldData[1];
   sabFldData[0].cElements = pRasterIO->SaveMemory2Size - 1;
   sabFldData[0].lLbound = 0;
   SAFEARRAY * psaFieldData = SafeArrayCreate(VT_UI1, 1, sabFldData);

   SafeArrayLock(psaFieldData);
   memcpy(psaFieldData->pvData, pBmpData, pRasterIO->SaveMemory2Size - 1);
   SafeArrayUnlock(psaFieldData);

   VariantInit(&vInputData);
   VariantInit(&vOutputData);

   V_VT(&vInputData) = (VT_ARRAY | VT_UI1);
   V_ARRAY(&vInputData) = psaFieldData;

   nRet = pRasterIO->EncodeABIC2(vInputData, 4, 472, 221, &vOutputData, FALSE);

   if(nRet == 0)
   {
      SafeArrayGetUBound(vOutputData.parray, 1, &uBound);

      CFile OutputFile(TEXT("c:\\Image2Raw.ica"), CFile::modeWrite | CFile::modeCreate);

      for(long i =0;i<(uBound+1);++i)
      {
         int tmp = 0;
         SafeArrayGetElement(vOutputData.parray, &i, &tmp);
         OutputFile.Write(&tmp,1);
      }

      OutputFile.Close();
   }

   VariantClear(&vInputData);
   VariantClear(&vOutputData);
   pRasterIO->Release();
   free(pBmpData);
}