Problem running VB DLL in Internet Explorer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exr
    New Member
    • Sep 2007
    • 1

    Problem running VB DLL in Internet Explorer

    The project I am doing requires custom functionality from a DLL executed from with Internet Explorer.

    The DLL is written in VB 2005. The DLL resides on the local machine, where it is registered with Regasm. The DLL implements iObjectSafety in order to allow IE to load it with an OBJECT tag.

    IE loads the DLL without error. The first time you call a function from the DLL it works like a charm. The second time you call any DLL function, it fails with "Object doesn't support this property or method".

    Here is sample code for the DLL:

    Code:
    Imports System.Runtime.InteropServices
    <ComImport()> _
    <Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")> _
    <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Public Interface IObjectSafety
        Function GetInterfaceSafetyOptions(ByRef iid As Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer
        Function SetInterfaceSafetyOptions(ByRef iid As Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer
    End Interface
    
    <Microsoft.VisualBasic.ComClass(iSiteTest.ClassId, iSiteTest.InterfaceId, iSiteTest.EventsId)> _
    <System.Serializable()> _
    Public Class myTest
        Implements IObjectSafety
        Public Const ClassId As String = "6DB79AF2-F661-44AC-8458-62B06BFDD9E4"
        Public Const InterfaceId As String = "E7E27E4B-9AE3-47f9-8B0D-7A2EB8DEB17C"
        Public Const EventsId As String = "E754DF7F-66A4-4d5d-A282-EA4FE481EE40"
    
        Public Sub New()
            MyBase.New()
        End Sub
    
        Public Function myFunction() As Integer
            Return 42
        End Function
    
        Private Const INTERFACESAFE_FOR_UNTRUSTED_CALLER As Integer = &H1
        Private Const INTERFACESAFE_FOR_UNTRUSTED_DATA As Integer = &H2
    
        Public Function GetInterfaceSafetyOptions(ByRef iid As Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions
            pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA
            pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA
            Return 0
        End Function
    
        Public Function SetInterfaceSafetyOptions(ByRef iid As Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions
            Return 0
        End Function
    
    End Class
    Here is sample code for running it in IE:

    [HTML]<head>
    <script language="javas cript">
    <!-- hide me from other browsers
    function showanswer() {
    var a = myControl.myFun ction();
    alert("The answer is "+a);
    }
    // end hiding from other browsers -->
    </script>
    </head>
    <body>
    <object id="myControl"
    classid=clsid:6 DB79AF2-F661-44AC-8458-62B06BFDD9E4>
    </object>
    <h1>Click below for an answer!</h1>
    <input type="button" name="answerbut ton" value="Click Me!" onClick="showan swer()">
    </body>
    </html>[/HTML]

    The first time you click the 'Click Me' button in IE, the function call works. Click the button a second time, and it fails.

    Can anyone point me to solving this?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .NET forum .

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Probably because you need to run server side code not client side, try:
      Code:
      <SERVER language="Javascript">
      function showanswer() {
         var a = myControl.myFunction();
         alert("The answer is "+a);
      }
      </SERVER>

      Comment

      Working...