JavaÖÐÈçºÎµ÷ÓÃVCµÄ¶¯Ì¬¿â
ÒÔǰһƪµÄDLLΪÀý²ûÊöJavaÈçºÎµ÷Óö¯Ì¬¿â
Ä¿Ç°´æÔÚÒ»¸öVC±àÒëµÄ·ÇMFC¶¯Ì¬¿âDLL£¨¾ßÌåÈçºÎÉú³É·ÇMFC¶¯Ì¬¿âDLL¼ûǰһƪÎÄÕ£©£¬Ãû³ÆΪmydll.dll£¬ÆäÖÐÓе¼³öº¯Êýmyadd£ºÐÎÈ磺int myadd(int,int)£¬ÏÖjavaÓ¦ÓóÌÐòÐèÒªµ÷Óøö¯Ì¬¿âµÄmyaddº¯Êý¡£¾ßÌåʵÏÖ²½ÖèÈçÏ£º
1¡¢±àдµ÷ÓÃmydll.dllµÄjava³ÌÐò
£¨1£©³ÌÐòtestMyDll .javaÈçÏ£º
public class testMyDll {
private native static int myadd(int a,int b);
static {
System.loadLibrary("javamydll"); //¸Ã¶¯Ì¬¿âÃû³ÆΪÖм䶯̬¿â£¬ÓÉjava³ÌÐòʹÓ㬸ºÔðµ÷ÓÃÐèҪʹÓõĶ¯Ì¬¿â¡£
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(myadd(4,5));
}
}
£¨2£©±àÒëtestMyDll .java³ÌÐò£¬¼ì²éÊÇ·ñ´æÔÚ´íÎó¡£
javac testMyDll .java
2¡¢Éú³ÉÍ·ÎļþtestMyDll.h£¬¹©Éú³ÉÖм䶯̬¿âʹÓá£
javah testMyDll
3¡¢Éú³ÉÖм䶯̬¿âjavamydll.dll
£¨1£©Ê¹ÓÃvc¹¤¾ßÏÈÉú³Éwin32 Dynamic-Link Library¿Õ¹¤³Ì
£¨2£©½«ÉÏÃæÉú³ÉµÄÍ·ÎļþtestMyDll.hÌí¼Ó½øÈ¥£¬Í¬Ê±»¹ÐèÒªÌí¼ÓjdkÏÂincludeĿ¼ÖÐ µÄjni.h¡¢jni_md.hÕâÁ½¸öÍ·Îļþ£¬×îºÃ½«jni.hÎļþ·ÅÈ밲װĿ¼ÏÂincludeµÄĿ¼ÏÂ
£¨3£©Ìí¼Óµ÷ÓÃÐèҪʹÓõĶ¯Ì¬¿âµÄʵÏÖÎļþtestMyDll.cpp
³ÌÐòÈçÏ£º
//testMyDll.cpp
#include <windows.h>
#include "testMyDll.h"
typedef int (*padd)(int,int);
JNIEXPORT jint JNICALL Java_testMyDll_myadd
(JNIEnv * a, jclass b, jint x, jint y)
{
HINSTANCE hins = ::LoadLibrary("mydll.dll");
if(hins == NULL)
{
return 0;
}
int res;
padd pa = (padd)GetProcAddress(hins,"myadd");
if(pa != NULL)
{
res = x+y;
}
::FreeLibrary(hins);
return res;
}
£¨4£©±àÒëÉú³ÉÖм䶯̬¿âjavamydll.dll
4¡¢½«Öм䶯̬¿âjavamydll.dllºÍÐèʹÓõĶ¯Ì¬¿âmydll.dll·ÅÔÚtestMyDll.classĿ¼Ï£¬ÔËÐиÃÀà: java testMyDll
³ÌÐòÊä³ö½á¹û£º9
´ÓÉÏÊöʵÏÖ·½·¨ÖпÉÒÔ¿´µ½£¬javaÐèÒªµ÷ÓÃÒÑÓеĶ¯Ì¬¿â£¬»¹ÐèÒª×Ô¼ºÉú³ÉÒ»¸öÖм䶯̬¿â£¬¸ºÔðµ÷ÓÃת»»¡£ËùÒÔЧÂʾͻáÓеãµÍ¡£
Ïà¹ØÎĵµ£º
Java³ÌÐòÔ±µÄÍƼöÔĶÁÊé¼®¡·
JavaEye (http://www.javaeye.com)
×÷ΪJava³ÌÐòÔ±À´Ëµ£¬×îÍ´¿àµÄÊÂÇéĪ¹ýÓÚ¿ÉÒÔÑ¡ÔñµÄ·¶Î§Ì«¹ã£¬¿ÉÒÔ¶ÁµÄÊéÌ«¶à£¬ÍùÍùÈÝÒ×ÎÞËùÊÊ´Ó¡£ÎÒÏë¾ÍÎÒ×Ô¼º¶Á¹ýµÄ¼¼ÊõÊé¼®ÖÐÌôÑ¡³öÀ´Ò»Ð©£¬°´ÕÕѧϰµÄÏȺó˳Ðò£¬ÍƼö¸ø´ó¼Ò£¬ÌرðÊÇÄÇЩÏë²»¶ÏÌá¸ß×Ô¼º¼¼ÊõˮƽµÄJava³ÌÐòÔ±ÃÇ¡£
Ò»¡¢Java±à³ÌÈëÃÅÀà ......
Web ServiceµÄ·Ï»°¾Í²»ËµÁË¡£¾Í˵ÔõôʹÓðɡ£
1.ÐèÒªjava»·¾³ µ½http:.//java.sun.com/J2SE ¿ÉÒÔÏÂÔØ Java Development Kit
2.ÐèÒªGoogle APIµÄJarÎļþ£¬Googleapi.jar¡£¿ÉÒÔµ½http://www.google.com/apisÏÂÔØ¡£Ìî¼Ó½øCLASSPATH.
3.ÉêÇëGoogle·ÃÎÊÕʺţ¬Ä¿Ç°GoogleÖ§³ÖÃâ·ÑÉêÇëµÄ·½Ê½£¬Óû§ÐèҪʹÓÃÒ»¸öem ......
ÒÔÏÂÊǼÆËãÁ½¸öÊýÎó²îÊÇ·ñÔÚ10% £¬Èç¹ûÔÚ10%ÒÔÄÚÊÇÕý³££¬ÆäËûÊDz»Õý³££¬ÓýÏСµÄÊý*10%+ÓýÏСµÄÊý=ÓýÏСµÄÊý*1.1%
double costNum =2;//µç·Ñƽ¾ùÈÕµçÁ¿
double amountNum =3; //µçÁ¿Æ½¾ùÈÕµçÁ¿
if(amountNum ......
Chapter I.
JavaµÄÓÅȱµã¸÷ÖÖÊéÉ϶¼ÓУ¬ÕâÀïֻ˵˵ÓÃJava×öACM-ICPCµÄÌص㣺
(1) ×îÃ÷ÏԵĺô¦ÊÇ£¬Ñ§»áJava£¬¿ÉÒԲμÓJava Challenge
(2) ¶ÔÓÚÊìϤC/C++µÄ³ÌÐòÔ±À´Ëµ£¬Java ²¢²»ÄÑѧ£¬ÕÒ±¾Ê飬һÁ½ÖÜÒµÓàʱ¼ä¾Í¿ÉÒԸ㶨ÁË¡£µ±È»£¬ÕâÀïÖ»ÊÇÖ¸Ò»°ã±à³Ì£¬ÏëÊìϤËùÓеÄJava¿â»¹ÊÇÐèҪЩʱ¼äµÄ¡£ÊÂʵÉÏ£¬Java Ö ......