How to pass a JNI C# class into Java or handle this situation?

前端 未结 6 2667
[愿得一人]
[愿得一人] 2021-02-20 01:42

I\'m trying to call a Java method from C#, it\'s called like this from java:

EgamePay.pay(thisActivity, payAlias, new EgamePayListener() {
            @Override
         


        
6条回答
  •  终归单人心
    2021-02-20 01:58

    You can link these projects together in VS201X via references. From here, you should be able to fill in the other layers(JNI/Java), and then start passing your pointers(as a long) around the system and invoking your functions.

    C# Layer

    Program.cs

    namespace CSharpLayer
    {
    class Program : CLILayer.CLIObject
    {
        static void Main(string[] args)
        {
            Program p = new Program();
    
            p.invokeJava();
        }
    
        public void invokeJava()
        {
            //Call into CLI layer function to loadJVM, call Java code, etc
            loadJava();
        }
    
        public override void callback(string data)
        {
            //This will be called from the CLI Layer.
        }
    
    }
    }
    

    C++/CLI Layer - DLL C++ project w/ CLR support(/clr)

    CLIObject.h

    #pragma once
    
    namespace CLILayer
    {
    public ref class CLIObject
    {
        public:
            CLIObject();
            ~CLIObject();
    
            void loadJava(System::String^ jvm, System::String^ classpath);
    
            virtual void callback(System::String^ data) = 0;
    };
    }
    

    CLIObject.cpp

    #include "CLIObject.h"
    #include 
    
    #include 
    #include 
    
    using namespace msclr::interop;
    using namespace CLILayer;
    
    CLIObject::CLIObject()
    {   
    }
    
    CLIObject::~CLIObject()
    {
    }
    CLIObject::loadJava(System::String^ jvmLocaion, System::String^ classpath)
    {
        std::string _jvmLoc = marshal_as(jvmLocation);
        std::string _classpath = marshal_as(classpath);
    }
    

提交回复
热议问题