I want to copy and paste a structure type of data (DRAGDATASTRUCT) to and from the clipboard.
I have registered the clipboard format in InitInstance and SetClipboardData in OnEditCopy, but when I try to get the data in OnEditPaste the data object doesn't contain the data copied.
An error(Unhandled exception in MFP.exe(MFC42D.Dll): 0xC0000005: Access Violation) occured when it ran up to the line
CString nailPath=pData->fileNameArray.GetAt(0);
in OnEditPaste().

If I appended all of the codes in OnEditPaste to the end of OnEditCopy, it works fine.
Any idea why it doesn't work in OnEditPaste? Thanks in advance.


BOOL CMFPApp::InitInstance()
{
...
m_EditClipFormat = ::RegisterClipboardFormat ("ThumNailList");
...
}



typedef struct tagDRAGDATASTRUCT {
CArray<int, int> selIndexArray; //index of the nail
CStringArray fileNameArray; //nail path
} DRAGDATASTRUCT;


void CMFPView::OnEditCopy()
{
HGLOBAL hgData=GlobalAlloc( GPTR, sizeof(DRAGDATASTRUCT));
ASSERT(hgData!=NULL);

DRAGDATASTRUCT* lpData=(DRAGDATASTRUCT*) GlobalLock(hgData);
ASSERT(lpData!=NULL);
//get Nail Path
LPCSTR pathName = GetNailPath(m_nCurNailIndex);
CStringArray stringArray;
stringArray.SetAtGrow(0, pathName);
memcpy(&lpData->fileNameArray,&stringArray, sizeof(stringArray)); //nail path
GlobalUnlock(hgData);

OpenClipboard();
EmptyClipboard();
::SetClipboardData(theApp.m_EditClipFormat, hgData );
CloseClipboard();


}


void CMFPView::OnEditPaste()
{
OpenClipboard();
if (!IsClipboardFormatAvailable(theApp.m_EditClipFormat))
return;
HGLOBAL hGlobal;
DRAGDATASTRUCT* pData;
hGlobal = ::GetClipboardData(theApp.m_EditClipFormat);
pData=(DRAGDATASTRUCT*)GlobalLock(hGlobal);
ASSERT(pData!=NULL);
CString nailPath = pData->fileNameArray.GetAt(0); //Access Violation occured here
GlobalUnlock(hGlobal);
CloseClipboard();

}