Function call sample
import com.jniwrapper.AnsiString; import com.jniwrapper.Function; import com.jniwrapper.Int; import com.jniwrapper.Pointer; /** * This class demonstrates how to invoke native functions from dynamic-link libraries (DLL) using * the {@link Function} class. */ public class FunctionCallSample extends BasicJNIWrapperSample { /** * This method invokes the sumStdCall native function using the STDCALL calling convention. */ public static void returnValueSample() { int a = 10, b = 100; Function add = SAMPLE_LIB.getFunction("sumStdCall"); Int result = new Int(); add.invoke(result, new Int(a), new Int(b)); System.out.println("The sum of a = " + a + " and b = " + b + " is " + result.getValue()); } /** * This method invokes the printStringCdeclCall native function using the CDECL calling convention. * printStringCdeclCall prints the specified string to the standard output stream on the native side. */ public static void noReturnValueStdCallSample(){ String str ="This string was put to the out stream in printStringCdeclCall native function."; Function putString = SAMPLE_LIB.getFunction("printStringCdeclCall"); putString.setCallingConvention(Function.CDECL_CALLING_CONVENTION); putString.invoke(null, new Pointer(new AnsiString(str))); } public static void main(String[] args){ returnValueSample(); noReturnValueStdCallSample(); } }
Suppose that there is an existing application, written in C, that monitors conditions on a factory floor, and you need to incorporate this functionality into a Java application.
The traditional approach using JNI involves Java and C developers as well as management coordination to keep the functionality synchronized.
By contrast, using JNIWrapper is trivial and saves time and efforts dramatically.
JNIWrapper can handle large amounts of data involved in interactions between the Java and native code, with no tuning on your side.
You can implement new data types or customize existing ones, taking full control over the parameter behavior. See Structures and Unions in our Programmers Guide. See also the related samples: Union Sample, Union Structure.
In addition to a default mechanism for finding and loading a native library, JNIWrapper provides a way to customize the library loading. Also, it's possible to load native libraries from JAR files.
All resources allocated by JNIWrapper are released automatically when no longer needed. You can treat JNIWrapper variables as ordinary Java objects that can be reclaimed by the Java garbage collector. Besides, JNIWrapper objects are safe with regard to finalizers: all resources are guaranteed available during finalization.
You can perform all native function calls simultaneously from different Java threads without the need for synchronization, just as if invoking simple Java methods. See Working with Multithreading in our Programmers Guide.
JNIWrapper supports both stdcall and cdecl calling conventions and multiple C/C++ data types including structures, unions and pointers. Callbacks are fully supported with any parameter and return types and both calling conventions. See Calling Native Functions in our Programmers Guide. See JNIWrapper samples
When you call a native function, JNIWrapper makes all native errors ready for debugging on the Java side, putting program execution completely in your hands. See Calling Conventions in our Programmers Guide.
Using the Code Generator Wizard bundled with JNIWrapper, you can generate Java wrappers for a required set of C types, including structures, unions and callbacks.
When you purchase JNIWrapper you receive WinPack, a free add-on enabling access to the Windows native API and libraries from Java code. WinPack provides several integration features to make your Java application look and behave like a Win32 citizen. WinPack requires no extensive knowledge of the Win32 API, nor any writing of cumbersome wrapper classes for JNI.
With WinPack, you can use familiar Windows dialog boxes and modify window properties however you choose. See the following samples: Choose Color Dialog, Select Folder Dialog, Open/Save File Dialog.
With just a snippet of code you can make your Java application read, write or delete the Windows registry keys and values. Most of the major data types are supported. See the following samples: Registry Key Set Values, Registry Key Enum Values.
Using the Services API, you can start, stop or delete a service, display all running services in a list, and change the service options. WinPack lets you monitor and manage system processes, modules, memory and event logs. See related samples: Access Services Remote Computer, Enum Processes Sample, Event Log Sample.
WinPack lets you listen to the file system events. You can also get file attributes, check disk space and identify the disk media type. See the File System Sample.
Runs on Microsoft Windows XP or later.
During evaluation period please use the email address, provided to you in the evaluation email.
If you have an active support subscription, please use the email address, provided to you in the email confirming the license purchase.
You can ask a question on our product forum. In order to do it, you will need a Google ID.
links.teamdev.com/jniwrapper-forum
Send email: jniwrapper-forum@teamdev.com
Your message will be automatically posted on the web.
Evaluation SupportProvided for 30 days |
Standard SupportProvided for one year with 25% discount for renewal |
Premium SupportContract-based time and materials service |
---|---|---|
Help with the product use | Help with the product use | Help with the product use |
Response within one business day | Response within one business day | Response within one business day |
Provided by email | Provided by email | Provided by email |
— | Product updates | Product updates |
— | — | Phone, chat and remote desktop |
— | — | Feature development |
— | — | Priority issue resolution |
Evaluate for Free | Request Renewal | Request Premium |
If you have questions, not covered by the documentation, please email us at sales@teamdev.com.
License use is governed by the product license agreement
The prices on this page are exclusive of any taxes.
JNIWrapper supports different operating systems and architectures:
Please make sure that you set the correct function calling convention. The defaults are: stdcall for Windows as it is used by most of the Windows API, and cdecl for Linux - it is used by almost all libraries.
JNIWrapper is not designed for integration with .NET libraries which were created using C# or any other .NET programming language. In fact such libraries have architecture which completely differs from regular Win DLL libraries. Nevertheless it is possible to integrate with a .NET library if it provides COM Interop level. In this case you can use our ComfyJ product for that.
Technically it’s possible to invoke the functions from such library using JNIWrapper, but it won’t give you the ability to work with C++ objects and their methods. There are two possible workarounds. First is to create the plain C wrapper functions for the required C++ functions from that library. Second one is to enable COM interop in that C++ library and then use our ComfyJ product for integration with it.
The simplest way is to package all required library files (including JNIWrapper libraries) to root folder of an application JAR file.
The simplest way is to package that file to the \META-INF\ subdirectory of an application JAR file.
Yes, you can use Codegen for JNIWrapper utility application to generate the corresponding Java wrapper for it.
Take a look at the license installation instruction.
Our licensing is based on versions of JNIWrapper. Having purchased the license for our product you get the right to use the current major version of the product.
Major and minor version upgrades issued during your active Standard Support subscription period are free of charge. Upon expiration of the Standard Support subscription you can renew it with a 25% discount from the actual license price.
Please take a look at the Product License Agreement.
You only need to purchase 2 licenses. We license our library by the number of people who write code using our library.
This is possible with the Per Developer License.
You can distribute unlimited number of copies of your product with our library enclosed.
You may want to purchase a Project License, which is cost-effective in case there are 3 and more developers on the team. The Project License is bound to a single project you do, but it allows any number of developers in your company to work with our library.
Project License is bound to your project via a fully-qualified class name. A fully-qualified name for a class is the package name followed by the class name, separated by a period (.). For example: com.mycompany.myproduct.MyClass
This can be any class of your application. The only requirement is that it should be included into your Java application class path.
When we say “project” we have in mind one product of your company including your future product versions or potential derivative works based on your product.
The Project License is tied to one project only.
The best solution would be to purchase the Company–wide License, which covers any number developers and projects in one company.
Upon the license purchase you will receive an archive with two types of license files: development and runtime. Development license is intended to be used in the development process. Runtime license is to be used for distribution of your software with JNIWrapper enclosed.
Yes, you can purchase JNIWrapper Source Code License; it is provided on a per developer basis. Please contact our sales team if you are interested in this option.
We will email you your trial key and a quick