C# code
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace MyLib {     [ComVisible(true)]     [Guid("2CBD3D76-35F1-4f9d-9C1B-9DBFEE412F76")]     public interface IMyClass     {         void Initialize();         void Dispose();         int Add(int x, int y);     }     [ComVisible(true)]     [Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")]     [ProgId("MyLib.MyClass")]     public class MyClass : IMyClass     {         public void Initialize()         {             //nothing todo         }         public void Dispose()         {             //nothing todo         }         public int Add(int x, int y)         {             return x + y;         }     } }


8、GUID属性里面的那个字符串,在“工具”菜单下面,“创建 GUID”
  选择 Registry Format,然后复制
  使用C#编写COM组件详尽过程

  注意在[Guid("....... 这个里面要去掉GUID前后的花括号

9、编译它
在命令提示符下面,进入Dll所在的目录
用 gacutil /i MyLib.dll 将这个DLL加入的全局缓存里
然后用 regasm MyLib.dll 注册这个dll
使用C#编写COM组件详尽过程

10、在VBScript里面试试。。。
HTML code
<script language="VBScript">
Dim o : Set o=CreateObject("MyLib.MyClass")
  
  o.Initialize     MsgBox "1 + 2 = " & o.Add(1,2)     o.Dispose     Set o=Nothing </script>
C# code
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace MyLib {     [ComVisible(true)]     [Guid("2CBD3D76-35F1-4f9d-9C1B-9DBFEE412F76")]     public interface IMyClass     {         void Initialize();         void Dispose();         int Add(int x, int y);     }     [ComVisible(true)]     [Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")]     [ProgId("MyLib.MyClass")]     public class MyClass : IMyClass     {         public void Initialize()         {             //nothing todo         }         public void Dispose()         {             //nothing todo         }         public int Add(int x, int y)         {             return x + y;         }     } }


8、GUID属性里面的那个字符串,在“工具”菜单下面,“创建 GUID”
  选择 Registry Format,然后复制
  使用C#编写COM组件详尽过程

  注意在[Guid("....... 这个里面要去掉GUID前后的花括号

9、编译它
在命令提示符下面,进入Dll所在的目录
用 gacutil /i MyLib.dll 将这个DLL加入的全局缓存里
然后用 regasm MyLib.dll 注册这个dll
使用C#编写COM组件详尽过程

10、在VBScript里面试试。。。
HTML code
<script language="VBScript">
Dim o : Set o=CreateObject("MyLib.MyClass")
  
  o.Initialize     MsgBox "1 + 2 = " & o.Add(1,2)     o.Dispose     Set o=Nothing </script>

相关文章:

  • 2022-02-06
  • 2022-01-12
  • 2021-10-13
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2021-12-05
  • 2021-08-27
  • 2021-10-10
  • 2021-10-16
相关资源
相似解决方案