Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:42:31+00:00 2026-06-03T09:42:31+00:00

The below mentioned code; worked well on 32 bit machine but its not working

  • 0

The below mentioned code; worked well on 32 bit machine but its not working on 64 bit machine ..

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

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  *)&(m1),1,1,fp); byteswritten+=1;
    fwrite((BYTE  *)&(m2),1,1,fp); byteswritten+=1;
    fwrite((long  *)&(bmfsize),4,1,fp); byteswritten+=4;
    fwrite((int  *)&(res1),2,1,fp); byteswritten+=2;
    fwrite((int  *)&(res2),2,1,fp); byteswritten+=2;
    fwrite((long  *)&(pixoff),4,1,fp); byteswritten+=4;

    fwrite((BITMAPINFOHEADER *)&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<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<widthDW;count++) {
            char dummy=0;
            fwrite(&dummy,1,1,fp);
            byteswritten++;                           
        }
    }             
    fclose(fp);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:42:32+00:00Added an answer on June 3, 2026 at 9:42 am

    edit:
    I looked at the windows header again, i missed the #pragma pack. so alignment is not the problem.

    Generally, if you need write fixed sized values to disk use explicitly sized data types, because the size of int/long etc may differ between compilers and architecture. On ANSI platforms you an include “stdint.h”, on visual c you can typedef these:

    typedef signed __int8 int8_t;
    typedef signed __int16 int16_t;
    typedef signed __int32 int32_t;
    typedef signed __int64 int64_t;
    typedef unsigned __int8 uint8_t;
    typedef unsigned __int16 uint16_t;
    typedef unsigned __int32 uint32_t;
    typedef unsigned __int64 uint64_t;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Video not working properly in the below mentioned code. What could be the problem
I'm trying to run the below-mentioned code in VB(Excel Macro) but I'm stuck with
the below mentioned code is working perfectly, that when clicking the thumbnail the larger
My below mentioned code still submits form on special character in name field. Validation
I got below mentioned code for adding my application to Windows Firewall Exception list.
HI all, Below mentioned javascript code works fine in all browsers including chrome(from second
I am using List in C#. Code is as mentioned below: TestCase.cs public class
I'm using below mentioned query with about 400,000 records in each table its taking
I have a simple requirement as mentioned below: A ListView or any control displays
I have the below mentioned code in a seperate class file for establishing connection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.