Results 1 to 9 of 9

Thread: Trapping Events in Formless Apps

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    3
    I am trying to use Winsock without a form and can't figure out how to trap events such as DataArrival and Error.

    Private Sub g_objWs_DataArrival(ByVal bytesTotal As Long)

    doesn't seem to get called.

    Can someone tell me how to do this?

    Thanks

  2. #2
    Junior Member
    Join Date
    Jul 1999
    Posts
    16

    this might help

    did you do these few things:

    Winsock1.RemoteHost = "www.host.com"
    Winsock1.RemotePort = 80
    Winsock1.Connect


    Private Sub Winsock1_Connect()
    Dim strCommand As String
    Dim strWebPage As String
    strWebPage = "http://www.host.com/urpage.htm"
    strCommand = "GET " + strWebpage + " HTTP/1.0" + vbCrLf
    strCommand = strCommand + "Accept: */*" + vbCrLf
    strCommand = strCommand + "Accept: text/html" + vbCrLf
    strCommand = strCommand + vbCrLf
    Winsock1.SendData strCommand
    End Sub

    after those two things, the dataarrival will be called. and you will have access to the error part also

    ShadowWalker
    webmaster of shadowkeep.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    3
    Thanks for the reply.

    In the following snippet, Sub g_objWs_Connect() is never called.

    ----------------------------------------

    Public g_objWs As MSWinsockLib.Winsock

    Sub Main()
    Set g_objWs = New MSWinsockLib.Winsock
    g_objWs.RemoteHost = udtParms.strAddress
    g_objWs.RemotePort = MAILPORT
    g_objWs.Connect
    While g_objWs.State <> sckConnected
    DoEvents
    Wend
    MsgBox "Connected"
    End Sub

    Private Sub g_objWs_Connect()
    MsgBox "connect event"
    End Sub
    -----------------------------------------
    I have code that works fine when I drag a Winsock component onto a form, but my app will run as a formless background task.

    Thanks,
    Cranky



  4. #4
    Junior Member
    Join Date
    Jul 1999
    Posts
    16

    control load

    did u load a control for winsock at runtime? that really is the only thing i can think ove. i can remember how to load it at runtime but i know i read it in one of the posts in here. so maybe that is what is wrong

    ShadowWalker
    webmaster of shadowkeep.com

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    3

    Thanks

    Hey, thanks for sticking with me on this.

    >>did u load a control for winsock at runtime?

    I think that:
    Set g_objWs = New MSWinsockLib.Winsock
    does this.

    Anyway, I gave up and used an invisible form with the winsock component on it.

    Thanks again,
    Cranky

  6. #6
    Junior Member
    Join Date
    Jul 1999
    Posts
    16

    welcome

    sorry i couldnt help anymore. i havnt gotten to the point of using a formless progi yet. im sure to have the same problem if i ever do =)

    ShadowWalker
    webmaster of shadowkeep.com

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Cranky

    Check out the WithEvents keyword. Basically, you declare your Winsock control, but add WithEvents after the Dim (or something like that). Then, add declarations for the events, and it works! (we hope)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    i havn't tried it, but i think parksie is right with the WithEvents buissiness.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  9. #9
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    First you must add a reference to MS Winsock. This MUST be done through PROJECT --> REFERENCES and NOT PROJECT --> COMPONENTS. Just browse to MSWinsck.ocx using the browse button.

    Then add this code to a class module
    Code:
    Private WithEvents m_objSock As MSWinsockLib.Winsock
    
    Private Sub Class_Initialize()
        Set m_objSock = New MSWinsockLib.Winsock
    End Sub
    You can then capture Winsock events without using forms



    Tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width