zoukankan      html  css  js  c++  java
  • C#写COM组件提供ASP使用(转)

    1. C#代码
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography;
    namespace ComTest
    {
    [Guid("DE03FB14-23D6-4be0-93EA-C27651A22A37")]
    public interface ITest
    {
    string Test(string test);
    }
    [Guid("0ED3C99A-6EBB-4df5-B03F-16CACE242C67")]
    public class CTest : ITest
    {
    public string Test(string test)
    {
    return test;
    }
    }
    }
    2. AssemblyInfo.cs文件设置
    [assembly: ComVisible(true)] 必须设置为True
    [assembly: AssemblyVersion("1.0.0.0")] 必须明确指定,不能用*号
    [assembly: AssemblyKeyFile(@"c:\keyfile.snk")]
    注:c:\keyfile.snk 由 sn -k c:\keyfile.snk 生成
    3. 生成tlb文件
    通过Ctrl+Shift+B生成DLL文件,然后通过tlbexp ComTest.dll /out:ComTest.tlb得到.tlb文件
    4. 注册tlb成com
    通过C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm /tlb:ComTest.tlb ComTest.dll /CodeBase
    5. 加入全局缓存中(非必须,建议不进行)
    gacutil -i ComTest.dll

    GetKey.bat(得到KeyFile批处理):
    path E:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin
    sn -k c:\keyfile.snk
    RegCom.bat(生成tlb并注册成com批处理):
    path E:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin
    tlbexp C:\Downloads\ComTest\ComTest\ComTest\bin\Release\ComTest.dll /out:C:\Downloads\ComTest\ComTest\ComTest\bin\Release\ComTest.tlb
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm /tlb:C:\Downloads\ComTest\ComTest\ComTest\bin\Release\ComTest.tlb C:\Downloads\ComTest\ComTest\ComTest\bin\Release\ComTest.dll /CodeBase
  • 相关阅读:
    258. Add Digits 数位相加到只剩一位数
    7. Reverse Integer 反转整数
    9. Palindrome Number 回文数的判断
    824. Goat Latin山羊拉丁文
    819. Most Common Word 统计高频词(暂未被禁止)
    Angular 2 模板语法
    HTML DOM Style opacity 属性
    Basic concepts (C language) – C 中文开发手册
    JavaScript手册 | JS Array 对象中的fill()方法
    HTML <form> 标签
  • 原文地址:https://www.cnblogs.com/xlong1900/p/1774563.html
Copyright © 2011-2022 走看看