Article # 7, added by Geoworks, historical record
| first | previous | index | next | last |

Using Clipboard




Question:
I am trying to implement drag and drop into my program and I want to get
the name of the transfer item. However, when I use this code to do it, I get
a VM_HANDLE_NOT_IN_USE error:

    TransferBlockID       transferID; /* File/Block of item header. */
    MemHandle             itemMem;    /* Mem block for item header. */
    ClipboardItemHeader * itemPtr;    /* Pointer to item header.    */

    ClipboardEndQuickTransfer( PasteCommon( CIF_QUICK, textOD,
                               pself->GDI_fileHandle, &itemBlock ) );
    transferID = ClipboardGetQuickItemInfo();
    itemPtr = VMLock( FileFromTransferBlockID( transferID ),
                      BlockFromTransferBlockID( transferID ),
                      &itemMem );
       /*
        * Add the new item to the map block.
        */
    @call self::MSG_SB_DOCUMENT_ADD_ITEM( itemBlock, itemPtr );
    VMUnlock( itemMem );

Answer:
Here is how to do it.
(Note: PasteCommon comes from the CLIPSAMP sample app.)

    ClipboardQuickNotifyFlags retFlags; /* Returned from PasteCommon. */

    retFlags = PasteCommon( CIF_QUICK, textOD,
                            pself->GDI_fileHandle, &itemBlock );
    transferID = ClipboardGetQuickItemInfo();
    itemPtr = VMLock( FileFromTransferBlockID( transferID ),
                      BlockFromTransferBlockID( transferID ),
                      &itemMem );
       /*
        * Add the new item to the map block.
        */
    @call self::MSG_SB_DOCUMENT_ADD_ITEM( itemBlock, itemPtr );
    VMUnlock( itemMem );
    ClipboardEndQuickTransfer( retFlags );

This code fragment works because it is getting the information
from the item header BEFORE calling ClipboardEndQuickTransfer, which
destroys that header. In the "bad" fragment, we were calling for
a VM block that was just freed, and thus we got the error message.