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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:06:27+00:00 2026-05-25T13:06:27+00:00

I have a C++ dll that contains methods that I need to use in

  • 0

I have a C++ dll that contains methods that I need to use in a Java program. I’ve been through all the Sun documentation on JNI, and numerous tutorials I found on the web, and I can’t seem to find the problem with my code. In fact, a fair portion of the code is cut and pasted from various tutorials and the Sun website.

My specific problem is as follows: My C++ native method receives a jdoubleArray from my Java program, which needs to be mapped to a c++ vector that can then be passed to a method in the C++ dll. The method in the dll returns another vector, that then needs to be mapped to a new jdoubleArray, and returned to the Java program. The problem seems to be that I’m not performing the mapping correctly.

The code I have is as follows (I’ve removed the call to the dll method for simplicity):

JNIEXPORT jdoubleArray JNICALL Java_jniarraypassing_JNIArrayPassing_passAndReturn(JNIEnv *env, jclass jcls, jdoubleArray arr)
{
     //First get a pointer to the elements within the jdoubleArray
     jsize len = env->GetArrayLength(arr);
     jboolean isCopy1;
     jdouble *body = env->GetDoubleArrayElements(arr, &isCopy1);

     //Create the vector<double> and reserve enough memory for mapping
     std::vector<double> newvector;
     newvector.reserve(len);

     //Copy the contents of the jdoubleArray to the vector<double>
     for (int i=0; i<len; i++)
     {
        newvector.push_back(body[i]);
     }

     //Release the pointer to the jdoubleArray
     if (isCopy1 == JNI_TRUE)
     {
        env->ReleaseDoubleArrayElements(arr, body, JNI_ABORT);
     }

     //Call the dll method here....

     jdoubleArray output = env->NewDoubleArray(newvector.size());
     jboolean isCopy2;
     jdouble* destArrayElems = env->GetDoubleArrayElements(output, &isCopy2);
     for (int i=0; i<newvector.size(); i++)
     {
        destArrayElems[i] = newvector[i];
     }
     if (isCopy2 == JNI_TRUE) 
     {
            env->ReleaseDoubleArrayElements(arr, destArrayElems, 0);
     }

     return output;
 }

When I output the contents of body[i] to the console, I get a series of numbers that look remarkably like Hexadecimal values (e.g. 003DFBE0), but they are all the same, so I don’t think they can be memory addresses.

The contents of the returned jdoubleArray consists entirely of default double values (i.e. 0.0), which I suspect is because the values from the original jdoubleArray are invalid?

What I need to find out, is

Any help would be appreciated!

  • 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-05-25T13:06:28+00:00Added an answer on May 25, 2026 at 1:06 pm

    According to the documentation, GetDoubleArrayElements may return a
    pointer to a copy, rather than a pointer to the actual data; this is why
    you need to call ReleaseDoubleArrayElements, for example. If you’re
    copying, then it’s normal that you don’t see the values you’ve written.
    If you’re using std::vector, I’d use GetDoubleArrayRegion and
    SetDoubleArrayRegion:

    jsize size = env->GetArrayLength( arr );
    std::vector<double> input( size );
    env->GetDoubleArrayRegion( arr, 0, size, &input[0] );
    
    //  ...
    
    jdoubleArray output = env->NewDoubleArray( results.size() );
    env->SetDoubleArrayRegion( output, 0, results.size(), &results[0] );
    

    I think this is the only way to initialize an output array.

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

Sidebar

Related Questions

I have a dll that was written in c++, I need to use this
I have a dll that contains a number of classes that all inherit from
I have a C# class library that contains methods that need to be used
Right now we have a dll file that contains all the database calls and
I have a specific DLL that contains some language processing classes and methods. One
I have a dll that contains a dot net assembly - common intermediate language.
I have a dll that contains a templated class. Is there a way to
I have an MFC extension DLL that I've written. It contains derived classes of
I have a DLL that I want to profile.. I tried to use Very
I have a DLL that I can use to pull the following information about

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.