Solved

Dynamic Winsock

Posted on 2000-04-24
5
213 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now