Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:41:58+00:00 2026-06-05T01:41:58+00:00

I’m trying to call a function in a delphi dll using JNA . the

  • 0

I’m trying to call a function in a delphi dll using JNA. the function definition is:

function myFuncGetName (aHandle : THandle; var aBuf : pwideChar ): integer; export;

my jna mapping looks like this:

int myFuncGetName(PointerByReference aHandle, WString aBuf);

the return value should be 0 for success and -1 for fail and I’m always getting -1.

I have started up WinDbg and attached to the process and it breaks at 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 an assembly wiz so correct me where I’m wrong.
I think its moving an address (function argument) from location ebp-8 to the edx register.
ebp-8 points to value 0 so edx is 0.
it moves eax to address pointed by edx.
Its not supposed to move anything to 0 so it all breaks?

Why aren’t my arguments correctly passed to the function?
I get aHandle from the same DLL from a previous call and I set up aBuf as
WString aBuf = new WString(“placeholderstring”);
I expect aBuf to be filled with real text after the function returns.

This is all running on Windows 7 with java 7 64bit. The DLL is a 32bit DLL.

UPDATE AND SOLUTION:

Thank you David and Rob for your comments. I have changed the delphi definition to use the stdcall declaration. Calling the function now returns 0 which it should. To retrieve the value of the pwideChar I did the 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));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:42:00+00:00Added an answer on June 5, 2026 at 1:42 am

    If that’s the real declaration of the DLL function, then the problem could be the calling convention. The default calling convention in Delphi is register, which stores the first two arguments in EAX and EDX, but the default C calling convention is cdecl, which stores them on the stack. Change the Delphi declaration to this:

    function myFuncGetName(aHandle: THandle; var aBuf: PWideChar): Integer; stdcall;
    

    (The export directive doesn’t really do anything anymore (as of Delphi 2, I think), so you can remove it. It’s been subsumed by the exports clause, which you should find elsewhere in the DLL source.)

    The Java side is also wrong. The second parameter in the Delphi code is a reference to a PWideChar. I see no WStringByReference type in JNA, but that’s what you’ll need. I can’t offer any advice on how to implement it yourself, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.