JNA to call Native Function

JNA to Call Native Function

Page 1 of 1

4 Replies - 1997 Views - Last Post: 21 December 2010 - 04:24 PM Rate Topic: -----

#1 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

JNA to call Native Function

Posted 19 December 2010 - 12:03 PM

I am new to JNA nd have a function in C
GetProductString( DWORD DeviceNum,LPVOID DeviceString, DWORD Options )


how to call this in JNA any idea please.
Is This A Good Question/Topic? 0
  • +

Replies To: JNA to call Native Function

#2 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

Re: JNA to call Native Function

Posted 21 December 2010 - 02:40 AM

I have this native function and I get the null value in JNA when I attach device to my system I think i have problem in LPVOID maping with JNA any Idea will be appreciated.

CP210x_GetProductString( DWORD DeviceNum,LPVOID DeviceString,DWORD Options)


1.DeviceNum—Index of the device for which the product description string, serial number, or full path is desired. 2.DeviceString—Variable of type CP210x_DEVICE_STRING returning the NULL-terminated serial number, device description or full path string. 3.Options—Flag that determines if DeviceString contains the product description, serial number, or full-path string
JNA code.........................................

public class Helloworld { public interface CLibrary extends Library{
CLibrary INSTANCE=(CLibrary)Native.loadLibrary((Platform.isWindows()? "CP210xManufacturing.dll":"c"),CLibrary.class); 

int CP210x_GetProductString(int dn,String [] ds,int op);

}
public static void main(String[] args) {

 int dn=0;
 String dsc=new String [100];
  if(CLibrary.INSTANCE.CP210x_GetProductString(dn,dsc,CP210x.CP210x_RETURN_SERIAL_NUMBER)==CP210x.CP210x_SUCCESS){

      {
         for(int i=0;i<dsc.length;i++)
          System.out.print(dsc[i]);
      }

  }
} }

This post has been edited by deartahir: 21 December 2010 - 02:41 AM

Was This Post Helpful? -1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: JNA to call Native Function

Posted 21 December 2010 - 04:33 AM

Duplicated topics merged. Please avoid double postings. :(
Was This Post Helpful? 0
  • +
  • -

#4 deartahir  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 41
  • Joined: 28-February 10

Re: JNA to call Native Function

Posted 21 December 2010 - 06:02 AM

View Postpbl, on 21 December 2010 - 03:33 AM, said:

Sorry,But I have problem of type Mapping.any solution will be appreciated.

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: JNA to call Native Function

Posted 21 December 2010 - 04:24 PM

Not many people are doing JNA, sorry. Unless you really need to access a device driver most Java programmers will prefer a full Java solution. Unfortunaly you will have to wait for a JNA experienced person to pass by.
You might, I said might, have more chances in the C++ forum
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1