Java and C language interface

  Step 1: Statement of local variables 

  For example: class NativeHello ( 

  Public native void nativeHelloWorld (); 

  (Static 

  System.loodlibrary ( "nativeTest ");// call nativeTest.dll library files 

  ) 

  ) 

  Step 2: generating header files 

  NativeHello.java javac compiler to use, reuse javah generated c of the headers. H documents 

  Step 3: Root document generation 

  Order as follows: javah-stubs NativeHello (Generation NativeHello.c) 

  Step 4: Prepare a C program (here assumed that document, entitled NativeTest.c) 

  # Include <stdio.h> 

  # Include <NativeHello.h> / / refers to the second step of the production. H documents 

  # Include <stubpreamble.h> / / JDK that the document include the 

  Void Nativehello_nativeHelloWorld (struct HNativeHello * this) ( 

………

  ) / * Function names Nativehello_nativeHelloWorld not arbitrary designation, can be generated from the first javah identified in the document, can also be used 

  Naming the following methods: class name _ the local approach (struct H * this category) * / 

  Step 5: Build DLL files 

  NativeHello.c nativeTest.c and will be compiled as DLL library files, the file name and System.loodlibrary ( "nativeTest") the same name in the paper 

  Finally talk about the testing method, source files are as follows: 

  (Class UseNative 

  Public static void main (String [] args) ( 

  NativeHello nh = new NativeHello (); 

  Nh.nativeHelloWorld (); 

  ) 

  ) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , ,

Releated Java Articles

Comments

Leave a Reply