C# 在com可见dll中重载方法
我正在创建一个COM可见dll,并试图重载一个方法 所以基本上这个代码:C# 在com可见dll中重载方法,c#,dll,vbscript,overloading,C#,Dll,Vbscript,Overloading,我正在创建一个COM可见dll,并试图重载一个方法 所以基本上这个代码: [ComVisible(true)] [ProgId("TAF.TextLog")] [Guid("af3f89ed-4732-4367-a222-2a95b8b75659")] public class TextLog { String _logFilePath; public TextLog() { } [ComVisible(true)] public void C
[ComVisible(true)]
[ProgId("TAF.TextLog")]
[Guid("af3f89ed-4732-4367-a222-2a95b8b75659")]
public class TextLog
{
String _logFilePath;
public TextLog()
{
}
[ComVisible(true)]
public void Create(string filePath)
{
String path = Path.GetDirectoryName(filePath);
if (Directory.Exists(path))
{
_logFilePath = filePath;
}
[ComVisible(true)]
public void Write(string message)
{
WriteMessage(null, message, AlertMsg.MsgTypes.Info);
}
[ComVisible(true)]
public void Write(string title, string message, AlertMsg.MsgTypes messageType)
{
WriteMessage(title, message, messageType);
}
private void WriteMessage(string title, string message, AlertMsg.MsgTypes messageType)
{
using (StreamWriter file = new StreamWriter(_logFilePath, true))
{
if (title == null)
file.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}\t{1}", DateTime.Now, message));
else
file.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}\t{1}\t{2}\t{3}", DateTime.Now, title, message, messageType));
}
}
}
但看起来这是不可能的。如果我从调用程序调用.Write(顺便说一下,这是一个非常简单的VBSCript),我会得到一个错误,即我的参数不正确
这是调用VBscript的代码:
Set myObj = CreateObject("TAF.TextLog")
myObj.Create("C:\temp\textlog.txt")
myObj.Write "title", "test message 1", 1
如果我在dll中只有一个.Write方法,它就可以正常工作。有人能告诉我在dll中是否可能出现这样的重载吗?COM实际上不支持重载
请参见COM不支持成员重载,每个名称必须是唯一的。不可避免的副作用。脚本解释器用于将脚本代码中使用的“写入”转换为dispid的函数。该方法仍然存在,只是无法让GetIDsOfNames()返回其dispid。类型库导出器通过重命名重载方法来解决此问题,它将是
Write_2()
没有解决方法当您使用后期绑定afaik时,必须避免重载。OK。谢谢你的解释。谢谢你的文章。