July 31st, 2014, 07:17 PM
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:
Then to register it I do:
//I have my own class derived from IDropTarget
class CDropTargetSpec :
HRESULT __stdcall QueryInterface (REFIID iid, void** ppvObject);
ULONG __stdcall AddRef (void);
ULONG __stdcall Release (void);
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);
The drag and drop itself is processed by the CDropTargetSpec class methods.
//Error checks are omitted for brevity
CDropTargetSpec *pDropTarget = new CDropTargetSpec();
CoLockObjectExternal(pDropTarget, TRUE, FALSE);
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:
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.
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD); //0x0049
So any ideas what am I missing here?
August 1st, 2014, 08:37 AM
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.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!