若该文为原创文章,转载请注明原文出处
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/113789727

长期继续带来更多我的项目与技术分享,征询请加QQ:21497936、微信:yangsir198808

红瘦子(红模拟)的博文大全:开发技术汇合(蕴含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬联合等等)继续更新中…(点击传送门)

Qt开发专栏:开发技术

上一篇:《Qt开发Activex笔记(二):Qt调用Qt开发的Activex控件》
下一篇:敬请期待...


前言

  开发Activex控件,以供其余应用程序调用,本篇章解说C#调用Activex控件,不限于Qt开发的Activex控件。
  Wpf要调用Activex控件,必要先用C#对Activex控件进行包装,而后提供给Wpf调用。


Demo

  


C#调用Activex办法

步骤一:注册activex控件

  运行之前先要注册,应用Qt下自带的idc注册一下。

idc -regserver activeHelloWorldDemo.dll

  

步骤二:确认activeQt控件的clsid

  查看一下,关上注册表并搜寻一下,确认clsid,如下图:
  

"2F12BFB8-137D-4DC2-9A93-634EFE5A6DFC"

步骤三:创立c#我的项目,引入com的dll

  将注册的dll引入到我的项目中,如下图:
  

  
  

步骤四:代码中应用控件

  

步骤五:编写代码

private void button1_Click(object sender, EventArgs e){    activeHelloWorldDemoLib.activeHelloWorldDemo dlg = new activeHelloWorldDemoLib.activeHelloWorldDemo();    dlg.show();}


源码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace trainSimulationDemo{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {        }        private void button1_Click(object sender, EventArgs e)        {            activeHelloWorldDemoLib.activeHelloWorldDemo dlg = new activeHelloWorldDemoLib.activeHelloWorldDemo();            dlg.show();        }    }}


上一篇:《Qt开发Activex笔记(二):Qt调用Qt开发的Activex控件》
下一篇:敬请期待...