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. Pointers / drag and drop

Pointers / drag and drop

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
4 Posts 4 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.
  • L Offline
    L Offline
    Luke Murray
    wrote on last edited by
    #1

    Hey i've been trying to get drag and drop to work with my own data (had it working with text) i think i'm getting confused with pointers, here my lastest try, this is in a listview using WTL and the drag and drop classes from code project

    DragData dragData;
    .. get data from selected items and add it to dragData ..
    ..

    medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(dragData));
    DragData *pMem = (DragData *)GlobalLock(medium.hGlobal);
    (*pMem) = dragData;
    GlobalUnlock(medium.hGlobal);

    I'm not sure whats wrong but it always crashes i think its the (*pMem) = dragData; but i'm not sure why, i've tried many different way, sometimes i got it not to crash but then the data is never at the 'drop' end. thanks for any help, been annoying me for awhile now, cya Luke.

    G D A 3 Replies Last reply
    0
    • L Luke Murray

      Hey i've been trying to get drag and drop to work with my own data (had it working with text) i think i'm getting confused with pointers, here my lastest try, this is in a listview using WTL and the drag and drop classes from code project

      DragData dragData;
      .. get data from selected items and add it to dragData ..
      ..

      medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(dragData));
      DragData *pMem = (DragData *)GlobalLock(medium.hGlobal);
      (*pMem) = dragData;
      GlobalUnlock(medium.hGlobal);

      I'm not sure whats wrong but it always crashes i think its the (*pMem) = dragData; but i'm not sure why, i've tried many different way, sometimes i got it not to crash but then the data is never at the 'drop' end. thanks for any help, been annoying me for awhile now, cya Luke.

      G Offline
      G Offline
      G Steudtel
      wrote on last edited by
      #2

      Hi, I think you are right, when you think it`s the line (*pMem) = dragData. Try this one instead : pMem = &dragData; The difference is pMem is the address of some storage, which may be assigned. (*pMem) is the storage itself, which may not be assigned, unless its a simple type (int, char etc. ) or it's assignment operator is overloaded. The next thing is, pMem is the storage you get from the system, to put some values in. So my code will crash too. So use a memory copy function like memcpy(pMem,&dragData,sizeof(dragData). I think this will do the job. G. Steudtel

      1 Reply Last reply
      0
      • L Luke Murray

        Hey i've been trying to get drag and drop to work with my own data (had it working with text) i think i'm getting confused with pointers, here my lastest try, this is in a listview using WTL and the drag and drop classes from code project

        DragData dragData;
        .. get data from selected items and add it to dragData ..
        ..

        medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(dragData));
        DragData *pMem = (DragData *)GlobalLock(medium.hGlobal);
        (*pMem) = dragData;
        GlobalUnlock(medium.hGlobal);

        I'm not sure whats wrong but it always crashes i think its the (*pMem) = dragData; but i'm not sure why, i've tried many different way, sometimes i got it not to crash but then the data is never at the 'drop' end. thanks for any help, been annoying me for awhile now, cya Luke.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        In addition to the other suggestion, you should get into the habit of checking return values, especially for dynamically allocated memory.

        1 Reply Last reply
        0
        • L Luke Murray

          Hey i've been trying to get drag and drop to work with my own data (had it working with text) i think i'm getting confused with pointers, here my lastest try, this is in a listview using WTL and the drag and drop classes from code project

          DragData dragData;
          .. get data from selected items and add it to dragData ..
          ..

          medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(dragData));
          DragData *pMem = (DragData *)GlobalLock(medium.hGlobal);
          (*pMem) = dragData;
          GlobalUnlock(medium.hGlobal);

          I'm not sure whats wrong but it always crashes i think its the (*pMem) = dragData; but i'm not sure why, i've tried many different way, sometimes i got it not to crash but then the data is never at the 'drop' end. thanks for any help, been annoying me for awhile now, cya Luke.

          A Offline
          A Offline
          AlexO
          wrote on last edited by
          #4

          I think you ment to

          DragData dragData;
          .. get data from selected items and add it to dragData ..
          ..

          medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(dragData));
          DragData *pMem = (DragData *)GlobalLock(medium.hGlobal);

          (*pMem) = dragData;

          //try coping memory, instead of passing stack(!?!?!?) variable
          ::memcpy(pMem, &dragData, sizeof(DragData));

          GlobalUnlock(medium.hGlobal);

          P.S. what is the reason for using GlobalAlloc?

          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