简体   繁体   中英

Calling java method from c++ code, without passing any JavaVm

I have class in C++ which must response for HTTP connection, that class must establish connection , send responses and do some other functions. This class is a part of huge project which I compile and finally get .so library for Android.

class HTTPSClient
{
public:
    WinHTTPSClient();

    ~WinHTTPSClient();

    bool Connect(const XMLString& a_strURL);
};

Now I want to call java functions from Connect function in c++. I have experiences in calling java functions from C++ code, but I always pass JavaVM to the class for example I call init(JavaVM* javaVm); and give as an argument javavm which comes from native code.

Now my question is: Can I call java method from C++ code without passing as an argument any JavaVm.

Define the JavaVM as a global/static variable of some class, eg, by wrapping it up as a singleton. The variable can be accessed without explicitly passing it as an argument.

You can use the Java Invocation API to create a VM directly in your native code.

Jim S.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM