On Wednesday, 13 April 2016 at 19:09:46 UTC, Andre Polykanine wrote:
Hello Chris,

CvDda> Just to inform you that we successfully use D and vibe.d for two CvDda> things:

This is just overwhelming!
How do you make bindings to NVDA API which is in Python?
I'm not an NVDA user (I'm using JAWS, if it matters), but I'm still
very interested in the technology.


Andre.

Hi Andre,

What is CvDda>? There are loads of different results in my search engine.

To answer your question: in Python you can load DLLs via Python's ctypes. You just load the DLL via `CDLL()` or `cdll.LoadLibrary()`. It's relatively easy to make a Windows DLL in D. To make it accessible for Python's C-types, just expose your functions like so

extern (C) {
 export void myFunction(){}
}

Of course, any arguments (at least on Windows) or return types should be C-style, i.e. `const char*` instead of `string`. To Python it all looks like C, it doesn't know about D. I've seen a plug-in written in Scheme and it is also loaded via Python's `CDLL()`.

To bind a Python function to your DLL just do something like this (assuming you're in a class):

// Load
self.myDLL = CDLL("path/to/dll")

If your function is void, just call it using

// call void function in DLL
self.myDLL.myFunciton();

If it returns something, you should first define the return value:

// assign return type to function in Python
self.myDLL.getError.restype = c_char_p

To pass arguments, it's best to convert Python to C-types like so:

// pass argument as C-type
self.myDLL.myFunction(c_char_p("text"))

It's all in the Python docs at https://docs.python.org/2/library/ctypes.html.

Reply via email to