Link to home
Start Free TrialLog in
Avatar of sdgaf
sdgaf

asked on

Simply question

Okay i have a program that I wrote in visual basic which I have had trouble converting it into MFC can someone help me out on how i can convert the code to MFC?

This code as you can see connects to port 4443, listens for data, puts the received data on a list box and if the Option1 radio button is clicked it closes the port for listening.

Visual Basic Code:

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
List1.AddItem "Time: " & Time & " - " & Winsock1.RemoteHostIP & " - Direct Connect"
Winsock1.Close
Winsock1.LocalPort = 4443
Winsock1.Listen
End Sub
--------------------------
Private Sub Option1_Click()
If Option1.Value = True Then Winsock1.Close
End Sub
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

you can use the WinSoct Control in VC using the "Project->Add To Project->Components and Controls" menu.
This will givee you a wrapper class of winsock, call the same functions with brackets....becoz vc uses set/get functions instead of properties.

Rosh :)
Avatar of sdgaf
sdgaf

ASKER

I used the following code and got errors saying Winsock1 undeclared. and LocalPort, Listen, and Close must point to a struct/class

Winsock1.LocalPort( 4443 );
Winsock1.Listen();
..
..
Winsock1.Close();
Ok as in roshmon's post, add that component. But there is more stuff you need to do to use this control. Open up your main Dialog, drag the new component (Miscrosoft WinSock Control 6.0 ) onto the dialog. Now hold down "ctrl" and double click on the winsock control. A new dialog should pop up, "Add Member Variable" for the name make it "Winsock1". Now hit ok. Now your code will work. ( I hope =) )
- Drew
Clarification: "double click on the winsock control" thats on your dialog.
Avatar of sdgaf

ASKER

I do not see the winsock control in 6.0. I see every other control except for winsock. How do i get the winsock????
ok do this:
Project ( at the top of the VC++ Window)->Add To Project (second item in the menu)->Components and Controls (the last item in that menu)
A new window will pop up, double click on the "Registered ActiveX Controls" folder to open it, then look for "Microsoft WinSock Control, version 6.0" (listed by alpha) so scroll midway into the 'M's'. When you find it double click on it. A confirmation will appear, hit Ok. A new dialog will popup, hit ok again, then close the "Components and Controls Gallery" window. Now try to do as I mentioned above. If you have any more ques feel free to ask.
ASKER CERTIFIED SOLUTION
Avatar of khaotiksociety
khaotiksociety

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial