| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> delphi >> bian cheng ying yong shi li :Java tong guo JNI yu Delphi jiao hu

bian cheng ying yong shi li :Java tong guo JNI yu Delphi jiao hu

2008-06-01 03:23:07 编辑來源:互联网 评论
 
 
 
本文为【编程应用实例:Java通过JNI与Delphi交互】的拼音翻译版
  qian yi duan shi jian , wo yong java kai fa yi ge an zhuang cheng xu , shi yong yu tomcat mysql gou jian de web huan jing 。 zai kai fa de guo cheng zhong yu dao yu xie zhu ce biao , zhu ce xi tong fu wu deng wen ti yong java ben shen hen nan jie jue , yu shi wo xiang dao yong JNI。C yu delphi liang zhe kai fa JNI, wo shi cong delphi zhuan dao java shang lai de , wo xuan ze le delphi。
  yong delphi kai fa JNI, shou xian cong http://delphi-jedi.org xia zai JNI.pas, ba ta jia ru dao gong cheng zhong jiu ke yi kai fa JNI le 。
  li ru chuang jian zhuo mian kuai jie fang shi :
  Delphi zhong de dai ma :
  library myDll
  uses
  JNI,windows,ComObj,ActiveX,ShlObj,SysUtils,Registry;
  // qu de zhuo mian mu lu
  function getDesktopPath():String;
  var
  Reg:TRegistry;
  DesktopPath:String;
  begin
  Reg:=TRegistry.Create;
  try
  Reg.RootKey:=HKEY_CURRENT_USER;
  Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',False);
  if Reg.ValueExists('Desktop') then DesktopPath:=Reg.ReadString('Desktop');
  Result:= DesktopPath;
  finally
  Reg.Free;
  end;
  end;
  // chuang jian zhuo mian kuai jie fang shi
  procedure CreateDesktopLink(ProgramPath, ProgramArg, LinkName, Descr,IconPath: String);
  var
  AnObj: IUnknown;
  ShellLink: IShellLink;
  AFile: IPersistFile;
  FileName: WideString;
  LinkPath:String;
  begin
  LinkPath:=getDesktopPath()+'\'+linkName;
  if UpperCase(ExtractFileExt(LinkPath))<>'.LNK' then // jian cha kuo zhan ming shi fou zheng que
  begin
  raise Exception.Create(' kuai jie fang shi de kuo zhan ming bi xu shi .lnk!');
  end;
  try
  OleInitialize(nil);// chu shi hua OLE ku , zai shi yong OLE han shu qian bi xu tiao yong chu shi hua
  AnObj := CreateComObject(CLSID_ShellLink);// gen ju gei ding de ClassID sheng cheng yi ge COM dui xiang , ci chu shi kuai jie fang shi
  ShellLink := AnObj as IShellLink;// qiang zhi zhuan huan wei kuai jie fang shi jie kou
  AFile := AnObj as IPersistFile;// qiang zhi zhuan huan wei wen jian jie kou
  // she zhi kuai jie fang shi shu xing , ci chu zhi she zhi le ji ge chang yong de shu xing
  ShellLink.SetPath(PChar(ProgramPath)); // kuai jie fang shi de mu biao wen jian , yi ban wei ke zhi xing wen jian
  ShellLink.SetArguments(PChar(ProgramArg));// mu biao wen jian shen shu
  ShellLink.SetWorkingDirectory(PChar(ExtractFilePath(ProgramPath)));// mu biao wen jian de gong zuo mu lu
  ShellLink.SetDescription(PChar(Descr));// dui mu biao wen jian de miao shu
  ShellLink.SetIconLocation(PChar(IconPath),0);
  FileName := LinkPath;// ba wen jian ming zhuan huan wei WideString lei xing
  AFile.Save(PWChar(FileName), False);// bao cun kuai jie fang shi
  finally
  OleUninitialize;// guan bi OLE ku , ci han shu bi xu yu OleInitialize cheng dui tiao yong
  end;
  end;
  // chuang jian zhuo mian kuai jie fang shi , zai JNI zhong tiao yong de jiu shi zhe ge fang fa
  // zhe ge guo cheng de ming ming hen you jiang jiu , ta yi Java kai tou , yong xia hua xian jiang Java lei de bao ming 、 lei ming he fang fa ming lian qi lai 。 zhe ge ming ming fang fa bu neng you wu , fou ze , Java lei jiang wu fa jiang nativ fang fa yu ta dui ying qi lai 。 tong shi , zai Win32 ping tai shang , ci guo cheng de tiao yong fang shi zhi neng sheng ming wei stdcall 。
  procedure Java_com_wpd_JavaWindows_createDesktopLink(PEnv: PJNIEnv; Obj: JObject;ProgramPath,ProgramArg,LinkName,Descr,iconPath:JString);stdcall;
  var
  JVM:TJNIEnv;
  PPath:String;
  PArg:String;
  LName:String;
  Description:String;
  IPath:String;
  begin
  JVM := TJNIEnv.Create(PEnv);
  PPath:=JVM.UnicodeJStringToString(ProgramPath);
  PArg:=JVM.UnicodeJStringToString(ProgramArg);
  LName:=JVM.UnicodeJStringToString(LinkName);
  Description:=JVM.UnicodeJStringToString(Descr);
  IPath:=JVM.UnicodeJStringToString(IconPath);
  CreateDesktopLink(PPath,PArg,LName,Description,IPath);
  JVM.Free;
  end;
  // xiang java fa song yi ge xin xi
  function Java_com_wpd_JavaWindows_sendMessage(PEnv: PJNIEnv; Obj: JObject):JObject;stdcall;
  var
  JVM:TJNIEnv;
  msg:JObject;
  m:String;
  begin
  JVM := TJNIEnv.Create(PEnv);
  //********* ru guo fa song de xin xi zhong bao han zhong wen zi fu , ze yao xian yao jing guo UTF8Encode zhuan ma , fou ze zai java zhong qu de shi hui shi luan ma
  m:=UTF8Encode(' zhong guo ren ');
  msg:=JVM.StringToJString(PChar(m));
  result:= msg;
  end;
  {$R *.res}
  exports
  Java_com_wpd_JavaWindows_createDesktopLink,
  Java_com_wpd_JavaWindows_sendMessage;
  end.
  ba shang mian de bian yi sheng cheng myDll.dll wen jian , fang dao java neng gou zhao dao de di fang 。
  java zhong de dai ma :
  package com.wpd;
  public class JavaWindows {
  public native void createDesktopLink(String programPath,String programArg,String linkPath,String description,String iconPath);
  public native String sendMessage();
  static{
  System.loadLibrary("myDll");
  }
  public static void main(String s[]){
  new JavaWindows().createDesktopLink("c:\text.exe",""," ce shi .LNK","","c:\test.ico");
  System.out.println(new JavaWindows().sendMessage());
  }
  }【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
