xsharp.eu • Passing Objects From C# to back to VO
Page 1 of 1

Passing Objects From C# to back to VO

Posted: Tue Aug 03, 2021 12:13 pm
by jeromegorlick
Hey,

I work in a program that is a hybrid of VO and C#. any new large development that can be done in c# and called from VO is. My problem is that I'm currently trying to pass an object from C# back to vo and having issues. currently I am passing an Object which has a int status and an array of embeddedobject. I can read the status fine from the original object but when I try to interact with with the embeddedobject array it appears to give me a pointer for each of the embedded objects. I did have some success passing object array back to a seperate method in c# with an index to retrieve a single object and simply iterate through each of the objects that way. It is super hacky but it gives me the object and I can access its internals however once I put these objects into an array and pass the array on to another method I am met with object references again. Has anyone had success with passing objects from c# back to VO. is there any specific datatypes within the object that might be causing it to respond in an unexpected way. Any help or suggestions is much appreciated.

Regards Jerome

Passing Objects From C# to back to VO

Posted: Mon Mar 14, 2022 12:28 am
by jeromegorlick
Update with solution, originally when we could not solve this problem we created as stack in .NET and retrieved items from the stack until null was returned to ensure we retrieved all of the required objects from .NET however the cause and solution has now been determined for arrays not passing to VO correctly. As part of another ticket I discovered that the reason behind the array not passing back properly was that .NET arrays are zero indexed but VO expects one indexed arrays. This can be solved by creating a one indexed array in .NET before passing the array to VO. This ensures compatibility with VO and we have had success passing complex objects reliably from .NET back to VO to help facilitate new API functionality from within our software. Hoping that this will help others in the future maintaining old VO code bases with new functionality implemented in .NET.

Warm Regards,
Jerome

Passing Objects From C# to back to VO

Posted: Mon Mar 14, 2022 11:55 am
by ic2
Hello Jerome,

I thought that it was not possible to pass C# arrays to VO, and not because of the zero based C# arrays, as these are supposed to be incompatible.

I convert C# arrays to a string (with a array2strng/string2array function) first. It's not ideal but it works for my purpose. If the array contains objects this won't work.

Dick

Passing Objects From C# to back to VO

Posted: Mon Mar 14, 2022 12:14 pm
by wriedmann
Hi Jerome,
I'm using COM very successfully to use .NET objects with their classes and methods in VO.
But I'm using the VO GUI classes and the SxS mechanism.
Wolfgang

Passing Objects From C# to back to VO

Posted: Mon Mar 14, 2022 9:48 pm
by jeromegorlick
Here is the code we are using to pass an array back to VO, I hope this helps. Not sure why it is said to not work when it seems to be working flawlessly for us.

c#

Code: Select all

public Array GetNetObject()
    {
        Array voReturnArray = Array.CreateInstance(typeof(object), new[] { NetList.Count }, new[] { 1 });
        Array.Copy(NetList.ToArray(), 0, voReturnArray, 1, NetList.Count);
        return voReturnArray;
    }

Passing Objects From C# to back to VO

Posted: Mon Mar 14, 2022 10:12 pm
by ic2
Hello Jerome,

That's absolutely interesting, thanks.

I was told long ago that this couldn't be done. Can't find it back now however. Probably even way back to Vulcan, and X# dealt with that at some point?

My conversion Array2String works but if I can pass arrays from C# unchanged it would be a lot easier for some data.

Dick