D-DLLs & Python

Chris wendlec at tcd.ie
Wed Feb 20 06:28:05 PST 2013


On Wednesday, 20 February 2013 at 14:05:40 UTC, Mike Parker wrote:
> Your function is being called from Python, correct? Then in 
> addition to the extern(C), the argument needs to be a char*, 
> not a D array or a reference to one.

Correct, and it works _now_*! The lines

printf("Incoming printf: %s\n", str);
writefln("writefln %s", to!string(str));

Print now:

Incoming printf: Hello from Python
writefln Hello from Python


So the correct signature is

extern (C) {export void printThis(char* str);}

Thanks you guys! I'm so glad I don't have to write a C-wrapper!

*("_now_" because I tried char* with extern (C) before as I would 
in my other Python modules, but it didn't work for some reason. 
Must have overlooked something. Mea culpa!).


More information about the Digitalmars-d-learn mailing list