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
  • 相关阅读:
    WEB浏览器与服务器通讯过程
    lua及luci学习
    让apache2不开机启动,管理Ubuntu的开机启动项
    在linux中如何调试C语言程序
    如何去除configure的默认选择-g O2
    C语言使用SQLite3数据库
    Linux下的C程序如何调用系统命令,并获取系统的输出信息到C程序中
    Opencv step by step
    Opencv step by step
    Opencv step by step
  • 原文地址:https://www.cnblogs.com/xlong1900/p/1774563.html
Copyright © 2011-2022 走看看