Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 29 Aug 2007 01:59:29 -0700,    group: microsoft.public.word.vba.addins        back       


VSTO Custom Task Panes   
I have written an Application level addin for Word 2007 in C# using
VSTO. I have a toggle button on my ribbon which displays a custom task
pane. This all works fine.

I also have a VB6 application which creates Word documents, this
application needs to tell my AddIn to display the custom task pane. So
I exposed a method in my AddIn which creates the custom task pane. If
I use the VB editor in Word to call that method everything works fine;
but if I call the method from a different application I get an invalid
cast exception:


Message:
{"Unable to cast COM object of type 'System.__ComObject' to interface
type 'Microsoft.Office.Tools.ICustomTaskPaneSite'. This operation
failed because the QueryInterface call on the COM component for the
interface with IID '{3CA8CD11-274A-41B6-A999-28562DAB3AA2}' failed due
to the following error: No such interface supported (Exception from
HRESULT: 0x80004002 (E_NOINTERFACE))."}

Stack trace:
   at
Microsoft.Office.Tools.CustomTaskPaneAdapter..ctor(IRuntimeServiceProvider
runtimeServiceProvider, UserControl control, String title, Object
window)
   at
Microsoft.Office.Tools.CustomTaskPaneFactoryAdapter.Microsoft.Office.Tools.ICustomTaskPaneFactoryContract.Create(UserControl
control, String title, Object window)
   at
Microsoft.Office.Tools.CustomTaskPaneCollection.AddHelper(UserControl
control, String title, Object window)
   at Microsoft.Office.Tools.CustomTaskPaneCollection.Add(UserControl
control, String title, Object window)
   at TestWordAddin.ThisAddIn.AddPanel(Window Window) in C:\Source\ECS
C#\TestWordAddin\TestWordAddin\ThisAddIn.cs:line 27


I have spent a while looking at this now and my theory is that because
my Custom Task Pane is a Control it must be created on the same thread
as Word, so when my Application creates the control I get an error.
That is where I am stuck, how do I invoke the correct thread (or am I
barking up the wrong tree)?

All comments gratefully received.

Dave



I have attached my AddIn code and the VB6 code which is calling my
addin's method.


My AddIn Code (simplified):

using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;

namespace TestWordAddin
{
    public partial class ThisAddIn
    {
        private ThisAddInCOM m_TestAddinUtils;

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

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

        public void AddPanel(Word.Window Window)
        {
            // Create and add a custom task pane to the specified
window
            try
            {
                UserControl1 panel = new UserControl1();
                Microsoft.Office.Tools.CustomTaskPane ctp =
this.CustomTaskPanes.Add(panel, "TestAddIn", Window);
                ctp.DockPosition =
Office.MsoCTPDockPosition.msoCTPDockPositionTop;
                ctp.Height = 57;
                ctp.Visible = true;
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }

        protected override Object RequestComAddInAutomationService()
        {
            if (m_TestAddinUtils == null)
                m_TestAddinUtils = new ThisAddInCOM(this);

            return m_TestAddinUtils;
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new
System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new
System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }

    /// <summary>
    /// Interface for COM interop
    /// </summary>
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
 
[System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch)]
    public interface IThisAddInCOM
    {
        void AddPanel(Word.Window Window);
    }

    /// <summary>
    /// Class for com interop (the addin cannot be exposed directly to
COM)
    /// </summary>
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
 
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
    public class ThisAddInCOM : IThisAddInCOM
    {
        private ThisAddIn AddIn;

        public ThisAddInCOM(ThisAddIn AddIn)
        {
            this.AddIn = AddIn;
        }

        public void AddPanel(Word.Window Window)
        {
            AddIn.AddPanel(Window);
        }
    }
}


My VB6 Code which call my Addin's method:

Dim wordapp As Word.Application
Dim testaddin_com As Object
Dim testaddin_addin As Object
Dim activeWindow As Word.Window
  'Display Custom task pane

  Set wordapp = GetObject(, "Word.Application")
  Set activeWindow = wordapp.activeWindow

  Set testaddin_com = wordapp.COMAddIns("TestWordAddIn")
  If Not testaddin_com Is Nothing Then
    Set wordapp = Nothing
    Set testaddin_addin = testaddin_com.object
    If Not testaddin_addin Is Nothing Then
      testaddin_addin.AddPanel activeWindow
    End If
  End If
date: Wed, 29 Aug 2007 01:59:29 -0700   author:   unknown

Re: VSTO Custom Task Panes   
The nice people at Microsoft have answered my question at:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2070081&SiteID=1

Dave
date: Tue, 04 Sep 2007 03:39:25 -0700   author:   unknown

Re: VSTO Custom Task Panes   
I couldn't get the other link to bring up the page in the Safari browser,
but by clicking on the RSS button, this link came up and was viewable:
 
feed://forums.microsoft.com/MSDN/rss.aspx?postID=2070081&forumID=16

You might have to cut and paste it into the browser address box.

> The nice people at Microsoft have answered my question at:
> 
> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2070081&SiteID=1
> 
> Dave
> 

-- 
Russ

 drsmN0SPAMikleAThotmailD0Tcom.INVALID
date: Mon, 10 Sep 2007 13:42:57 -0400   author:   Russ LID

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us