加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 08:06:08 所属栏目:百科 来源:网络整理
导读: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 DonetToVB

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读