Click here to Skip to main content
15,664,115 members
Home / Discussions / C#
   

C#

 
AnswerRe: Winforms or WPF Pin
Eddy Vluggen24-Oct-12 1:18
professionalEddy Vluggen24-Oct-12 1:18 
AnswerRe: Winforms or WPF Pin
V.24-Oct-12 2:42
professionalV.24-Oct-12 2:42 
AnswerRe: Winforms or WPF Pin
Keith Barrow24-Oct-12 6:49
professionalKeith Barrow24-Oct-12 6:49 
AnswerRe: Winforms or WPF Pin
Gerry Schmitz24-Oct-12 15:37
mveGerry Schmitz24-Oct-12 15:37 
AnswerRe: Winforms or WPF Pin
Bernhard Hiller26-Oct-12 0:34
Bernhard Hiller26-Oct-12 0:34 
Questioncreate a node with color in c# Pin
mahendiran bala23-Oct-12 23:43
mahendiran bala23-Oct-12 23:43 
AnswerRe: create a node with color in c# Pin
Pete O'Hanlon23-Oct-12 23:49
subeditorPete O'Hanlon23-Oct-12 23:49 
QuestionVSTO 2010 Word Addin, passing arguments problem PinPopular
Shah Ali Haider23-Oct-12 22:52
Shah Ali Haider23-Oct-12 22:52 
I am trying to develop a VSTO 2010 Word Addin. It has a custom task pane with a countdown timer (user control) in it. Idea is that when a word document is opened total time (in hours and minutes) is passed to the Addin which in turn passes it to the countdown timer control. When i run the addin in VS2010 and pass the user control two integers values i.e. hours and minutes in the Addin_Startup it works fine.

Now i am trying to open a word document on button click from an asp.net page. When i click the button a word document should open and time in hours and minutes should be passed to the addin which will then give it to the user control and the timer should run for the given time.

Problem is i cant figure out how to pass two integers to the addin and where to pass them. Following is my code which sometimes give "Catastrophic failure error" and other times it gives me "Unable to cast COM object of type 'System.__ComObject' to interface type 'MyWordAddin.IAddInUtilities'"

ThisAddin Class
C#
namespace MyWordAddin
{
    public partial class ThisAddIn
    {
        private ctlClock myUserControl;
        private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
        private int hour, min;
        private AddInUtilities utilities;

        protected override object RequestComAddInAutomationService()
        {
            if (utilities == null)
            {
                utilities = new AddInUtilities();
            }
            return utilities;
        }

        public int Min
        {
            get { return min; }
            set { min = value; }
        }

        public int Hour
        {
            get { return hour; }
            set { hour = value; }
        }


        public Microsoft.Office.Tools.CustomTaskPane MyCustomTaskPane
        {
            get { return myCustomTaskPane; }
            set { myCustomTaskPane = value; }
        }

        public void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //MessageBox.Show("Start Up Called");
            myCustomTaskPane.VisibleChanged += new EventHandler(myCustomTaskPane_VisibleChanged);

        }
        public void setTime(int h, int m)
        {
            Hour = h;
            Min = m;
            myUserControl = new ctlClock(Hour, Min);
            //myUserControl = new ctlClock(0, 1);
            myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl, "Remaining Time");
            myCustomTaskPane.Visible = true;
        }

        private void yCustomTaskPane_VisibleChanged(object sender, System.EventArgs e)
        {
            Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked = myCustomTaskPane.Visible;
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }



AddinUtilities class
C#
namespace MyWordAddin
{
    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAddInUtilities
    {
        void setAddinTime(int h, int min);
    }

    [ComVisible(true)]
    //[Serializable()]
    [ClassInterface(ClassInterfaceType.None)]
    public class AddInUtilities : StandardOleMarshalObject,IAddInUtilities
    {
        public void setAddinTime(int hour, int min)
        {
            Globals.ThisAddIn.setTime(hour, min);          
            
        }

   }

    
}


