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. HEAP CORRUPTION DETECTED!

HEAP CORRUPTION DETECTED!

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
11 Posts 5 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.
  • S susanne1

    hallo, i have the following piece of code , when i try to delete the lpKeyPoint i get HEAP CORRUPTION DETECTED! LPPOINT lpKeyPoint; lpKeyPoint = (LPPOINT)new LPPOINT(); GetCaretPos((LPPOINT)lpKeyPoint); if(lpKeyPoint) { delete lpKeyPoint; lpKeyPoint = NULL; } How can i solve this problem? Thanks.

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #2

    susanne1 wrote:

    lpKeyPoint = (LPPOINT)new LPPOINT()

    That should be:

    lpKeyPoint = new POINT();

    :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    In testa che avete, signor di Ceprano?

    S 1 Reply Last reply
    0
    • CPalliniC CPallini

      susanne1 wrote:

      lpKeyPoint = (LPPOINT)new LPPOINT()

      That should be:

      lpKeyPoint = new POINT();

      :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      S Offline
      S Offline
      susanne1
      wrote on last edited by
      #3

      thanks it worsk,but when i move the curosor up i get a worng value of y: CPoint* ptrKeyPoint = new CPoint(); int nCursorLine = 0; if((pMsg->message == WM_KEYDOWN)||(pMsg->message == WM_LBUTTONDOWN)) { if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_UP)||(pMsg->wParam == VK_DOWN) || (pMsg->message == WM_LBUTTONUP)) { GetCaretPos((LPPOINT)ptrKeyPoint); nCursorLine = ptrKeyPoint->y; } if(ptrKeyPoint) { delete ptrKeyPoint; ptrKeyPoint = NULL; } }

      CPalliniC S 2 Replies Last reply
      0
      • S susanne1

        thanks it worsk,but when i move the curosor up i get a worng value of y: CPoint* ptrKeyPoint = new CPoint(); int nCursorLine = 0; if((pMsg->message == WM_KEYDOWN)||(pMsg->message == WM_LBUTTONDOWN)) { if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_UP)||(pMsg->wParam == VK_DOWN) || (pMsg->message == WM_LBUTTONUP)) { GetCaretPos((LPPOINT)ptrKeyPoint); nCursorLine = ptrKeyPoint->y; } if(ptrKeyPoint) { delete ptrKeyPoint; ptrKeyPoint = NULL; } }

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #4

        susanne1 wrote:

        when i move the curosor up i get a worng value of y:

        What do you mean (i.e. details please)? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        S 1 Reply Last reply
        0
        • CPalliniC CPallini

          susanne1 wrote:

          when i move the curosor up i get a worng value of y:

          What do you mean (i.e. details please)? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          S Offline
          S Offline
          susanne1
          wrote on last edited by
          #5

          when i press the arrow key up.

          G CPalliniC 2 Replies Last reply
          0
          • S susanne1

            when i press the arrow key up.

            G Offline
            G Offline
            Garth J Lancaster
            wrote on last edited by
            #6

            susanne1 wrote:

            when i press the arrow key up.

            I think he can get that - what y value do you get ? 'g'

            CPalliniC 1 Reply Last reply
            0
            • G Garth J Lancaster

              susanne1 wrote:

              when i press the arrow key up.

              I think he can get that - what y value do you get ? 'g'

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #7

              Garth J Lancaster wrote:

              I think he can get that

              Well, it's Monday............. :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • S susanne1

                when i press the arrow key up.

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #8

                I try again: "How do you know that y value is wrong (please provide us details)?" :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                S 1 Reply Last reply
                0
                • CPalliniC CPallini

                  I try again: "How do you know that y value is wrong (please provide us details)?" :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  S Offline
                  S Offline
                  susanne1
                  wrote on last edited by
                  #9

                  the cursor stands on the second line and ptrKeyPoint->y = 32; it sohould be 16 instead of 32 because it starts with ptrKeyPoint->y = 0; (for the first line).

                  1 Reply Last reply
                  0
                  • S susanne1

                    thanks it worsk,but when i move the curosor up i get a worng value of y: CPoint* ptrKeyPoint = new CPoint(); int nCursorLine = 0; if((pMsg->message == WM_KEYDOWN)||(pMsg->message == WM_LBUTTONDOWN)) { if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_UP)||(pMsg->wParam == VK_DOWN) || (pMsg->message == WM_LBUTTONUP)) { GetCaretPos((LPPOINT)ptrKeyPoint); nCursorLine = ptrKeyPoint->y; } if(ptrKeyPoint) { delete ptrKeyPoint; ptrKeyPoint = NULL; } }

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #10

                    Ummmm - just don't use the heap, OK - this should work just as well:

                    CPoint keyPoint;
                    int nCursorLine = 0;
                    if((pMsg->message == WM_KEYDOWN)||(pMsg->message == WM_LBUTTONDOWN))
                    {
                    if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_UP)||(pMsg->wParam == VK_DOWN) || (pMsg->message == WM_LBUTTONUP))
                    {
                    GetCaretPos(&keyPoint);
                    nCursorLine = keyPoint.y;
                    }

                    See what I've done there - I've declared and defined the CPoint item as a local, so it's on the stack. Then you don't need to worry about deallocation or anything. Much simpler.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    R 1 Reply Last reply
                    0
                    • S Stuart Dootson

                      Ummmm - just don't use the heap, OK - this should work just as well:

                      CPoint keyPoint;
                      int nCursorLine = 0;
                      if((pMsg->message == WM_KEYDOWN)||(pMsg->message == WM_LBUTTONDOWN))
                      {
                      if((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_UP)||(pMsg->wParam == VK_DOWN) || (pMsg->message == WM_LBUTTONUP))
                      {
                      GetCaretPos(&keyPoint);
                      nCursorLine = keyPoint.y;
                      }

                      See what I've done there - I've declared and defined the CPoint item as a local, so it's on the stack. Then you don't need to worry about deallocation or anything. Much simpler.

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #11

                      But corrupting the heap is much more fun. ;)

                      It is a crappy thing, but it's life -^ Carlo Pallini

                      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