Question about COleDropTarget .

Environment: Win95 OSR2 & VC++5

Hi all,
     I have a question about using COleDropTarget to
make a drop-file support app .  My question is ,when a
drag-drop operation is over how to get the file's name
and path in the OnDrop() function ?
     Although I can handle the WM_DROPFILES to get
what I want , I think there also should be these infos in the COleDataObject type object come along with the OnDrop()
function .  

      I'v made below call :
CFile *pFile = pDataObject->GetFileData(CF_HDROP);

It seemed successful and return a value , but I can't get the file's name and path with :  pFile-> GetFilePath () .

      Did I do something wrong ? Can anyone tell me the correct method to do this ?

      Any idea will be greatly appreciated !
Who is Participating?
Andy_KeysConnect With a Mentor Commented:
You use the DragQueryFile to get fileneme from the CF_HDROP struct.
demonPAuthor Commented:
Edited text of question
demonPAuthor Commented:
Hi Andy,
   Thanks for your answer , could you explain it
more clearly ?
   DragQueryFile() can just accept HDROP handle as
parameter , how can I get it in OnDrop() function ?

Sorry I was a bit vague
try something like

unsigned int a, uiFiles

HRESULT hres = pDataObject->GetData(this->_pdtobj, &fmte, &medium);
if (SUCCEEDED(hres))
HDROP hdrop = medium.hGlobal;
uiFiles = DragQueryFile(hdrop, (UINT)-1, NULL, 0);
char szFile[MAX_PATH];
char szBuf[MAX_PATH*2+64];
//now loop to get the individual names
for(a =0; a < uiFiles; a++ )
DragQueryFile(hdrop, a, szFile, sizeof(szFile));
This may need a bit of tiding but I hope it helps

demonPAuthor Commented:
Hi Andy,
     I have tried your code , it worked very well .
But it seemed I found a relatively simple method to
do it .

    I just called:
hDropFile = (HDROP)GetGlobalData(CF_HDROP);

Now the handle can be used by DragQueryFile() and
everything is OK ,too .

    Thank you for the answer !


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.