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

  • Home
  • SEARCH
  • 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 8494057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:11:44+00:00 2026-06-10T23:11:44+00:00

In windows you can include the windows.h header file when trying to parse bmp

  • 0

In windows you can include the windows.h header file when trying to parse bmp files and the dataTypes WORD and DWORD are predefined for you (from what I have read). In linux, I need to use these dataTypes, but I do not know how to define them and cannot include the windows.h header. How do I go about doing this in C++?

  • 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-10T23:11:45+00:00Added an answer on June 10, 2026 at 11:11 pm

    Include <stdint.h>, and then you can portably replace WORD with uint16_t and DWORD with uint32_t. And BYTE with uint8_t, of course:

    If you want you can add the following code:

    #include <stdint.h>
    typedef uint32_t DWORD;
    typedef uint16_t WORD;
    typedef uint8_t BYTE;
    

    But beware! If you want to be portable, you must have in mind the endianness of the multi-byte values. Microsoft code almost always assume little-endian, but Linux can be run in both little and big-endian machines.

    UPDATE:

    Your new problem you talk about in the comments about the BITMAPFILEHEADER is not related to the type of the fields but to the packing of the struct: the compiler may add padding bytes between fields in the struct in order to satisfy alignment (or other requirements).

    Microsoft compilers align integer type to an address multiple of its size. That is, WORD and SHORT values are aligned to an address multiple of 2, and DWORD and LONG values to multiple of 4.

    If you see the definition of your struct:

    typedef struct {
        WORD    bfType;      //offset 0
        DWORD   bfSize;      //offset 4
        WORD    bfReserved1; //offset 8
        WORD    bfReserved2; //offset 10
        DWORD   bfOffBits;   //offset 12
    } BITMAPFILEHEADER;
    

    Note that the bfSize field is sized 4 bytes, so it will be aligned to a multiple of 4. Instead of being in offset 2 of the struct, it will be in offset 4, adding 2 padding bytes.

    Now, all Windows headers all compiled with the option #pragma pack that tells the compiler to ignore the alignment restrictions in struct fields. So the former struct is actually:

    #pragma pack(push)
    typedef struct {
        WORD    bfType;      //offset 0
        DWORD   bfSize;      //offset 2
        WORD    bfReserved1; //offset 6
        WORD    bfReserved2; //offset 8
        DWORD   bfOffBits;   //offset 10
    } BITMAPFILEHEADER;
    #pragma pack(pop)
    

    The GCC compiler supports the #pragma pack only as a compatibility with MS compilers, and only with x86 compilers.

    If you want to go fully portable you should read the struct directly, but read the bytes as a stream and build the values one by one (read 2 bytes into bfType, read 4 bytes into bfSize, etc.)

    If you want to go portable to other Linux you can use the GCC pragma (but beware of the endiannes):

    typedef struct __attribute__((packed)) {
        WORD    bfType;      //offset 0
        DWORD   bfSize;      //offset 2
        WORD    bfReserved1; //offset 6
        WORD    bfReserved2; //offset 8
        DWORD   bfOffBits;   //offset 10
    } BITMAPFILEHEADER;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you use jQuery to include/require a different php file if window height
When trying to debug a program on Windows I can't seem to find where
I have a system service running on my Windows machine that can impersonate the
I'm trying to compile (using cygwin) a C header file that includes netinet/ether.h. On
In MSVC++ #include files are searched for differently depending on whether the file is
I have a blank c++ project and when I include windows.h and try to
I an trying to develop a windows application using C# that can play streamed
I have a LRESULT CALLBACK function in a header file(hook.h) that I both forward
I'm trying to open some html file with the default browser from my code.
When i call window.open, I can include a list of parameters. One of these

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.