java - function mapping delphi/pascal dll in jna handle and string -


i'm trying call function in delphi dll using jna. function definition is:

function myfuncgetname (ahandle : thandle; var abuf : pwidechar ): integer; export; 

my jna mapping looks this:

int myfuncgetname(pointerbyreference ahandle, wstring abuf); 

the return value should 0 success , -1 fail , i'm getting -1.

i have started windbg , attached process , breaks @ myfuncgetname.

057cb384 eb11            jmp     mydll!myfuncgetname+0x87 (057cb397) 057cb386 b8dcb37c05      mov     eax,offset mydll!myfuncgetname+0xcc (057cb3dc) 057cb38b 8b55f8          mov     edx,dword ptr [ebp-8] 057cb38e 8902            mov     dword ptr [edx],eax  ds:002b:00000000=???????? <-- ### breaks here ### 057cb390 c745f4ffffffff  mov     dword ptr [ebp-0ch],0ffffffffh 

i'm not assembly wiz correct me i'm wrong. think moving address (function argument) location ebp-8 edx register. ebp-8 points value 0 edx 0. moves eax address pointed edx. not supposed move 0 breaks?

why aren't arguments correctly passed function? ahandle same dll previous call , set abuf wstring abuf = new wstring("placeholderstring"); expect abuf filled real text after function returns.

this running on windows 7 java 7 64bit. dll 32bit dll.

update , solution:

thank david , rob comments. have changed delphi definition use stdcall declaration. calling function returns 0 should. retrieve value of pwidechar did following:

int charcount= "placeholder".length(); pointerbyreference abuf = new pointerbyreference(new memory(charcount*4)); int returnvalue = myfuncgetname(ahandle, abuf); if(returnvalue == 0) {     system.out.println(abuf.getvalue().getstring(0, true)); } 

if that's real declaration of dll function, problem calling convention. default calling convention in delphi register, stores first 2 arguments in eax , edx, default c calling convention cdecl, stores them on stack. change delphi declaration this:

function myfuncgetname(ahandle: thandle; var abuf: pwidechar): integer; stdcall; 

(the export directive doesn't anymore (as of delphi 2, think), can remove it. it's been subsumed exports clause, should find elsewhere in dll source.)

the java side wrong. second parameter in delphi code reference pwidechar. see no wstringbyreference type in jna, that's you'll need. can't offer advice on how implement yourself, though.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -