Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CList class

CList class

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    packetlos
    wrote on last edited by
    #1

    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?

    R 1 Reply Last reply
    0
    • P packetlos

      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?

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      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 consider new()ing instances of DATAGRAM 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups