c# 开发activex (已经在系统注册 regasm )在vc 6.0 调用 可以再vc 里面看到控件 但是 不能添加变量 报 the activex control is not registered properly 有谁遇到这样得问题?

解决方案 »

  1.   

    声明属性InterfaceType(ComInterfaceType.InterfaceIsDual),ComVisible(true),以支持register 和 unregister。 6    [
    17        Guid("627AD403-FA50-4a08-B875-770520865DD6"),
    31        ClassInterface(ClassInterfaceType.None),
    40        ComVisible(true)
    41    ]
    42    public partial class yourclass{...}每次修改之后需要重新注册。
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using Microsoft.Win32;
    using System.Reflection;
    namespace ClassLibrary2
    {
        [Guid("7B5F5BA2-0EAE-4351-AE55-B24C63C1ACDD")]
        public interface Iuser
        {
            void msg();
        }    [ProgId("testttttttt")]
        [Guid("6E5DB382-61E6-4b07-9ABC-43EC54FCE810")]
        [ClassInterface(ClassInterfaceType.AutoDispatch)]
        public partial class TestCom : UserControl
        {
            public TestCom()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                this.BackColor = Color.Red;
            }        private void msg()
            {
                MessageBox.Show("this is a test");
            }
        }
    }
    AssemblyInfo.cs 设置了[assembly: ComVisible(true)] 不能添加变量 vc 6.0 mfc 类向导 添加控件变量 因为vc 中 控件显示ID 必须将该ID 与类型映射 所以添加变量 
    现在得情况是控件已经托到窗体了,但是就是无法添加变量
      

  3.   

     UserControl :Iuser 补充一下 
      

  4.   

    贴错了using System.Runtime.InteropServices; // COM attributes
    using Microsoft.Win32; // RegistryKey
    using System.Windows.Forms;
    using System;
    using System.Text;
    using System.Reflection;
    using System.Drawing;
    namespace WindowsControlLibrary1 {
      // Stops control from getting a new CLSID
      // at each registration
      [ProgId("newcontrols")]
      [Guid("E73CD054-1247-4853-AF05-B7D26D993E85")]
      [ClassInterface(ClassInterfaceType.AutoDispatch)]
      public class UserControl2 : UserControl ,Iusercontrol
      {
          private Button button1;
                public void name()
          { 
          }      private void InitializeComponent()
          {
              this.button1 = new System.Windows.Forms.Button();
              this.SuspendLayout();
              // 
              // button1
              // 
              this.button1.Location = new System.Drawing.Point(32, 57);
              this.button1.Name = "button1";
              this.button1.Size = new System.Drawing.Size(408, 153);
              this.button1.TabIndex = 0;
              this.button1.Text = "button1";
              this.button1.UseVisualStyleBackColor = true;
              this.button1.Click += new System.EventHandler(this.button1_Click);
              // 
              // UserControl2
              // 
              this.BackColor = System.Drawing.Color.Brown;
              this.Controls.Add(this.button1);
              this.Name = "UserControl2";
              this.Size = new System.Drawing.Size(518, 328);
              this.ResumeLayout(false);      }      private void button1_Click(object sender, EventArgs e)
          {      }
      }    [Guid("7A4673AD-39E4-4856-876B-4451C5B0EB25")]
        public interface Iusercontrol
        {
            void name();    }
    }