Thread: Help! CListCtrl access violation

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    Angry Help! CListCtrl access violation

    I have used CListCtrl in the past with no problem, but in my current project I get an access violation.

    I have traced it down to the face that the m_hWnd in not set. Trying to set it also results in an access violation.

    I am able to create the column headers with no problem. It is when I perform an InsertItem that the error occurs. I have compared my implementation with what I had done in my previous project and it all looks the same.

    Code:
    	m_PayoutSheet.SetExtendedStyle(m_PayoutSheet.GetExtendedStyle()|LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS|LVS_EX_GRIDLINES);
    
    	m_PayoutSheet.InsertColumn(0,"Place",LVCFMT_LEFT,40,-1);
    	m_PayoutSheet.InsertColumn(1,"Percentage",LVCFMT_LEFT,80,-1);
    	m_PayoutSheet.InsertColumn(2,"Prize",LVCFMT_LEFT,50,-1);
    	char PlaceT[255];
    	char PercentageT[255];
    	sprintf(PlaceT,"%d",Place);
    	sprintf(PercentageT,"%d",Percentage);
    	m_PayoutSheet.InsertItem(0,PlaceT);
    	// Insert subitem for col 1
    	m_PayoutSheet.SetItemText(1, 1, PercentageT);
    Best Regards,

    Bonkey

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Update:

    The column headers are created in OnInitDialog(). The InsertItem is in a seperate funtion.

    A quick test just proved I was able to do an InsertItem inside OnInitDialog(). Not sure why that is, but I wanted to provide more info.
    Best Regards,

    Bonkey

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Where have you put this code ? Keep in mind that you cannot do this in the constructor of the window class.

    Edit:

    m_PayoutSheet.InsertItem(0,PlaceT);
    // Insert subitem for col 1
    m_PayoutSheet.SetItemText(1, 1, PercentageT);

    I don't have my help handy, but if one of the 1s in SetItemText is the index of the item, shouldn't that be a zero ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    It is in a function called SavePayoutData().

    The only thing weird about it is that is is called from another dialog. But I do the exact same thing in my other project with no problems.
    Best Regards,

    Bonkey

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    There must be something wrong with the function. I am having problems with a CList in the same function, if I move it out, it works.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Istream::Release access violation? [C++]
    By A10 in forum Windows Programming
    Replies: 10
    Last Post: 01-13-2009, 10:56 PM
  2. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. access violation
    By bonkey in forum C++ Programming
    Replies: 15
    Last Post: 11-20-2003, 10:22 AM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM