Using JNative call dll

| 1 TrackBack

Reference from JNative Howto

JNative is simpler than JNI.

1.Copy JNativeCpp.dll to Windows/systems32 folder.
2.Copy JNative.jar to your java project lib folder.
3.The example code to call dll function:

package jnative;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.xvolks.jnative.JNative;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.Type;

public class OMSignAPI {

    public static final String DLL_NAME = "C:\\Program Files\\OrderMaster\\OMSignAPI.dll";
    private static JNative api;

    public static void main(String[] args) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd kk:mm:ss");
        Timestamp now = new Timestamp(new Date().getTime());
        
        try {
            GoOrder("MTX001","",dateFormat.format(now).toString(),1,7400);
        } catch (NativeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static final void IniDllAndPosition(String signID,
            int iniPosition) throws NativeException, IllegalAccessException {
        api = new JNative(DLL_NAME, "IniDllAndPosition");
        api.setRetVal(Type.INT);
        int i = 0;
        api.setParameter(i++, Type.STRING, signID);
        api.setParameter(i++, Type.INT, "" + iniPosition);
        api.invoke();
        int a = Integer.parseInt(api.getRetVal());
        if (a == 0){
            System.out.println("OMSignAPI IniDllAndPosition Error!!");
        }
    }

    public static final void GoOrder(String signID, String bySignStr,
            String dateTimeStr, int nowPosition, double nowPrice)
            throws NativeException, IllegalAccessException {
        api = new JNative(DLL_NAME, "GoOrder");
        api.setRetVal(Type.INT);
        int i = 0;
        api.setParameter(i++, Type.STRING, signID);
        api.setParameter(i++, Type.STRING, bySignStr);
        api.setParameter(i++, Type.STRING, dateTimeStr);
        api.setParameter(i++, Type.INT, "" + nowPosition);
        api.setParameter(i++, Type.DOUBLE, "" + nowPrice + ".0");
        api.invoke();
        int a = Integer.parseInt(api.getRetVal());
        if (a == 0){
            System.out.println("OMSignAPI GoOrder Error!!");
        }
    }
}

1 TrackBack

TrackBack URL: http://server.everfine.com.tw/blog/mt-tb.cgi/289

Using JNA call dll from Philipz學習日誌 on August 23, 2010 4:12 PM

JNA is simpler than JNative. Using JNative call dll is howto use JNative call dll, but its code is more... Read More

February 2012

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Archives

Powered by Movable Type 4.34-en

About this Entry

This page contains a single entry by philipz published on March 30, 2010 4:12 PM.

JNDI Setting of Hibernate on Websphere 6.x was the previous entry in this blog.

VMWare NAT problems on Windows 2008 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.