LoadOffset example for C++ 5.0 and later

void COffsetCOMView::OnFileSave()
{
    int nRet,nDataSize =0;
    short nOffsetBegin = 0;
   
    CString m_strHeader = TEXT("Lead Technologies Corporation");
   
    FILE *fp = fopen(TEXT("c:\\1.cmp"),"w");
    nDataSize = m_strHeader.GetLength()*sizeof(TCHAR);
    TCHAR *Data = (TCHAR *)malloc((nDataSize+1)*sizeof(TCHAR));
    memset(Data,0,nDataSize);
    memcpy(Data ,m_strHeader.GetBuffer(nDataSize),nDataSize);
   
    nOffsetBegin = nDataSize + sizeof(nOffsetBegin);
    fwrite(&nOffsetBegin ,2,1,fp);
    fwrite(Data,nDataSize,1,fp);
   
    if(Data)
    {
       free(Data);
       Data = NULL;
    }
    fclose(fp);
   
    nRet = m_pRasterIO->SaveOffset(m_RasterView.GetRaster(),
                         TEXT("C:\\1.cmp"),
                         nOffsetBegin,
                         FILE_LEAD,
                         0,
                         (QFactorConstants)-1,
                         0);

    if (nRet == 0)
    {
       CString strMsg;
       strMsg.Format(TEXT("Size of the embedded image file = %d"),m_pRasterIO->GetFileSizeWritten());
       MessageBox(strMsg,TEXT("SUCCESS"));
    }
}
 

void COffsetCOMView::OnFileLoadoffset()
{
    short nOffsetBegin;
    fpos_t FileSize =0;
   
    FILE *fp = fopen(TEXT("c:\\1.cmp"),"rb");
    fread(&nOffsetBegin,sizeof(nOffsetBegin),1,fp);
    fseek(fp ,0,SEEK_END);
    fgetpos(fp,&FileSize);
    fclose(fp);
   
    int nRet = m_pRasterIO->LoadOffset(m_RasterView.GetRaster(),
                            TEXT("c:\\1.cmp"),
                            nOffsetBegin,
                            (long)(FileSize-nOffsetBegin),
                            0, 0, 1);
    }