VB调用C# DLL 传递数组参数问题

前端之家收集整理的这篇文章主要介绍了VB调用C# DLL 传递数组参数问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

C# 端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;


namespace DonetToVBDll
{
//[ComVisible(true)]
//[Guid("F1DAF282-2FBC-4343-8CA7-EF8E277E0EEA")]
[ProgId("DonetToVBDll.clsComServer")]
[ClassInterface(ClassInterfaceType.None)]
public class clsComServer : IComServer
{
public int Add(int x,int y)
{
return x + y;
}


public int Subtract(int x,int y)
{
return x - y;
}


public string SayHello(string strName)
{
return strName + "你好,我是DoNetDLL,欢迎调用";
}


public string[] TransArray(string[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
arr[i] = arr[i] + "Trans";
}


return arr;
}

}
}



Vb端

Option Explicit


Private Sub cmdAdd_Click()
Dim objDoNet As clsComServer
Dim lngResult As Long

Set objDoNet = New DonetToVBDll.clsComServer
lngResult = objDoNet.Add(CLng(txtX.Text),CLng(txtY.Text))
MsgBox lngResult
End Sub


Private Sub cmdSayHello_Click()
Dim objDoNet As Object
Dim strResult As String

Set objDoNet = CreateObject("DonetToVBDll.clsComServer")
strResult = objDoNet.SayHello(txtName.Text)
MsgBox strResult
End Sub


Private Sub cmdSubtract_Click()
Dim objDoNet As Object
Dim lngResult As Long

Set objDoNet = CreateObject("DonetToVBDll.clsComServer")
lngResult = objDoNet.Subtract(CLng(txtX.Text),CLng(txtY.Text))
MsgBox lngResult

End Sub


Private Sub cmdTransArr_Click() Dim arr() As String Dim objDoNet As Object Dim arrGet() As String ReDim arr(3) arr(0) = "Limin" arr(1) = "Ronaldo" arr(2) = "Lixuefen" arr(3) = "Rivaldo" Set objDoNet = CreateObject("DonetToVBDll.clsComServer") arrGet = objDoNet.TransArray(arr) MsgBox UBound(arrGet) End Sub

原文链接:https://www.f2er.com/vb/258436.html

猜你在找的VB相关文章