Nik*_*dev 5 c# outlook internet-explorer interop bho
我目前正在实现一个浏览器帮助程序对象,它允许将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);
Run Code Online (Sandbox Code Playgroud)
在执行此代码的最后一个(实际设置伪HDROP描述符)时,我得到以下异常:"无效的FORMATETC结构(HRESULT异常:0x80040064(DV_E_FORMATETC))".
有人经历过描述问题或了解这个问题的原因是什么?
更具体的环境 - 我在使用IE 10的win7 32位上遇到了这个问题,但我很确定特别是那台机器的原因是32位.
| 归档时间: |
|
| 查看次数: |
712 次 |
| 最近记录: |