Qt development Activex notes (three): C# calls the Activex control developed by Qt

If the article is an original article, please indicate the original source for reprinting.
The blog address of this article: https://blog.csdn.net/qq21497936/article/details/113789727

We will continue to bring more projects and technology sharing for a long time, please add QQ: 21497936, WeChat: yangsir198808 for inquiries

Red Fatty (Red Imitation)'s blog post: development technology collection (including Qt practical technology, Raspberry Pi, 3D, OpenCV, OpenGL, ffmpeg, OSG, single-chip microcomputer, software and hardware combination, etc.) is being continuously updated... (click on the portal)

Qt Development Column: Development Technology

Previous article: " Qt Development Activex Notes (2): Qt calls Activex controls developed by Qt "
Next article: Stay tuned...


Preface

  Develop Activex controls for other applications to call. This chapter explains how to call Activex controls in C#, not limited to Activex controls developed by Qt.
  To call the Activex control in Wpf, it is necessary to wrap the Activex control in C# first, and then provide it to Wpf to call.


Demo

  Insert picture description here


C# call Activex method

Step 1: Register the activex control

  Register before running, use the idc that comes with Qt to register.

idc -regserver activeHelloWorldDemo.dll

  Insert picture description here

Step 2: Confirm the clsid of the activeQt control

  Check it, open the registry and search to confirm clsid, as shown below:
  Insert picture description here

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

Step 3: Create c# project and introduce com's dll

  Import the registered dll into the project, as shown below:
  Insert picture description here

  Insert picture description here
  Insert picture description here

Step 4: Use controls in the code

  Insert picture description here

Step Five: Write the code

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

Source code

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();
        }
    }
}

Previous article: " Qt Development Activex Notes (2): Qt calls Activex controls developed by Qt "
Next article: Stay tuned...

Guess you like

Origin blog.csdn.net/qq21497936/article/details/113789727