I have a technical problem that I can not find the solution despite much research.
I want to access the bounds property of the CAMetalLayer class via org.lwjgl.system.macosx.ObjCRuntime and org.lwjgl.system.JNI but as it is a structure type return value I do not see how.
When the return value is a class, a primitive type or void, I use objc_msgSend and everything is ok. Example:
long objc_msgSend = ObjCRuntime.getLibrary().getFunctionAddress("objc_msgSend");
long cAMetalLayerClassPtr = ObjCRuntime.objc_getClass(createCS("CAMetalLayer"));
long cAMetalLayerInstance = ObjCRuntime.class_createInstance(cAMetalLayerClassPtr, 0L);
long mlayermsgSend = JNI.invokePPP(cAMetalLayerInstance, sel_getUid("init"), objc_msgSend);
On the other hand, when the return value is a structure, the program crashes at the invocation of objc_msgSend_stret. And that's understandable since in XCode the use of objc_msgSend_stret is a casting of the return value.
Example Objective-c calls (that work) of objc_msgSend and then objc_msgSend_stret:
//Create CAMetalLayer instance.
CAMetalLayer* metalLayer = [CAMetalLayer alloc];
//Prepare init() call.
SEL initMethod = sel_getUid("init");
//Define objc_msgSend pointer with id return type.
id (*initMsg)(id inst, SEL sel) = (void*) objc_msgSend;
//Call init() like [metalLayer init]
metalLayer = (*initMsg)(metalLayer, initMethod);
//Define objc_msgSend_stret pointer with CGRect return type.
CGRect (*ptrBoundMsg)(id inst, SEL sel) = (void*) objc_msgSend_stret;
//Prepare bounds getter call.
SEL boundsGetter = sel_getUid("bounds");
//Call bounds like [metalLayer bounds] : what i need in Java.
CGRect structBounds = (*ptrBoundMsg)(metalLayer, boundsGetter);
I do not see how in Java call objc_msgSend_stret with the correct typecasting. Does someone have an idea?
I also went to the track DynCall and after a day of research I can not make a code, even very simple, that works.