CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Sep 2007
    Posts
    4

    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:


    Code:
    <head>
    <script language="javascript">
    <!-- hide me from other browsers
    function showanswer() {
       var a = myControl.myFunction();
       alert("The answer is "+a);
    }
    // end hiding from other browsers -->
    </script>
    </head>
    <body>
    <object id="myControl"
    classid=clsid:6DB79AF2-F661-44AC-8458-62B06BFDD9E4>
    </object>
    <h1>Click below for an answer!</h1>
    <input type="button" name="answerbutton" value="Click Me!" onClick="showanswer()">
    </body>
    </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?
    Last edited by PeejAvery; September 3rd, 2007 at 11:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured