Author Topic: Creating ActiveX Control in current AddIn Project  (Read 4826 times)

EANewbie1

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Creating ActiveX Control in current AddIn Project
« on: July 05, 2021, 10:15:13 pm »
Hi folks,

I know similar topics have been published to this topic, however I couldn't find an answer to my problem.

I'm trying to create an ActiveX control inside of my current AddIn Project, so that I can use it for the Repository Method AddWindow(). So far in the threads I've seen solutions regarding a own Project and DLL for the ActiveX control and adding this project to the addIn solution. But is it possible to create a UserControl inside of the addIn solution and wrap it as an ActiveX control, so that no other project or dll needs to be included?

I created a UserControl inside of my VisualStudio AddIn project which includes a button. How do I "turn it into" an ActiveX control and how do I register it when it is already included inside my AddIn solution (which is already registered)? Also: In a few threads and git repositories (e.g. https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/MyAddin/MyEAControl.cs from Geert Bellekens) I've seen the System.Runtime.InteropServices package being used for the GUID and COM-Visibility. Why is it included and when is it needed?

See my UserControl code
Code: [Select]
using System;
using System.Windows.Forms;

namespace MTI.src.ui
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void PerformVIT_Click(object sender, EventArgs e)
        {
            //doSomething
        }
    }
}

And my EA_MenuClick method:
Code: [Select]
        public void EA_MenuClick(EA.Repository repository, string location, string menuName, string itemName)
        {
            if (itemName == "&Create")

                userControl = (UserControl1)repository.AddWindow("Perform Test", "MTI.src.ui.UserControl1");
            repository.ShowAddinWindow("MTI.src.ui.UserControl1");
        }

Sorry for the whole lot of questions.

Any help or advice will be most appreciated since I'm an EA newbie and also fairly new to C#.

Alex

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11176
  • Karma: +410/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating ActiveX Control in current AddIn Project
« Reply #1 on: July 05, 2021, 10:22:17 pm »
I think

Code: [Select]
repository.ShowAddinWindow("MTI.src.ui.UserControl1");should be
Code: [Select]
repository.ShowAddinWindow("Perform Test");
You don't necessarily need the attributes

Code: [Select]
[Guid("01ce6c0d-0bf0-409a-9cb6-db7d96a05a20")]
[ComVisible(true)]
Only if you want some more control on what to export with which GUID.

Geert

EANewbie1

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating ActiveX Control in current AddIn Project
« Reply #2 on: July 07, 2021, 05:16:24 am »
I think

Code: [Select]
repository.ShowAddinWindow("MTI.src.ui.UserControl1");should be
Code: [Select]
repository.ShowAddinWindow("Perform Test");
You don't necessarily need the attributes

Code: [Select]
[Guid("01ce6c0d-0bf0-409a-9cb6-db7d96a05a20")]
[ComVisible(true)]
Only if you want some more control on what to export with which GUID.

Geert

Thank you for your answer and the clue Geert! I changed the parameter for the method call. However, there is still no window. I quess it has something to do with the registration. Do you by any means know how I can solve my stated problem with the control created inside of my AddIn Project? How do I register it if the DLL for the AddIn is already registered?

Alex

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11176
  • Karma: +410/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating ActiveX Control in current AddIn Project
« Reply #3 on: July 07, 2021, 06:54:56 am »
If you have "register for COM interop" on, then your usercontrol should be registered.

Check the registry for "MTI.src.ui.UserControl1" to check.

Geert

EANewbie1

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating ActiveX Control in current AddIn Project
« Reply #4 on: July 27, 2021, 11:15:15 pm »
If you have "register for COM interop" on, then your usercontrol should be registered.

Check the registry for "MTI.src.ui.UserControl1" to check.

Geert

Sorry for the late Response. After re-registering the AddIn DLL using regasm I got it to work!

I used the following commands in the windows command promt for unregistering and re-registering the DLL.
Code: [Select]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files\DirectoryOfYourDLL\AddIn.dll" /u
Code: [Select]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files\DirectoryOfYourDLL\AddIn.dll" /codebase

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11176
  • Karma: +410/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating ActiveX Control in current AddIn Project
« Reply #5 on: August 18, 2021, 03:48:28 pm »
If you have "register for COM interop" on, then your usercontrol should be registered.

Check the registry for "MTI.src.ui.UserControl1" to check.

Geert

Sorry for the late Response. After re-registering the AddIn DLL using regasm I got it to work!

I used the following commands in the windows command promt for unregistering and re-registering the DLL.
Code: [Select]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files\DirectoryOfYourDLL\AddIn.dll" /u
Code: [Select]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files\DirectoryOfYourDLL\AddIn.dll" /codebase
That works, but there is also an checkbox in Visual Studio that makes VS do that for you.

Geert