Using a Winsock Control in a ActiveX DLL 
Author Message
 Using a Winsock Control in a ActiveX DLL

Hi, I want to use Winsock in my ActiveX DLL.
The question is where should I put the Winsock Control?
I need its events, e.g. DataArrival, Error......
Thanks.


Mon, 08 Dec 2003 10:23:17 GMT  
 Using a Winsock Control in a ActiveX DLL
I had the same idea and problem. I assume the Winsock OCX needs a
container like a form or a usercontrol. So in my opinion there is no way
to use a OCX linke Winsock in a ActivX DLL.
I ended up in putting it on a form which is part of an ActivX-EXE (!) I
do not show this form (invisible), but honestly I do not like this
solution very much. I am sure that there are other 3.party components
you might use.

Cheers,
Oliver

fix schrieb:

Quote:

> Hi, I want to use Winsock in my ActiveX DLL.
> The question is where should I put the Winsock Control?
> I need its events, e.g. DataArrival, Error......
> Thanks.



Mon, 08 Dec 2003 19:13:24 GMT  
 Using a Winsock Control in a ActiveX DLL
Oh, thanks,
me too, I also don't like to put it in the form,
I have some variables in the class module,
but I don't want clients to access this variables.
If it is the only solution, I should accept it........


Quote:
> I had the same idea and problem. I assume the Winsock OCX needs a
> container like a form or a usercontrol. So in my opinion there is no way
> to use a OCX linke Winsock in a ActivX DLL.
> I ended up in putting it on a form which is part of an ActivX-EXE (!) I
> do not show this form (invisible), but honestly I do not like this
> solution very much. I am sure that there are other 3.party components
> you might use.

> Cheers,
> Oliver

> fix schrieb:

> > Hi, I want to use Winsock in my ActiveX DLL.
> > The question is where should I put the Winsock Control?
> > I need its events, e.g. DataArrival, Error......
> > Thanks.



Mon, 08 Dec 2003 20:32:53 GMT  
 Using a Winsock Control in a ActiveX DLL
Click on Project|References, click Browse and set the file types to *.ocx
and select MSWINSCK.OCX, click Ok. Then, place the following line of code in
the Declarations section:

  Dim WithEvents oWinsock as MSWinsockLib.Winsock

When ready to use the control:

  Set oWinsock = New MSWinsockLib.Winsock
  oWinsock.Connect "www.microsoft.com", 80

Examples of how to sink the events that oWinsock object will raise...

  '-- this event will be raised when the connection is made to the remote
host
  Private Sub oWinsock_Connect()

    MsgBox "Connected with " & oWinsock.RemoteHost , _
         vbInformation Or vbOKOnly, _
         Now()

   End Sub

  '-- this event will be raised when the host sends any data, use the
.GetData method to fetch it
  Private Sub oWinsock_DataArrival(bytesTotal as Long)

    MsgBox "Just received " & cStr(bytesTotal) & " bytes of data from " &
oWinsock.RemoteHost, _
         vbInformation Or VbOKOnly, _
         Now()

  End Sub

When you're finished, be sure to close the connection and release the
object:

  if Not (oWinsock.State = sckClosed) then _
    oWinsock.Close

  Set oWinsock = nothing

An alternative to all this would be to use the Winsock API directly. Which,
IMHO, would be "butt-ugly".

HTH


Quote:
> Hi, I want to use Winsock in my ActiveX DLL.
> The question is where should I put the Winsock Control?
> I need its events, e.g. DataArrival, Error......
> Thanks.



Mon, 08 Dec 2003 21:36:04 GMT  
 Using a Winsock Control in a ActiveX DLL
Click on Project|References, click Browse and set the file types to *.ocx
and select MSWINSCK.OCX, click Ok. Then, place the following line of code in
the Declarations section:

  Dim WithEvents oWinsock as MSWinsockLib.Winsock

When ready to use the control:

  Set oWinsock = New MSWinsockLib.Winsock
  oWinsock.Connect "www.microsoft.com", 80

Examples of how to sink the events that oWinsock object will raise...

  '-- this event will be raised when the connection is made to the remote
host
  Private Sub oWinsock_Connect()

    MsgBox "Connected with " & oWinsock.RemoteHost , _
         vbInformation Or vbOKOnly, _
         Now()

   End Sub

  '-- this event will be raised when the host sends any data, use the
.GetData method to fetch it
  Private Sub oWinsock_DataArrival(bytesTotal as Long)

    MsgBox "Just received " & cStr(bytesTotal) & " bytes of data from " &
oWinsock.RemoteHost, _
         vbInformation Or VbOKOnly, _
         Now()

  End Sub

When you're finished, be sure to close the connection and release the
object:

  if Not (oWinsock.State = sckClosed) then _
    oWinsock.Close

  Set oWinsock = nothing

An alternative to all this would be to use the Winsock API directly. Which,
IMHO, would be "butt-ugly".

HTH


Quote:
> Hi, I want to use Winsock in my ActiveX DLL.
> The question is where should I put the Winsock Control?
> I need its events, e.g. DataArrival, Error......
> Thanks.



Mon, 08 Dec 2003 21:34:35 GMT  
 Using a Winsock Control in a ActiveX DLL
