Author Topic: RegisterRibbonX from c#  (Read 706 times)

0 Members and 1 Guest are viewing this topic.

AndyW

  • Sr. Member
  • ****
  • Posts: 326
    • PC Mimic Diagram
RegisterRibbonX from c#
« on: June 16, 2022, 04:14:44 AM »
Has anyone had any success in using RegisterRibbonX from c#. All I get is a COMException with 'Invalid Parameter'. I am trying to automate a Visio appliction (no an addin).

Code
diagramRibbon= newMyApp.Library.DiagramRibbon();

visioApp.RegisterRibbonX(diagramRibbon, visioDoc, Visio.VisRibbonXModes.visRXModeDrawing, "Diagram Ribbon");

If I call this from VBA it works, so my DiagramRibbon class seems okay, so it seems Interop is affecting this.
Live life with an open mind

Nikolay

  • Hero Member
  • *****
  • Posts: 1095
    • UnmanagedVisio
Re: RegisterRibbonX from c#
« Reply #1 on: June 16, 2022, 07:37:54 AM »
I am not sure if RegisterRibbbonX works for out-of-process scenario like yours
What kind of object does newMyApp.Library.DiagramRibbon() return?
It should implement idispatch and iribbonextensibility interfaces at least, as far as I understand?
In c# terms, should be marked as ComVisible(true) and implement the method the Interface to return the ribbon xml
Probably it should be doable though. Ad far as I remember Visio event monitor (from SDK) is a stand-alone app (exe) and has a ribbon. If I remember correctly of course:)
« Last Edit: June 16, 2022, 07:52:12 AM by Nikolay »

AndyW

  • Sr. Member
  • ****
  • Posts: 326
    • PC Mimic Diagram
Re: RegisterRibbonX from c#
« Reply #2 on: June 16, 2022, 08:15:24 AM »
Hmm, I had no considered the out-of-process aspect. My ribbon class works if I call it with VBA from a Visio diagram

Code
namespace MyApp.Library
{
    [ComVisible(true)]
    [Guid("0577A201-E8BF-451F-B464-7F558F2C29E7")]
    public class DiagramRibbon : Office.IRibbonExtensibility
    {
        public DiagramRibbon() { }

        public string GetCustomUI(string RibbonID)
        {
            StreamReader customUIReader = new System.IO.StreamReader("D:\\App\\Ribbon_Diagram.xml");
            string customUIData = customUIReader.ReadToEnd();
            return customUIData;
        }
    }
}
Live life with an open mind

Nikolay

  • Hero Member
  • *****
  • Posts: 1095
    • UnmanagedVisio
Re: RegisterRibbonX from c#
« Reply #3 on: June 16, 2022, 04:16:54 PM »
Could it be that you create a temporary variable "diagramRibbon" and then it is immediately destroyed when the function exists the scope?
For me, your code does not seem to throw exceptions at least.