.net 注册的 dll 在 vb6 中不显示功能 [英] .net registered dll does not show function in vb6
问题描述
要在 vb6 应用程序中使用的 net dll (PasswordHashLibrary).创建项目后,我转到项目属性 -> 构建 -> 注册 COM 互操作.
net dll (PasswordHashLibrary) to be used in vb6 application. after creating the project, i went to project properties -> build -> Register for COM interop.
然后使用 regasm 命令在我的机器上注册这个 dll.启动了一个新的 vb6 项目 -> 添加了对 PasswordHashLibrary 的引用
Then registered this dll on my machine using regasm command. Started a fresh vb6 project -> added reference to PasswordHashLibrary
现在vb6项目允许我写如下
Now the vb6 project allows me to write the following
Dim objHash As New PasswordHashLibrary.Hash
- PasswordHashLibrary = 命名空间
- 哈希 = 类
但它不允许我调用内部的任何函数(类和函数是公共的)
But it doesn't let me call any functions inside (class and functions are public)
例如我有一个静态函数
PasswordHashLibrary.Hash.HashPassword("abc")
PasswordHashLibrary.Hash.HashPassword("abc")
它给出了编译时错误
未找到方法或数据成员
当我尝试调试并在对象浏览器中查看时,没有成员存在
When i try to debug and look in object browser there is no member present
我的完整 .Net 代码
namespace PasswordHashLibrary
{
public class Hash
{
private const int PBKDF2IterCount = 1000; // default for Rfc2898DeriveBytes
private const int PBKDF2SubkeyLength = 256 / 8; // 256 bits
private const int SaltSize = 128 / 8; // 128 bits
public static string HashPassword(string password)
{
//my code goes here
}
}
}
推荐答案
我删除了静态属性并添加了一个可以解决问题的接口!
I removed the static attribute and added an interface that did the trick!
namespace PasswordHashLibrary
{
public interface ComClassInterface
{
}
public class Hash : ComClassInterface
{
private const int PBKDF2IterCount = 1000; // default for Rfc2898DeriveBytes
private const int PBKDF2SubkeyLength = 256 / 8; // 256 bits
private const int SaltSize = 128 / 8; // 128 bits
//[ComVisible(true)]
public string HashPassword(string password)
{
//my code goes here
}
}
}
这篇关于.net 注册的 dll 在 vb6 中不显示功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!