Click here to Skip to main content
15,887,967 members
Home / Discussions / COM
   

COM

 
AnswerRe: Question about VARIANT deallocation Pin
Vi210-Aug-09 22:01
Vi210-Aug-09 22:01 
GeneralRe: Question about VARIANT deallocation Pin
GuimaSun12-Aug-09 4:12
GuimaSun12-Aug-09 4:12 
GeneralRe: Question about VARIANT deallocation Pin
Vi212-Aug-09 21:37
Vi212-Aug-09 21:37 
GeneralRe: Question about VARIANT deallocation Pin
Vi213-Aug-09 0:20
Vi213-Aug-09 0:20 
Questioncalling messagebox funtion from a c# code Pin
nicetohaveyou8-Aug-09 8:22
nicetohaveyou8-Aug-09 8:22 
AnswerRe: calling messagebox funtion from a c# code Pin
Hristo-Bojilov10-Aug-09 3:27
Hristo-Bojilov10-Aug-09 3:27 
QuestionInvalidCastException by registering events on Office Add-In Pin
maesi19808-Aug-09 5:54
maesi19808-Aug-09 5:54 
AnswerRe: InvalidCastException by registering events on Office Add-In [modified] Pin
maesi198010-Aug-09 0:45
maesi198010-Aug-09 0:45 
I found out a solution that works. If someone has a better working solution, please post it Smile | :)

The code snippet of my new code in C#:

 m_excelAddInUtils = (IAddInUtilities)obj;

// create a Channel with port 0 --> otherwise an Exception will be
//throwed: "This remoting proxy has no channel sink which means either 
//the server has no registered server channels that are listening, or 
//this application has no suitable client channel to talk to the server.
IpcChannel serverChannel = new IpcChannel("localhost:0");
ChannelServices.RegisterChannel(serverChannel);

//Use a second instance of the utility class. With the first instance provided by the COMAddIn.Object property, I 
//haven't found out how to marshal an event registering without throwing 
//an InvalidCastException
AddInFIMUtilities addInUtilClass = new AddInFIMUtilities();

//Register the second instance (CLR object) to the COM instance over the 
//provided utility interface
m_excelAddInUtils.AddToSaveObserverList(addInUtilClass);
//Now the event registering works without cast exceptions
addInUtilClass.AddInSaveEvent += new AddInSaveEventHandler(addInUtilClass_OnFIMSaved);


The new delegate in Add-In class:

public delegate void AddInSaveEventHandler();


On the Add-In class I created a new IDispatch Interface:

[Guid("69075652-6A6D-442c-B534-5816D5046F04")]
[ComVisibleAttribute(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IAddInEvents
{
    void AddInSaveEventHandler();
}


And extended the Main method interface:

[Guid("6CA66587-1A1E-4cd6-B55A-20F07F18C343")]
    [ComVisibleAttribute(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAddInUtilities
    {
        //Service to register the CLR client object to COM observer list
        [DispId(1)]
        void AddToSaveObserverList(IAddInUtilities addInUtils);

        [DispId(2)]
        void FireSaveEvent();
    }


The new methods in the Utility class:

public void AddToSaveObserverList(IAddInUtilities addInUtils)
{
    Globals.ExcelFIMAddIn.SaveObserverList.Add(addInUtils);
}

public void FireSaveEvent()
{
    AddInSaveEvent();
}


On the Add-In class itself, these extensions are required:

<pre>private List<IAddInUtilities> m_saveObserverList = new List<IAddInUtilities>();


public List<IAddInUtilities> SaveObserverList
{
get { return m_saveObserverList; }
}

And eventually firing the event:

foreach (IAddInUtilities addInFIMUtil in this.SaveObserverList)
{
    try
    {
        ((AddInFIMUtilities)addInUtil).FireSaveEvent();
    }
    catch
    {
                    
    }
}


modified on Monday, August 10, 2009 6:52 AM

QuestionCom Component Pin
sekannak6-Aug-09 23:58
sekannak6-Aug-09 23:58 
AnswerRe: Com Component Pin
Randor 9-Aug-09 9:53
professional Randor 9-Aug-09 9:53 
GeneralRe: Com Component Pin
sekannak9-Aug-09 18:57
sekannak9-Aug-09 18:57 
QuestionWMP loop playing - black between each play Pin
pimb26-Aug-09 2:46
pimb26-Aug-09 2:46 
AnswerRe: WMP loop playing - black between each play --- found a solution Pin
pimb26-Aug-09 2:53
pimb26-Aug-09 2:53 
Questioninvoke output parameters to javascript? Pin
Hongjun Ge5-Aug-09 6:11
Hongjun Ge5-Aug-09 6:11 
AnswerRe: invoke output parameters to javascript? Pin
Vi25-Aug-09 20:49
Vi25-Aug-09 20:49 
GeneralRe: invoke output parameters to javascript? Pin
Hongjun Ge6-Aug-09 3:54
Hongjun Ge6-Aug-09 3:54 
GeneralRe: invoke output parameters to javascript? Pin
Vi26-Aug-09 20:24
Vi26-Aug-09 20:24 
GeneralRe: invoke output parameters to javascript? Pin
Hongjun Ge7-Aug-09 5:57
Hongjun Ge7-Aug-09 5:57 
QuestionHow can I call a MSWord VBA macro from MFC *and* passing it arguments Pin
sashoalm4-Aug-09 4:34
sashoalm4-Aug-09 4:34 
QuestionCalling activeX method with array Pin
Nicolas Bonamy2-Aug-09 23:21
Nicolas Bonamy2-Aug-09 23:21 
QuestionICaptureGraphBuilder2:RenderStream strange problem Pin
Hristo-Bojilov30-Jul-09 11:48
Hristo-Bojilov30-Jul-09 11:48 
AnswerRe: ICaptureGraphBuilder2:RenderStream strange problem Pin
Hristo-Bojilov30-Jul-09 22:04
Hristo-Bojilov30-Jul-09 22:04 
QuestionCOM InprocServer32 Remoting Pin
sdk_tiger30-Jul-09 3:05
sdk_tiger30-Jul-09 3:05 
AnswerRe: COM InprocServer32 Remoting Pin
Baltoro2-Aug-09 11:34
Baltoro2-Aug-09 11:34 
GeneralRe: COM InprocServer32 Remoting [modified] Pin
sdk_tiger3-Aug-09 3:47
sdk_tiger3-Aug-09 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.