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. CListCtrl Crash On Add Item

CListCtrl Crash On Add Item

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiodebugginghelp
8 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.
  • D Offline
    D Offline
    dehseth
    wrote on last edited by
    #1

    Hello, I have created a MFC application in Visual Studio 2005. I have added to my dialog based app a CListCtrl with View lvwReport. I add a pointer to this ctrl in header file:

    CListCtrl* listView;

    And I get the pointer at init dialog and insert columns:

    this->listView = (CListCtrl*) GetDlgItem(LISTVIEW);
    this->listView->InsertColumn(0, "Sıra No", LVCFMT_LEFT, 50);
    this->listView->InsertColumn(1, "Dosya Adı", LVCFMT_LEFT, 170);
    this->listView->InsertColumn(2, "Bağlantı", LVCFMT_LEFT, 320);
    this->listView->InsertColumn(3, "Durum", LVCFMT_CENTER, 100);
    this->listView->InsertColumn(4, "Dosya Şifresi", LVCFMT_LEFT, 130);

    which is fine till now. I also added a textbox and a button in dialog. When user enters something to dialog and clicks button. The text in textbox should be inserted to list control:

    int r = this->listView->InsertItem(count, countStr.getBuffer());

    When I started app in debug mode enter smt and clikc it it gives me an error: Unhandled exception at 0x275b9098 in dot.exe: 0xC0000005: Access violation reading location 0x00000050. :doh: and shows a line in afxwin2.inl file: _AFXWIN_INLINE LRESULT CWnd::_AFX_FUNCNAME(SendMessage)(UINT message, WPARAM wParam, LPARAM lParam) { ASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd, message, wParam, lParam); } Seems like I am not creating smt. What am I missing in here :confused:

    C 1 Reply Last reply
    0
    • D dehseth

      Hello, I have created a MFC application in Visual Studio 2005. I have added to my dialog based app a CListCtrl with View lvwReport. I add a pointer to this ctrl in header file:

      CListCtrl* listView;

      And I get the pointer at init dialog and insert columns:

      this->listView = (CListCtrl*) GetDlgItem(LISTVIEW);
      this->listView->InsertColumn(0, "Sıra No", LVCFMT_LEFT, 50);
      this->listView->InsertColumn(1, "Dosya Adı", LVCFMT_LEFT, 170);
      this->listView->InsertColumn(2, "Bağlantı", LVCFMT_LEFT, 320);
      this->listView->InsertColumn(3, "Durum", LVCFMT_CENTER, 100);
      this->listView->InsertColumn(4, "Dosya Şifresi", LVCFMT_LEFT, 130);

      which is fine till now. I also added a textbox and a button in dialog. When user enters something to dialog and clicks button. The text in textbox should be inserted to list control:

      int r = this->listView->InsertItem(count, countStr.getBuffer());

      When I started app in debug mode enter smt and clikc it it gives me an error: Unhandled exception at 0x275b9098 in dot.exe: 0xC0000005: Access violation reading location 0x00000050. :doh: and shows a line in afxwin2.inl file: _AFXWIN_INLINE LRESULT CWnd::_AFX_FUNCNAME(SendMessage)(UINT message, WPARAM wParam, LPARAM lParam) { ASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd, message, wParam, lParam); } Seems like I am not creating smt. What am I missing in here :confused:

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Why don't you instead associate a member variable with the control through the resource editor ?

      dehseth wrote:

      countStr.getBuffer()

      Yurk, never ever call GetBuffer without having read the documentation ! You don't need to call GetBuffer because CString provides cast operators. Calling GetBuffer will only bring you troubles.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      D 1 Reply Last reply
      0
      • C Cedric Moonen

        Why don't you instead associate a member variable with the control through the resource editor ?

        dehseth wrote:

        countStr.getBuffer()

        Yurk, never ever call GetBuffer without having read the documentation ! You don't need to call GetBuffer because CString provides cast operators. Calling GetBuffer will only bring you troubles.

        Cédric Moonen Software developer
        Charting control [v1.5] OpenGL game tutorial in C++

        D Offline
        D Offline
        dehseth
        wrote on last edited by
        #3

        It is not CString I am using in there. And that's not the problem. I wrote a constant string still fails.. I guess the problem is initializing something...

        C 1 Reply Last reply
        0
        • D dehseth

          It is not CString I am using in there. And that's not the problem. I wrote a constant string still fails.. I guess the problem is initializing something...

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          That was just a remark. I asked a question first which is more important: why are you using your list control this way ? Why not simply associate a member variable with the list control through the resource editor ?

          Cédric Moonen Software developer
          Charting control [v1.5] OpenGL game tutorial in C++

          D 1 Reply Last reply
          0
          • C Cedric Moonen

            That was just a remark. I asked a question first which is more important: why are you using your list control this way ? Why not simply associate a member variable with the list control through the resource editor ?

            Cédric Moonen Software developer
            Charting control [v1.5] OpenGL game tutorial in C++

            D Offline
            D Offline
            dehseth
            wrote on last edited by
            #5

            Well I have added member variable by right clicking on the CList control. Wizard just added control variable in .h file:

            public:
            // ClistCtrl control
            CView list;

            And added DDX Control code in .cpp file:

            DDX_Control(pDX, LISTVIEW, list);

            But I got these errors during compile: 1. error C2259: 'CView' : cannot instantiate abstract class 2. error C2248: 'CView::CView' : cannot access protected member declared in class 'CView' 3. error C2259: 'CView' : cannot instantiate abstract class Well I changed the CView type to CListCtrl. The application compiled successfully but when I tried to add an item it gives me this error: Unhandled exception at 0x275b9098 in dot.exe: 0xC0000005: Access violation reading location 0x00000050. and shows file afxcrit.h at line: LeaveCriticalSection(&_afxResourceLock[nLockType]); I guess the previous problem still remains... :confused: One more thing application also crashes at the same point when I click column header (it does not contain any data) :wtf:

            modified on Wednesday, September 3, 2008 6:54 AM

            C 1 Reply Last reply
            0
            • D dehseth

              Well I have added member variable by right clicking on the CList control. Wizard just added control variable in .h file:

              public:
              // ClistCtrl control
              CView list;

              And added DDX Control code in .cpp file:

              DDX_Control(pDX, LISTVIEW, list);

              But I got these errors during compile: 1. error C2259: 'CView' : cannot instantiate abstract class 2. error C2248: 'CView::CView' : cannot access protected member declared in class 'CView' 3. error C2259: 'CView' : cannot instantiate abstract class Well I changed the CView type to CListCtrl. The application compiled successfully but when I tried to add an item it gives me this error: Unhandled exception at 0x275b9098 in dot.exe: 0xC0000005: Access violation reading location 0x00000050. and shows file afxcrit.h at line: LeaveCriticalSection(&_afxResourceLock[nLockType]); I guess the previous problem still remains... :confused: One more thing application also crashes at the same point when I click column header (it does not contain any data) :wtf:

              modified on Wednesday, September 3, 2008 6:54 AM

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              I think you are doing a big mess with your code :omg: . If MFC associated a CView object, then it means you did something completely wrong. Ok, start everything over: put a list control where you want with the resource editor (and remove what you did earlier). Then right click on it and select 'Add Variable'. Then in the dialog that appear, leave the 'Control variable' check marked and insert the name in 'Variable name'. Finally click ok. This should add a CListCtrl variable in your class that you can then use.

              Cédric Moonen Software developer
              Charting control [v1.5] OpenGL game tutorial in C++

              D 1 Reply Last reply
              0
              • C Cedric Moonen

                I think you are doing a big mess with your code :omg: . If MFC associated a CView object, then it means you did something completely wrong. Ok, start everything over: put a list control where you want with the resource editor (and remove what you did earlier). Then right click on it and select 'Add Variable'. Then in the dialog that appear, leave the 'Control variable' check marked and insert the name in 'Variable name'. Finally click ok. This should add a CListCtrl variable in your class that you can then use.

                Cédric Moonen Software developer
                Charting control [v1.5] OpenGL game tutorial in C++

                D Offline
                D Offline
                dehseth
                wrote on last edited by
                #7

                Yeap you are right. I found the problem. I added MS ListView version 6.0 activeX control and did not add any related lib. So I removed that control and added another version of listView now it is working. Thank you very much for your replies. ;) Now I need to solve other problems... Learning Visual C++ seems like never ends :)

                C 1 Reply Last reply
                0
                • D dehseth

                  Yeap you are right. I found the problem. I added MS ListView version 6.0 activeX control and did not add any related lib. So I removed that control and added another version of listView now it is working. Thank you very much for your replies. ;) Now I need to solve other problems... Learning Visual C++ seems like never ends :)

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #8

                  dehseth wrote:

                  Learning Visual C++ seems like never ends

                  I suggest to buy a good book. You will see that it is far more efficient to do so rather than trying to work everything by yourself. It will save you hours of frustration.

                  Cédric Moonen Software developer
                  Charting control [v1.5] OpenGL game tutorial in C++

                  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