Communication between winforms control in folder-hp and VSTO addin

Add-in Express™ Support Service
That's what is more important than anything else

Communication between winforms control in folder-hp and VSTO addin
 
Thomas Reinberger




Posts: 5
Joined: 2005-10-09
Hi,

I have an outlook application which runs in two appDomains. The AddinExpress.VSTO.ADXOutlookModule runs in another appDomain than my winforms control that is beeing displayed within a folder homepage similiar to your ADX extensions API. I get my AddinExpress.VSTO.ADXOutlookModule in the winformscontrol as AddinExpress.VSTO.ADXRemoteObject. So I can call methods in the addin by callMethod(string name, object[] args). The return value is in this case a transparent proxy. But unfortunately, I have complex objects and so I would need a reference to the ?Â?Ð?ìreal?Â?Ð?í object and not a transparent proxy. Do you have an idea how I can get it? I read some time ago that this should be possible with reflection (?).

Best regards
Thomas
Posted 31 Aug, 2006 11:18:58 Top
David Ing




Posts: 56
Joined: 2006-06-27
Thomas, apologies if I misunderstood, but would it be simpler just to use the ADX Outlook Extensions and then host your winform control in the same app-domain? As in, solve the marshalling problem by converting over to using the ADX extensions and not having to marshal?
Posted 31 Aug, 2006 14:05:53 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Thomas.

Try to pass the handle of the .NET control and then obtain the control in another domain using the Control.FromHandle method.
Posted 31 Aug, 2006 17:17:47 Top
Thomas Reinberger




Posts: 5
Joined: 2005-10-09
Hi,

@David: unfortunately this is not possible as ADX Extensions does not yet support AddInExpress for VSTO.

@Sergey:

For testing purposes I created a test winforms application without outlook (as this problem also applies to non-outlook apps).

There is only one assembly with the following classes:

Class1.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WndHandleAppDomains
{

class Class1: MarshalByRefObject
{
public void ChangeUserControl1Label(IntPtr wndHandle)
{
Control ctl = Control.FromHandle(wndHandle);

if (ctl != null)
{
UserControl1 userControl1 = (UserControl1) ctl;
userControl1.label1.Text = "Control modified!";
}
}
}
}

UserControl1 contains just a public label.

In Form1 I have a button with the following eventhandler:

private void button1_Click(object sender, EventArgs e)
{
// create a new appdomain
AppDomain newDomain = AppDomain.CreateDomain("myCustomAppDomain");

object obj = newDomain.CreateInstanceAndUnwrap("WndHandleAppDomains", "WndHandleAppDomains.Class1");

if (obj != null)
{
Class1 class1 = (Class1) obj;
class1.ChangeUserControl1Label(Handle);
}
}

Everything works up to the point where class1.ChangeUserControl1Label tries to find the control with Control.FromHandle because it returns null due to the fact that Form1 and Class1 run in different AppDomains as it would be in our outlook solution.

Did I misunderstood your suggestion?

Thomas
Posted 01 Sep, 2006 05:58:51 Top
Thomas Reinberger




Posts: 5
Joined: 2005-10-09
This may just be an idea:

Allows the usage of AddInExpress.NET (not VSTO) with the load component to use the ClickOnce updating mechanism as well? If so, we don't need to use VSTO and hence can use either our old mechanism or the ADX extension.

Thomas
Posted 01 Sep, 2006 08:12:53 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Thomas.

The 'Add-In Express .NET' product doesn't work with the ClickOnce updating mechanism. In this case the best way is to use the 'Add-In Express .NET for VSTO' product.
As to the Control.FromHandle method, it was just an idea. I didn't test it. But I am working on this now and I will send you an email when I find a solution.
Posted 02 Sep, 2006 18:21:18 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Thomas.

Did you try to cast the reference returned by the 'CallMethod' method to the target type of the control? The fact is that the Control class of the .NET Framework inherits the MarshalByRefObject class. So you can to communicate with the transparent proxy as it is a real control.
By the way, I know a good book devoted to the .NET Remoting. It is the 'Microsoft .NET Remoting' written by by Scott McLean, James Naftel, Kim Williams. I am reading this book now and I would suggest you to familiarize yourself with it.

https://www.microsoft.com/mspress/books/sampchap/6172.asp
Posted 03 Sep, 2006 19:53:20 Top