• [JNA系列]Java调用Delphi编写的Dll之实例Delphi使用PAnsiChar


    Delphi代码

     1 unit UnitDll;
     2 
     3 interface
     4 
     5 uses
     6   StrUtils, SysUtils, Dialogs;
     7 
     8 function DoBusinessAnsi(pvData: PAnsiChar): PAnsiChar; stdcall;
     9 
    10 implementation
    11 
    12 function DoBusinessAnsi(pvData: PAnsiChar): PAnsiChar; stdcall;
    13 var
    14   lvData: AnsiString;
    15 begin
    16   ShowMessage(pvData);
    17   lvData := pvData;
    18   ShowMessage(lvData);
    19   lvData := lvData + FormatDateTime('YYYYMMDDHHMMSSZZZ',Now);
    20   Result := PAnsiChar(lvData);
    21   ShowMessage(Result);
    22 end;
    23 
    24 end.

    Java调用代码

     1 package com.jna.demo;
     2 
     3 import com.sun.jna.Library;
     4 import com.sun.jna.Native;
     5 
     6 public class JnaDemo {
     7     
     8     public interface RtcPubLibrary extends Library{
     9         RtcPubLibrary instance = (RtcPubLibrary) Native.loadLibrary("JavaDll", RtcPubLibrary.class);
    10         public String DoBusinessAnsi(String pvData);
    11     }
    12 
    13     public static void main(String[] args) {
    14         System.setProperty("jna.encoding", "GBK");
    15         StringBuilder sBuilder = new StringBuilder();
    16         sBuilder.append("123测试");
    17         String pvData2 = sBuilder.toString();
    18         System.out.println("String-->" + RtcPubLibrary.instance.DoBusinessAnsi(pvData2));
    19     }
    20 
    21 }

    正常返回结果:String-->123测试20160825160443394

  • 相关阅读:
    两元素交换(不借用第三个元素)
    魔兽系统
    员工打卡
    NET框架
    jQuery测试
    Android屏幕适配终结者
    android-auto-scroll-view-pager (无限广告轮播图)
    AndroidImageSlider(图片轮播控件)
    PagerSlidingTabStrip(viewPage滑动菜单)
    怎样把淘宝的数据转到拍拍上
  • 原文地址:https://www.cnblogs.com/zhunian/p/5807228.html
Copyright © 2020-2023  润新知