2014-09-03 2 views
2

COM 표시 DLL을 만들고 메서드를 오버로드하려고했습니다.com 표시 DLL에서 메서드 오버로드

그래서 기본적으로이 코드 :

[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)); 
     } 
    } 
} 

은 다음과 같습니다 그러나 수 없습니다. 내가 전화를하면 (매우 간단한 VBSCript 방식으로) 호출 프로그램에서 쓰기, 나는 내 매개 변수가 올바르지 않은 오류가 발생합니다. 나는 DLL에 하나에 .write 방법이있는 경우

Set myObj = CreateObject("TAF.TextLog") 
myObj.Create("C:\temp\textlog.txt") 
myObj.Write "title", "test message 1", 1 

가 잘 작동 :

는 호출 VBScript 코드입니다. 누군가가이 같은 과부하가 dll에서도 가능하다고 말할 수 있습니까?

답변

2

COM 멤버 오버로드를 지원하지 않습니다 참조, 각각의 이름 고유해야합니다. 피할 수없는 부작용이 IDispatch::GetIDsOfNames()입니다. 스크립트 인터프리터가 스크립팅 코드에서 사용 된 "쓰기"를 dispid로 변환하는 데 사용하는 함수입니다. 이 메서드는 여전히 존재하며 GetIDsOfNames()가 해당 dispid를 반환하도록하는 방법은 없습니다. 형식 라이브러리 내보내기가 오버로드 된 메서드 이름을 바꿔이 문제를 해결하면 Write_2()이됩니다.

지연 바인딩 afaik를 사용할 때 과부하가 발생하지 않도록해야합니다.

+0

확인. 설명해 주셔서 감사합니다. – Mytzenka