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 8961327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:51:55+00:00 2026-06-15T15:51:55+00:00

Using JNA, I am loading a dll written in C++ and calling function present

  • 0

Using JNA, I am loading a dll written in C++ and calling function present within that C++ function:

 int xxfunction(Char* ptr){...}

Here I need to send a char array so that function will assign value to it. Basically I need to pass char array by reference.

According to the JNA documentation, C++ char* equivalent in Java is String, so I created a String object and passed it to the function like shown below:

Java function declaration:

interface foo extends Library
{
 ....//loading dll and other work
  int xxfunction(String chararray);//function declaration
}

Java function call:

public static void main(String args[]) 
{
 String str="abcd";
 int i=fooinstance.xxfunction(str);//function call
}

but when I executed this code it is giving me:

A fatal error has been detected by the Java Runtime Environment:
Failed to write core dump. Minidumps are not enabled by default on
client versions of Windows

The crash happened outside of the Java Virtual Machine in native code. See problematic frame for where to report the bug.

So is it the correct way to pass String as an argument where function expects char pointer?
C++ char equivalent in java is byte, so do I need to pass byte array as a parameter?

I can’t even pass Pointer object from JNA to function because it gives me IllegalargumentException.

  • 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-15T15:51:56+00:00Added an answer on June 15, 2026 at 3:51 pm

    Only const char* should ever be mapped to a Java String. If there is any possibility of it not being const, you should pass a buffer instead (byte[], Memory, or NIO Buffer), and then use Native.toString() on the “returned” value.

    As a matter of style, you should always provide the callee with the length of the provided buffer so that it has enough information available to avoid overwriting the buffer.

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

Sidebar

Related Questions

I am using JNA and need to use the MapVirtualKeyEx function. Here is the
How can you list all available function names in a given dll using JNA?
I'm trying to call a function in a delphi dll using JNA . the
The first difficulty in using JNA with J9 is that the J9 JVM does
I'm using JNA to access a dll and everything work fine ... while i'm
I'm using a native c++ dll out of an Java application with the JNA
I am trying to call OpenEvent of kernel32.dll using JNA and it fails with
I am trying to run the following C function from Java using JNA, but
I'm working on wrapping a C DLL library to Java using JNA. The library
I'm using JNA to call Carbon APIs. The particular API call that I want

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.