Uniquely identifying outlook Inspector windows

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

Uniquely identifying outlook Inspector windows
 
Kamal Vaghjiani




Posts: 5
Joined: 2006-02-15
I'm having problems trying to identify a inspector window when referenced from a toolbar button event.

I'm using System.Collections.SortedList to store the instance of outlook inspectors.

heres some code....

internal System.Collections.SortedList MySortedList = System.Collections.SortedList();

private void adxOutlookEvents_NewInspector(object sender, object inspector, string folderName)
{
MySortedList.Add(inspector.GetHashCode(),new myCustomObject());
}

private void adxOutlookEvents_InspectorClose(object sender, object inspector, string folderName)
{
MySortedList.Remove(inspector.GetHashCode());
}

// CommandBarButton Custom Event
private void btnClick_DoSomething(object sender)
{
Outlook._Inspector inspector = OutlookApp.ActiveInspector();
Object obj= MySortedList.GetByIndex(inspector.GetHashCode()));
}

InspectorClose event works fine, the inspector instance is found in MySortedList and Removed.

In btnClick_DoSomething it does not find the instance in MySortedList.

Could this be a problem with OutlookApp.ActiveInspector()

Please help.



Posted 09 Jun, 2006 06:48:30 Top
Kamal Vaghjiani




Posts: 5
Joined: 2006-02-15
Sergey

Thanks for your email.

Where do you fill the SortedList - inspectors in the code you sent me

Posted 09 Jun, 2006 07:49:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
I do it in the InspectorActivate event handler.
Actually your code is correct. You just need to get rid of the ActiveInspector method as shown in my example.
Posted 09 Jun, 2006 08:52:18 Top
Kamal Vaghjiani




Posts: 5
Joined: 2006-02-15
Sergey

Thanks, I changed my code to store inspector interface in a SortedList.

The only change I had to make is to declare the following

internal object activeInspector = null; (as per your code)
internal IntPtr activeInspectorPointer = IntPtr.Zero; (new)

I added activeInspectorPointer because the following code would give me differant values when referenced toolbar btn click events

pointer = Marshal.GetIUnknownForObject(activeInspector);

So in the adxOutlookEvents_InspectorActivate event I added the following

activeInspectorPointer = Marshal.GetIUnknownForObject(activeInspector);

and used this to look up the inspector instance in my SortedList.


Posted 13 Jun, 2006 06:05:41 Top
Sergey Grischenko


Add-in Express team


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

Your code is correct. I have another example where I use the GetHashCode function. You can download it if you wish.
http://www.add-in-express.com/files/projects_pub/oleditcontrolsexample.zip
Posted 13 Jun, 2006 10:43:08 Top