VBA:使用dll标记为限制的function
我写了一个C#的DLL使用TCP套接字发送信息从客户端到服务器。 我从我的dll使用StartClient函数,但运行到错误:function标记为受限,或该函数使用Visual Basic中不支持的自动化types。
该错误发生在returnValue = sabatheWise.StartClient(端口,IpAddress,缓冲区)行,StartClient以黄色突出显示。 我认为这个错误是由于我已经确定的参数之一。 此外,即使我声明端口为一个int在我的DLL,当我看在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);
该方法被标记为受限制,因为不支持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)
- 如何在Visual Studio 2012中更改Concurrency Visualizer线程视图的导出的.csv文件中的列分隔符?
- Excel Interop将斜杠添加到NumberFormat
- 将string转换为DateTime时出现奇怪的行为
- 如何使用asp.net创build和下载excel文档
- 如何在Excel VSTO中获取单元格和对象(如图表,graphics和图片)的openxml?
- ExcelDnaUtil vs Interop.Excel
- C#:发布到Web服务器(IIS 8)时,将Excel文件上载到SQL不起作用
- 将string数组插入到Excel表单中
- 如何在asp.net中将RDLC报告导出为.xlsx格式?