How to save 8 bit bmp image in 64 BIT Machine ? worrked well on 32 bit machine
<p>The below mentioned code; worked well on 32 bit machine but its not working on 64 bit machine ..</p>

<p>Any Ideas/ Suggestions - and how to fix this ???
what do u think guys - SAVE IMAGE 8 BIT BMP in 64 MACHINE</p>

<pre><code>void BMPFile::SaveBMP(char* fileName,BYTE * buf,UINT width,UINT height)
{
    short res1=0;
    short res2=0;
    long pixoff=54;
    long compression=0;
    long cmpsize=0;
    long colors=0;
    long impcol=0;
    char m1='B';
    char m2='M';

    DWORD widthDW = WIDTHBYTES(width *24);

    long bmfsize=sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) +
                            widthDW * height;   
    long byteswritten=0;

    BITMAPINFOHEADER header;
    header.biSize=40;                       // header size
    header.biWidth=width;
    header.biHeight=height;
    header.biPlanes=1;
    header.biBitCount=24;                   // RGB encoded, 24 bit
    header.biCompression=BI_RGB;            // no compression
    header.biSizeImage=0;
    header.biXPelsPerMeter=0;
    header.biYPelsPerMeter=0;
    header.biClrUsed=0;
    header.biClrImportant=0;

    FILE *fp;   
    fp=fopen(fileName,"wb");
    if (fp==NULL)
    {
        return;
    }

    // should probably check for write errors here...

    fwrite((BYTE  *)&amp;(m1),1,1,fp); byteswritten+=1;
    fwrite((BYTE  *)&amp;(m2),1,1,fp); byteswritten+=1;
    fwrite((long  *)&amp;(bmfsize),4,1,fp); byteswritten+=4;
    fwrite((int  *)&amp;(res1),2,1,fp); byteswritten+=2;
    fwrite((int  *)&amp;(res2),2,1,fp); byteswritten+=2;
    fwrite((long  *)&amp;(pixoff),4,1,fp); byteswritten+=4;

    fwrite((BITMAPINFOHEADER *)&amp;header,sizeof(BITMAPINFOHEADER),1,fp);
    byteswritten+=sizeof(BITMAPINFOHEADER);

    long row=0;
    long rowidx;
    long row_size;
    row_size=header.biWidth*3;
    long rc;
    for (row=0;row&lt;header.biHeight;row++) 
    {
        rowidx=(long unsigned)row*row_size;                           

        // write a row
        rc=fwrite((void  *)(buf+rowidx),row_size,1,fp);
        if (rc!=1) 
        {
            break;
        }
        byteswritten+=row_size; 

        // pad to DWORD
        for (DWORD count=row_size;count&lt;widthDW;count++) {
            char dummy=0;
            fwrite(&amp;dummy,1,1,fp);
            byteswritten++;                           
        }
    }             
    fclose(fp);
}
</code></pre>
