I am writing a script host in VB.NET by implementing hand written
IActiveScriptSite and IActiveScriptSiteWindow interfaces on a class.
IActiveScriptSite methods are called successfully by a VBScript engine,
however IActiveScriptSiteWindow methods aren't. The consequence of this is
that VBScript will error when a MsgBox function is called.
Is it possible to write the class and interfaces so that the VBScript engine
can call methods on both interfaces.
Some code snippets:
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("BB1A2AE1-A4F9-11cf-8F20-00805F2CD064")> _
Interface IActiveScript
Sub SetScriptSite(<[In](), MarshalAs(UnmanagedType.Interface)> ByVal
site As IActiveScriptSite)
.
.
.
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("DB01A1E3-A42B-11cf-8F20-00805F2CD064")> _
Interface IActiveScriptSite
Sub GetLCID(ByRef id As System.UInt32)
.
.
.
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("D10F6761-83E9-11cf-8F20-00805F2CD064")> _
Interface IActiveScriptSiteWindow
Sub GetWindow(ByRef phwnd As IntPtr)
Sub EnableModeless(ByVal fEnable As Int32)
End Interface
.
.
.
Public Class ScriptHost
Implements IActiveScriptSite
Implements IActiveScriptSiteWindow
.
.
.
Create the VBScript engine and run script:
Dim scriptEngine As New VBScript
Try
Dim iasp As IActiveScriptParse
iasp = CType(scriptEngine , IActiveScriptParse)
iasp.InitNew()
Dim ias As IActiveScript
ias = CType(scriptEngine , IActiveScript)
ias.SetScriptSite(Me)
Dim sss As String = "MsgBox " & Chr(34) & "test" & Chr(34) &
vbCrLf
iasp.ParseScriptText("MsgBox " & Chr(34) & "test " & Chr(34) &
vbCrLf, Nothing, Nothing, vbCrLf, Nothing, 0, 2, Nothing, Nothing)
ias.SetScriptState(2)
ias.Close()
Thanks in advance
GeorgeGilbot - 28 Feb 2006 13:11 GMT
Further to this I wrote a test scripting engine. In the engine's
SetScriptSite() method, calling QueryInterface for IActiveScriptSiteWindow on
the passed IActiveScriptSite failed with E_NOINTERFACE. I'm not sure of what
to do next to find out what's happening.