如果我想用Java调VC写的DLL,可以吗?

hongliang_hu 2002-02-07 03:25:25
如果我想用Java调VC写的DLL,可以吗?
...全文
62 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongliang_hu 2002-02-08
  • 打赏
  • 举报
回复
But if there is no HWND,how can I draw my graphics by calling C++ DLL ? I can not get the varay "HWND" , it is no use to pass stream to DLL .
passingguy 2002-02-07
  • 打赏
  • 举报
回复
my god ,
you copy the documents?
why don't you paste more?
shit!
scarab 2002-02-07
  • 打赏
  • 举报
回复
The Java Native Interface (JNI) is the native programming interface for Java that is part of the JDK. By writing programs using the JNI, you ensure that your code is completely portable across all platforms.

The JNI allows Java code that runs within a Java Virtual Machine (VM) to operate with applications and libraries written in other languages, such as C, C++, and assembly. In addition, the Invocation API allows you to embed the Java Virtual Machine into your native applications.

Programmers use the JNI to write native methods to handle those situations when an application cannot be written entirely in the Java programming language. For example, you may need to use native methods and the JNI in the following situations:


?The standard Java class library may not support the platform-dependent features needed by your application.
?You may already have a library or application written in another programming language and you wish to make it accessible to Java applications.
?You may want to implement a small portion of time-critical code in a lower-level programming language, such as assembly, and then have your Java application call these functions.


Programming through the JNI framework lets you use native methods to do many operations. Native methods may represent legacy applications or they may be written explicitly to solve a problem that is best handled outside of the Java programming environment.

The JNI framework lets your native method utilize Java objects in the same way that Java code uses these objects. A native method can create Java objects, including arrays and strings, and then inspect and use these objects to perform its tasks. A native method can also inspect and use objects created by Java application code. A native method can even update Java objects that it created or that were passed to it, and these updated objects are available to the Java application. Thus, both the native language side and the Java side of an application can create, update, and access Java objects and then share these objects between them.

Native methods can also easily call Java methods. Often, you will already have developed a library of Java methods. Your native method does not need to "re-invent the wheel" to perform functionality already incorporated in existing Java methods. The native method, using the JNI framework, can call the existing Java method, pass it the required parameters, and get the results back when the method completes.

The JNI enables you to use the advantages of the Java programming language from your native method. In particular, you can catch and throw exceptions from the native method and have these exceptions handled in the Java application. Native methods can also get information about Java classes. By calling special JNI functions, native methods can load Java classes and obtain class information. Finally, native methods can use the JNI to perform runtime type checking.
passingguy 2002-02-07
  • 打赏
  • 举报
回复
as i know, no HWND in java.
and even object can be passed, how about struct???
but i suggest you to use stream.
it can be reconstructed to everything that you want.

give me points!!!!!!!!!!!!!!!!!!!!!!
hongliang_hu 2002-02-07
  • 打赏
  • 举报
回复
Thanks a lot . Can you tell me is there HWND in Java ?
And if I want pass a region to my DLL wtitten by C++ ,
is Java able to pass a struct such as "RECT" into the
DLL written by C++ .
passingguy 2002-02-07
  • 打赏
  • 举报
回复
appendix:
JNI是什么?怎么包装?Java还可以调本地的DLL吗?
包装 means change the name for java to use.
remember,only dll by c/c++ can be used by java.

will you give me points??
I am waiting.............................
passingguy 2002-02-07
  • 打赏
  • 举报
回复
first,i have to say sorry that I have no Chinese Input Methods here.
so,i must write in English as well.
:-(
You can use JNI to dispatch these problems.
I think if you really wanna do so,
you may define your native methods' name first,
then, use Javah.exe to create the header file for c/c++
in your c/c++ program, you can copy the names and paramers of methods in that .h file(and you have to do so) as the definitions.
Then , fill your methods, and make a .dll,
in java program, use System.load("name of dll")
now, you can use them

attention:you must use key word "native" to declare your java methods like this
public native void myMethod(type parameter)
and you must think about the difference of types between java and c++,
if I were you, I would use stream as return type and parameter.
in java and c++,the standard streams are the same.
hongliang_hu 2002-02-07
  • 打赏
  • 举报
回复
先直接给点感性认识。我想用VC写个底层,通用的,可以给Java、ASP、Delphi等,可是,Java等方面的知识太少。我现在只要一些概念,心里有个低。
wolfsquare 2002-02-07
  • 打赏
  • 举报
回复
JNI教程
http://java.sun.com/docs/books/tutorial/native1.1/index.html
hongliang_hu 2002-02-07
  • 打赏
  • 举报
回复
JNI是什么?怎么包装?Java还可以调本地的DLL吗?
wolfsquare 2002-02-07
  • 打赏
  • 举报
回复
可以,当然前提是要用JNI来给该DLL做一层包装。

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