VBScriptEngine - Use of complex objects as function parameters #626
Replies: 4 comments 4 replies
-
Hello @DanielGerlach2, We've tried to replicate your scenario based on your description, but we're unable to reproduce any issues. Here's our test program: Public Class Session
End Class
Public Module App
Sub Import(ActSession As Session, Table As String, Data As String)
Console.WriteLine("In Import: '{0}' '{1}' '{2}'", ActSession, Table, Data)
End Sub
End Module
Module Program
Sub Main()
Using ScriptEngine As New VBScriptEngine()
ScriptEngine.AddHostType(GetType(App))
ScriptEngine.AddHostObject("ActSession", New Session)
ScriptEngine.Evaluate("App.Import(ActSession, ""Table"", ""1;2;3;4"")")
End Using
End Sub
End Module Output:
We omitted the Thanks! |
Beta Was this translation helpful? Give feedback.
-
I tried to break the problem down to an example project, but the transfer works correctly there. I'll try again in the next few days to get it reproducible. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay, but as often happens, other important projects got in the way. I tried to recreate the behavior in a sample project, but unfortunately, it was unsuccessful. I'll try to describe the principle again verbally; perhaps you'll then have a clue as to where the problem might be. In the main project, there is an interface "IScript" that, depending on the settings, uses either ClearScript or the "old" MSScriptcontrol, with both ClearScript and the Scriptcontrol implementing the methods/properties. The objects are then passed to the scripting via AddObject, which uses the above-mentioned example call to "AddHostObject." What could be the reason why the object is then passed with the type "ClearScript.HostItem" instead of the original type? The session object is not CLSCompliant. |
Beta Was this translation helpful? Give feedback.
-
Since the problem is not reproducible in a test project, I want to debug the ClearScript code and see if I can identify a possible error line. Unfortunately, the stacktrace only shows the following error line: respectively from this line: So I downloaded the source code and build and integrated the DLLs myself. Since our program DLLs have a StrongName/StrongKey, I tried following your instructions (https://microsoft.github.io/ClearScript/Details/Build.html). As you can see, the files are stored locally, and I have full access to the entire directory. ... |
Beta Was this translation helpful? Give feedback.
-
Certain objects are passed to the script control so that they are available and can be used in scripting.
e.g.
ScriptEngine.AddHostObject("ActSession", HostItemFlags.GlobalMembers + HostItemFlags.DirectAccess, ActiveSession)
ActiveSessio has its own type βSessionβ.
I can access the hosted object via script code and, among other things, access properties, etc.
e.g.
Sub Main
MsgBox(ActSession.TimeStamd)
...
End Sub
However, if I now use the item as a parameter to call a function, I get the following error:
Class does not support automation.
e.g.
Sub Main
App.Import(ActSession, "Table", "1;2;3;4")
...
End Sub
Definition
Sub Import(ActSession as Session, Table as String, Data as String)
If I change the definition to Sub Import(ActSession as Object, Table as String, Data as String) i got the following error on the first access of the parameter.
ClearScript.HostItem cannot be converted to Session
Beta Was this translation helpful? Give feedback.
All reactions