qian yi duan shi jian , wo yong java kai fa yi ge an zhuang cheng xu , shi yong yu tomcat mysql gou jian de web huan jing 。 zai kai fa de guo cheng zhong yu dao yu xie zhu ce biao , zhu ce xi tong fu wu deng wen ti yong java ben shen hen nan jie jue , yu shi wo xiang dao yong JNI。C yu delphi liang zhe kai fa JNI, wo shi cong delphi zhuan dao java shang lai de , wo xuan ze le delphi。 yong delphi kai fa JNI, shou xian cong http://delphi-jedi.org  xia zai JNI.pas, ba ta jia ru dao gong cheng zhong jiu ke yi kai fa JNI le 。 li ru chuang jian zhuo mian kuai jie fang shi : Delphi zhong de dai ma : library myDll uses JNI,windows,ComObj,ActiveX,ShlObj,SysUtils,Registry; // qu de zhuo mian mu lu function getDesktopPath():String; var Reg:TRegistry; DesktopPath:String; begin Reg:=TRegistry.Create; try Reg.RootKey:=HKEY_CURRENT_USER; Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',False); if Reg.ValueExists('Desktop') then DesktopPath:=Reg.ReadString('Desktop'); Result:= DesktopPath; finally Reg.Free; end; end; // chuang jian zhuo mian kuai jie fang shi procedure CreateDesktopLink(ProgramPath, ProgramArg, LinkName, Descr,IconPath: String); var AnObj: IUnknown; ShellLink: IShellLink; AFile: IPersistFile; FileName: WideString; LinkPath:String; begin LinkPath:=getDesktopPath()+'\'+linkName; if UpperCase(ExtractFileExt(LinkPath))<>'.LNK' then // jian cha kuo zhan ming shi fou zheng que begin raise Exception.Create(' kuai jie fang shi de kuo zhan ming bi xu shi .lnk!'); end; try OleInitialize(nil);// chu shi hua OLE ku , zai shi yong OLE han shu qian bi xu tiao yong chu shi hua AnObj := CreateComObject(CLSID_ShellLink);// gen ju gei ding de ClassID sheng cheng yi ge COM dui xiang , ci chu shi kuai jie fang shi ShellLink := AnObj as IShellLink;// qiang zhi zhuan huan wei kuai jie fang shi jie kou AFile := AnObj as IPersistFile;// qiang zhi zhuan huan wei wen jian jie kou // she zhi kuai jie fang shi shu xing , ci chu zhi she zhi le ji ge chang yong de shu xing ShellLink.SetPath(PChar(ProgramPath)); // kuai jie fang shi de mu biao wen jian , yi ban wei ke zhi xing wen jian ShellLink.SetArguments(PChar(ProgramArg));// mu biao wen jian shen shu ShellLink.SetWorkingDirectory(PChar(ExtractFilePath(ProgramPath)));// mu biao wen jian de gong zuo mu lu ShellLink.SetDescription(PChar(Descr));// dui mu biao wen jian de miao shu ShellLink.SetIconLocation(PChar(IconPath),0); FileName := LinkPath;// ba wen jian ming zhuan huan wei WideString lei xing AFile.Save(PWChar(FileName), False);// bao cun kuai jie fang shi finally OleUninitialize;// guan bi OLE ku , ci han shu bi xu yu OleInitialize cheng dui tiao yong end; end; // chuang jian zhuo mian kuai jie fang shi , zai JNI zhong tiao yong de jiu shi zhe ge fang fa // zhe ge guo cheng de ming ming hen you jiang jiu , ta yi Java kai tou , yong xia hua xian jiang Java lei de bao ming 、 lei ming he fang fa ming lian qi lai 。 zhe ge ming ming fang fa bu neng you wu , fou ze , Java lei jiang wu fa jiang nativ fang fa yu ta dui ying qi lai 。 tong shi , zai Win32 ping tai shang , ci guo cheng de tiao yong fang shi zhi neng sheng ming wei stdcall 。 procedure Java_com_wpd_JavaWindows_createDesktopLink(PEnv: PJNIEnv; Obj: JObject;ProgramPath,ProgramArg,LinkName,Descr,iconPath:JString);stdcall; var JVM:TJNIEnv; PPath:String; PArg:String; LName:String; Description:String; IPath:String; begin JVM := TJNIEnv.Create(PEnv); PPath:=JVM.UnicodeJStringToString(ProgramPath); PArg:=JVM.UnicodeJStringToString(ProgramArg); LName:=JVM.UnicodeJStringToString(LinkName); Description:=JVM.UnicodeJStringToString(Descr); IPath:=JVM.UnicodeJStringToString(IconPath); CreateDesktopLink(PPath,PArg,LName,Description,IPath); JVM.Free; end; // xiang java fa song yi ge xin xi function Java_com_wpd_JavaWindows_sendMessage(PEnv: PJNIEnv; Obj: JObject):JObject;stdcall; var JVM:TJNIEnv; msg:JObject; m:String; begin JVM := TJNIEnv.Create(PEnv);     //********* ru guo fa song de xin xi zhong bao han zhong wen zi fu , ze yao xian yao jing guo UTF8Encode zhuan ma , fou ze zai java zhong qu de shi hui shi luan ma m:=UTF8Encode(' zhong guo ren '); msg:=JVM.StringToJString(PChar(m)); result:= msg; end; {$R *.res} exports Java_com_wpd_JavaWindows_createDesktopLink, Java_com_wpd_JavaWindows_sendMessage; end. ba shang mian de bian yi sheng cheng myDll.dll wen jian , fang dao java neng gou zhao dao de di fang 。 java zhong de dai ma : package com.wpd; public class JavaWindows { public native void createDesktopLink(String programPath,String programArg,String linkPath,String description,String iconPath); public native String sendMessage(); static{ System.loadLibrary("myDll"); } public static void main(String s[]){ new JavaWindows().createDesktopLink("c:\text.exe",""," ce shi .LNK","","c:\test.ico"); System.out.println(new JavaWindows().sendMessage()); } }
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有