CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    IDropTarget + elevated process. Msgs for ChangeWindowMessageFilter to make it work?

    I'm using the following approach to register an individual control in my MFC/C++ application for a drag-and-drop operation:

    Code:
    //I have my own class derived from IDropTarget
    class CDropTargetSpec :
        public IDropTarget
    {
        //IUnknown implementation
        HRESULT __stdcall QueryInterface (REFIID iid, void** ppvObject);
        ULONG   __stdcall AddRef (void);
        ULONG   __stdcall Release (void);
    
        //IDropTarget implementation
        HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
        HRESULT __stdcall DragOver (DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
        HRESULT __stdcall DragLeave (void);
        HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
    
        //...
    };
    Then to register it I do:

    Code:
    //Error checks are omitted for brevity
    CDropTargetSpec *pDropTarget = new CDropTargetSpec();
    CoLockObjectExternal(pDropTarget, TRUE, FALSE);
    RegisterDragDrop(hDragRecepientWnd, pDropTarget));
    The drag and drop itself is processed by the CDropTargetSpec class methods.

    This approach works fine, except when my app runs elevated. In that case the registration methods succeed, but when I try to drag and drop files into my window, none of the methods from CDropTargetSpec class get called and the mouse shows "Not Available" cursor.

    I know that Microsoft added that UIPI thing which prevents messages from lower processes to be dispatched into elevated processes. They also added the ChangeWindowMessageFilter API to bypass it, but I can't seem to figure out what messages I need to allow for my drag-and-drop to work.

    I keep finding the following code sequence that I need to call from the WM_INITDIALOG method for my app:

    Code:
    ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
    ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
    ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);  //0x0049
    but even though it works for a simple drag-and-drop into the app itself, my method above for the IDropTarget doesn't seem to work.

    So any ideas what am I missing here?

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: IDropTarget + elevated process. Msgs for ChangeWindowMessageFilter to make it wor

    you cannot pass information from non elevated programs to elevated programs via IDropTarget (or via several other IPC methodologies for that matter), because that violates the UAC contract. For the same reasons you also can't (normally) inject windows hooks, send keystrokes or mousemouves/clicks, send windows messages or ........

    Either make your app run non elevated, or require the other apps to be elevated also. There are alternatives, but they'll involve special marshalling apps and/or services. For Drop targets, you're pretty much out of luck entirely, unless you can live with a non elevated 'dummy' app that accepts the droptraget, then relays the info via a supported means (like sockets, or any IPC initiated FROM the elevated app towards the non elevated) to the elevated app.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured