Run-Time Check Failure #2 - Stack around the variable 'sCommand_ID' was corrupted. byte* EMSP2_0::C_MSG_Head::getBytes()
{
byte sTotal_length[2];
Utility::shortToBytes(mh.Total_length,sTotal_length);
result[0]=sTotal_length[0];
result[1]=sTotal_length[1];
//delete sTotal_length;
byte sCommand_ID[2];
Utility::shortToBytes(mh.Command_ID,sCommand_ID);
result[2]=sCommand_ID[0];
result[3]=sCommand_ID[1];
result[4]=mh.Crypt;
byte sSeqNum[4];
Utility::intToBytes(mh.Seqnum,sSeqNum);
result[5]=sSeqNum[0];
result[6]=sSeqNum[1];
result[7]=sSeqNum[2];
result[8]=sSeqNum[3];
byte sUserNo[4];
Utility::intToBytes(mh.UserNo,sUserNo);
result[9]=sUserNo[0];
result[10]=sUserNo[1];
result[11]=sUserNo[2];
result[12]=sUserNo[3];
bsize=13;
return result;}
result的定义为byte result[13];
{
byte sTotal_length[2];
Utility::shortToBytes(mh.Total_length,sTotal_length);
result[0]=sTotal_length[0];
result[1]=sTotal_length[1];
//delete sTotal_length;
byte sCommand_ID[2];
Utility::shortToBytes(mh.Command_ID,sCommand_ID);
result[2]=sCommand_ID[0];
result[3]=sCommand_ID[1];
result[4]=mh.Crypt;
byte sSeqNum[4];
Utility::intToBytes(mh.Seqnum,sSeqNum);
result[5]=sSeqNum[0];
result[6]=sSeqNum[1];
result[7]=sSeqNum[2];
result[8]=sSeqNum[3];
byte sUserNo[4];
Utility::intToBytes(mh.UserNo,sUserNo);
result[9]=sUserNo[0];
result[10]=sUserNo[1];
result[11]=sUserNo[2];
result[12]=sUserNo[3];
bsize=13;
return result;}
result的定义为byte result[13];
解决方案 »
- MFC中的edit控件怎样能被多次赋值并且控件上都显示出所赋的值
- 如何实现网页查询,并得到返回的结果 Wininet实现
- 这些标点符号[]\;',./的虚键代码是什么,MSDN里怎么查不到?
- ODBC 的数据库为空时, 不能 AddNew()的问题。。。 急,在线等。
- 急等:在自己封装的Dll中,对一个CWnd对象调用CreateEx()时出错!
- 如何通过程序的方式来修改系统IP?
- 调用问题!
- 求助:SendARP()返回的结果显示返回的字节数为0,错误代码用FormatMessage()显示为“连接到系统上的设备没有发挥作用”。可是我的网络明
- 有SDK/MFC编程爱好者的群吗?我要加入啊!
- 如何系统的学习流媒体技术
- 鼠标指针变化是哪个消息啊?????????
- 大牛门,你们觉得现在或者说以后VC搞哪些方向特别有发展?电子政务?安全审计?信息安全?……
Utility是我自己写的一组函数,用于网络操作的,
/*
用于准换字节和整数,用于替换ms 的nltoh,hlton,nstoh,hston
函数增加代码的可用性*/
#if !defined _UTILITY_H
#define _UTILITY_H
#pragma once
class Utility
{ public:
inline static void fillchar( byte* arr,char ch)//对字节数组清零
{ int size=sizeof(arr);
for(int i=0;i<size;i++)
{
arr[i]=ch;
}
}
inline static short bytesToShort( byte abyte[])//字节数组到字
{
int j;
int length=sizeof(abyte);
if(length <= 2)
j = length;
else
j = 2;
int i = 0;
for(int k = 0; k < j; k++)
i = (i << 8) + (abyte[k] & 0xff); return i;
}
inline static int bytesToInt( byte abyte[])//字节数组到整数
{
int j;
int length=sizeof(abyte);
if(length <= 4)
j = length;
else
j = 4;
int i = 0;
for(int k = 0; k < j; k++)
i = (i << 8) + (abyte[k] & 0xff); return i;
} inline static byte* decodeMsgID( byte abyte[])//消息ID解码
{
byte* abyte1=new byte(20);
int i;
int length=sizeof(abyte);
if(length < 10)
i = length;
else
i = 10;
for(int j = 0; j < i; j++)
{
abyte1[j * 2] = (byte)((abyte[j] >> 4 & 0xf) + 48);
abyte1[j * 2 + 1] = (byte)((abyte[j] & 0xf) + 48);
} return abyte1;
} inline static byte* intToBytes(int i, byte* abyte0)//整数到字节转换
{
fillchar(abyte0,0);
abyte0[3] = ( byte)i;
i >>= 8;
abyte0[2] = i;
i >>= 8;
abyte0[1] = i;
i >>= 8;
abyte0[0] = i;
return abyte0;
}
inline static byte* shortToBytes(short i, byte* abyte0 )//字到字节转换
{
fillchar(abyte0,0);
abyte0[1] = ( byte)i;
i >>= 8;
abyte0[0] = i;
return abyte0;
}
inline static void exchange(byte* bytes,int len)
{
for(int i=0;i<len/2;i++)
{ byte temp=bytes[i];
bytes[i]=bytes[len-i-1];
bytes[len-i-1]=temp;
}
}
inline static void ZeroBytes(byte* bytes,int len)
{
for(int i=0;i<len;i++)
{
bytes[i]=0;
}
}
inline static int HToNL(const int value)
{ byte theb[4];
Utility::ZeroBytes(theb,4);
int nl=0;
memcpy(theb,&value,4);
Utility::exchange(theb,4);
memcpy(&nl,theb,4);
return nl;
}
inline static int NToHL(int nl)
{
byte theb[4];
Utility::ZeroBytes(theb,4);
int hl=0;
memcpy(theb,&nl,4);
Utility::exchange(theb,4);
memcpy(&hl,theb,4);
return hl;}
};
#endif
是正常的都进行过测试的