Click here to Skip to main content
15,920,602 members
Home / Discussions / COM
   

COM

 
GeneralRe: Question about VARIANT deallocation Pin
GuimaSun10-Aug-09 8:43
GuimaSun10-Aug-09 8:43 
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 
On one side I have a C# application (WPF) from which I want to call an Office Add-In class. On my Office Add-In project I've exposed a class and an interface to COM. I'm able to call functions from my exposed Add-In object, but I'm not able to register an event, which should by fired by the exposed Add-In project.

My C# code:

officeAddIn = excel.COMAddIns.Item(ref addinName);
object obj = officeAddIn.Object;
IAddInUtilities m_excelFIMAddInUtils = (IAddInUtilities)obj;

AddInEnablingEventHandler addInEnablingEventHandler = new AddInEnablingEventHandler(m_excelFIMAddInUtils_AddInEnablingEvent);
m_excelFIMAddInUtils.EnableAddIn(true);
//Until here, it works fine

m_excelFIMAddInUtils.AddInEnablingEvent += addInEnablingEventHandler 
//Failes! --> InvalidCastException


My AddIn Project:

[ComVisible(false)]
    [Serializable()]
    public delegate void AddInEnablingEventHandler();

 public partial class ExcelFIMAddIn
    {
        private AddInFIMUtilities m_utilities;
        private Office.IRibbonExtensibility m_ribbon;     
        
        protected override object RequestComAddInAutomationService()
        {
            
            if (m_utilities == null)
            {
                m_utilities = new AddInFIMUtilities();
       
            }
            return m_utilities;
        }
    
        protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            RibbonExcelFIM ribbon = new RibbonExcelFIM();
            ribbon.FIMSaveEvent += new FIMSaveEventHandler(ribbon_FIMSaveEvent);
            return ribbon;
            /**
            if(this.Application == null)
            {
                m_ribbon = new RibbonExcelFIM();
            }
            else
            {
                
                m_ribbon = base.CreateRibbonExtensibilityObject();
            }
            return m_ribbon;
             */
        }      
    }

    [Guid("6CA66587-1A1E-4cd6-B55A-20F07F18C343")]
    [ComVisibleAttribute(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAddInUtilities
    {
        void EnableAddIn(bool isAddInEnabled);
        event AddInEnablingEventHandler AddInEnablingEvent;

    }

    [ComVisibleAttribute(true)]
    [Guid("F2FA4759-AEA0-4f4e-838B-3BBBC77837AB")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("AddInFIMUtilites")]
    [Serializable()]
    public class AddInFIMUtilities : StandardOleMarshalObject, IAddInUtilities
    { 
        public event AddInEnablingEventHandler AddInEnablingEvent;

        public void EnableAddIn(bool isAddInEnabled)
        {
            m_isAddInEnabled = isAddInEnabled;
            if (isAddInEnabled)
            {
                if (AddInEnablingEvent != null)
                {
                    AddInEnablingEvent();
                }
                else
                {
                }
            }
        }
    }


What I'm doing wrong? Is there a solution which someone can provide me?
Thanks in advance

Marcel
AnswerRe: InvalidCastException by registering events on Office Add-In [modified] Pin
maesi198010-Aug-09 0:45
maesi198010-Aug-09 0:45 
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 

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.