Controller Application which tries to open word document and send two integers to the addin
C#
namespace ControllerApplication
{
    public class CCWordApp
    {
        private Word._Application oWordApp;	// a reference to Word application

        public Word._Application OWordApp
        {
            get { return oWordApp; }
            set { oWordApp = value; }
        }
        private Word.Document oWordDoc;		// a reference to the document

        public Word.Document OWordDoc
        {
            get { return oWordDoc; }
            set { oWordDoc = value; }
        }

        public CCWordApp()
        {
            // activate the interface with the COM object of Microsoft Word
            oWordApp = new Word.Application();
            oWordDoc = new Word.Document();
            
            
        }

        // Open a new document
        public void Open()
        {
                object addinName = "MyWordAddIn";
                Microsoft.Office.Core.COMAddIn addin = oWordApp.COMAddIns.Item(addinName);
                IAddInUtilities utils = null;
                    utils = (IAddInUtilities)addin.Object;
                    utils.setAddinTime(0, 8);
          
            
            Object oMissing = System.Reflection.Missing.Value;
            oWordApp.Visible = true;
            oWordDoc = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            oWordDoc.Activate();
        }


When i run the controller application, upon click event of start button it some times give me "Catastrophic failure" other times it gives me "Unable to cast COM object of type 'System.__ComObject' to interface type 'MyWordAddin.IAddInUtilities'" and sometimes it stucks on the last line of code saying "An object instance not passed to and object". I have bold selected the code where error arises. I cant figure out what really is the problem here and why i cant pass two simple integers to my addin. There sure be something i am doing in a very wrong manner. Please guide me.
AnswerRe: VSTO 2010 Word Addin, passing arguments problem Pin
Richard Deeming24-Oct-12 2:15
mveRichard Deeming24-Oct-12 2:15 
AnswerRe: VSTO 2010 Word Addin, passing arguments problem Pin
Pete O'Hanlon24-Oct-12 3:56
subeditorPete O'Hanlon24-Oct-12 3:56 
QuestionWebRequest and WebResponse has issues Pin
Xarzu23-Oct-12 21:28
Xarzu23-Oct-12 21:28 
AnswerRe: WebRequest and WebResponse has issues Pin
J4amieC23-Oct-12 21:36
J4amieC23-Oct-12 21:36 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu25-Oct-12 11:04
Xarzu25-Oct-12 11:04 
AnswerRe: WebRequest and WebResponse has issues Pin
n.podbielski23-Oct-12 22:10
n.podbielski23-Oct-12 22:10 
GeneralRe: WebRequest and WebResponse has issues Pin
Jan Steyn24-Oct-12 3:31
Jan Steyn24-Oct-12 3:31 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu25-Oct-12 11:10
Xarzu25-Oct-12 11:10 
GeneralRe: WebRequest and WebResponse has issues Pin
n.podbielski25-Oct-12 20:14
n.podbielski25-Oct-12 20:14 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu27-Oct-12 18:59
Xarzu27-Oct-12 18:59 
GeneralRe: WebRequest and WebResponse has issues Pin
n.podbielski27-Oct-12 20:18
n.podbielski27-Oct-12 20:18 
QuestionGetting Square Root of BigInteger Pin
gibsray23-Oct-12 7:52
gibsray23-Oct-12 7:52 
AnswerRe: Getting Square Root of BigInteger Pin
jschell23-Oct-12 8:22
jschell23-Oct-12 8:22 
SuggestionRe: Getting Square Root of BigInteger Pin
Matt T Heffron23-Oct-12 11:30
professionalMatt T Heffron23-Oct-12 11:30 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski23-Oct-12 22:37
n.podbielski23-Oct-12 22:37 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 4:27
harold aptroot24-Oct-12 4:27 
GeneralRe: Getting Square Root of BigInteger Pin
Matt T Heffron24-Oct-12 6:39
professionalMatt T Heffron24-Oct-12 6:39 

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.