Specify a 'wire format' and read and write that format from and to a buffer when receiving or sending. Make sure your 'wire format' specifies byte ordering for multibyte values.
You have two issues here: structure member alignment and padding byte ordering Generally it is easier to do it 'the hard way' (read and write to a buffer) than try to be cute and invoke all the various pragmas and compiler voodoo you need to get the structures to line up identically across multiple architectures and compilers. I once maintained a piece of code which did network communication by reading and writing directly into structures the way you're trying to do it. It supported 10 compilers across 6 architectures and 4 operating systems. It was not pretty, and I don't recommend anyone ever do it that way by choice. "Jane B. Halfond" wrote: > Hi, > > I'm currently writing a bitmap compression routine and trying to send a byte > stream which behind the scenes contains a structure of information (see > below). This byte stream is being sent from the PC to the Palm. I know > there's a problem with byte alignment with structures and therefore, tried > to byte swap the information on both sides. For some reason, something > isn't working right. Does anyone have any suggestions for sending > structures as byte streams from the PC to the Palm. > > Note: Either a byte stream of a CompARecordType record is being sent to the > Palm or of type CompNoneRecordType. > > I'm using MSVC++ v6 and Metrowerks for Palm development v6. > > Thanks, > Jane > > --- > Jane Halfond > Synergy Solutions, Inc. > http://www.synsolutions.com > a BarPoint.com Company > http://www.barpoint.com > 1-212-461-2292 > > // Because MSVC doesn't support UInt8, we need to use byte > #ifdef MSVC_COMPILED > #define UInt8 byte > #endif > > enum CompStyle { eCompNone = 0, eCompA }; > > typedef struct CompHeaderTypeTag > { > CompStyle eCompStyle; > unsigned long rawSize; // raw size of the uncompressed > data > unsigned long numBlocks; // number of CompATypes appearing in > the > compressed structure > } CompHeaderType; > > typedef struct CompABlockTypeTag > { > UInt8 token; > UInt8 repeat; > } CompABlockType; > > typedef struct CompARecordTypeTag > { > CompHeaderType hdr; > CompABlockType blocks[]; > } CompARecordType; > > typedef struct CompNoneRecordTypeTag > { > CompHeaderType hdr; > UInt8 buffer[]; > } CompNoneRecordType; > > -- > For information on using the Palm Developer Forums, or to unsubscribe, please > see http://www.palmos.com/dev/tech/support/forums/ -- Adam Wozniak Senior Software Design Engineer Surveyor Corporation [EMAIL PROTECTED] 4548 Broad Street [EMAIL PROTECTED] San Luis Obispo, CA 93401 -- For information on using the ACCESS Developer Forums, or to unsubscribe, please see http://www.access-company.com/developers/forums/
