.net registered dll does not show function in vb6

China☆狼群 提交于 2019-12-11 16:58:15

问题


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


来源:https://stackoverflow.com/questions/47275357/net-registered-dll-does-not-show-function-in-vb6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!