|
-
September 2nd, 2007, 10:55 AM
#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:
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.
-
September 5th, 2007, 09:38 PM
#2
Re: Problem running VB DLL in Internet Explorer
I don't really have an answer for you... Have you tried trapping the error in Visual Studio by attaching to the running IExplore process and recreating the error? You should also be able to drop breakpoints on your source code and step through it. Maybe that will give you a better idea of what is causing the error? The error message provided by IE is less than stellar.
Good luck!
p.s. I am making the assumption that you have VS2005 as this was written in VB2005.
-
September 6th, 2007, 05:56 PM
#3
Re: Problem running VB DLL in Internet Explorer
Yes, I did try debugging as suggested.
IE fails on the statement:
var a = myControl.myFunction();
BUT, only the second time this is executed. The first time it is executed it works as expected. Somehow IE is invalidating (garbage collecting?) myControl after its first call.
-
September 7th, 2007, 06:46 AM
#4
Re: Problem running VB DLL in Internet Explorer
IE doesn't have garbage collection. It sounds to me that the DLL, for whatever reason, doesn't like being referenced twice. Try the following to test my theory.
Now, does it give you the error the first time the function is fired?
Code:
var a = myControl.myFunction();
alert("The answer is "+a);
function showanswer() {
var a = myControl.myFunction();
alert("The answer is "+a);
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 7th, 2007, 08:54 AM
#5
Re: Problem running VB DLL in Internet Explorer
Yes, same error message. I does not seem to matter how the DLL is called, the second time always gives an error message. Even if you put two functions in the DLL, it doesn't matter which function you call the second time, the control cannot be referenced again.
If you reference the DLL in a windows script file (i.e. not in IE), then you can call the function as many times as you want without error.
I think the problem is somehow related to the implementation of the iObjectSafety interface.
-
September 7th, 2007, 09:10 AM
#6
Re: Problem running VB DLL in Internet Explorer
Try changing your IE security settings.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 12th, 2007, 07:37 PM
#7
Re: Problem running VB DLL in Internet Explorer
Yes, tried changing IE security to enable EVERYTHING, still with no effect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|