I have created Outlook add-in that implements my defined interface IExposedClass (among other things for exposing some methods from add-in also).
In external app (automating Outlook): object addInObj = isentrisAddIn.Object; MyExcelAddin1.IExposedClass addInExposedAgain = (MyExcelAddin1.IExposedClass)addInObj; object temp = addInExposedAgain.GetAppointments(); // Call a method on addin object DataTable dt = (DataTable) objectTemp; // objectTemp is _ComObject type
calling some method, add-in that should return complex data type (eg.DataTable). While doing cast to DataTable getting invalid cast exception. The same result happens if I call GetAdressBookDT() method. In this case scenarion marshaling described on various articles doesn't work as it seems (maybe I didn't understand those articles or missed some important facts about it).
on link http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=459557&SiteID=1 there is a good explanation what I'm trying to do.
I thought that second approach would lead me to solution of my problem but... I defined my interface like this:
public interface IExposedClass { object GetAdressBook(); DataTable GetAdressBookDT(); void RefreshAdressBook(); object GetAppointments(); string Test(); DataTable GetAppointmentsDT(); void RefreshAppointments(); System.Exception LastException {get;} bool IsInitializing {get;} bool IsInitialized {get;} string PluginVersion {get;} }
For bool and string properties/methods interfacing to add-in is working fine. But for method that should return DataTable or object, calls to GetAppointmentsDT() are invoking _ComObject specified cast exception, and call to GetAppointments() method thtat is returning DataTable as object, in external app in fact is returning _ComObject type that I can't cast to DataTable due invalid cast exception. I was trying to find code that would help me resolve my problem doing marshaling but didn't find anything of that type.
So my question is how can I accomplish that and do anybody have idea or code that would help me to figure that out?
THX!
|
|