Support Forums
using a dll

Hi,

I'm trying to use a C# based dll with my VTScada application. To do so, I'm using The function DLL.

It's working well with integers, floats and strings, but I have to do some gymnastics to get a bool (I use an integer return type and apply a modulo 2 to the variable to get a 0 or a 1), and I flat out can't get any types of object. I'm trying to use a pointer as a return type but I always get an Invalid value.

My dll decrypt a file and return an array of objects. These objects represent events that I will store in the VTScada librarian. I can't decrypt my files in VTScada, this is why I need to make my dll work with it.

Is there a way to pass an object or an array of objects from a dll to VTScada?

Hi, I'm trying to use a C# based dll with my VTScada application. To do so, I'm using The function DLL. It's working well with integers, floats and strings, but I have to do some gymnastics to get a bool (I use an integer return type and apply a modulo 2 to the variable to get a 0 or a 1), and I flat out can't get any types of object. I'm trying to use a pointer as a return type but I always get an Invalid value. My dll decrypt a file and return an array of objects. These objects represent events that I will store in the VTScada librarian. I can't decrypt my files in VTScada, this is why I need to make my dll work with it. Is there a way to pass an object or an array of objects from a dll to VTScada?

Thanks for the questions. I've sent this off to our Development group and will follow-up when I hear back.

Thanks for the questions. I've sent this off to our Development group and will follow-up when I hear back.

Trihedral Engineering Ltd.

Hey Marc, I've got the following back from our R&D team:

As a note: Where the documentation for VTScada's DLL() mentions pointers this is a pointer to a buffer that will end up as a string in VTScada script, so the DLL would need to return the object(s) as a flat buffer.

If the DLL had a function decrypt() that returns a length of the decrypted file, and a function getDecryptedFile() the DLL calls from VTScada script would look like this:

dllHandle = LoadDLL("mydll.dll");
If Valid(dllHandle) Done;
[
  decryptedFileLength = DLL(dllHandle, "decrypt", 2, ...)
  decryptedFile = DLL(dllHandle, "getDecryptedFile",  4, decryptedFileLength, ...)
]

Essentially, an array of C# objects can't be transferred directly via DLL(). The earlier example was just for a single file, but multiple files could be passed in several ways, for example:
•The decrypt() function returning the number of files and then in a loop another call to the DLL to determine the length of the n-th file, and finally retrieving that file from the DLL
• Serialising the array e.g. "<32 bit length of first decrypted file><contents of first file><32 bit length of second decrypted file>..." and converting that into an array in VTScada via SRead().

Another option that may or may not be applicable is to make it a COM DLL where it would be possible to return arrays.

Hey Marc, I&#039;ve got the following back from our R&amp;D team: As a note: Where the documentation for VTScada&#039;s DLL() mentions pointers this is a pointer to a buffer that will end up as a string in VTScada script, so the DLL would need to return the object(s) as a flat buffer. If the DLL had a function decrypt() that returns a length of the decrypted file, and a function getDecryptedFile() the DLL calls from VTScada script would look like this: ```` dllHandle = LoadDLL(&quot;mydll.dll&quot;); If Valid(dllHandle) Done; [ decryptedFileLength = DLL(dllHandle, &quot;decrypt&quot;, 2, ...) decryptedFile = DLL(dllHandle, &quot;getDecryptedFile&quot;, 4, decryptedFileLength, ...) ] ```` Essentially, an array of C# objects can&#039;t be transferred directly via DLL(). The earlier example was just for a single file, but multiple files could be passed in several ways, for example: &bull;The decrypt() function returning the number of files and then in a loop another call to the DLL to determine the length of the n-th file, and finally retrieving that file from the DLL &bull; Serialising the array e.g. &quot;&lt;32 bit length of first decrypted file&gt;&lt;contents of first file&gt;&lt;32 bit length of second decrypted file&gt;...&quot; and converting that into an array in VTScada via SRead(). Another option that may or may not be applicable is to make it a COM DLL where it would be possible to return arrays.

Trihedral Engineering Ltd.

edited Apr 16 '18 at 2:52 pm

Hi Dave,

I tried your first option and it worked like a charm. Knowing that the DLL needed to return an object as a buffer in order to be able to read it in VTScada was the key to make the magic happen. I would humbly suggest to had that information in the documentation to avoid a lot of headaches for other developpers.

Thank you and the R&D team for the help and support!

Hi Dave, I tried your first option and it worked like a charm. Knowing that the DLL needed to return an object as a buffer in order to be able to read it in VTScada was the key to make the magic happen. I would humbly suggest to had that information in the documentation to avoid a lot of headaches for other developpers. Thank you and the R&amp;D team for the help and support!

Thanks for following-up. I'm glad it worked out. I'll forward your suggestion off to the folks managing documentation.

Thanks for following-up. I&#039;m glad it worked out. I&#039;ll forward your suggestion off to the folks managing documentation.

Trihedral Engineering Ltd.

170
4
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft