zoukankan      html  css  js  c++  java
  • c#制作com组件供wincc调用

    1,建立com组件

        [ComVisible(true)]
        [Guid("751452F7-4541-4483-83E0-22EDC1278F58")]
        public interface IMxbLiabray
        {
            void Initialize();
            void Dispose();
            int Add(int x, int y);
        }
    
    
        [ComVisible(true)]
        [Guid("258CBDAF-D4CD-41D4-9480-A81793846816")]
        public class MxbLiabray : Form,IMxbLiabray
        {
            private static MxbLiabray Form1;
            private int m_value;
    
            private Button button1;
            private ListBox listBox1;
            public int Add(int x, int y)
            {
                MessageBox.Show($"x + y");
                m_value = x + y;
                return x + y;
            }
    
            public void Dispose()
            {
            }
    
            public void Initialize()
            {
                button1 = new Button();
                button1.Left = 200;
                button1.Text = "Exit";
                button1.Click += new EventHandler(button1_Click);
    
                listBox1 = new ListBox();
                this.Controls.Add(button1);
                this.Controls.Add(listBox1);
                Form1 = new MxbLiabray();
                Application.Run(Form1);
            }
    
    
            private void button1_Click(object sender, System.EventArgs e)
            {
                int count = 1;
                // Check to see whether the user wants to exit the application.
                // If not, add a number to the list box.
                while (MessageBox.Show("Exit application?", "",
                    MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    listBox1.Items.Add(count);
                    count += 1;
                }
    
                // The user wants to exit the application.
                // Close everything down.
                Application.Exit();
            }

    1,代码中,使用接口,以及guid和comvisible=true;

    2,在生成之中进行打勾

    image

    签名那里打勾---生产强程序集

    image

    3,生成com组件和注册dll到全局缓存

    regasm .MxbLiabray.dll

    gacutil.exe /i .MxbLiabray.dll

    4,在wincc中调用

    Sub procedure1
    Dim obj
    Dim k
    Set obj = CreateObject("MxbLiabray.MxbLiabray")
    k=obj.Initialize
    End Sub

    注意名称:

    在注册表中查看注册的com组件名称:

    image

    5,使用OLEVIER查看计算机内的组件,但是查不到我注册的类..

  • 相关阅读:
    Node.js:events事件模块
    Node.js:console模块
    Node.js:DNS模块的使用
    CSS3 Notes: -webkit-box-reflect实现倒影
    H5 Notes:PostMessage Cross-Origin Communication
    H5 Notes:Navigator Geolocation
    Notes:SVG(4)基于stroke-dasharray和stroke-dashoffset圆形进度条
    Notes:SVG(3)---滤镜和渐变
    如何写出优美的 C 代码 面向对象的 C
    Source Insight快捷键
  • 原文地址:https://www.cnblogs.com/frogkiller/p/12456146.html
Copyright © 2011-2022 走看看