2016-05-19 4 views
1

TCPソケットを使用してクライアントからサーバーに情報を送信するC#dllを作成しました。私はdllからStartClient関数を使用していますが、エラーが発生しています:関数が制限付きとしてマークされているか、関数がVisual Basicでサポートされていないオートメーションタイプを使用しています。VBA:dllで制限付きとマークされた機能

エラーは、startClientが黄色で強調表示されたreturnValue = sabatheWise.StartClient(port、IpAddress、buffer)行で発生します。私はエラーが私が特定したパラメータの1つのために発生していると思う。また、私は私のDLLでintとしてポートを宣言しても、私はVBAのオブジェクトブラウザを見ると、私は長いとして識別されたポートを参照してください。ポートを長整数または整数として入力すると、VBAコードに違いはありません。同じエラーが発生します。

これについてのガイダンスは高く評価されます。ここで

は、VBAコードである:ここで

Sub TestProgram() 

Dim port As Long 
port = 15050 
Dim IpAddress As String 
IpAddress = "192.123.456.78" 
Dim buffer() As Byte 
'Dim BufferSize As Integer 
'BufferSize = 16048 
Dim sabatheWise As TCPMessage.AsynchronousClient 
Set sabatheWise = New TCPMessage.AsynchronousClient 
Dim returnValue As Long 
returnValue = sabatheWise.StartClient(port, IpAddress, buffer) 
If returnValue = 0 Then Debug.Print "The program was successful" 
If returnValue = -1 Then Debug.Print "The program failed" 

End Sub 

は、DLLの関連部分である:

public int StartClient(int port, string IpAddress, byte[] buffer) 
    { 
     // Connect to a remote device.   
     try 
     { 

      IPAddress ipAddress = IPAddress.Parse(IpAddress); 
      IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); 

      // Create a TCP/IP socket. 
      Socket client = new Socket(AddressFamily.InterNetwork, 
      SocketType.Stream, ProtocolType.Tcp); 

      // Connect to the remote endpoint. 
      client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); 
      connectDone.WaitOne(); 

      // Send test data to the remote device. 
      client.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, 
       new AsyncCallback(SendCallback), client); 
+0

あなたは 'buffer'を満たしていますか?他のすべては*見た目はいいですが、それはあなたの呼び出しですばやく見つけることができる唯一のものです。 – TyCobb

答えて

1

byte[] bufferがサポートされていないため、この方法は、制限されたとしてマークされています。 、それを動作させる参照によって整列化するためのバッファを定義し、バッファが割り当てられていることを確認するために:

public int StartClient(int port, string IpAddress, ref byte[] buffer) { 
    ... 
} 
Dim buffer(0 to 16048) As Byte 
Dim client As New TCPMessage.AsynchronousClient 
Dim returnValue As Long 

returnValue = client.StartClient(3838, "127.0.0.1", buffer) 
関連する問題