在MFC对话框中使用c#编写的ActiveX控件

编程入门 行业动态 更新时间:2024-10-18 16:42:46
本文介绍了在MFC对话框中使用c#编写的ActiveX控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好 我已经用C#编写了ActiveX控件.参见下面的代码:

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

namespace ActiveXCSharp { [ComVisible(true)] [ProgId("ActiveXCSharp.ButtonAx2")] [ComSourceInterfaces(typeof(IButtonAx2))] [ClassInterface(ClassInterfaceType.AutoDual)] public class ButtonAx2 : Button, IButtonAxInterface { // ptr to dll adapter private IntPtr _adapterDllPtr; private const uint DotNetButtonPressed = 0x0400; public ButtonAx2() { Application.EnableVisualStyles(); InitComEvents(); 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) { ButtonClicked(); } } private void ButtonAx2Click(object sender, EventArgs e) { SendMessage(_adapterDllPtr.ToInt32(), DotNetButtonPressed, IntPtr.Zero, IntPtr.Zero); FireButtonClickedEvent(); } #endregion eventhandling #region IButtonAxInterface Member public void SetButtonCaption(String strNewCaption) { Text = strNewCaption; } public void SetAdapterDllPtr(IntPtr iAdapterDllPtr) { _adapterDllPtr = iAdapterDllPtr; } #endregion IButtonAxInterface Member [ComRegisterFunction] public static void RegisterClass(string key) { ... } [ComUnregisterFunction] public static void UnregisterClass(string key) { ... } #region MAPPING_OF_USER32_DLL_SECTION ... #endregion } }

我想在MFC对话框中使用它.我可以将控件放到设计器上,它将在设计和运行时正确显示.但是我无法创建它的实例. 当我右键单击设计器上的控件并选择创建变量时,会出现一个消息框,提示无法访问ActiveX控件的类型库." 该控件已注册,并且与.dll相同,还有.tlb. 我的问题是如何创建ActiveX实例以在C ++代码中使用? 最好的问候Michael

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

推荐答案

我找到了解决方案. 也许其他人有兴趣.我使用.NET Framwork 2.0,在这种情况下,属性为ComRegisterFunction的方法必须具有签名void methodName(Type).在更高版本的框架中,也允许使用签名void methodName(String). 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.

更多推荐

在MFC对话框中使用c#编写的ActiveX控件

本文发布于:2023-11-17 12:38:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   对话框中   MFC   ActiveX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!