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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:38+00:00 2026-05-24T03:01:38+00:00

I’m in the process of doing some Java<->.NET interop code using a native library

  • 0

I’m in the process of doing some Java<->.NET interop code using a native library between them, so far things are going fairly well.

However for some reason I cannot run any methods under JNIEnv.

System::String^ JNIStringToNet(JNIEnv * env, jstring js)
{
    const char *buf = env->GetStringUTFChars(js, 0); // segfault

Now I can pass variables back and forth and do all other kinds of communication, so I’m figuring I haven’t initialized this correctly or something.

I’m loading it like this:

this.Lib = (LibHandler)Native.loadLibrary(this.Name, LibHandler.class);     

(I prefer Native.loadLibrary because it seems to allow me to do more with it easier, such as class sharing between multiple libraries and unhooking and rehooking it from the JVM on the fly).

Edit:

Seriously any method:

std::cout << "Getting version:" << std::endl;
std::cout << env->GetVersion() << std::endl;

Getting version:

(segfault)

Any ideas on wht JNIEnv would segfault for every method? This should be set up by the JVM, correct?

Edit 2:

This is a Java application that is calling a C++ library that will interface with a .NET library (so it’s a CLR compiled C++ library, if that makes any difference), to limit any external factors I’m not even calling the .NET DLL but just converting strings that come in back out (or well… trying).

So for example from Java:

this.Lib = (LibHandler)Native.loadLibrary(this.Name, LibHandler.class);
this.Lib.myCPPMethod(); // Segmentation fault during this call, JVM crashes.

Curious if it was the CLR that was causing it: Disabled clr compilation and stripped everything out that was CLR related, still does it.

Edit 3:

Got it to dump:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000000000000, pid=1596, tid=7248
#
# JRE version: 6.0_23-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (19.0-b09 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x0000000000000000

So yeah, looks like the JVM isn’t giving me memory access for some reason.

Edit 4:

Actual call:

JNIEXPORT jstring JNICALL Query(JNIEnv * env, jobject jobj, jstring start, jstring end)
{ 
    std::cout << "Getting version:" << std::endl;
    jint j = env->GetVersion();
    return jstring("test");
}

Edit 5:

Works with System.loadLibrary:

JNIEXPORT void JNICALL Java_LibTest_T(JNIEnv *env, jobject jobj)
{ 
    std::cout << "Getting version:" << std::endl;
    jint j = env->GetVersion();
    std::cout << j << std::endl;
}

Output:

java -Djava.library.path="(dir)\lib\64" EntryPoint
Getting version:
65542

Ack! I mean some headway, but I can’t unload libraries from the JVM that are loaded in System.loadLibrary can I?

I basically need to be able to unhook these libraries from the JVM and swap them out, on top of that they all need to “share” a single class and be able to be bound to the class at runtime… which is kinda why I went with Native.loadLibrary.

Currently I do this:

Load the DLL:

this.Lib = (LibHandler)Native.loadLibrary(this.Name, LibHandler.class);

Unhook it:

this.Lib = null;
Runtime.getRuntime().gc(); // Force the JVM to drop it immediately.

Class I load them all into:

public interface LibHandler extends Library{ 
    void T();
}

Any way to work similarly with System.loadLibrary?

Edit 6:

Feel free to call me dumb, I’m using JNA, NOT JNI, which is completely different and a huge source of my problems…. is there a way to do this with JNI? Or can I get JNIEnv to register with JNA somehow? I’m guessing I can drop JNI from the C++ library and straight up use wstrings?

I’ll get back with this tomorrow.

  • 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-24T03:01:38+00:00Added an answer on May 24, 2026 at 3:01 am

    Well I feel bad.

    Native.loadLibrary == JNA.

    System.loadLibrary == JNI.

    The purpose of JNA is to not require any real knowledge of the JVM environment, so you can run native libraries as is, so instead of jstring you can use char*…

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
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 have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.