![]() | ![]() |
Home | Products | Support | SiteMap | |
![]() |
Read Me NCH Unified APIThis is the "readme.html" documentation supplied in the nchapi.zip archive. It is designed to be a supplement source of information additional to that available from our website: www.nchsoftware.com/api.
Included FilesThere should have been several files included along with this documentation. The purpose of these files follows:
Included DirectoriesThere should be several directories also included which contain all the Visual Studio, header and source files (where appropriate) required for the provided working examples. The directories/examples included are:
API SpecificationAll commands and arguments are passed to the Unified API as an array of strings, with the number of these also sent. Commands are all preceded by a dash ('-') and are in lowercase with no spaces. Arguments can contain any characters necessary. Please note that both commands and arguments are case sensitive! Once the command has been executed by the program the API will respond by returning a number and a result string. The number is the return value of the command just sent and follows this guideline:
Java DocumentationThere are several methods for how to use the NCH Unified API's capability in your Java code. The options are:
Important note regarding class and package namingAs a result of the style in which Java code can interface with native DLL code, the package name and class name of the class that calls the DLL code is hard-coded into the DLL. Thus, the only class that can call the JNI method in nchapi.dll is "nch.api.NCHAPIClient". If you choose to go down the route specified in #2 above, be aware that you must name your own class this.
1) Using the provided NCHAPIClient classThe provided class is designed to make interaction with the Unified API DLL as painless as possible. You will need to compile the class on your own and include it in your JARs. There are two constructors provided in the class. You should use one or the other, depending on where you want to place the nchapi.dll.
1.1) NCHAPIClient() ConstructorThis constructor will look for the nchapi.dll in a series of directories. If you have not defined a java.library.path environment variable on the command-line to java.exe (e.g., "-Djava.library.path=c:\dlls\"), then it will look through the directories in the computer's %PATH%. Java will use the first copy of nchapi.dll it finds.
1.1.1) Relying on %PATH%If you allow Java to search through the %PATH% to find the nchapi.dll, it is recommended that you place the dll in c:\[Windows Directory]\System32, as this directory is included in the %PATH% environment variable by default.
1.1.2) Relying on java.library.pathIf you specify a directory in which nchapi.dll is placed and use the -Djava.library.path= statement, you can put the nchapi.dll in any directory on the system, even one which is not included in the %PATH% environment variable, and change the location easily at program start-up time.
1.2) NCHAPIClient(String pathToDLL) ConstructorLike in 1.1.2, this constructor will allow you to place the dll in any location on the computer. Pass into this constructor the directory where your software can find nchapi.dll. Use this constructor if you want to place the dll in a directory that is not in the %PATH% but you do not want to specify it on the command-line. For instance, you might use this constructor if you want to save the DLL location in a configuration file and read it at runtime.
1.3) Calling the Unified APICalling the API is done via the sendCommand() method. You should consult the documentation for the NCH software application you wish to communicate with for the exact parameters you need to use. The first argument to sendCommand() is the name of the application you wish to call. The second argument is a String array, each element of which is a parameter to the API call. This method will return an integer value that can be used to determine the success or failure of the API call. See the NCHAPI_* constants in the class -- these are the possible return values. In a nutshell, the constant values mean:
1.4) The Verbose Result StringIn addition to the integer result returned by sendCommand(), the API returns a more verbose string that can be used for enhanced debugging. The exact format of this code depends on the API call that you made. This result string is basically a human-readable result that tells exactly what happened (for example, a call may get an integer result of NCHAPI_ERROR and a result string of "Recording could not be started because the software is currently playing another MP3."). This result string can be returned from the NCHAPIClient class after sendCommand() is called via a call to getResultString().
2) Writing your own NCHAPIClient ClassAre you REALLY sure you want to write your own version of the class? In 99% of cases, you will be simply reproducing the class we provide you. If you choose to not use the NCHAPIClient class, there are several steps you will need to account for and things to know that are handled by the client class. Please read the following and be sure you understand ALL OF IT COMPLETELY before continuing.2.1) Package Name and LocationAs mentioned above, due to limitations in JNI, you **MUST** name the class that calls the code in nchapi.dll "NCHAPIClient" and it **MUST** be located in a package named "nch.api". There is no way around this.2.2) Loading the DLLThere are two ways to load a DLL with Java:
2.2.1) System.load(...);This load is used when you want to specify the path to the DLL to load. For example:System.load("c:\dlls\nchapi.dll"); 2.2.2) System.loadLibrary(...);This load is used when you want the JVM to search %PATH% and java.library.path (see 1.1) for the DLL to load. If you use this style, you must use the following line of code to load the nchapi.dll:System.loadLibrary("nchapi");Note that there is no ".dll" in the above. This is the proper convention.
2.3) Declaring the Native MethodYou must also prepare the JVM to know that it needs to call a native method. Do this by declaring the method that you will be connecting to in the .dll. Use this piece of code:private static native int NCHAPISendCommand(String szServerKey, int nArgs, String[] szArgs, String[] szResultString); 2.4) Calling the Native MethodTo call the native method, you need to pass in more arguments than you do in using our NCHAPIClient class. Here are the arguments to pass in and what they mean:
Other InformationIf you have problems writing your application, please see www.nch.com.au/support.
|
![]() |
|
© NCH Software | Top | Home |