我使用Visual Basic 2010 Express构建了一个DLL。它建立在VB 4.0框架之上。构建之后,我运行了管理命令提示符:
C:\windows\...v4.0.30319\RegAsm C:\...\bin\release\ClassLibrary1.dll
已选中COM-visible复选框。但我的其他程序无法连接到它,标题中提到了错误消息。
类库只包含1个类。它在SMSCOMMS.vb中:
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New()
End Sub
Public Sub initPort(ByVal COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 19200
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
End Sub
Public Function testFunction() As Integer
Return 1
End Function
Public Function SendSMS(ByVal receiver As String, ByVal message As String) As Boolean
If SMSPort.IsOpen = True Then
'sending AT commands
SMSPort.WriteLine("AT+CMGF=1" & Chr(13)) 'set command message format to text mode(1)
'SMSPort.WriteLine("AT+CSCA=+639170000130" & Chr(13)) 'set service center address (which varies for service providers (idea, airtel))
SMSPort.WriteLine("AT+CMGS=" & Chr(34) & receiver & Chr(34) & Chr(13)) ' enter the mobile number whom you want to send the SMS
SMSPort.WriteLine(message & Chr(26)) 'SMS sending
SMSPort.Close()
Return True
End If
Return False
End Function
Public Sub Open()
If Not (SMSPort.IsOpen = True) Then
SMSPort.Open()
End If
End Sub
Public Sub Close()
If SMSPort.IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
答案 0 :(得分:0)
我使用了visual basic 2012。有一个Com interop的复选框。