Drag n drop from managed to unmanaged apps

A

Arvind Ghai

Hi,
Could you please help !
I am facing a problem in implementation of drag drop
between managed and unmanaged code.
I prepare a data object in managed environment to support
drag drop with a custom format.

DataObject dataOb = new DataObject();
DataFormats.Format myCustomFormat = DataFormats.GetFormat
("CustomFormat");
String data = "Custom Text";
dataOb.SetData(myCustomFormat.Name, data);

If the drop operation is completed over an Unmanaged
application's window (which is registered for Ole drop) I
use the following code slice.

void DropData(HWND hwnd, IDataObject *pDataObject)

{

UINT cF = RegisterClipboardFormat("CustomFormat");

FORMATETC fmtetc = {cF, 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL};

STGMEDIUM stgmed;



if(pDataObject->QueryGetData(&fmtetc) == S_OK)

{

if(pDataObject->GetData(&fmtetc, &stgmed) ==
S_OK)

{

PVOID data = GlobalLock(stgmed.hGlobal);

SetWindowText(hwnd, (char *)data);

GlobalUnlock(stgmed.hGlobal);

ReleaseStgMedium(&stgmed);

}

}

}



Here I get problem. The resulting window text is not the
desired text "Custom Text", instead it gives some junk.

Also if the data is of different type other than string, I
don't know how to get desired presentation of data in
unmanaged code.

If I do the same exercise with standard data format as
DataFormats.Text (managed) and corresponding CF_TEXT
(unmanaged) it works fine.

Regards
Arvind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top