Re: Question about SHCreateShellFolderView and Drag and Drop.. Drop on NSE is fine.. but Drag from NSE (DropSource), is problem

From: Henk Devos (info_at_dontspamme.regxplor.com)
Date: 08/09/04


Date: Mon, 9 Aug 2004 12:16:30 +0200

1. Why is EnumFormatEtc not implemented? I don't think you can ever get it
working like this.
2. The clipformats are CF_HDROP and a registered clipformat.
You might be asked for many formats that you don't support.
These will for example be formats for the drag image etc.
Some of these formats will be set first with SetData (if you do things
properly).
3. I don't understand why you call DoDragDrop when the IDataObject is
requested?
You are only requested to provide an interface, not to start a drag and drop
operation.
Note that the interface may be asked for many purposes other than drag and
drop (for example to enable/disable the copy command in the Edit menu). I
don't think you want to start a drag and drop operation when a menu is being
displayed.
What you should do is just return the IDataObject and let the sell start the
drag and drop operations (which will include the SetData calls).

--
Henk Devos
www.whirlingdervishes.com
"Sridhar Anupindi" <sanupindi@gmail.com> wrote in message
news:dc23f516.0408071615.9e501d6@posting.google.com...
> Hi All,
>
>  We have implemented a NameSpace Extension in c# which suppports Drag
> & Drop. We have implemented DropTarget Interface succesfully and we
> are able to Drag from Explorer to my NSE without any problems. I am
> creating IID_IDropTarget both in CreateViewObject and GetUIObjectOf
> methods. Please see Code below just for your reference.
> -----------------------------
> public void CreateViewObject(IWin32Window hwndOwner, ref Guid riid,
> out IntPtr ppv)
> {
> if (NsExtension.IID_IShellView.Equals(riid))
> {
> ShellFolderViewCreate sfvc = new ShellFolderViewCreate(this,
> this);
> Marshal.ThrowExceptionForHR(Shell32.SHCreateShellFolderView(ref
> sfvc, out ppv));
>
> if (ppv == IntPtr.Zero)
> {
> throw new COMException();
> }
> }
> else if (NsExtension.IID_IDropTarget.Equals(riid))
> {
> WindowsShell.Interop.IDataObject dataObject =
> (WindowsShell.Interop.IDataObject) folderObj.DataObject;
> ppv = Marshal.GetComInterfaceForObject(new
> DropTargetImpl(folderObj,dataObject), typeof(IDropTarget));
> }
> else if (NsExtension.IID_IContextMenu.Equals(riid))
> {
> ppv = Marshal.GetComInterfaceForObject(new ContextMenuImpl(null,
> folderObj), typeof(IContextMenu));
> }
> else
> {
> throw new COMException();
> }
> }
> -------------------------
> public void GetUIObjectOf(IWin32Window hwndOwner, uint cidl, IntPtr[]
> apidl, ref Guid riid, IntPtr rgfReserved, out IntPtr ppv)
> {
> else if (riid.Equals(NsExtension.IID_IDropTarget))
> {
> if (cidl != 1)
> {
> throw new ArgumentOutOfRangeException("cidl", cidl, "Expected
> exactly one PIDL to retrieve IDataObject");
> }
>
> IFolderObject obj =
> folderObj.Restore(ItemIdList.Create(apidl[0]).GetItemData()[0]);
> WindowsShell.Interop.IDataObject dataObject =
> (WindowsShell.Interop.IDataObject)obj.DataObject;
> ppv = Marshal.GetComInterfaceForObject(new
> DropTargetImpl(folderObj, dataObject), typeof(IDropTarget));
> }
> else
> {
> throw new COMException();
> }
> }
> -------------------------------------
>
> Now the problem is while implementing DND from NSE to Explorer. I am
> creating the DataObject under GetUIObjectOf with IID_DataObject. In
> the constructor of my DataObject I am registering the custom formats,
> HDrop etc with FORMATETC. In the GetUIOBjectOf method only we are
> creating DropSource Object and then calling DoDragDrop method. The
> sequence of events after this are DataObject.EnumFormatEtc() which
> returns E_NOTIMPL, hence goes into DataObject.QueryGetData(). Here the
> FORMATETC I am receiving as a parameter does not have any of the
> Registered Clipboard Formats which I did in the Constructor, coz of
> which I am unable to process my custom data.(but I am receiving the
> following cfFormat values HDrop(15) and some large number(2011234319)
> which I unable to understand.) I would really appreciate your help in
> this regard.
>
> Here is my Implementation of Interfaces and implementation..
>
> ----------
> GetUIObjectOf Implementation
> else if (riid.Equals(NsExtension.IID_IDataObject))
> {
> IFolderObject obj =
> folderObj.Restore(ItemIdList.Create(apidl[0]).GetItemData()[0]);
> WindowsShell.Interop.IDataObject dobj = new
> DataObjectImpl(folderObj, apidl, apidl.Length);
> WindowsShell.Interop.IDropSource dsrc = new DropSourceImpl();
> int dwEffect = (int) (DragDropEffects.Copy|DragDropEffects.Move)
> ;
> int pdwEffect = 0;
> DoDragDrop(dobj,dsrc, dwEffect,out pdwEffect);
> ppv = Marshal.GetComInterfaceForObject(dobj,
> typeof(WindowsShell.Interop.IDataObject));
> }
> ----------------
> IDataObject........
> {
> [ComImport,
> Guid("0000010e-0000-0000-C000-000000000046"),
> InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
> CLSCompliant(false)]
> public interface IDataObject
> {
> int GetData([In] ref FORMATETC pformatetcIn, ref STGMEDIUM pmedium);
> void GetDataHere([In] ref FORMATETC pformatetc, [In, Out] ref
> STGMEDIUM pmedium);
> int QueryGetData([In] ref FORMATETC pformatetc);
> int GetCanonicalFormatEtc([In] ref FORMATETC pformatectIn, [Out] out
> FORMATETC pformatetcOut);
> int SetData([In] ref FORMATETC pformatetc, [In] ref STGMEDIUM
> pmedium, [In] bool fRelease);
> int EnumFormatEtc([In] uint direction, [Out,
> MarshalAs(UnmanagedType.Interface)] out IEnumFormatEtc
> ppenumFormatEtc);
> int DAdvise([In] ref FORMATETC pformatetc, [In] uint advf, [In,
> MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink, [Out] out
> uint pdwConnection);
> int DUnadvise([In] uint dwConnection);
> int EnumDAdvise([Out] out IEnumStatData ppenumAdvise);
> }
> --------------------------
> using System;
> using System.Windows.Forms;
> using WindowsShell.Interop;
> using System.Runtime.InteropServices;
> namespace WindowsShell.Nspace
> {
> /// <summary>
> /// Summary description for DataObjectImpl.
> /// </summary>
> internal class DataObjectImpl:WindowsShell.Interop.IDataObject
> {
> IFolderObject Root;
>
> [DllImport("user32", EntryPoint="RegisterClipboardFormat")]
> public static extern uint RegisterClipboardFormatA(string lpString);
>
> [DllImport("user32", EntryPoint="GetClipboardFormatName")]
> public static extern int GetClipboardFormatNameA(int wFormat, out
> string lpString, int nMaxCount);
>
> string CFSTR_PREFERREDDROPEFFECT =("Preferred DropEffect");
> string CFSTR_SHELLIDLIST ="Shell IDList Array";      // CF_IDLIST
> string CFSTR_FILECONTENTS ="FileContents";            //
> CF_FILECONTENTS
> string CFSTR_FILEDESCRIPTOR ="FileGroupDescriptor";
> // This is my custom FOrmat...
> string CFSTR_CWEXTENSIONDATA = "CWExtensionFormat";
>
> uint m_PreferredDropEffect;
> uint m_ShellIdList;
> uint m_CWExtensionData;
> uint m_FileDescriptor;
> uint m_FileContents;
> int m_iCurrent=0;
>
> public int S_OK =unchecked((int)0x00000000L);
> public int E_NOTIMPL=unchecked((int)0x80004001L);
> public int E_INVALIDARG=unchecked((int)0x80070057L);
> public int DV_E_DVASPECT=unchecked((int)0x8004006BL);
> public int DV_E_TYMED=unchecked((int)0x80040069L);
> int m_itemCount=0;
> int m_cFormatsAvailable =4;
> FORMATETC[] m_fmtetc;
>
> internal DataObjectImpl(IFolderObject rootObj, IntPtr[] apidl, int
> ItemCount)
> {
> file://populate the dataobject
> Root = rootObj;
>
> m_CWExtensionData =
> RegisterClipboardFormatA(CFSTR_CWEXTENSIONDATA);
> m_PreferredDropEffect =
> RegisterClipboardFormatA(CFSTR_PREFERREDDROPEFFECT);
> m_ShellIdList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
> file://m_FileDescriptor =
> RegisterClipboardFormatA(CFSTR_FILEDESCRIPTOR);
> file://m_FileContents = RegisterClipboardFormatA(CFSTR_FILECONTENTS);
>
> m_itemCount = ItemCount;
>
> m_fmtetc = new FORMATETC[m_cFormatsAvailable];
>
> SetDefFormatEtc(ref m_fmtetc [0],m_CWExtensionData);
> SetDefFormatEtc(ref m_fmtetc [1],m_ShellIdList);
> SetDefFormatEtc(ref m_fmtetc [2],(uint) CLIPFORMAT.CF_HDROP);
> SetDefFormatEtc(ref m_fmtetc [3],m_PreferredDropEffect);
>
> }
> void SetDefFormatEtc(ref FORMATETC pFE, uint cfFormat)
> {
> pFE.cfFormat  = cfFormat;
> pFE.dwAspect =DVASPECT.DVASPECT_CONTENT;
> pFE.tymed = TYMED.TYMED_ISTREAM;
> pFE.lindex =-1;
> pFE.ptd = 0;
> }
> int WindowsShell.Interop.IDataObject.GetData(ref FORMATETC
> pformatetcIn, ref STGMEDIUM pmedium)
> {
> throw new NotImplementedException();
> }
> void WindowsShell.Interop.IDataObject.GetDataHere(ref FORMATETC
> pformatetc, ref STGMEDIUM pmedium)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.QueryGetData(ref FORMATETC
> pformatetc)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.GetCanonicalFormatEtc(ref
> FORMATETC pformatectIn, out FORMATETC pformatetcOut)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.SetData(ref FORMATETC
> pformatetc, ref STGMEDIUM pmedium, bool fRelease)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.EnumFormatEtc(uint direction,
> out IEnumFormatEtc ppenumFormatEtc)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.DAdvise(ref FORMATETC
> pformatetc, uint advf, IAdviseSink pAdvSink, out uint pdwConnection)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.DUnadvise(uint dwConnection)
> {
> throw new NotImplementedException();
> }
> int WindowsShell.Interop.IDataObject.EnumDAdvise(out IEnumStatData
> ppenumAdvise)
> {
> throw new NotImplementedException();
> }
> }
> }
> ----------------
> IDropSource....
> using System.Runtime.InteropServices;
>
> namespace WindowsShell.Interop
> {
> /// <summary>
> /// Summary description for IDropSource.
> /// </summary>
> [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
> GuidAttribute("00000121-0000-0000-C000-000000000046")]
> public interface IDropSource
> {
> [PreserveSig]
> uint QueryContinueDrag(
> [MarshalAs(UnmanagedType.Bool)] bool fEscapePressed,
> uint grfKeyState);
> [PreserveSig]
> uint GiveFeedback(
> uint dwEffect);
>
> }
>
> }
> -----------
> using System;
> using WindowsShell.Interop;
> using System.Runtime.InteropServices;
> using System.Windows.Forms;
> namespace WindowsShell.Nspace
> {
> internal class DropSourceImpl:WindowsShell.Interop.IDropSource
> {
> public uint DRAGDROP_S_DROP =unchecked((uint)0x00040100L);
> public uint DRAGDROP_S_CANCEL=unchecked((uint)0x00040101L);
> public uint DRAGDROP_S_USEDEFAULTCURSORS=unchecked((uint)0x00040102L);
> internal DropSourceImpl()
> {
> }
> uint IDropSource.QueryContinueDrag( bool fEscapePressed,uint
> grfKeyState)
> {
> if(fEscapePressed == true)
> {
> return DRAGDROP_S_CANCEL;
> }
> return DRAGDROP_S_DROP;
> }
> uint IDropSource.GiveFeedback(uint dwEffect)
> {
>
> return DRAGDROP_S_USEDEFAULTCURSORS;
> }
> }
> }
> --------------------
> Note:  I am using the IShellView interface provided by
> SHCreateShellFolderView() in NSE.
>
> I really appreciate your help coz I am stuck here and unable to
> proceed further. Thanks in Advance...
>
> Sridhar Anupindi
>


Relevant Pages

  • probleme with drag-n-drop windows shell extension
    ... public static extern uint RegisterClipboardFormatA; ... public static extern int GetClipboardFormatNameA(int wFormat, ... void WindowsShell.Interop.IDataObject.GetData(ref FormatEtc ... int WindowsShell.Interop.IDataObject.SetData(ref FormatEtc pformatetc, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: hooking
    ... int m_Stride; ... bool Logger = false; ... pDevice, D3DPRIMITIVETYPE pType, UINT nMinIndex, UINT nNumVertices, UINT ... nStartIndex, UINT nPrimitiveCount); ...
    (microsoft.public.dotnet.framework)
  • Re: hooking
    ... int m_Stride; ... bool Logger = false; ... pDevice, D3DPRIMITIVETYPE pType, UINT nMinIndex, UINT nNumVertices, UINT ... nStartIndex, UINT nPrimitiveCount); ...
    (microsoft.public.dotnet.framework)
  • waveOutPrepareHeader crashes with Vista x64
    ... uint waveOutOpen( ... int dwCallbackInstance, ... uint waveOutGetErrorTextA( ...
    (microsoft.public.dotnet.framework.interop)
  • Re: how to reboot, or shutdown the computer ?
    ... static extern bool ExitWindowsEx(uint uFlags, ... public static extern int CreateToolhelp32Snapshot(uint flags, ... public static extern System.Boolean LookupPrivilegeValue(string lpSsytemName, ...
    (microsoft.public.dotnet.languages.csharp)