I
I
iRumba2015-08-12 07:30:35
WPF
iRumba, 2015-08-12 07:30:35

How to transfer an object by reference via DragDrop?

Hello. I need to transfer control from one process to another by drag and drop. Without delving into the essence of this action, I wrote
DragDrop.DoDragDrop(_el, _el, DragDropEffects.Move);
to start dragging, where _el is the element being dragged
var ll = e.Data.GetData("System.Windows.Controls.Label") as Label;
for receiving, where e - DragEventArgs
Well, I get the error
"The media type is incorrect (Exception from HRESULT: 0x80040069 (DV_E_TYMED))"
Even before the launch it seemed to me that something was wrong here)
Serialization is not suitable for me, since I need to transfer already initialized object (Label in my case is just for practice).
I didn’t really understand what marshalization is and I don’t know if it will suit me.
IpcChannel will not work for me either (it seems), because it is needed for remote access to an object (if I understood everything correctly).
Then the question is, what will suit me for my task?
I need to somehow transfer by drag and drop a reference to an object whose type both processes know about, similar to dragging tabs in the Google Chrome browser.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Makarov, 2015-08-12
@DmitryITWorksMakarov

I didn't really understand.
You cannot transfer a direct link from an object from process to process. Processes have different memory. Processes objects do not see each other.
If you only need the state of an object: for example, in one process you initialized it in one way or another and transfer it to the second process. Then it is enough that assemblies with the type of your object are loaded into the processes, and clone your object through serialization.
But since you write that serialization is not suitable for you, I can assume that you want to access the methods and properties of an object of another process from one process, so that this causes some kind of response in the first process (well, let's say through events that generate when the state of the object changes). Then the second process needs some proxy object, which, when its methods and properties are accessed, will access the methods and properties of the original object through a certain message system. It's similar to .NET Remoting or WCF.

V
Vitaly Pukhov, 2015-08-12
@Neuroware

It is impossible to transfer an "object" from one application to another, because everyone has their own memory and you cannot just "give" a piece of your memory to another process "for use". In your case, I see the solution only through serialization. I see no problem serializing an initialized object, usually it is these objects that are serialized. It is also not clear what kind of object is being dragged, perhaps it is enough to pass its "parameters" and on another process just create it again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question