我在 .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/