C# Com Interop 类方法在 VB6 中不可见?

标签 c# .net dll vb6

我在 .NET 中创建了一个 C# Com Interop 类,并在我的开发机器上适本地注册了它,并在程序集中将 Com-Visible 设置为 true。但是,当我在我的 vb6 应用程序中引用该库时,我能够看到库名称、类名称,但看不到与它们关联的方法或属性吗?

如果有人能帮我解决这个问题,我已经被困了很长一段时间了!

这是我的类(class):

using System;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace VNDBUtils
{
public enum VNConstants : long
{
    cenMySQLDataStore = 32
}

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("CF4EFB82-6EE1-4A84-9CA9-07B135888B68")]
[ComVisible(true)]
public interface IVNSqlFormatter
{
    //Properties
    long DS_Type { get; set; }
    string DS_Query { get; set; }

    //Methods
    string Format_Entity(string strString);
    string MqStrMan_MakeStringEndWith(string strString, string strMatch);
    bool MqStrMan_StringEndsWith(string strString, string strMatch);
    string MqStrMan_MakeStringStartWith(string strString, string StrMatch);
    bool MqStrMan_StringStartsWith(string strString, string strMatch);
    string Right(string value, int length);
    string Left(string value, int maxLength);
    string Format_Value(string strString);
}



[ClassInterface(ClassInterfaceType.None)]
[Guid("3884D59D-AB76-41E7-82B6-21C66DBDCBF3")]
[ComVisible(true)]
public class VNSqlFormatter : IVNSqlFormatter
{

    private const string SQUARE_LEFT = "[";
    private const string SQUARE_RIGHT = "]";

    public long DS_Type { get; set; }
    public string DS_Query { get; set; }

    public string Format_Entity(string strString)
    {           
        strString = strString.Trim();

        if (DS_Type == (long)VNConstants.cenMySQLDataStore)
        {
            return strString;
        }
        else
        {
            return MqStrMan_MakeStringEndWith(MqStrMan_MakeStringStartWith(strString, SQUARE_LEFT), SQUARE_RIGHT);
        }

    }

    public string MqStrMan_MakeStringEndWith(string strString, string strMatch)
    {
        if (MqStrMan_StringEndsWith(strString, strMatch) == false)
        {
            return strString + strMatch;
        }
        else
        {
            return strString; 
        }

    }

    public bool MqStrMan_StringEndsWith(string strString, string strMatch)
    {
        return String.Equals(Right(strString, strMatch.Length), strMatch);

    }

    public string MqStrMan_MakeStringStartWith(string strString, string strMatch)
    {
        if (MqStrMan_StringStartsWith(strString, strMatch) == false)
        {
            return strMatch + strString;
        }
        else
        {
            return strString; 
        }
    }

    public bool MqStrMan_StringStartsWith(string strString, string strMatch)
    {
       return String.Equals(Left(strString, strMatch.Length), strMatch);
    }

    public string Right(string value, int length)
    {
        if (String.IsNullOrEmpty(value))
        {
            return String.Empty;
        }

        return value.Length <= length ? value : value.Substring(value.Length - length);
    }

    public string Left(string value, int maxLength)
    {
        if(String.IsNullOrEmpty(value))
        {
            return String.Empty; 
        }

        maxLength = Math.Abs(maxLength);
        return value.Length <= maxLength ? value : value.Substring(0, maxLength);
    }

    public string Format_Value(string strString)
    {
            return strString.Replace("'", "''");
    }

}

最佳答案

评论中的讨论导致如下,未设置ProgId属性。

[ClassInterface(ClassInterfaceType.None)]
[Guid("3884D59D-AB76-41E7-82B6-21C66DBDCBF3")]
[ComVisible(true)]
[ProgId("VNDBUtils.VNSqlFormatter")]
public class VNSqlFormatter : IVNSqlFormatter
{
    /* implementation information */
}

关于C# Com Interop 类方法在 VB6 中不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29834096/

相关文章:

c# - ToString() 在这里是好是坏还是多余?

c# - 使用不同文件夹中的 DLL 运行 mono .exe

visual-studio - 如何告诉链接器我希望在 Debug模式下构建的 dll 具有 d 后缀

c# - 在列表框中绑定(bind)图像

c# - 代码页问题

c# - 不可变变量和不可变对象(immutable对象)

.net - NVelocity 项目死了吗?有替代品吗?

c# - 为什么应该将 NuGet 包 dll 添加到源代码管理中?

c#访问二维数组的哈希表

c# - 在 visual studio 2005 中构建模式下拉,未显示 Release模式