Using OLE32 for files drag and drop

G

Guest

The history:
I have a C# form that must accept files "drag and drop" including Outlook
messages .msg. In order to support Outlook .msg file drop, I must use Ole32
(regular .net drag and drop support can't get the content of the .msg).

Now this works fine except that when I use Ole32, I can't get the list of
files that are dropped on my form. I.e. When I select say 2 files from the
Desktop and drop it on the form, I can't get the file list (I expect 2
filenames), yet I only get 1 filename (the last one that was selected).
Maybe I just don't know what call to make to get all files.

Here is a sample of the calls
int OleDrop(object pDataObj, int grfKeyState, long pt, ref int pdwEffect)
{
cachedEffect = DragDropEffects.None; // Default to
DROPEFFECT_NONE

// Retrieve the list of files/folders
NativeMethods.IOleDataObject dataObject =
(NativeMethods.IOleDataObject)pDataObj;

string filename = "";
NativeMethods.STGMEDIUM medium = new NativeMethods.STGMEDIUM();

NativeMethods.FORMATETC format = new NativeMethods.FORMATETC();
format.cfFormat =
(ushort)NativeMethods.ShellClipboardFormats.CFSTR_FILENAMEW.Id;
format.dwAspect = NativeMethods.DVASPECT_CONTENT;
format.lindex = -1;
format.ptd = new IntPtr(0);
format.tymed = NativeMethods.TYMED_HGLOBAL |
NativeMethods.TYMED_ISTORAGE | NativeMethods.TYMED_ISTREAM |
NativeMethods.TYMED_FILE;

int result = dataObject.OleGetData(format, medium);
if (NativeMethods.Succeeded(result))
{
HandleRef hGlobal = new HandleRef(null, medium.unionmember);
IntPtr pdata = NativeMethods.GlobalLock(hGlobal);

// Determine the number of items in the array
filename = Marshal.PtrToStringAuto(pdata);

NativeMethods.GlobalUnlock(new HandleRef(null,
medium.unionmember));
}

return result;
}

To sum this up, OleGetData(...) will get me the data I need but I only know
how to use PtrToStringAuto(...) to convert the data to the filename. And
this only gets me a single filename and not the list of all files dropped.
What are the sequence of call should I make to get the list of all files that
were dropped?

If it can help, I have the sample code I can send if you think you can point
me to the right direction.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top