通过BHO从Outlook拖放到Internet Explorer在x32 / 86计算机上不起作用

本文关键字:x32 计算机 不起作用 Explorer BHO Outlook 拖放 Internet 通过 | 更新日期: 2023-09-27 17:56:14

我目前正在实现一个浏览器助手对象,该对象允许将电子邮件从Outlook拖动到Internet Explorer的页面。

我正在遵循以下帖子中描述的方法:将拖放功能从MS Outlook实现到我们的Web应用程序中。我已经让它工作,但只能在 x64 机器上工作。在 x32/86 机器上,我在以下代码段中出现异常(显然,为了简单起见,我已将真实文件名插入替换为假文件名插入):

DropFiles df = new DropFiles();
string filename = @"D:'projects'hello.txt";
byte[] binaryData = Encoding.Unicode.GetBytes(filename);
binaryData = binaryData.Concat(new byte[] { 0, 0 }).ToArray();
IntPtr pointerToGlobalMemory = Marshal.AllocHGlobal(Marshal.SizeOf(df) + binaryData.Length);
df.Files = Marshal.SizeOf(df);
df.Wide = true;
Marshal.StructureToPtr(df, pointerToGlobalMemory, true);
IntPtr newPointer = new IntPtr(pointerToGlobalMemory.ToInt32() + Marshal.SizeOf(df));
Marshal.Copy(binaryData, 0, newPointer, binaryData.Length);
var descriptorFormat = new COMInterop.FORMATETC();
descriptorFormat.cfFormat = HdropDescriptorId; // 15
descriptorFormat.ptd = IntPtr.Zero;
descriptorFormat.dwAspect = COMInterop.DVASPECT.DVASPECT_CONTENT;
descriptorFormat.lindex = -1;
descriptorFormat.tymed = COMInterop.TYMED.TYMED_HGLOBAL;
var td = new COMInterop.STGMEDIUM();
td.unionmember = pointerToGlobalMemory;
td.tymed = COMInterop.TYMED.TYMED_HGLOBAL;
dataObject.SetData(ref descriptorFormat, ref td, true);

在执行此代码的最后一个 ling(实际上设置假 HDROP 描述符)时,我收到以下异常:"无效的 FORMATETC 结构(来自 HRESULT 的例外:0x80040064 (DV_E_FORMATETC))"。

是否有人遇到过描述的问题或知道此问题的原因是什么?

更具体地说,环境 - 我在 win7 32 位和 IE 10 上遇到了这个麻烦,但我很确定原因,尤其是在那台机器中是 32 位。

通过BHO从Outlook拖放到Internet Explorer在x32 / 86计算机上不起作用

您需要实现自己的 IDataObject 并将其传递给原始 IDropTarget.Drop,而不是劫持来自 Outlook 的现有 IDataObject。