Solved

Dynamic Winsock

Posted on 2000-04-24
5
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

630 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