Link to home
Start Free TrialLog in
Avatar of lankford
lankford

asked on

VB6: ActiveX DLL events in a web page?

I've already asked this question, but it's not showing up in the Visual Basic Topic Area!  Arrg.  Anyway, here's a duplicate.  I hope this one shows up.

How can I respond to my objects events in a web page?  That is a very open ended question, so I'll be much more specific with an example below?

Create the text file "example.hta" and paste the following:

------------- example.hta start ---------------
<!-- frames -->
<html>
<head>
<HTA:APPLICATION
    ID="oMyApp"
    VERSION="1.0"
    CAPTION="yes"
    MAXIMIZEBUTTON="yes"
    MINIMIZEBUTTON="yes"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    VERSION="1.0"
    SCROLL="no">
    <title>Hello World Example</title>
    <script language="VBScript">
         Dim myVar
         set myVar = CreateObject("pjtHelloWorld.classHelloWorld")
         
         sub myVar_listenUP(theMessage)
              inComing.innerText = theMessage
         end sub
         
         sub saySomething()
              myVar.sayHello
         end sub
         
         sub getObjectVersion()
              versionNumber.innertext = myVar.getVersion
         end sub
    </script>
</head>
<body>
    <h1 onclick="getObjectVersion()">Hello World Program - The Beginning (version <span id=versionNumber></span>)</h1>
    <div id=inComing onclick="saySomething()">click me</div>
</body>
</html>
------------- example.hta end ---------------

Now, make a new project in VB 6.  Make it an Active-X Dll project.  Name your project "pjtHelloWorld" and name the class file "classHelloWorld".  Open the code window for your class and enter the following code:

------------- classHelloWorld code begin --------------
Public Event listenUp(ByVal message As String)

Public Property Get getVersion() As String
   getVersion = App.Major & "." & App.Minor & "." & App.Revision
End Property

Public Sub sayHello()
   RaiseEvent listenUp("Hello World")
End Sub
------------- classHelloWorld code end   --------------
Save your project.  Make pjtHelloWorld.dll.  Double-click example.hta to run it.

If you click on the title anywhere, you'll see the version number pop in.  The HelloWorld object is being instantiated, and the property is properly fetched when wanted.

Now click the text that says "click me".  Nothing happens.  Why?  I can't figure out how to respond to events that I raise from my active-x dll project in the web page.

Please alter my example such that you can respond to the events from the HTA for the points.

Thanks in advance for your help.

--lankford
Avatar of lankford
lankford

ASKER

Well, I'm answering my own question here.  I don't see where I can delete my question anymore though.  Oh well.

If anyone is interested, it turns out that I couldn't find a way to do it with an ActiveX DLL.  Instead, I compiled my functionality into an ActiveX OCX control that has no visible interface.  This allows you to use an
object tag like the following:

<object
  id="myOCX"
  classid="CLSID:7A97D874-3CA6-4E1D-9F2A-70CB9119FB09"
  width="1"
  height="1">
</object>

Having this tag available when you load the page into the browser's memory allows it to hook the events together.  So, in my VBScript, I could respond to the event "myEvent" like so:

sub myOCX_myEvent(parameters)
     ' respond here
end sub

--lankford
Avatar of Richie_Simonetti
Ask to community support. You could PAQ instead of delete it.
lankford, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

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