Click here to Skip to main content
15,029,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have written an ActiveX control in C#. See code below:

namespace ActiveXCSharp
	public class ButtonAx2 : Button, IButtonAxInterface
		// ptr to dll adapter
		private IntPtr _adapterDllPtr;
		private const uint DotNetButtonPressed = 0x0400;

		public ButtonAx2()

			Click += ButtonAx2Click;

		#region eventhandling
		private void InitComEvents()
			ButtonClicked = ComEventButtonClicked;

		public delegate void ButtonClickedEventHandler();
		public event ButtonClickedEventHandler ButtonClicked;
		// Dummy Method to use when firing the event
		private void ComEventButtonClicked() { }

		private void FireButtonClickedEvent()
			if (ButtonClicked != null)

		private void ButtonAx2Click(object sender, EventArgs e)
			            DotNetButtonPressed, IntPtr.Zero, IntPtr.Zero);

		#endregion eventhandling

		#region IButtonAxInterface Member

		public void SetButtonCaption(String strNewCaption)
			Text = strNewCaption;

		public void SetAdapterDllPtr(IntPtr iAdapterDllPtr)
			_adapterDllPtr = iAdapterDllPtr;

		#endregion IButtonAxInterface Member

		public static void RegisterClass(string key)

		public static void UnregisterClass(string key)






I want to use it in an MFC-Dialog. I can drop the control on the designer and it will proper shown on design- and runtime. But i'am not able to create an instance of it.

When i rightclick the control on the designer and choose create variable a Messagebox appears that says "Access to the type library for ActiveX controls isn't possible."

The control is registered and at the same place as the .dll there is also the .tlb.

My question is how can i create an instance of my activeX for the use in the C++ code?

Best regards Michael
Updated 14-Sep-11 0:11am

1 solution

I found a solution.
Maybe someone else is interested. I use .NET Framwork 2.0, and in this the method with the attribute ComRegisterFunctionmust have the signature void methodName(Type). In later frameworks the signature void methodName(String) is also allowed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900