Solved: DragDrop Source on Windows didn’t worked for me

Hello
I am trying to do dragndrop file from my vst and the FL version 20.9 build 2748 won’t accept the DragSource made by the following code called in MouseMoved in CControl

auto dropSource = VSTGUI::makeOwnedVSTGUI::CDropSource();
auto dropCallback = VSTGUI::makeOwned();
dropSource->add(path, length, VSTGUI::IDataPackage::kFilePath);
VSTGUI::DragDescription dragDesc(dropSource);
doDrag(dragDesc, dropCallback);

I am creating file in temp dir. Dragging to the desktop works great, and dragging from vst to the Ableton works fine, but not in FL. It shows forbidden cursor.
Dragging the created in temp folder file manually from explorer to the FL works fine.
My SDK is vst-sdk_3.7.2_build-28_2021-03-30 but I can see not a lot changed in the win32dragging
Edit: it wont work also in latest FL

Here is the event trace in FL dropping to the channel:
GiveFeedback (moving) effect: 0
hresult: 262400 outEffect: 0 //it says ok but no(?)
Drag finished
Cursor seems not to focus to the FL (?) but still be in VST(?)

I checked in some other VST and the dropping worked in it to the channel and also to the playlist

after doing some heavy research seems you need to run another window from another thread (crazy lol) and do doDragDrop from it. IDataObjectAsyncCapability not works because the issue is before copying the file itself.

The problem is because there should be pceltFetched integer set to 1 in Win32DataObjectEnumerator::Next in win32dragging.cpp
MSDN tells it is optional param if celt is 1, but FLS still checks it. You need to set it to 1 (if success, because 1 element was fetched)

	COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE Next (ULONG celt, FORMATETC* rgelt, ULONG* pceltFetched) override
	{
		if (!rgelt)
			return E_INVALIDARG;
		const void* buffer;
		IDataPackage::Type dataType;
		auto dataSize = data->getData (index++, buffer, dataType);
		if (dataSize)
		{
			if (pceltFetched) {
				*pceltFetched = 1; //FL checks this!!!
			}
			if (dataType == IDataPackage::kText)
			{

Doing dragndrop from another thread is bad…
It seems to work from window from another thread or another process, because it seems to go thru OS, and OS translates these calls…
Dont ask how i how I found it :slight_smile: Almost went crazy after 1.5 month of no success…
Best
Michal

EDIT:
Also, there should be logic OR in the CDropTarget::DragEnter and CDropTarget::DragOver. Without it it sometimes may not work (for example it won’t accept the files from Image Line Edison)

		DragEventData data;
		data.drag = dragData;
		pFrame->getCurrentMousePosition (data.pos);
		pFrame->getCurrentMouseButtons (data.modifiers);
		auto result = pFrame->getFrame ()->platformOnDragEnter (data);
		if (result == DragOperation::Copy)
			*effect = DROPEFFECT_COPY;
		else if (result == DragOperation::Move)
			*effect = DROPEFFECT_MOVE;
		else if (result == DragOperation::CopyOrMove) <---------
			*effect = (DROPEFFECT_COPY | DROPEFFECT_MOVE);  <------- WORKS BETTER ;)
		else
			*effect = DROPEFFECT_NONE;