Solved

Dynamic Winsock

Posted on 2000-04-24
5
217 Views
Last Modified: 2013-11-13
I have downloaded the controls from Ostrosoft and do not want them compiled into ocx format, so I have added them to my code. The problem is when I do this, the whois control will fail with "Improper use of NEW keyword" and highlights this reference of code
"Set wsTCP = New Winsock". I will be more than happy to show my complete code to this. I am simply trying to combine all there controls into one useful program for my personal use.
The address for the controls is http://www.ostrosoft.com/vb/controls/whois_sample.html

Thanks in advance.
0
Comment
Question by:Laqua
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
wsh2 earned 100 total points
ID: 2746318
To Dynamically load a control.. (although.. why aren't you just adding the Winsock control to your form?).. try this:

1. Start a New Standard.Exe project.
2. Copy/Paste the following into the Form1 code window.
3. Press F5 to run.

<----- Code Begin ----->

Option Explicit

Private WithEvents wskGnutella As VBControlExtender

Private Sub ConnectToServer(sHostAddr As String, lPort As Long)
   wskGnutella.object.RemoteHost = sHostAddr
   wskGnutella.object.RemotePort = lPort
   wskGnutella.object.Connect
End Sub

Private Sub Form_Load()
   
   Dim strControlName As String
   Dim strControlType As String
   Dim strLicense As String
   
   strControlType = "MSWinSock.Winsock.1"
   strControlName = "wskGnutella"
   strLicense = Licenses.Add(strControlType)
   Set wskGnutella = Controls.Add(strControlType, strControlName)
   
   Call ConnectToServer("www.yahoo.com", 21)

End Sub

Private Sub wskGnutella_objectevent(Info As EventInfo)
   
   Dim p As EventParameter
   Debug.Print Info.Name
   For Each p In Info.EventParameters
      Debug.Print p.Name, p.Value
   Next

   MsgBox "It finally worked! Thank god you figured it out Chris!"

End Sub

<----- Code End ----->
0
 
LVL 1

Expert Comment

by:zivf
ID: 2746536
You cannot do what you tried to do because the winsock control is in an OCX, and not in a DLL, this means that it must be put on a form, and not created using the NEW keyword.
I wanted to do the same a while ago in order not to need to put a form just in order to create a network connection, and you cannot do this with the winsock control.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2746630
Pardon me zivf.. where do you see the word NEW in the comment above yours? Perhaps you should read or perhaps even try other's comments, before locking down a question with an answer.. you might just learn something about Visual Basic.. <smile>.
0
 

Author Comment

by:Laqua
ID: 2788759
It can be done, as wsh2 has shown. My problem is guys, it is going into a custom control and MUST be created dynamically on the form the custom control is on. eg: myctrl is added to form1,when form one gets username and password and sends to myctrl. myctrl creates a winsock connection and whalah. I know it is possible, but when I did it before it was by an example that someone gave me and I have lost the link to that page.
0
 

Author Comment

by:Laqua
ID: 2811012
Although this does not work for what I originally tried to do, it did help me with a different problem. Thanks.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question