Click here to Skip to main content
13,594,789 members
Rate this:
 
Please Sign up or sign in to vote.
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:

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:

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:

#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 21-Jun-15 1:41am
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.
saudi-knight 21-Jun-15 14:56pm
   
But there's not much code in the C# side so how will that help exactly? Could you please explain? Thanks!
7-Jan-16 1:59am
   
hello, did you solve this problem? If so can you please post your solution? many thanks!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.180621.3 | Last Updated 21 Jun 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100