.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:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

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

 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm  d:\app\mytest.dll

 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm MyEnCrypt.dll /tlb:MyEncrypt.tlb   

   C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm   test.dll /tlb:test.tlb

  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm   IMComInterface.dll  /tlb:IMComInterface.tlb

    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\regasm   IMComInterface.dll

32位系统

C:\Windows\Microsoft.NET\v2.0.50727\regasm.exe  IMComInterface.dll

C:\Windows\Microsoft.NET\v4.0.30319\regasm.exe  IMComInterface.dll

64位系统

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe  IMComInterface.dll

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe  IMComInterface.dll

 

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe /u IMComInterface.dll

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /u IMComInterface.dll

 

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

RegAsm : error RA0000 : “E:\MYDEV\test.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文件

Properties\AssemblyInfo.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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值