Outlook Add-in accessing main add-in from OptionsPage

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

Outlook Add-in accessing main add-in from OptionsPage
 
Matt Driver


Matt


Posts: 152
Joined: 2004-08-17
Hi

I have the following scenario: A class called POMI.Settings that holds the settings for my add-in. This is defined in the Public AddinModule() declarations as:

//define object to hold setting for POMI
public POMI.Settings settings;
//define static object representing
public static AddinModule staticAddinModule = null;

In the Add-in Module Initiailizer I then do the following:

settings = new Settings();

Now I want to access this object from my options page the idea being that when settings are changed in the options page they are reflected immediately in the main add-in rather than the user having to restart the add-in and load the settings again using the the AddinModule_AddinStartupComplete event and reading the registry again.

So in my OutlookProperties apply event I perform the following:

if( POMI.AddinModule.staticAddinModule != null )
{
POMI.AddinModule.staticAddinModule.settings.Refresh();
}

I.E. call the refresh settings function in my object publically declared in the main addin.

The problem is that the POMI.AddinModule.staticAddinModule.settings object is always NULL when referenced from the options page.

Are the addin and optionspage running in seperate app domain ? which would explain why I cannot do the above.

Is their any other quick way of referencing public objects declared in the add-in from the Optionspage ?

I am going to try and create a remoting object in the add-in and call this from the options page so see if this works.

Thoughts welcome

Thanks

Matt
Posted 25 May, 2006 06:48:02 Top
Sergey Grischenko


Add-in Express team


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

The fact is that Outlook loads the add-in assembly twice - at first when Outlook starts and second time when you open the Options dialog in Outlook. Thus you have two instances of your dll running at the same time.
In case of using C++ shim the situation is more complicated. Namely, the add-in assembly is loaded in another application domain.
To access the addinmodule you should use the COMAddin.Object property.
If you use the C++ shim, you will get the ADXRemoteObject type. Please use the GetProxyProperty, SetProxyProperty and CallProxyMethod methods to access the addinmodule. Also you can look at the OutlookPropertyPage example from the ADX installation package to learn how it works.
Posted 25 May, 2006 08:11:25 Top
Matt Driver


Matt


Posts: 152
Joined: 2004-08-17
Hi

I am afraid I cannot find the example above in the 3 ADX installation package examples or the OLToys Demo. I am looking in the wrong place.

Matt
Posted 25 May, 2006 10:29:13 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Matt, the example is located in the '<ADX installation folder>\QDemo\VS.NET 2003\Advanced\OutlookPropertyPage' folder.
The ADX version should be v2.4.1757 or later.
Posted 25 May, 2006 15:27:00 Top
Matt Driver


Matt


Posts: 152
Joined: 2004-08-17
Thanks Sergey

I have never seen those examples they are very useful. I have the OptionsPage example running but have a question.

When the code loops round checking the guid's to see if the add-in matches the option page guid the example always displays guid's.

When I add the same code to my project and loop round the code instead of the GUID being returned in the str.xxx I only get the path e.g:

@"C:\VSS\Office 2003 Pivotal Outlook Mail Integration V3.0.1\POMI\POMI.sln"

My Add-in Guid is reported as: "!{8b6b433e-1ba3-4b6f-af4c-fbd68449d4b1}" using the line:

string guid = "!" + typeof(POMI.AddinModule).GUID.ToString("B");

I never get the GUID that matches, any ideas

Matt
Posted 01 Jun, 2006 06:59:21 Top
Sergey Grischenko


Add-in Express team


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

Did you include the code below to the addinmodule?

private void AddinModule_AddinStartupComplete(object sender, System.EventArgs e)
{
Guid g = this.GetType().GUID;
RegisterActiveObject(Marshal.GetIUnknownForObject(HostApplication), ref g, ACTIVEOBJECT_WEAK, ref objectHandle);
}

private void AddinModule_AddinBeginShutdown(object sender, System.EventArgs e)
{
if (objectHandle != 0)
RevokeActiveObject(objectHandle, IntPtr.Zero);
}
Posted 01 Jun, 2006 07:31:23 Top
Matt Driver


Matt


Posts: 152
Joined: 2004-08-17
Many Thanks I have it all working.

Matt :D
Posted 01 Jun, 2006 15:32:10 Top