如果你有Delphi的,就应该会写BCB的。
#pragma pack(push)
#pragma pack(1)
struct DataPacket_S
{
WORD Transfer;
BYTE DataType; //数据类型
BYTE Command; //命令
DWORD DataLen; //数据长度;
BYTE DataBuffer[512]; //数据
};
#pragma pack(pop)
....
{
struct DataPacket_S *pDPS;
BYTE *buf;
buf = (BYTE *)malloc(sizeof(DataPacket_S));
pDPS = (struct DataPacket_S *)buf;
pDPS->Transfer = htons(0x1234);
pDPS->DataType = 0x56;
pDPS->Command = 0x78;
pDPS->DataLen = htonl(512);
memset(pDPS->DataBuffer,0x9,512);
send(...,buf, ...);
}