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

evilrat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 22 06:03:17 PDT 2017


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.


More information about the Digitalmars-d-learn mailing list