Problem with WithEvents inside an ActiveX.Exe 
Author Message
 Problem with WithEvents inside an ActiveX.Exe

I am calling this code from inside the Exe, but the Exe is an OOP Server for
a WebClass.

My DataArrival Event is never triggered. Any Ideas?

Thanks,

Ashley

Code:

Option Explicit
Public WithEvents sockStratusSocket As Winsock
Private Responses As New Collection

Public Function ReceiveTransaction(strMsgNumber As String) As String
    sockStratusSocket_DataArrival (sockStratusSocket.BytesReceived)
On Error GoTo ErrorHandler
    Dim counter As Long
    For counter = 1 To 1000
        DoEvents
    Next counter
' First check if the message has already been recieved
    Dim msg As String
    msg = ""
On Error Resume Next
    msg = Responses.Item(strMsgNumber)
On Error GoTo ErrorHandler
    If msg = "" Then
    ' We didn't find it
    Else
    ' return and delete this item
        msg = Responses.Item(strMsgNumber)
        Responses.Remove (strMsgNumber)
    End If
    ReceiveTransaction = msg
    Exit Function
ErrorHandler:

End Function

Public Sub SendData(vdata As String)
On Error GoTo ErrorHandler
    Dim counter As Long
' Probably need contention
    With sockStratusSocket
    If .State <> sckConnected Then
        .Close
        .RemoteHost = "142.160.82.21"
        .RemotePort = "7012" ' Production System
        For counter = 1 To 1000
            DoEvents
        Next counter
        .Connect
        Dim trash As String
        ' .GetData (trash)
        ' Check to see if we connected, if we are in the process of
connecting,
        ' we should delay for a little while, and see if it connects,
        ' if not we should throw an error
    Else
    End If
    .SendData (vdata)
    End With
    Exit Sub
ErrorHandler:
' We will want to see what happened to the Socket !!!
    Call RaiseError(ERR.Number, ERR.Source, ERR.Description)
End Sub

Private Sub Class_Initialize()
    Set sockStratusSocket = New Winsock
    Dim counter As Long
    With sockStratusSocket
    If .State <> sckConnected Then
        .RemoteHost = "142.160.82.21"
        .RemotePort = "7012" ' Production System
        For counter = 1 To 1000
            DoEvents
        Next counter
        .Connect
        Dim trash As String
        ' .GetData (trash)
        ' Check to see if we connected, if we are in the process of
connecting,
        ' we should delay for a little while, and see if it connects,
        ' if not we should throw an error
    Else
    End If
    End With
End Sub

Private Sub sockStratusSocket_DataArrival(ByVal bytesTotal As Long)
' Probably need contention
    Dim counter As Long
    For counter = 1 To 1000
        DoEvents
    Next counter
    Dim msg As String
    Dim data As String
    With sockStratusSocket
    Call .PeekData(data)
    If data = "" Then
        ' Data isn't back yet, so we simply return
    ElseIf Mid(data, 1, 3) = "MSH" Then
        If Mid(data, Len(data) - 3, 3) = "END" Then
            ' data is a complete message
            ' pull it out of the socket and set msg = to it
            DoEvents
            .GetData (msg)
        Else
            ' Not Complete, need to pull it from the socket, and
            ' loop until the next part which is valid can be peeked
            .GetData (msg)
            Dim completemsg As Boolean
            completemsg = False
            Dim loopmax As Long
            loopmax = 0
            Do Until completemsg
                loopmax = loopmax + 1
                If loopmax > 100 Then
                    ' log the msg that we have so far and raise an error
                    ERR.Raise MyUnhandledError, "SockStratus", "Packet only
Half Recieved"
                End If
                For counter = 1 To 1000
                    DoEvents
                Next counter
                Call .PeekData(data)
                If data = "" Then
                    ' We need to wait a little bit and try again
                    ' if this recurs we need to log the message and
                    ' throw an error
                    For counter = 1 To 1000
                        DoEvents
                    Next counter
                ElseIf Mid(data, 1, 3) = "MSH" Then
                    ' it's {*filter*}ed up the last message is invalid,
                    ' log the message, then don't pull from socket
                    Exit Sub
                ElseIf Mid(data, Len(data) - 4, 3) = "END" Then
                    ' then we should pull this , and combine it with the
other data
                    ' and we are done
                    .GetData (data)
                    msg = msg & data
                    completemsg = True
                Else
                    ' there are more than two segments, add this to data and
loop
                    .GetData (data)
                    msg = msg & data
                End If
            Loop
        End If
        ' Complete Message Received
        ' add to collection
        Call Responses.Add(msg, Mid(msg, 104 + 1, 20))
    Else
        ' We have a problem, not the start of a message
        ' pull the packet and log it, return "",
    End If
    End With
End Sub



Fri, 03 Aug 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Problem with WithEvents inside an ActiveX.Exe

2. WithEvents between EXE and ActiveX EXE ?

3. WithEvents and ActiveX EXE

4. Withevents on remote ActiveX-EXE's?

5. ActiveX EXE Forms Inside MDI --- Possible?

6. WithEvents, ActiveX Server, DCOM -- Problem

7. ActiveX Doc inside ExplorerBar Problem

8. Accessing IE5 DOM from inside my clientside activex obj in a activex dll

9. Hosting a WebBrowser Control Inside ActiveX Document or ActiveX Control to be Ho

10. ActiveX control inside ActiveX control ?

11. ActiveX.exe or ActiveX DLL or ActiveX Control?????????????

12. ActiveX DLL, ActiveX EXE & ActiveX OCX version

 

 
Powered by phpBB® Forum Software