Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Java invokes dll files

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to call the dll file by Java, which is very detailed and has certain reference value. Friends who are interested must finish it!

Java calls the dll file

Recently, according to C++ to do a picture quality inspection project, currently need to be called in java, so first generate dll file on C++, and then call dll file based on java to achieve the function.

Environment

C++:VS2017 (it was fatal to configure opencv before)

Java:idea2020+jdk1.8 .

Note: be careful when installing jdk, the path path is easy to edit, do not create it, it will be overwritten.

Next, let's go to the text.

1. To create a Java project, suppose you define the HelloWorld function, where "winproject1" is the dll file to be called later, now enter cmd and cd to the current directory, and then javah-jni HelloWorld.HelloWorld, which will generate a HelloWorld_HelloWorld.h under the directory.

Later, you need to move this header file to the include in the previous installation jdk directory, such as: DJava% your path%\ Java\ include.

two。 Open vs2017, create a new console project, and then configure the path where the project contains the directory, adding the following two paths, and the insurance point can add these paths to the additional directory.

Write the code in the header file above in vs2017:

JNIEXPORT void JNICALL Java_HelloWorld_HelloWorld_sayHello (JNIEnv *, jobject, jstring, jstring) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report