Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So this is the error I get on Eclipse:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (0xe0434352), pid=7696, tid=8632
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b15) (build 1.8.0_45-b15)
# Java VM: Java HotSpot(TM) Client VM (25.45-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [KERNELBASE.dll+0xc42d]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
This is the C# dll:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StringAPI
{
    public class Test
    {
        public string Something(string username)
        {
            return username;
        }
    }
}
This is the Java code:

Java
import java.util.Scanner;

public class String_Displayer
{
    static
    {
        System.loadLibrary("StringAPIWrapper");
    }

    public native String something(String username);

    public static void main(String[] args)
    {
        String_Displayer sd = new String_Displayer();
        System.out.println("Please enter your name:");
        @SuppressWarnings("resource")
        Scanner scan = new Scanner(System.in);
        String username = scan.next();
        String s = sd.something(username);
        System.out.print(sd.something(username));
    }

And this is the C++/CLI Wrapper dll:

C++
#include "stdafx.h"
#include "com_StringDisplayer_String_Displayer.h"
#include "StringAPIWrapper.h"
#include <vcclr.h>
#include <iostream>

using namespace std;
using namespace System;
using namespace StringAPI;

JNIEXPORT jstring JNICALL Java_com_StringDisplayer_String_1Displayer_something (JNIEnv *env, jclass jc, jstring js)
{
    const jchar* temp = (env)->GetStringChars(js, 0); 
    if (temp == NULL)
    {
        return NULL;
    }

    String^ managedString = gcnew System::String((const wchar_t*)temp);
    env->ReleaseStringChars(js, temp);
    Test^ test1 = gcnew Test();
    String^ result = test1->Something(managedString);

    pin_ptr<const wchar_t> resultChars = PtrToStringChars(result);
    return env->NewString((jchar*)resultChars, result->Length);
}


What I'm sure of is the function that calls the C# function is working properly. I've also tried to just write it directly from C++/CLI using System::Console::Writeline without converting to a jstring but it didn't work. I know that using Writeline does actually work: If I do System::Console::WriteLine("test"); and comment out the call to C#, "test" is written to the java console.
Posted
Comments
Kornfeld Eliyahu Peter 21-Jun-15 8:22am    
Maybe a case problem between Something and something?
saudi-knight 21-Jun-15 8:40am    
what do you mean?
Kornfeld Eliyahu Peter 21-Jun-15 8:44am    
I mean that all C++/C# and Java are case sensitive languages...
You have the Something method in C++ and C#, but you have something in Java...
saudi-knight 21-Jun-15 8:48am    
Nope, thats not the issue. You're essentially creating a new function with jni and through the wrapper you're calling the C# function serperatly. Also, I've double checked just in case.
KarstenK 21-Jun-15 14:29pm    
Tip: set a break point in the C# code. It should work to debug it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900