zoukankan      html  css  js  c++  java
  • .net DLL 注册 regasm delphi调用

    .net DLL 注册 regasm

     regasm

    regasm myTest.dll

     regasm.exe

    打开vs2005自带的工具“Visual Studio 2005命令提示”,输入上述命令

    在没有安装vs开发环境的电脑上,必须安装。net framwork环境2.0以上,或根据项目要求安装合适的framwork版本。

    不能再普通的cmd命令下执行,找不到命令。

    进入普通的cmd窗口

    cd C:WINDOWSMicrosoft.NETFrameworkv2.0.50727

    进入这个目录下,再执行regasm命令就可以识别了。

     C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 egasm  d:appmytest.dll

     C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 egasm MyEnCrypt.dll /tlb:MyEncrypt.tlb   

       C:WINDOWSMicrosoft.NETFrameworkv4.0.30319 egasm   test.dll /tlb:test.tlb

      C:WINDOWSMicrosoft.NETFrameworkv4.0.30319 egasm   IMComInterface.dll  /tlb:IMComInterface.tlb

        C:WINDOWSMicrosoft.NETFrameworkv4.0.30319 egasm   IMComInterface.dll

    32位系统

    C:WindowsMicrosoft.NETFrameworkv2.0.50727 egasm.exe  IMComInterface.dll

    C:WindowsMicrosoft.NETFrameworkv4.0.30319 egasm.exe  IMComInterface.dll

    64位系统

    C:WindowsMicrosoft.NETFramework64v2.0.50727 egasm.exe  IMComInterface.dll

    C:WindowsMicrosoft.NETFramework64v4.0.30319 egasm.exe  IMComInterface.dll

    C:WindowsMicrosoft.NETFramework64v2.0.50727 egasm.exe /u IMComInterface.dll

    C:WindowsMicrosoft.NETFramework64v4.0.30319 egasm.exe /u IMComInterface.dll

    有的dll只能用4.0注册,2.0注册失败。

    RegAsm : error RA0000 : “E:MYDEV est.dll”不是有效的 .NET 程序集,因 此未能加载它

    delphi调用

    方法一

    打开vs2005自带的工具“Visual Studio 2005命令提示”,输入 TlbExp  路径/TestClass.dll 得到一个TestClass.tlb 文件。

    打开Delphi,选择“Project”--“import type library”找到刚才的TestClass.tlb,点击 CreateUnit,生成生成的TLB的pas文件

      var aClass: TestClass
      begin
        aClass :  CoTestClass.Create;
        aClass. YourProcedure ('参数'); 
      end;

    方法二、不需生成tlb文件,仿照调用Excel的方式。代码如下:
     var aClass: Variant;
    begin
      aClass:= CreateOleObject('TestDll.TestClass');
      aClass.YourProcedure ('参数');
    end;

    vs2015 c#封装com文件

    PropertiesAssemblyInfo.cs

    [assembly: ComVisible(true)];//从fasel改为true

    也可以在工程里改

    右键单击工程--》属性--》应用程序--》点击程序集信息--》最下面的复选框(使程序集Com可见)

    TlbExp  路径/TestClass.dll 得到一个TestClass.tlb 文件

    regasm MyEnCrypt.dll /tlb:MyEncrypt.tlb   

    TlbExp  TestClass.dll

    查找delphi生成的TLb文件里的

      Co*** = class
        class function Create: **ComInterface;
        class function CreateRemote(const MachineName: string): **ComInterface;
      end;

    imcom:IMComInterface_TLB._CIMComInterface;

    imcom := IMComInterface_TLB.CoCIMComInterface.Create;

    C++

    IMComInterface_TLB.cpp

    const GUID CLSID_CIMComInterface =

     _CIMComInterface *imcom = CoCIMComInterface::Create();

    不用看TLB.h文件了。根据TLB.cpp就可以知道名称进行定义和create了。

    IMComInterface_TLB.h

    _CIMComInterface *imcom = CoCIMComInterface::Create();

    typedef TCoClassCreatorT<TCOM_CIMComInterface, _CIMComInterface, &CLSID_CIMComInterface, &IID__CIMComInterface> CoCIMComInterface;

    {F6240F08-CBDB-3E72-87E9-7A9FBD39B554}

    IMComInterface.CIMComInterface

    const GUID CLSID_CoClass_n_yh_interface = {0x022C078C, 0x48B9, 0x49CC,{ 0x8E, 0xB5, 0x3D,0xD0, 0x85, 0x2E,0xEF, 0xFB} };

    comid,还可以直接查看dll文件记事本查看,里边搜索YinHai.XIAN,找到真实的ID

    YinHai.XIAN.Actual.Interface.1.0

  • 相关阅读:
    运维笔记--docker容器部署mongodb 数据持久化
    odoo开发学习-debug&开发者模式 取消
    python开发 -- 批量修改文件后缀名为指定格式
    python开发 -- 判断文件编码格式是否为UTF8 有/无BOM格式
    odoo开发学习 -- 模块目录结构
    odoo开发学习 -- Python2 or Python3?关于环境搭建的软件版本选择
    odoo开发学习 --一点题外话
    odoo各版本新特性及变更记录 --持续更新
    odoo开发学习 -- odoo12 Docker镜像制作
    odoo开发学习--saas环境搭建(一)
  • 原文地址:https://www.cnblogs.com/cb168/p/6598368.html
Copyright © 2011-2022 走看看