调用从VB6通过COM可见的DLL .NET方法 [英] Calling .NET methods from VB6 via COM visible DLL

查看:237
本文介绍了调用从VB6通过COM可见的DLL .NET方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个.NET的DLL,这使得一些方法COM可见。

I have created a .NET DLL which makes some methods COM visible.

一种方法是有问题的。它看起来是这样的:

One method is problematic. It looks like this:

bool Foo(byte[] a, ref byte[] b, string c, ref string d)

VB6给出一个编译错误,当我试图调用方法:

VB6 gives a compile error when I attempt to call the method:

函数或接口标记为   受到限制,或者该函数使用一个   自动化类型不支持   Visual Basic中。

Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.

我读到数组参数必须由引用传递,所以我改变了签名的第一个参数:

I read that array parameters must be passed by reference, so I altered the first parameter in the signature:

bool Foo(ref byte[] a, ref byte[] b, string c, ref string d)

VB6仍然给出了同样的编译错误。

VB6 still gives the same compile error.

我怎么可能改变签名是用VB6兼容?

How might I alter the signature to be compatible with VB6?

推荐答案

声明与裁判的阵列参数是必须的。你的第2次尝试应该有工作就好了,也许你忘了重新生成的.tlb?

Declaring the array argument with "ref" is required. Your 2nd attempt should have worked just fine, perhaps you forgot to regenerate the .tlb?

测试code:

[ComVisible(true)]
public interface IMyInterface {
 bool Foo(ref byte[] a, ref byte[] b,string c, ref string d);
}

[ComVisible(true)]
public class MyClass : IMyInterface {
  public bool Foo(ref byte[] a, ref byte[] b, string c, ref string d) {
    throw new NotImplementedException();
  }
}


  Dim obj As ClassLibrary10.IMyInterface
  Set obj = New ClassLibrary10.MyClass
  Dim binp() As Byte
  Dim bout() As Byte
  Dim sinp As String
  Dim sout As String
  Dim retval As Boolean
  retval = obj.Foo(binp, bout, sinp, sout)

这篇关于调用从VB6通过COM可见的DLL .NET方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