Solved

Dynamic Winsock

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 51
MS Access 03, TransferText, decimal places 8 78
Problem to App 4 97
Sub or Function is not defined 6 43
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

809 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