"Error HRESULT E_FAIL has been returned from a call to a COM component" when trying drag and drop an image to Skype c#

StackOverflow https://stackoverflow.com/questions/19775784

  •  03-07-2022
  •  | 
  •  

Frage

I'm trying to drag and drop an image from my C# app to Skype and the following error occurs: Error HRESULT E_FAIL has been returned from a call to a COM component. With other applications like Word, Excel works fine.

                        // Find the data behind the ListViewItem
                        DashboardItem item = (DashboardItem)listView.ItemContainerGenerator.
                            ItemFromContainer(listViewItem);

                        DragDropEffects returnedEffect = DragDropEffects.None;
                        dragging = true;

                        switch (item.Type)
                        {
                            case DashboardItem.ContentType.IMG:
                                BitmapSource realFile = new BitmapImage(new Uri(item.Content));
                                if (realFile != null)
                                {
                                    using (MemoryStream bitmapAsStream = Utils.BitmapSourceToStream(realFile))
                                    {
                                        if (bitmapAsStream != null)
                                        {
                                            using (MemoryStream dib = new MemoryStream())
                                            {
                                                    dib.Write(bitmapAsStream.GetBuffer(), 14, (int)(bitmapAsStream.Length - 14));
                                                    DataObject dragData = new DataObject(DataFormats.Dib, dib);
                                                    //Error next line
                                                    returnedEffect = DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy);
                                                    bitmapAsStream.Close();
                                                    dib.Close();
                                                }
                                            }
                                        }
                                    }
                                }
                                break;

I would like to repproduce the same bahavior as Windows Explorer when dropping an image to Skype. Any ideas?

War es hilfreich?

Lösung

When you drop an image from Explorer to Skype, the file is being sent. As far as I understood your code, you're dragging an image object, not a file.

If you would like to send a file from your file system, use this method.

If however you'd like to create the file in runtime without saving it to the file system, you could implement a virtual file, as described in the "Virtual file" section of this guide.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top