1

So, I have a weird issue. I am doing a simple PInvoke call to get a boolean from managed code.

C/C++

Q_DECL_EXPORT bool net_variant_getBool(NetVariantContainer* container)
{
    bool result = container->variant->getBool();

    // This function will only return the right value if I use the following code in OSX in release mode (debug works with or without it).
    // qDebug("Return value is: %d", result);

    return result;
}

C#

[DllImport("QmlNet.dylib")]
static extern bool net_variant_getBool(IntPtr variant);

The code above, as is, works perfectly on Linux/Windows in either debug or release mode, and OSX in debug mode only.

On OSX in release mode, the resulting value in C# is wrong. If I attempt to log what the returning bool is (to figure out the issue), it prints out the right value, and then the right value is returned! That's right, the qDebug macro above that is commented out will fix my issue if compiled in. Wth?

This problem only presents it's self in Release mode on OSX/clang.

Here is the compilation output on OSX for both debug and release builds. https://gist.github.com/pauldotknopf/3949b7e86d6a4bfb59788dd0b7c44536

I'm utterly lost. Anybody have any ideas? I don't want to ship debug libs!

1

1 Answer 1

1

It turns out that bool is a non-blittable type and can't be used as a return value. See here.

I changed my code to return a byte instead.

Sign up to request clarification or add additional context in comments.

1 Comment

[MarshalAs(UnmanagedType.I1)] see stackoverflow.com/questions/4608876/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.