I am currently tasked with creating an Active-X plugin for one of our clients. Now I have successfully created the Active-X plugin in C # /. NET (a Windows Form control that inherits from the System.Windows.Forms.UserControl class), however the application that hosts the plugin shows the class name of the control in the dialog box title which displays the Active-X plugin.
After much searching and disassembling, I found that the IOleObject.GetUserType method IOleObject.GetUserType called by the host and that it is the return value of this method, which is used by the host as the title of the dialog box. Looking at the System.Windows.Forms.UserControl class, I found that this class inherits from the System.Windows.Forms.Control class, which in turn explicitly implements the System.Windows.Forms.UnsafeNativeMethods.IOleObject interface.
I would like to know if there is a way to override the GetUserType method in the UserControl class, or if there is another way to accomplish what I want (maybe the solution is very simple, but so far I have not seen it). I have already tried various "possible" solutions:
I tried IOleObject interface, but since System.Windows.Forms.UnsafeNativeMethods.IOleObject is internal, this cannot be done (you must use the same interface, and redefining the interface does not lead to the same interface).
I tried to use CLR injection as described by Ziad Elmalki on CodeProject .
I tried to use some form of AOP. Since the Control class inherits from System.MarshalByRefObject to System.ComponentModel.Component , I thought it was possible for my user control to be able to return some kind of proxy that would intercept the calls sent to the GetUserType method.
Unfortunately, I could not get this to work. What works is changing the class name, but since class names do not have spaces or other special characters, this is not an acceptable solution (underscores are not the same thing).
To develop here an example of the code that I want to execute (note that it is not complete):
using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Forms; [ ComVisible(true) , ClassInterface(ClassInterfaceType.AutoDual) , Description("My Active-X plug-in") , Guid("...") ] public partial class MyControl : UserControl { public override int GetUserType(int dwFromOfType, out string userType) { userType = "The caption to show in the host";
Hope someone here can help me.
Thanks in advance!
source share