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

  • Home
  • SEARCH
  • 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 7493481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:59:12+00:00 2026-05-29T16:59:12+00:00

I am trying to make a callback interface between C# and Java using JNA.

  • 0

I am trying to make a callback interface between C# and Java using JNA.

C# <–CLI–> Visual C++ 2010 <–JNA–> Java

Between Java and C++ I am using unmanaged structures to get callback functionality. In C++ I am trying to wrap structure, that has callback pointers, into managed object.

Between Java and C++ everything works until I’m trying to use gcroot for managed object generation in unmanaged code.

UPDATE it even fails without gcroot. Just with “Logger^ logger = gcnew Logger(logStruct);”

My current solution is as follows:

Java

LoggerStruct.java

package jnatest;

import com.sun.jna.Callback;
import com.sun.jna.Structure;
import java.util.logging.Logger;

public class LoggerStruct extends Structure {
    private Logger logger;

    public interface GetLevelCallback extends Callback {
        int callback();
    }

    public GetLevelCallback getLevel;

    public LoggerStruct(Logger log) {
        super();
        this.log = log;

        getLevel = new GetLevelCallback() {
            public int callback() {
                return logger.getLevel().intValue();
            }
        }

        setFieldOrder(new String[] {"getLevel"});
    }
}

ITestLib.java

package jnatest;

import com.sun.jna.Library;
import com.sun.jna.Native;

public interface ITestLib extends Library {
    ITestLib INSTANCE = (ITestLib) Native.loadLibrary("JNATestC", ITestLib.class);
    int callbackTest(LoggerStruct logStruct);
}

Main.java

package jnatest;

import com.sun.jna.NativeLibrary;
import java.util.logging.Logger;
import java.util.logging.FileHandler;

public class MainClass {
    public static void main(String[] args) throws Exception  {
        NativeLibrary.addSearchPath("JNATestC", "C:\\JNATest");

        Logger log = Logger.getLogger("Test");
        FileHandler fileTxt = new FileHandler("Logging.txt");
        log.addHandler(fileTxt);

        LoggerStruct logStruct = new LoggerStruct(log);

        ITestLib.INSTANCE.callbackTest(logStruct);
    }
}

C++

JNATestC.h

#pragma once

extern "C" {
    struct LoggerStruct {
        int (*getLevel)();
    }
    __declspec(dllexport) void callbackTest(LoggerStruct * logStruct);
}

namespace JnaWrapperTypes {
    public ref class Logger { // "public ref" because I have to use it in C# as well
        private:
            LoggerStruct * logStruct;
        public:
            Logger(LoggerStruct * logStruct);
            ~Logger() {} 
            int getLevel();
    };
}

JNATestC.cpp

#include "stdafx.h"
#include <vcclr.h>
#include "JNATestC.h"

namespace JnaWrapperTypes {
    Logger::Logger(LoggerStruct * logStruct) {
        this->logStruct = logStruct;
    }
    Logger::getLevel() {
        return logStruct->getLevel();
    }
}

using namespace JnaWrapperTypes;
using namespace StaticCSharpNamespace; // Just an example. Not existing C# lib.

extern "C" {
    __declspec(dllexport) void callbackTest(LoggerStruct * logStruct) {
        int level = logStruct->getLevel();

        gcroot<Logger^> logger = gcnew Logger(logStruct); // IF I ADD "gcroot" FOR "Logger" THEN WHOLE INVOKE FAILS
        level = logger->getLevel();

        StaticCSharpClass::staticMethod(logger); // I want to pass Managed object to C# later

        gcroot<System::String^> str = gcnew System::String(""); // This doesn't generate error
    }
}

I wrote these on the fly. I hope these validate as well.

What am I doing wrong? For example if I use…

gcroot<System::String^> str = gcnew System::String("");

…everything works just fine.

Is there another way to pass managed object to C#?

Log for this error LOG

UPDATE

It seems that anykind of my own Class usage will head me to failure.

UPDATE

Anykind of my own Managed object or function use heads me to failure.

UPDATE

StaticCSharpClass::staticMethod(); fails as well. Looks like all operations related to Managed objects fail.

UPDATE

If I invoke the same method from .NET, everything works fine.

just to make this problem more findable
Internal Error (0xe0434352)

  • 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-29T16:59:14+00:00Added an answer on May 29, 2026 at 4:59 pm

    Should have googled for error “Internal Error (0xe0434352)”.

    http://jira.talendforge.org/browse/TDI-19427

    It leads to point that I have to register the dll for GAC (Global Assembly Cache), because Java searches only GAC and Application Base directories for dll. And because Java.exe paths aren’t configurable.

    == Solution ==

    Use post build event to register assembly for GAC:

    gacutil /i "$(TargetPath)"
    

    Great monologue! =)

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

Sidebar

Related Questions

I am trying to make an ajax json callback using a .net application. So
I'm trying to make an asynchronous HTTP GET request using Webclient, however, the registered
Hope this doesn't get too complicated. :) thing is.. I'm trying to make my
I'm trying to make Jeditable works on new elements created using this jquery file
I'm trying to make an SSL call using HTTPWebRequest and its continually failing saying
I am trying to make an asynchronous request to get some data from my
I'm trying to make some div to animate, then in the callback, call another
I am trying to make my Ajax-enabled table pagination 508-compliant (accessible using JAWS version
So, I'm trying to make a simple call using jQuery .getJSON to my local
I'm trying to make a javascript game and I'm using WebSQL to store game

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.