DecodeABIC2 Example for C++ 5.0 and later

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

   VARIANT vInputData,vOutputData;

   BITMAPINFO *pBmpInfo = NULL;
   BITMAPFILEHEADER BmpFileHeader;

   memset(&BmpFileHeader, 0, sizeof(BmpFileHeader));

   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);

   pBmpInfo = (BITMAPINFO *)malloc(sizeof(*pBmpInfo) + 16 * sizeof(RGBQUAD));
   memset(pBmpInfo, 0, sizeof(*pBmpInfo) + 16 * sizeof(RGBQUAD));

   strFileName = "c:\\Image2Raw.ica";
   CFile File(strFileName, CFile::modeRead);
   nFileSize = File.GetLength();

   SAFEARRAYBOUND sabFldData[1];
   sabFldData[0].cElements = nFileSize;
   sabFldData[0].lLbound = 0;
   SAFEARRAY * psaFieldData = SafeArrayCreate(VT_UI1, 1, sabFldData);


   pData = (unsigned char *)malloc(nFileSize);
   File.Read(pData, nFileSize);
   File.Close();

   SafeArrayLock(psaFieldData);
   memcpy(psaFieldData->pvData, pData, nFileSize);
   SafeArrayUnlock(psaFieldData);

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

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

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

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

      pBmpInfo->bmiHeader.biSize = sizeof(pBmpInfo->bmiHeader);
      pBmpInfo->bmiHeader.biWidth = 472;
      pBmpInfo->bmiHeader.biHeight = 221;
      pBmpInfo->bmiHeader.biBitCount = 4;

      BmpFileHeader.bfType = 'B' | ('M' << 8);
      BmpFileHeader.bfSize = sizeof(*pBmpInfo) + 16 * sizeof(RGBQUAD) + sizeof(BmpFileHeader) + uBound+1;
      BmpFileHeader.bfReserved1 = 0;
      BmpFileHeader.bfReserved2 = 0;
      BmpFileHeader.bfOffBits = sizeof(*pBmpInfo) + 16 * sizeof(RGBQUAD) + sizeof(BmpFileHeader);

      for (i = 0; i < 16; ++i)
      {
         pBmpInfo->bmiColors[i].rgbBlue = 0x11 * i;
         pBmpInfo->bmiColors[i].rgbRed = 0x11 * i;
         pBmpInfo->bmiColors[i].rgbGreen = 0x11 * i;
         pBmpInfo->bmiColors[i].rgbReserved = 0;
      }

      CFile OutputFile(TEXT("c:\\Abic.bmp"), CFile::modeWrite | CFile::modeCreate);

      OutputFile.Write(&BmpFileHeader, sizeof(BmpFileHeader));
      OutputFile.Write(pBmpInfo, sizeof(*pBmpInfo) + 16 * sizeof(RGBQUAD));

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


      free(pData);
      OutputFile.Close();
   }

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