D-DLLs & Python

Mike Parker aldacron at gmail.com
Wed Feb 20 06:05:39 PST 2013


On Wednesday, 20 February 2013 at 12:48:53 UTC, Chris wrote:
> I tried extern (C) which has some advantages. However, it still 
> doesn't produce the desired result (tried slicing too).
>
> extern(C) {
>   export void synthesize(ref char[] str) {
> 	printf("Incoming printf: %s\n", &str);
> 	writefln("writefln %s", &str);
> 	writefln("writefln %s", to!string(&str));
> 	writefln("writefln %s", to!string(str));
>   }
> }
>
> OUTPUT:
>
> Incoming printf: Hello from Python
> writefln 2366A34
> writefln 2366A34
> Traceback (most recent call last):
>   File "loaddll.py", line 4, in <module>
>     lib.printThis(c_char_p("Hello from Python"))
> WindowsError: [Error -532414463] Windows Error 0xE0440001

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.


More information about the Digitalmars-d-learn mailing list