java - Allocating WinDef.RECT struct in JNA -


i have c function (compiled dll) takes windef.rect object , prints out 4 co-ordinates:

dllexport void test(rect rect) {     printf("rect: %i, %i, %i, %i", rect.top, rect.left, rect.bottom, rect.right); } 

on java (jna) side, i'm attempting pass windef.rect follows:

windef.rect rect = new windef.rect(); rect.bottom=0; rect.left=0; rect.right=0; rect.top=0; jna.instance.test(rect); 

however, nonsense numbers out (which aren't consistent , vary every time), eg:

rect: -857788769, 11343200, 8044544, 8044544 

i'm assuming i'm not defining rect correctly on jna side (the c++ function fine called other native functions in same dll), beyond i'm bit stuck!

i had useful answer on over jna mailing list:

your native signature asking struct , jna mapping defaults struct* semantics. change native sig or use structure.byvalue; struct* preferred unless explicitly need otherwise.

in case need native library remain unchanged, solution declaring subclass of windef.rect , tagging structure.byvalue:

public static class rectbyvalue extends windef.rect implements structure.byvalue {} 

this used in place of windef.rect, , appears work without issue.

note while fix worked ok me, other(s) have reported otherwise - in comment below, switching types lprect potential fix.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -