locked
Error when Implement the DragDrop

    Question

  • Hi! Why do I always get a COMException error (message: Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))) when I'm implementing the DoDragDrop Method. 

    Can anyone share their ideas on how to handle this?

    Thanks in advance.
    Wednesday, August 24, 2005 12:33 PM

Answers

  • Hi,

    When you drag over a window, COM will check to see if that window has a drop target registered.  If it does, it will call IDropTarget::DragEnter to give the drop target the opportunity to indicate whether it can accept drops from the drop source.  To do this, it calls IDataObject::QueryGetData against the source IDataObject with any and all formats that it can support.  More than likely, the drop source won't be able to support every format--in which case it will return DV_E_FORMATETC (which Com interop will convert to an exception).

    When you say that you get a COMException, are you talking about a handled exception or an unhandled one? 

    One possibility is that you have break on all thrown Common Language Runtime exceptions turned on and you are just seeing the 1st chance exceptions that are thrown when the QueryGetData call fails.  This is by design and you either need to disable breaking on exceptions while you are doing this or use remote debugging so that the switch to debugging doesn't interrupt your attempts to drag.  If you remote debug, you can simply ignore all of those exceptions as they occur since they will ultimately be handled.

    If you are actually getting an unhandled exception, please elaborate more on what you are doing (as Devon suggested).  What kind of a drop source are you using, where are you trying to drop, etc.  It may be the case that you are simply trying to drop an unsupported format--though I didn't think that DoDragDrop would actually propogate that error back.

    Sincerely,

    Geoff Darst
    Microsoft VSTO Tools

    Wednesday, September 28, 2005 4:38 PM
    Answerer

All replies

  • Hello,

    - What format are you attempting to drag/drop?  Can you share a couple lines of code?
    - Where are you dragging from? The actions pane?

    thanks,

    Devin

    Wednesday, September 28, 2005 3:31 PM
  • Hi,

    When you drag over a window, COM will check to see if that window has a drop target registered.  If it does, it will call IDropTarget::DragEnter to give the drop target the opportunity to indicate whether it can accept drops from the drop source.  To do this, it calls IDataObject::QueryGetData against the source IDataObject with any and all formats that it can support.  More than likely, the drop source won't be able to support every format--in which case it will return DV_E_FORMATETC (which Com interop will convert to an exception).

    When you say that you get a COMException, are you talking about a handled exception or an unhandled one? 

    One possibility is that you have break on all thrown Common Language Runtime exceptions turned on and you are just seeing the 1st chance exceptions that are thrown when the QueryGetData call fails.  This is by design and you either need to disable breaking on exceptions while you are doing this or use remote debugging so that the switch to debugging doesn't interrupt your attempts to drag.  If you remote debug, you can simply ignore all of those exceptions as they occur since they will ultimately be handled.

    If you are actually getting an unhandled exception, please elaborate more on what you are doing (as Devon suggested).  What kind of a drop source are you using, where are you trying to drop, etc.  It may be the case that you are simply trying to drop an unsupported format--though I didn't think that DoDragDrop would actually propogate that error back.

    Sincerely,

    Geoff Darst
    Microsoft VSTO Tools

    Wednesday, September 28, 2005 4:38 PM
    Answerer