C++ binding issues with C++ function returning a simple POD struct.

ParticlePeter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 22 11:25:09 PDT 2017


On Monday, 22 May 2017 at 13:03:17 UTC, evilrat wrote:
> On Monday, 22 May 2017 at 11:25:31 UTC, ParticlePeter wrote:
>>
>> Then I am not getting your hack, this function here, does not 
>> exist on the C++ side.
>> -------- HACK -------------------
>> // extern(C++) of course
>> void GetCursorPos(ImVec2* v);
>>
>> How is it supposed to work then if there is no definition?
>
> you "forge" this signature insted of correct one, I suggest 
> also wrap it some handy version in case this is "suddenly got 
> working"
>
> version (PROPER_ABI)
> {
>  extern(C++) ImVec2 GetCursorPos();
> }
> else // hacky one
> {
>  extern(C++) void GetCursorPos(ImVec2* v);
>  ... put helper here to match excepted API, in case of C++ 
> class add it to the end as 'final'...
> }
>
> This works because it matches name mangling on this one. And 
> even if its not it is possible to hammer it in with pragma 
> mangle.

Never stop learning, that actually works! But only with the 
pragma mangle hammer. Nice, but again some more mangle pragmas. 
The better way seems to be Jerry's suggestion, works as well, see 
bellow.



More information about the Digitalmars-d-learn mailing list