Calling a function on a c-object

Mar 25, 2013 at 3:56 PM
Edited Mar 25, 2013 at 3:59 PM

we have a C-library which is registered in windows and which we use for our shared informations.
We access this lib from VB.NET. We have instances to objects within that library, which we pass from VB.NET to the jint instance by setParameter()

Depending on the way how we create the object, we get the error "Function expected" when we try to execute a method on that object.

The javascript code looks like this:

// now we access an object from a list of objects within the 
var pp = input.ParameterList.getFieldFromFieldCollection("field1")

// the objects have a member called "value". We need to call get_Value() to access.
return pp.get_Value().toString()
Now, as said, when we create the input object "manually" from within VB.NET, the above javascript works fine.

When we create the input object within other c methods and pass it through VB.NET, we always get "Function expected".

Any clues how to resolve this?
Mar 27, 2013 at 2:09 PM
Edited Mar 27, 2013 at 2:09 PM
Just an update:

When we create the father object within VB.NET and set its members to the original, it works. We can even modify the members of that instance within JavaScript, they are then changed in the original object. It seems that somehow the father object (OURComDataTypes.COURDocument) cannot be passed correctly to JavaScript, when it is created within the modules of our application written in C (COM).

The first 3 lines of the function correct that. While this is a valid workaround, we are still confused why this could happen. Does anyone have an idea what we can do?
Public Function CallJavaScript(ByVal method As String, ByRef input As OURComDataTypes.COURDocument) As Boolean
    Dim input1 As New OURComDataTypes.COURDocument  // create a new instance 
    input1.ParameterList = input.ParameterList      // share members with the original
    input1.Children = input.Children                // dito
    If JavaScriptContext Is Nothing Then
        ' initialize the javascript engine
        JavaScriptContext = New Jint.JintEngine
        JavaScriptContext.AllowClr = True
    End If

    Dim ScriptTextContent As String = ReadScript(method)
    If (ScriptTextContent.Length = 0) Then
        Throw New Exception("JavaScript for method " & method & " is empty")
        CallJavaScript = False
        Exit Function
    End If

    If Not input Is Nothing Then
         JavaScriptContext.SetParameter("input", input1)
    End If

        returnString = JavaScriptContext.Run(ScriptTextContent)
End Function