Question

I'm currently implementing a browser helper object which would allow dragging emails from the outlook to the internet explorer's page.

I'm following the approach described in the following post: Implementing a Drag-and-Drop function from MS Outlook into our web application. I've got it working but only on x64 machines. On the x32/86 machines i'm getting the exception in the following piece of code (obviously i've replaced real filename inserting with fake one for simplicity):

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);

On the executing the last ling of this code (actually setting the fake HDROP descriptor) i'm getting the following exception: "Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))".

Did someone experienced described problem or have an idea what can be the reason of this issue?

To be more specific about environment - i'm having this trouble on win7 32 bit with IE 10 but i'm pretty sure that the reason especially in that machine is 32 bit.

Était-ce utile?

La solution

You need to implement your own IDataObject and pass it to the original IDropTarget.Drop instead of hijacking an existing IDataObject coming from Outlook.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top