Embedding VB application in IE page

This has probably been covered a million times in this forum. What I'm looking for is a complete answer with examples or links to good examples that will help me accomplish what I'm looking to do. Basically, I don't want to have to do much more research after this.

(1) I want to use Winsock in VB from a class. If I don't have a form, I can't use the control. So how can I use Winsock in a UI-less program (complete answer with example, please).

(2) I want to create a web page that enbeds a VB app. The page will have data from the server. The app, using Winsock, will be communicating with another server with more app-specific data. How can I accomplish this (VB and HTLM please)? I had tried a quick test with an ActiveX EXE and DLL and the <object> tag. The form I opened was not embedded in the page as I intended - it opened as a modal form. And IE said it didn't support nonmodal.

  a. Should I create an ActiveX DLL or EXE to embed in the page?
  b. Can I have a form (UI) that is displayed IN the page? Or, must I create a UI-less object that interacts with standard HTML controls? (examples, please)
  c. When an object tag is used, when is the object instantiated? Is that reference enough? When is it destroyed?

(3) Is there anything I'm missing? Again, web page hosted in IE that has, as part of the page, a custom VB app with an interface that communicates via Winsock to another server.

I am offering so many points because I am asking for detailed responses (I tried to offer more, but EE capped me at 500). Let me know if you need more information.

Who is Participating?
EDDYKTConnect With a Mentor Commented:
1. http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10967841.html

a.create a activex ocx
b. yes if use ocx
c. instantiated when page is loading, destroyed when outof scope

inthedarkConnect With a Mentor Commented:
Here is a better example of Winsock within a class. No need to create an ocx.


The key points are:

1) You create an ActiveX DLL (or works just as well from within a standard exe).
2) You add a dummy form to your project with a dummy winsock control on the form.
(Dont put any code in the dummy form)
3) in your dll class when it initialises you need code like this:

Dim frmMyDummyForm As Form
Private WithEvents sckMySock  As Winsock
Private Sub Class_Initialize()

    ' instantiate the Winsock Control
    Set MyForm = New frmSck ' MUST use the New clause
    Set sckMySockl = frmMyDummyForm.WinSock1 ' whatever you called you winsock on your dummy form

End Sub

You class will now work using the events just as it would if it was on a form.

Hope this helps:@)
RhinoInformationAuthor Commented:
Thanks for the replies. I should have realized OCX...user control. Duh.

Related to the original Q, how can I set a reference from the OCX to the copy of IE that's hosting it?? Basically, I have a browser session open that has session variables on the server. I need to open a new page from IE that lives in the same session. SO, I need to be able to open a new page from the page that's hosting the OCX in order to be in the same session. I believe that if I create a new IE object that it will be in a different session (the difference between opening multiple copies of the browser versus opening a new browser window from the menu).

Just for your info, I found something a little better on this site:

In the DLL, go to the projects menu, select references and browse.  Browse to mswinsock.ocx in system dir.  You have now added a reference to the winsock library (you can't do this with all controls.)

In your class declare a variable at the General Declarations level.

Private WithEvents Winsock1 as Winsock

You should see the object dropdown on the left of the codepane will now have a Winsock1 entry.  Using the event dropdown on the right, you can enter code to handle all the events for the winsock 'control.'
All Courses

From novice to tech pro — start learning today.