Using custom c++ dll in Sikulix

Asked by matteoa

I've written a small c++ dll to crypt and decrypt strings, I have to use it from .net and from Sikulix; it works if called from .net code.
The two functions have these prototypes:
int encrypt( char str2Encrypt[]);
void decript(unsigned char strDecrypt[]);

Checking in the Jython source I've found c:\jython2.7.2\Lib\ctypes\ that gave me some hints about how to load it:
import ctypes
from ctypes import *
libc = ctypes.LibraryLoader (".\\DllPAss.dll")

And this works (at least no runtime error), the output of the
print libc
line is:
<ctypes.LibraryLoader object at 0x4>.
My problem is that then I'm stuck since the line:
libc.LoadLibrary("encrypt") and others attempt I've done
outputs these errors:
[error] script [ testScript ] stopped with error in line 17
[error] TypeError ( 'str' object is not callable )
[error] --- Traceback --- error source first
line: module ( function ) statement
289: __init__ ( LoadLibrary ) return self._dlltype(name)
17: main ( <module> ) libc.LoadLibrary("encrypt")
[error] --- Traceback --- end --------------

I'm not an expert of python, so the problem could be that I'm simply ignoring the way it should be, does anyone has an example to follow?
Thanks in advance

My config is as follows:
sikulix 2.0.5, java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :

I am rather sure, that it is not such easy, to access native libraries from Jython based on Java.

A native library either needs a Java API (usually based on a JNI/JNA usage) or you have to use JNA yourself (sun.jna....) to access the C++ API.

An example for the first way is bytedeco's javacpp and for the second way you have to get familiar with JNA.

When you have the Java solution, then you can use it directly from within Jython/SikuliX scripts having your stuff on the Java class path.

Another option of course is to look for available libraries compatible with Jython, that have the features you need.

Revision history for this message
matteoa (matteoa) said :

Hello RaiMan,
thanks for you response....
I've found this extension:
Whose creator claim that is able to use the standard Ctype from "standard" Python that could solve my problem.
Any experience with that?
I'll give it a try, and report here as soon as I understand how to install and make it work not being an expert in Java, nor Python...;-)
Thanks a lot!

Revision history for this message
RaiMan (raimund-hocke) said :

no experiences but looks promising.

I really appreciate any feedback on your experiences and findings.

Revision history for this message
RaiMan (raimund-hocke) said :

this is now tracked on GitHub:

Can you help with this problem?

Provide an answer of your own, or ask matteoa for more information if necessary.

To post a message you must log in.