关于vb的dll文件的问题

2025-01-07 16:39:18
推荐回答(1个)
回答1:

VB编写的组件是COM组件,意思是可以通过regsvr32.EXE注册的组件
新建工程,ActiveX DLL
工程名:AAA,生成的组件文件名是AAA.DLL
类模块名:Class1
Public Function TEST(ByVal Char As String) As String
TEST = TextToAsc(Char)
End Function

'字串转ASC
Private Function TextToAsc(ByVal sValues As String) As String
Dim intI As Integer
Dim sTemp As String
Dim sChar As String

For intI = 1 To Len(sValues)
sChar = Asc(Mid(sValues, intI, 1))
sTemp = sTemp & "-" & sChar
Next
TextToPass = Trim(Mid(sTemp, 2, Len(sTemp)))
End Function

----------------------------------------------
VB和VB.NET 调用COM组件
Dim sMess As String
Dim oSrv As Object
Dim Char As String
Char="ABCEDFG"

Set oSrv = CreateObject("AAA.Class1")
sMess = oSrv.TEST(Char)
----------------------------------------------
C# 先要在引用里,导入AAA.DLL
using AAA
AAA.Class1 AAA1= new AAA.Class1();
string Char = "ABCDEFG";
string sMess = "";
sMess = AAA1.TEST(Char);
------------------------------
其他C++ . Delphi......就没试过了。不过调用COM组件都大同小异的。