There are two key links in how to call VC-written OCX control in C#
Two key links: import the ocx control and create an instance.
1 Register ocx:
2 Execute in the CMD window:
Generate two files:,
3 Quoting in the project
4 Call
sms = new ();
();
It's ready to use
Here is an example of calling the OCX component developed by vc in C# console mode
1. Register component regsvr32 C:\WINDOWS\system32\
2. Use tool pairs to convert them, and encapsulate them into two class libraries (,)
3. Code
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using AXHH;//ocx control
using HH;//ocx control
using ;
namespace Ocx_test
{
public class Program
{
//Set static variables
static AXHH hh;
[STAThread]
static void Main(string[] args)
{
//Initialize the ocx control
hh = new AXHH();
//Explanatory call to the CreateControl() method of this instance to call other methods, otherwise the system will report an exception when called.
();
//Calling control properties and methods
="127.0.0.1";
();
}
}
4. Note that if it is a multi-threaded call, prefix the thread name.Start(), for example:
Thread name.SetApartmentState();//Set mode, must be set before starting.
// The startup thread will call the ThreadStart delegation.
Thread name.Start();