MFC设计器中的“无法访问ActiveX控件类型库”错误

问题描述 投票:0回答:1

问题 我尝试在Visual Studio设计器中添加ActiveX控件的变量时(通过右键单击 - >“添加变量”或通过类向导)在MFC基于对话框的应用程序中获得“无法访问ActiveX控件类型库”错误。我需要它来处理这个ActiveX控件的方法和事件,它是从Windows窗体控件创建并在系统中注册的(Windows 7)。

是)我有的 这是简化的C#COM实现(一个从MFC端调用的方法和一个用于通知MFC任何事件的事件):

[ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IWinFormControl
{
    [DispId(1)]
    string MethodTest(string s);
}

[ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IWinFormControlEvents
{
    [DispId(2)]
    void SimpleEvent(string s);
}

[ComVisible(true),
ClassInterface(ClassInterfaceType.None),
ComDefaultInterface(typeof(IWinFormControl)),
ComSourceInterfaces(typeof(IWinFormControlEvents))]
public partial class WinFormControlImpl : UserControl, IWinFormControl
{
    public delegate void SimpleEventType(string s);
    public event SimpleEventType SimpleEvent; 

    public WinFormControlImpl()
    {
        this.InitializeComponent();
    }

    private void Button_Click(object sender, EventArgs e)
    {
        if (this.SimpleEvent != null)
        {
            this.SimpleEvent("TESTEVENT");
        }
    }

    public string MethodTest(string s)
    {
        MessageBox.Show("TESTMETHOD " + s);
    }

    // ... ComRegisterFunction and ComUnregisterFunction
}

“注册COM互操作”项目标志检查,在构建组件成功添加到注册表后,我可以使用TstCon32实用程序测试它并在那里调用MethodTest。

在MFC项目中,我在设计视图中打开对话框面板,右键单击并选择“插入ActiveX控件”,然后成功找到我的ActiveX控件并将其插入到对话框面板中。应用程序运行,我看到我的ActiveX与所有内容。但我无法为此控件创建变量。

我尝试了什么 研究给了我两个一般的解决方法。首先是忘记COM,将.NET项目的引用添加到MFC项目中,并使用CWinFormsControl和/ CLR创建用于用户控制的本机C ++包装器。这不适合我的任务。

另一种可能的解决方案是手动为ActiveX控件创建变量,但我找不到足够的示例来实现它。我找到的最接近的黑客是在question,其中在CWnd变量中创建的ActiveX对象和通过接口访问的COM的功能,但我不知道如何将这个变量信息的可视内容显示在对话框面板中。

问题是:如何在MFC基于对话框的窗口中为ActiveX组件(在C#中创建)创建变量?

c# c++ mfc com activex
1个回答
0
投票

希望能帮助到你 :

if (m_pWndFramework == NULL)//  CWnd* m_pWndFramework;

{

    m_pWndFramework = new CWnd;
    CRect rcRange;    //set the display area
    rcRange.left = 0;
    rcRange.top = 0;
    rcRange.right = 500;
    rcRange.bottom = 500;

    //get the ID of the user control
    m_pWndFramework = GetDlgItem(IDC_TESTT1);

    //if(bCreate)
    {
        IUnknown * pUn = m_pWndFramework->GetControlUnknown(); 
        if(pUn)
        { 
            pUn->QueryInterface(IID_IDispatch,(void **)&m_pFramework);     //m_pFramework
            bResult = TRUE;
        }
    }
}

m_pFramework->messageShowClose();
© www.soinside.com 2019 - 2024. All rights reserved.