D-DLLs & Python

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


On Wednesday, 20 February 2013 at 14:43:06 UTC, John Colvin wrote:
> On Wednesday, 20 February 2013 at 14:28:06 UTC, Chris wrote:
>> 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!).
>
> yeah, although extern(C) doesn't have to have any braces.

You are right of course!

>
> I've never had to use export before, but then that could be a 
> .so/.dylib vs .dll thing

"export" is used in the DLL how-to. I never had to use it for my 
.so/.dylib modules either. I am new to Windows and it is a very 
strange beast. Like cooking without pots and pans.


More information about the Digitalmars-d-learn mailing list