array指针数组的赋值有关问题


array指针数组的赋值问题
/*VS2005 C++ FORM dotnet platform 

问题是我对ssinfoglaobal1[1]->ssdata[1]->CounterValue 赋值时,怎么把
ss
infoglaobal1[1]->ssdata[2]->CounterValue 
ssinfoglaobal1[1]->ssdata[3]->CounterValue 
ss
infoglaobal1[1]->ssdata[4]->CounterValue 
ssinfoglaobal1[1]->ssdata[5]->CounterValue 
ss
infoglaobal1[1]->ssdata[6]->CounterValue 
等的值也给修改了?

对ptr = ssinfoglaobal1[1];
ptr->timeout = SSTIMEOUTMAX;
ptr->mach = mach;
ptr->mac
l = macl;
ptr->bcid = mstr.Bcid;
的赋值也是把 ss
infoglaobal1[2]
ss
infoglaobal1[3]
ss
infoglaobal1[4]
ss
infoglaobal1[5]
的值给修改了。

一般在服务器重启后出现这种问题。
*/

#define CNT
IDSSNUM 0x4

#define STRUCTSSENTRYDATASIZE 48  
typedef struct
{
  UINT8 MacAddr[6];
  UINT16 Bcid;
  UINT32 IPADDR;
  UINT16 DIUC;
  UINT16 UIUC;

  UINT16 DL
ZONE;
  UINT16 ULZONE;
  UINT32 SsPower;
  UINT16 Rssi1;
  UINT16 Rssi2;
  UINT16 Cnr1;
  UINT16 Cnr2;

  UINT32 Rx
Bytes;
  UINT32 TxBytes;
  UINT32 Error
Pdus;
  UINT32 timer;
}STRUCTSsEntryData;


public ref class UdpState
{
  public: UdpClient^ udpClient ;  
  public: IPEndPoint^ ipEndPoint ;  
  public: unsigned long id;
};

public ref class DISPLAYDATA1
{
public:
unsigned long CounterID;
unsigned long CounterValue;
};
public ref class SS
INFOGLOBAL
{
public:
unsigned long bsid
h;
unsigned long bsidl;
unsigned long mac
h;
unsigned long macl;
unsigned long bcid;
unsigned long time
out;
array <DISPLAYDATA1^>^ ssdata;
};

static int bcid1index;
static array<SS
INFOGLOBAL^>^ ssinfoglaobal1;//[8]
static unsigned long isMessageReceived ;
System::IAsyncResult^ socket1
result;
private: System::Net::Sockets::UdpClient^ socket1;
private: System::Net::IPEndPoint^ ipEndPoint;

void Initialize(void)
{  
ssinfoglaobal1 = gcnew array<SSINFOGLOBAL^>(128);
for(i = 0; i<128; i++)
{
ssinfoglaobal1[i] = gcnew SSINFOGLOBAL();
ssinfoglaobal1[i]->ssdata = gcnew array<DISPLAYDATA1^>(CNTIDSSNUM);
for(j = 0; j < CNT
IDSSNUM; j++)
{
ssinfoglaobal1[i]->ssdata[j] = gcnew DISPLAYDATA1();
}
}
}

void receivemonitordataforbs(void)
{
UdpState^ udpState = gcnew UdpState();
udpState->ipEndPoint = ipEndPoint;
udpState->udpClient = socket1;
  while(1)
  {
if(isMessageReceived == 0)
{
isMessageReceived = 1;
try
{
socket1result = socket1->BeginReceive(gcnew AsyncCallback(ReceiveCallback), udpState);
}catch( Exception^ e )
{
isMessageReceived = 0;
this->textBox31->Text += e->ToString(); Console::WriteLine( e->ToString() );
continue;
}
}else
{

System::Threading::Thread::Sleep(10);
Application::DoEvents();
}
  }
}
static void ReceiveCallback(System::IAsyncResult^ asyncResult)
{
int i, j, count;
int msg
len, msgnum, index;
unsigned long buf
len;
unsigned long startbytes;
unsigned long mach,macl;

long long l
tmp0;
array<unsigned char>^ receiveBytes ;
DBGSTAT Dbgstat;
STATVALUE Msgstat;


UdpClient^ udpClient =((UdpState^)(asyncResult->AsyncState))->udpClient;
IPEndPoint^ ipEndPoint =((UdpState^)(asyncResult->AsyncState))->ipEndPoint;

try{
receiveBytes = udpClient->EndReceive(asyncResult, ipEndPoint);
}
catch( Exception^ e) 
{
isMessageReceived = 0;
Console::WriteLine( e->ToString() );
return;
}


Dbgstat.CommandType = (receiveBytes[0]<<24) + (receiveBytes[1]<<16) + (receiveBytes[2]<<8) + receiveBytes[3];
Dbg
stat.DataLength = (receiveBytes[4]<<24) + (receiveBytes[5]<<16) + (receiveBytes[6]<<8) + receiveBytes[7];
startbytes = 8;
buf
len = receiveBytes->Length;
if(buflen < (Dbgstat.DataLength+DBGSTATHEADERLENGTH))
{
Dbg
stat.DataLength = (buflen - DBGSTATHEADERLENGTH)&0xfff8;
}
if(DBGSTATCMDQUERYREPLY == Dbgstat.CommandType)
{
isMessageReceived = 2;
}
if(Dbg
stat.DataLength > 0)
{

msgnum = 0;

if(DBG
STATCMDCPSSGLOBALANSWER == Dbgstat.CommandType)
{
STRUCTSsEntryData mstr;
SS
INFOGLOBAL^ ptr;

int bcid
index = 0xffff;

startbytes = DBGSTATHEADERLENGTH;
while(startbytes < Dbgstat.DataLength)
{
mstr.MacAddr[0] = receiveBytes[startbytes];
mstr.MacAddr[1] = receiveBytes[startbytes+1];
mstr.MacAddr[2] = receiveBytes[startbytes+2];
mstr.MacAddr[3] = receiveBytes[startbytes+3];
mstr.MacAddr[4] = receiveBytes[startbytes+4];
mstr.MacAddr[5] = receiveBytes[startbytes+5];
mstr.Bcid = (receiveBytes[startbytes+6]<<8) + receiveBytes[startbytes+7];
m
str.IPADDR = (receiveBytes[startbytes+8]<<24) + (receiveBytes[startbytes+9]<<16) + (receiveBytes[startbytes+10]<<8) + (receiveBytes[startbytes+11]);
mstr.DIUC = (receiveBytes[startbytes+12]<<8) + receiveBytes[startbytes+13];
m
str.UIUC = (receiveBytes[startbytes+14]<<8) + receiveBytes[startbytes+15];

mstr.DLZONE = (receiveBytes[startbytes+16]<<8) + receiveBytes[startbytes+17];
mstr.ULZONE = (receiveBytes[startbytes+18]<<8) + receiveBytes[startbytes+19];
mstr.SsPower = (receiveBytes[startbytes+20]<<24) + (receiveBytes[startbytes+21]<<16) + (receiveBytes[startbytes+22]<<8) + (receiveBytes[startbytes+23]);
m
str.Rssi1 = (receiveBytes[startbytes+24]<<8) + receiveBytes[startbytes+25];
mstr.Rssi2 = (receiveBytes[startbytes+26]<<8) + receiveBytes[startbytes+27];
m
str.Cnr1 = (receiveBytes[startbytes+28]<<8) + receiveBytes[startbytes+29];
mstr.Cnr2 = (receiveBytes[startbytes+30]<<8) + receiveBytes[startbytes+31];

m
str.RxBytes = (receiveBytes[startbytes+32]<<24) + (receiveBytes[startbytes+33]<<16) + (receiveBytes[startbytes+34]<<8) + (receiveBytes[startbytes+35]);
m
str.TxBytes = (receiveBytes[startbytes+36]<<24) + (receiveBytes[startbytes+37]<<16) + (receiveBytes[startbytes+38]<<8) + (receiveBytes[startbytes+39]);
m
str.ErrorPdus = (receiveBytes[startbytes+40]<<24) + (receiveBytes[startbytes+41]<<16) + (receiveBytes[startbytes+42]<<8) + (receiveBytes[startbytes+43]);
m
str.timer = (receiveBytes[startbytes+44]<<24) + (receiveBytes[startbytes+45]<<16) + (receiveBytes[startbytes+46]<<8) + (receiveBytes[startbytes+47]);

bcidindex = 0xffff;

mach = (receiveBytes[start
bytes]<<24) + (receiveBytes[startbytes+1]<<16) + (receiveBytes[startbytes+2]<<8) + (receiveBytes[startbytes+3]);
macl = (receiveBytes[start
bytes+4]<<24) + (receiveBytes[startbytes+5]<<16);

for(j = 0; j < (int)bcid1
index; j++)
{
if((ssinfoglaobal1[j]->mach == mach)&&(ssinfoglaobal1[j]->macl == macl))
{
ptr = ssinfoglaobal1[j];
ptr->timeout = SSTIMEOUTMAX;
ptr->bcid = mstr.Bcid;
bcid
index = j;
break;
}
}
if(bcidindex == 0xffff)
{
if(bcid1
index < 128)
{
ptr = ssinfoglaobal1[bcid1index];
ptr->time
out = SSTIMEOUTMAX;
ptr->mac
h = mach;
ptr->macl = macl;
ptr->bcid = m
str.Bcid;
bcidindex = bcid1index;
bcid1index++;
}else
{
isMessageReceived = 0;
return;
}
}
ss
infoglaobal1[bcidindex]->ssdata[0]->CounterValue = mstr.Bcid;
ssinfoglaobal1[bcidindex]->ssdata[1]->CounterValue = mach;
ssinfoglaobal1[bcidindex]->ssdata[2]->CounterValue = macl;
ssinfoglaobal1[bcidindex]->ssdata[3]->CounterValue = (mstr.DLZONE<<16)+mstr.ULZONE;
ssinfoglaobal1[bcidindex]->ssdata[4]->CounterValue = (mstr.DIUC<<16)+mstr.UIUC;
ssinfoglaobal1[bcidindex]->ssdata[5]->CounterValue = mstr.IPADDR;
ss
infoglaobal1[bcidindex]->ssdata[6]->CounterValue = mstr.SsPower;
ssinfoglaobal1[bcidindex]->ssdata[7]->CounterValue = (mstr.Rssi1<<16)+mstr.Rssi2;
ssinfoglaobal1[bcidindex]->ssdata[8]->CounterValue = (mstr.Cnr1<<16)+mstr.Cnr2;
ssinfoglaobal1[bcidindex]->ssdata[9]->CounterValue = mstr.RxBytes;
ssinfoglaobal1[bcidindex]->ssdata[10]->CounterValue = mstr.TxBytes;
ssinfoglaobal1[bcidindex]->ssdata[11]->CounterValue = mstr.ErrorPdus;

startbytes += STRUCTSSENTRYDATASIZE;
}
}
}
}


C++/VC 程序开发 数组

little明 11 years, 8 months ago

不能把关键的贴上来啊?

Astria answered 11 years, 8 months ago

请把出问题的语句标出


HKG字幕组 answered 11 years, 8 months ago

有难度,关注中~~~

工口君2010 answered 11 years, 8 months ago

Your Answer