hi,
I'm trying to implement drag and drop property in my dialog based application,
by using COleDropTarget and COleDataSource.
OnBeginDrag I allocate global memory, cache global data and call DoDragDrop
HANDLE hdata = GlobalAlloc ( GPTR, sizeof ( TVITEM ) ) ;
TVITEM *pItem = ( TVITEM* ) ::GlobalLock ( hdata ) ;
::GlobalUnlock ( hdata ) ;
//here I fill the pItem fields
COleDataSource m_coledatasource ;
m_coledatasource.CacheGlobalData ( MY_REGISTERED_FORMAT, hdata ) ;
DROPEFFECT dropeffect = m_coledatasource.DoDragDrop( DROPEFFECT_COPY | DROPEFFECT_MOVE ) ;
in the OnDrop function I handle the dropping and call GlobalFree
BOOL CMyOleDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point )
{
HANDLE hGlobal = pDataObject -> GetGlobalData ( MainDlg->contact_cp_format ) ;
TVITEM *pItem = ( TVITEM* ) GlobalLock ( hGlobal ) ;
//do the actual dropping
GlobalUnlock ( hGlobal ) ;
GlobalFree(hGlobal);
}
The problem I'm facing is when I try to call GlobalFree(hdata)
after the DoDragDrop returns with the DROPEFFECT_NONE
the problem appears only when I start to drag a certain item then cancel the drop, then if i try to drag and drop the same item again
exceptions occur when I try to access the pItem fields in the OnDrop function.
this behaviour disappears if I remove the GlobalFree(hdata).
what am i missing?
how does the global alloc and free work?
is it freeing something related to my item?
I also noticed that "always" the handle retuned by GetGlobalData is not the same one that was returned when GlobalAlloc was called. Is that normal for CacheGlobalData and GetGlobalData?
any help would be greatly apreciated
I'm trying to implement drag and drop property in my dialog based application,
by using COleDropTarget and COleDataSource.
OnBeginDrag I allocate global memory, cache global data and call DoDragDrop
HANDLE hdata = GlobalAlloc ( GPTR, sizeof ( TVITEM ) ) ;
TVITEM *pItem = ( TVITEM* ) ::GlobalLock ( hdata ) ;
::GlobalUnlock ( hdata ) ;
//here I fill the pItem fields
COleDataSource m_coledatasource ;
m_coledatasource.CacheGlobalData ( MY_REGISTERED_FORMAT, hdata ) ;
DROPEFFECT dropeffect = m_coledatasource.DoDragDrop( DROPEFFECT_COPY | DROPEFFECT_MOVE ) ;
in the OnDrop function I handle the dropping and call GlobalFree
BOOL CMyOleDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point )
{
HANDLE hGlobal = pDataObject -> GetGlobalData ( MainDlg->contact_cp_format ) ;
TVITEM *pItem = ( TVITEM* ) GlobalLock ( hGlobal ) ;
//do the actual dropping
GlobalUnlock ( hGlobal ) ;
GlobalFree(hGlobal);
}
The problem I'm facing is when I try to call GlobalFree(hdata)
after the DoDragDrop returns with the DROPEFFECT_NONE
the problem appears only when I start to drag a certain item then cancel the drop, then if i try to drag and drop the same item again
exceptions occur when I try to access the pItem fields in the OnDrop function.
this behaviour disappears if I remove the GlobalFree(hdata).
what am i missing?
how does the global alloc and free work?
is it freeing something related to my item?
I also noticed that "always" the handle retuned by GetGlobalData is not the same one that was returned when GlobalAlloc was called. Is that normal for CacheGlobalData and GetGlobalData?
any help would be greatly apreciated