//1.结构定义
TMsgHead=packed record
iMsgLen:Longint;
iMsgID:Longint;
sMsgSerial:Array[0..11] of char;
end; TMsgBody_Bind=packed record
iLoginType:Byte;
sLoginUser:Array[0..15] of char;
sLoginPwd:Array[0..15] of char;
sReserve:Array[0..7] of char;
end; TMsg_Bind=packed record
MsgHead:TMsgHead;
MsgBody:TMsgBody_Bind;
end;//2.赋值-----------------------------------------------
function TLT.BindData_Create():TMsg_Bind;
var
BindData:TMsg_Bind;
begin
ZeroMemory(@BindData,Sizeof(BindData));
BindData.MsgBody.iLoginType:=$1;
.....赋值操作
//调用,发送-----------------------------------------------
procedure TForm1.SckLtConnect(Sender: TObject; Socket: TCustomWinSocket);
var
BindData:TMsg_Bind;
begin
BindData:=Lt.BindData_Create;
sckLt.Socket.SendBuf(BindData,sizeof(BindData));
......................
result:=BindData;//-------------------------------------------------
现在的问题是,结构里面的iloginType等类型,赋数值之后,使用socket发送结构,发现数字1是用01 00 00 00 表示的,而不是00 00 00 01表示的,请问怎么会这样,服务器那边要求必须是00 00 00 01,这该怎么办呀??盼高手指教!
TMsgHead=packed record
iMsgLen:Longint;
iMsgID:Longint;
sMsgSerial:Array[0..11] of char;
end; TMsgBody_Bind=packed record
iLoginType:Byte;
sLoginUser:Array[0..15] of char;
sLoginPwd:Array[0..15] of char;
sReserve:Array[0..7] of char;
end; TMsg_Bind=packed record
MsgHead:TMsgHead;
MsgBody:TMsgBody_Bind;
end;//2.赋值-----------------------------------------------
function TLT.BindData_Create():TMsg_Bind;
var
BindData:TMsg_Bind;
begin
ZeroMemory(@BindData,Sizeof(BindData));
BindData.MsgBody.iLoginType:=$1;
.....赋值操作
//调用,发送-----------------------------------------------
procedure TForm1.SckLtConnect(Sender: TObject; Socket: TCustomWinSocket);
var
BindData:TMsg_Bind;
begin
BindData:=Lt.BindData_Create;
sckLt.Socket.SendBuf(BindData,sizeof(BindData));
......................
result:=BindData;//-------------------------------------------------
现在的问题是,结构里面的iloginType等类型,赋数值之后,使用socket发送结构,发现数字1是用01 00 00 00 表示的,而不是00 00 00 01表示的,请问怎么会这样,服务器那边要求必须是00 00 00 01,这该怎么办呀??盼高手指教!
Motorola的CPU中多字节整数是高位在前,低位在后的。
从楼主的描述来看,服务器端的程序是别人已经写好了的。如果真是这样的话,只能自己写转换函数来转换顺序了。
然后自己写处理函数,转换字节.....不过还是搞定了..谢谢大家!!!