{"id":284888,"date":"2017-04-12T20:55:57","date_gmt":"2017-04-12T16:55:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284888"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284888","title":{"rendered":"JNI \u0438 Delphi. \u041f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0441 C++ \u043d\u0430 Delphi"},"content":{"rendered":"<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u0421++ \u043d\u0430 Delphi. \u0420\u0430\u0437 \u043c\u044b \u0437\u0430\u043d\u044f\u043b\u0438\u0441\u044c JNI, \u0442\u043e \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0421++ \u043d\u0430 Delphi. \u0418 \u0442\u0430\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0443\u0436\u0435 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u0443\u044e \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0441 \u0421++ \u043d\u0430 Delphi. \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u0430 \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043d\u0430 \u0421++:<\/p>\n<pre><code class=\"cpp\">JNIEXPORT void JNICALL Java_JavaHowTo_sayHello   (JNIEnv *env, jobject obj) {     const char *str;     jclass myclass_class =(jclass) env-&gt;NewGlobalRef           (env-&gt;FindClass (&quot;MyClass&quot;));     \/\/ we need the MyClass constructor         jmethodID constructorID = env-&gt;GetMethodID          (myclass_class, &quot;&quot;, &quot;()V&quot;);     \/\/ and the sayHello() method     jmethodID methodID = env-&gt;GetMethodID          (myclass_class, &quot;sayHello&quot;, &quot;()Ljava\/lang\/String;&quot;);     \/\/ instanciate a MyClass object     jobject myclass_object =  env-&gt;NewObject          (myclass_class, constructorID);     \/\/ call the sayHello() method     jstring s = (jstring)  env-&gt;CallObjectMethod          (myclass_object, methodID);     \/\/ convert the Java String to use it in C     str = env-&gt;GetStringUTFChars(s, 0);     printf(&quot;%s&quot; , str);     env-&gt;ReleaseStringUTFChars(s, str);       }<\/code><\/pre>\n<p> \u0410 \u0442\u0430\u043a \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430 Delphi:<a name=\"habracut\"><\/a><\/p>\n<pre><code class=\"delphi\">procedure Java_JavaHowTo_sayHello(JNIEnv: PJNIEnv; Obj: JObject); var  myclass_class: JClass;  constructorID, methodID: JMethodID;  myclass_object: JObject;  s: JString;  Str: PAnsiChar; begin  myclass_class:= JNIenv^.NewGlobalRef(JNienv, JNIEnv^.FindClass(JNIEnv, 'MyClass'));  \/\/ we need the MyClass constructor  constructorID:= JNIEnv^.GetMethodID(JNIEnv, myclass_class, '', '()V');  \/\/ and the sayHello() method  methodID:= JNIEnv^.GetMethodID(JNIEnv, myclass_class, 'sayHello', '()Ljava\/lang\/String;');  \/\/ instanciate a MyClass object  myclass_object:= JNIEnv^.NewObject(JNIEnv, myclass_class, constructorID);  \/\/ call the sayHello() method  s:= JNIEnv^.CallObjectMethod(JNIEnv, myclass_object, methodID);  \/\/ convert the Java String to use it in C  str:= JNIEnv^.GetStringUTFChars(JNIEnv, s, 0);  JNIEnv^.ReleaseStringUTFChars(JNIEnv, s, str); end;<\/code><\/pre>\n<p> \u0418 \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u044f \u0443\u0431\u0440\u0430\u043b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0443\u0441\u043e\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u00abprintf(\u00bb%s&quot;, str);&quot; \u0438 \u0443\u043a\u0430\u0437\u0430\u043b \u00abStr\u00bb \u043d\u0435 \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u043b \u043a\u0430\u043a PAnsiChar \u0442.\u0435. \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0438 \u043e\u0442 \u043d\u0438\u0445 \u043d\u0438\u043a\u0443\u0434\u0430 \u043d\u0435 \u0434\u0435\u0442\u044c\u0441\u044f =)<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/326364\/\"> https:\/\/habrahabr.ru\/post\/326364\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u0421++ \u043d\u0430 Delphi. \u0420\u0430\u0437 \u043c\u044b \u0437\u0430\u043d\u044f\u043b\u0438\u0441\u044c JNI, \u0442\u043e \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0421++ \u043d\u0430 Delphi. \u0418 \u0442\u0430\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0443\u0436\u0435 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u0443\u044e \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0441 \u0421++ \u043d\u0430 Delphi. \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u0430 \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043d\u0430 \u0421++:<\/p>\n<pre><code class=\"cpp\">JNIEXPORT void JNICALL Java_JavaHowTo_sayHello   (JNIEnv *env, jobject obj) {     const char *str;     jclass myclass_class =(jclass) env-&gt;NewGlobalRef           (env-&gt;FindClass (&quot;MyClass&quot;));     \/\/ we need the MyClass constructor         jmethodID constructorID = env-&gt;GetMethodID          (myclass_class, &quot;&quot;, &quot;()V&quot;);     \/\/ and the sayHello() method     jmethodID methodID = env-&gt;GetMethodID          (myclass_class, &quot;sayHello&quot;, &quot;()Ljava\/lang\/String;&quot;);     \/\/ instanciate a MyClass object     jobject myclass_object =  env-&gt;NewObject          (myclass_class, constructorID);     \/\/ call the sayHello() method     jstring s = (jstring)  env-&gt;CallObjectMethod          (myclass_object, methodID);     \/\/ convert the Java String to use it in C     str = env-&gt;GetStringUTFChars(s, 0);     printf(&quot;%s&quot; , str);     env-&gt;ReleaseStringUTFChars(s, str);       }<\/code><\/pre>\n<p> \u0410 \u0442\u0430\u043a \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430 Delphi:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284888","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284888"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284888\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}