CList class
-
Hi, What is the best way of using MFC's List to store data of this type?
typedef struct DATAGRAM { UINT packetID; // Sequence Number ip_header* ipHeader; // IP header pcap_pkthdr* wpHeader; // Winpcap header const UCHAR* pkt_data; // Packet data } DATAGRAM;
ipHeader* etc are pointers to further structs. I tried plain
CList DATAGRAM, DATAGRAM&
and are having problems with code like:packetCapture.AddTail(filledStruct);
The addtail is in a fairly fast loop and added data is going in fine and coming out of the list corrupted (due to something going out of scope before the operation is completed perhaps?) I am probably doing something extremely retarded, any ideas?
-
Hi, What is the best way of using MFC's List to store data of this type?
typedef struct DATAGRAM { UINT packetID; // Sequence Number ip_header* ipHeader; // IP header pcap_pkthdr* wpHeader; // Winpcap header const UCHAR* pkt_data; // Packet data } DATAGRAM;
ipHeader* etc are pointers to further structs. I tried plain
CList DATAGRAM, DATAGRAM&
and are having problems with code like:packetCapture.AddTail(filledStruct);
The addtail is in a fairly fast loop and added data is going in fine and coming out of the list corrupted (due to something going out of scope before the operation is completed perhaps?) I am probably doing something extremely retarded, any ideas?
Did you mean to do this instead?
packetCapture.AddTail (&filledStruct);
Also remember that
filledStruct
must be in scope for its address to be valid when you access the list after populating it. You might want to considernew()
ing instances ofDATAGRAM
and adding those instances to the list. They will be around as long as your application runs since they're created on the heap. Be sure to free up this memory before your app exits. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com