www.delorie.com/djgpp/v2faq/faq148.html   search  

| Previous | Next | Up | Top |

18.5 How to move structs returned by real-mode services?

Q: My program uses the contents of a structure returned by a VBE function, but some of the struct members are garbled!


A: Most probably, this happens because of incorrect declaration of the structure in your program. Many people copy a declaration from some real-mode program, and that is exactly what gets them into trouble.

Here are some gotchas in this context:

For example, the following real-mode structure declaration:
      struct ncb {
        unsigned ncb_command;
        int ncb_status;
        char far *ncb_buffer;  /* a far pointer to a buffer */
        char ncb_name[32];
        int far (*ncb_dispatch)();  /* a pointer to a far function */
      };

should be converted to this in a DJGPP program:
      struct ncb {
        unsigned short ncb_command __attribute__((packed));
        short ncb_status __attribute__((packed));
        unsigned short ncb_buf_offset __attribute__((packed));
        unsigned short ncb_buf_segment __attribute__((packed));
        char ncb_name[32] __attribute__((packed));
        unsigned short ncb_dispatch_offset __attribute__((packed));
        unsigned short ncb_dispatch_segment __attribute__((packed));
      };


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)