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