Hi,
I have an ActiveX Dll with a single class and a form. The form contains a Winsock control (I have to have the form for this control). When the Winsock receives data (in the DataArrival event) I want to raise an event to the class with the data, which in turn will raise an event to the calling EXE.
The event from within the DataArrival event does not seem to be picked up from within the class, any ideas why?
I have made sure that the withevents keyword has been used when declaring the form in the class (therefore the event is available in the list in the class code).
Data is returned from the server side of the socket, that is not a problem.
Can anyone tell me what I have missed???
Here is the code for the ActiveX Dll form and class, and also the code for the calling Standard EXE form:
##### Form:
Option Explicit
Private PString As String
Private PDataLength As Long
Public Event InternalDataArrived(strData As String)
Private Sub Form_Load()
End Sub
Private Sub sckWinsock_Connect()
PString = ""
End Sub
Private Sub sckWinsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
sckWinsock.GetData strData
RaiseEvent InternalDataArrived(strData)
End If
End Sub
##### Class called CCommsServer:
Option Explicit
Public Event DataReceived(ByVal objXML As String)
'local variable(s) to hold property value(s)
Private FServerName As String 'local copy
Private FSocketNumber As Long 'local copy
Private WithEvents frmForm As frmComms
Public Property Let SocketNumber(ByVal vData As Long)
FSocketNumber = vData
End Property
Public Property Get SocketNumber() As Long
SocketNumber = FSocketNumber
End Property
Public Property Let ServerName(ByVal vData As String)
FServerName = vData
End Property
Public Property Get ServerName() As String
ServerName = FServerName
End Property
Public Sub CloseConnection()
frmComms.sckWinsock.Close
End Sub
Public Sub OpenConnection()
Set frmForm = New frmComms
frmComms.sckWinsock.Connect ServerName, SocketNumber
End Sub
Public Sub SendData(LQuery As String)
' A delay is required here to allow the state to get to 7
frmComms.sckWinsock.SendData LQuery
End Sub
Private Sub Class_Terminate()
Set frmForm = Nothing
End Sub
Private Sub frmForm_InternalDataArrived(strData As String)
RaiseEvent DataReceived(strData)
End Sub
##### Form in Standard EXE to call the ActiveX Dll
Option Explicit
Private WithEvents objCommsServer As CCommsServer
Private Sub Command1_Click()
Set objCommsServer = New CCommsServer
With objCommsServer
.ServerName = "Server"
.SocketNumber = "1001"
.OpenConnection
End With
End Sub
Private Sub Command2_Click()
With objCommsServer
.SendData ("SQLSelect * from Complaint"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
End With
End Sub
Private Sub Command3_Click()
objCommsServer.CloseConnection
End Sub
Private Sub Form_Load()
End Sub
Private Sub objCommsServer_DataReceived(ByVal objXML As String)
MsgBox objXML
End Sub
I have an ActiveX Dll with a single class and a form. The form contains a Winsock control (I have to have the form for this control). When the Winsock receives data (in the DataArrival event) I want to raise an event to the class with the data, which in turn will raise an event to the calling EXE.
The event from within the DataArrival event does not seem to be picked up from within the class, any ideas why?
I have made sure that the withevents keyword has been used when declaring the form in the class (therefore the event is available in the list in the class code).
Data is returned from the server side of the socket, that is not a problem.
Can anyone tell me what I have missed???
Here is the code for the ActiveX Dll form and class, and also the code for the calling Standard EXE form:
##### Form:
Option Explicit
Private PString As String
Private PDataLength As Long
Public Event InternalDataArrived(strData As String)
Private Sub Form_Load()
End Sub
Private Sub sckWinsock_Connect()
PString = ""
End Sub
Private Sub sckWinsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
sckWinsock.GetData strData
RaiseEvent InternalDataArrived(strData)
End If
End Sub
##### Class called CCommsServer:
Option Explicit
Public Event DataReceived(ByVal objXML As String)
'local variable(s) to hold property value(s)
Private FServerName As String 'local copy
Private FSocketNumber As Long 'local copy
Private WithEvents frmForm As frmComms
Public Property Let SocketNumber(ByVal vData As Long)
FSocketNumber = vData
End Property
Public Property Get SocketNumber() As Long
SocketNumber = FSocketNumber
End Property
Public Property Let ServerName(ByVal vData As String)
FServerName = vData
End Property
Public Property Get ServerName() As String
ServerName = FServerName
End Property
Public Sub CloseConnection()
frmComms.sckWinsock.Close
End Sub
Public Sub OpenConnection()
Set frmForm = New frmComms
frmComms.sckWinsock.Connect ServerName, SocketNumber
End Sub
Public Sub SendData(LQuery As String)
' A delay is required here to allow the state to get to 7
frmComms.sckWinsock.SendData LQuery
End Sub
Private Sub Class_Terminate()
Set frmForm = Nothing
End Sub
Private Sub frmForm_InternalDataArrived(strData As String)
RaiseEvent DataReceived(strData)
End Sub
##### Form in Standard EXE to call the ActiveX Dll
Option Explicit
Private WithEvents objCommsServer As CCommsServer
Private Sub Command1_Click()
Set objCommsServer = New CCommsServer
With objCommsServer
.ServerName = "Server"
.SocketNumber = "1001"
.OpenConnection
End With
End Sub
Private Sub Command2_Click()
With objCommsServer
.SendData ("SQLSelect * from Complaint"
End With
End Sub
Private Sub Command3_Click()
objCommsServer.CloseConnection
End Sub
Private Sub Form_Load()
End Sub
Private Sub objCommsServer_DataReceived(ByVal objXML As String)
MsgBox objXML
End Sub