473,413 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Using OLE32 for files drag and drop

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.
Jun 12 '07 #1
1 3835
The DragQueryFile API should give you the count and names.
See here more:
http://msdn2.microsoft.com/en-us/library/ms647250.aspx

"Vu-Loc Nguyen" <Vu*********@discussions.microsoft.comha scritto nel
messaggio news:86**********************************@microsof t.com...
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.

Jun 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hemant_mishal | last post by:
Hi All, I am writting a java script library which will provide inter frame drag and drop operation. The more precise will be OLE drag and drop, which means only data will be transfered from frame...
5
by: Pradnyesh Rane | last post by:
Hi, I am encountering the following linker error on VC7. LINK : fatal error LNK1171: unable to load ole32.dll This error is only encountered for the "Debug" configuration. The project...
0
by: Oberon | last post by:
How do I navigate through records using drag 'n' drop controls? I have an example in C# for Windows forms that relies on BindingContext but this is not available for ASP.NET. How do I solve that...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
16
by: Asaf | last post by:
I am trying to create and use a COM object with C#.NET 2005. The assembly is set to "Register for COM interop" but when I am trying to call it from VB on Word 2003 I am getting this error: ...
1
by: Darren | last post by:
I'm trying to create a file using drag and drop. I want to be able to select a listview item drag it to the shell and create a file. Each icon in the listview represents a blob in a database. When...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
0
by: Mukesh Agarwal | last post by:
Hi, I am developing a windows application, in which I am giving two options to the user for the file selection. 1. Open File Dialog 2. Drag/ Drop Now I want that the user can Drag/Drop...
2
by: weird0 | last post by:
i am developing an application in which i can drag and drop icons using c#. I tried out a few tutorials on code-project.com, but they don't seem to work and are too hard to understand, like the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.