I did almost the sam thing as you did, and I tried to port my source to a
Standard EXE and it works!
But I really don't know why I didn't get any of the events fired.
My source (of the ActiveX DLL):
Option Explicit
Dim WithEvents mwsckWinsock As MSWinsockLib.Winsock 'Equivalent Winsock
Control
Private Enum NewsReaderConstants
    fnrListGroup = 1
End Enum
Private Enum ListGroupConstants
    fnrConnected = 1
    fnrFinished
End Enum
Private mState As NewsReaderConstants   'Component State
Private mListGroupState As ListGroupConstants   'Client ask for group list,
this is the current process
Private mReturnString As String 'String to return to client
Private mConversation As String 'The conversion between this component and
the news server

Public Function ListGroup(Server As String, Optional Port As Long = 119) As
Long
    mState = fnrListGroup
    If Trim(Server) = "" Then
        ListGroup = 1
        Exit Function
    Else
        With mwsckWinsock
            .RemoteHost = "msnews.microsoft.com" 'Server
            .RemotePort = 119 'Port
            .Connect
        End With
        mListGroupState = fnrConnected
    End If
    ListGroup = 0
End Function

Public Function GetGroupList() As String
'Do Until mListGroupState = fnrFinished
    DoEvents
'Loop

End Function

Private Sub Class_Initialize()
    Set mwsckWinsock = New MSWinsockLib.Winsock
    mState = -1
    mListGroupState = -1
    mReturnString = ""
    mConversation = ""
End Sub

Private Sub mwsckWinsock_Close()
    Debug.Print "Close"
End Sub

Private Sub mwsckWinsock_Connect()
    Debug.Print "Connected!"
End Sub

Private Sub mwsckWinsock_ConnectionRequest(ByVal requestID As Long)
    Debug.Print "ConnectionRequest"
End Sub

Private Sub mwsckWinsock_DataArrival(ByVal bytesTotal As Long)
    Static ServerResponse As String    'Server Response
    Dim TempStr As String   'Temp String for buffer
    Dim ResponseCode As Integer

    mwsckWinsock.GetData TempStr    'Receive data
    ServerResponse = ServerResponse & TempStr   'Concat to server response
    If InStr(ServerResponse, vbCrLf) > 0 Then   'Command Received
            ResponseCode = CInt(Left(ServerResponse, 3))
            mConversation = mConversation & "S: " & ServerResponse & vbCrLf
            ServerResponse = ""
    End If

    Select Case mState  'Component State
    Case fnrListGroup   'Client ask for group list
        Select Case mListGroupState 'List group state
        Case fnrConnected

        End Select
    End Select
End Sub

Private Sub mwsckWinsock_Error(ByVal Number As Integer, Description As
String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As
String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Debug.Print "Error"
End Sub

Private Sub mwsckWinsock_SendComplete()
    Debug.Print "SendComplete"
End Sub

Private Sub mwsckWinsock_SendProgress(ByVal bytesSent As Long, ByVal
bytesRemaining As Long)
    Debug.Print "SendProgress"
End Sub



Quote:
> Click on Project|References, click Browse and set the file types to *.ocx
> and select MSWINSCK.OCX, click Ok. Then, place the following line of code
in
> the Declarations section:

>   Dim WithEvents oWinsock as MSWinsockLib.Winsock

> When ready to use the control:

>   Set oWinsock = New MSWinsockLib.Winsock
>   oWinsock.Connect "www.microsoft.com", 80

> Examples of how to sink the events that oWinsock object will raise...

>   '-- this event will be raised when the connection is made to the remote
> host
>   Private Sub oWinsock_Connect()

>     MsgBox "Connected with " & oWinsock.RemoteHost , _
>          vbInformation Or vbOKOnly, _
>          Now()

>    End Sub

>   '-- this event will be raised when the host sends any data, use the
> .GetData method to fetch it
>   Private Sub oWinsock_DataArrival(bytesTotal as Long)

>     MsgBox "Just received " & cStr(bytesTotal) & " bytes of data from " &
> oWinsock.RemoteHost, _
>          vbInformation Or VbOKOnly, _
>          Now()

>   End Sub

> When you're finished, be sure to close the connection and release the
> object:

>   if Not (oWinsock.State = sckClosed) then _
>     oWinsock.Close

>   Set oWinsock = nothing

> An alternative to all this would be to use the Winsock API directly.
Which,
> IMHO, would be "butt-ugly".

> HTH



> > Hi, I want to use Winsock in my ActiveX DLL.
> > The question is where should I put the Winsock Control?
> > I need its events, e.g. DataArrival, Error......
> > Thanks.



Mon, 08 Dec 2003 22:06:32 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using a Winsock Control in a ActiveX DLL

2. Using Winsock in an ActiveX Dll

3. Using Winsock from within a ActiveX DLL

4. activeX dll, using Winsock and some kind of a timer

5. Using Winsock in an ActiveX Dll

6. activeX dll, using Winsock and some kind of a timer

7. using Winsock in an ActiveX .DLL

8. Winsock Activex DLL and winsock events

9. Winsock control in ActiveX DLL

10. Winsock Control - ActiveX DLL

11. Winsock control wrapped in ActiveX DLL?

12. call winsock DLL from an ActiveX DLL

 

 
Powered by phpBB® Forum Software