.net registered dll does not show function in vb6

2019-08-20 11:27发布

问题:

net dll (PasswordHashLibrary) to be used in vb6 application. after creating the project, i went to project properties -> build -> Register for COM interop.

Then registered this dll on my machine using regasm command. Started a fresh vb6 project -> added reference to PasswordHashLibrary

Now the vb6 project allows me to write the following

Dim objHash As New PasswordHashLibrary.Hash
  • PasswordHashLibrary = namespace
  • Hash = Class

But it doesn't let me call any functions inside (class and functions are public)

for instance i have a static function

PasswordHashLibrary.Hash.HashPassword("abc")

It gives compile time error

method or data member not found

When i try to debug and look in object browser there is no member present

My Full .Net Code

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
    }

  }
}

回答1:

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
    }
  }
}