|
||||||||||||||
Troubleshooting TipsThe following topics describe problems that you might encounter when using Microsoft® J/Direct™. For each situation, possible solutions are provided. UnsatisfiedLinkError When Calling a Method
Getting SecurityException When Calling a DLL Method or Using an @dll.struct ClassDLL calling and the use of @dll.struct classes is restricted to Java applications and signed Java applets. For more information about signing applets, see the article on Signing a Cabinet File with Java Permissions. StringBuffers Truncated on Return From DLL FunctionYou must ensure that the StringBuffer's capacity is sufficient to contain the string you need before you invoke the DLL function. You can specify the capacity in the StringBuffer's constructor, and you can use the StringBuffer.ensureCapacity method to guarantee a minimum capacity prior to the DLL call. Mysterious Syntax Errors Within @dll DirectivesExtra white space within @dll.import and @dll.struct directives can cause syntax errors. Avoid using white space inside @dll constructs. Compiler Cannot Find Basic System Packages Like java.langThe compiler shipped with SDK for Java looks for system packages in the classes.zip file. This conflicts with the new Package Management scheme used by the Microsoft VM, which stores system packages as .zip files with obfuscated names under the %WINDIR%\java\packages directory. Unfortunately, the Java Language Compiler has not yet been updated to recognize this new scheme. To compile Java programs against the new VM, you must create an old-style .zip file and ensure that it is included in the CLASSPATH. Normally, the SDK installation program does this for you. If, however, you installed the SDK by some other method, or if your configuration has been corrupted since the installation, you may need to recreate CLASSES.ZIP. The easiest way to do this is to type clspack -auto at the MS-DOS® command prompt. This will create a single CLASSES.ZIP in your %WINDIR%\java\Classes directory that contains all classes stored in the package manager. The Microsoft compiler for Java looks for classes in this location by default, so there is no need to set your CLASSPATH environment variable. Compiler Cannot Find the com.ms.dll PackageAn older version of classes.zip is being used. Try renaming all older versions of classes.zip on your disk drive and follow the instructions under Compiler Cannot Find Basic System Packages Like java.lang for creating a new classes.zip file. Syntax Errors When Using J/Direct with Inner ClassesThe version of the Java compiler that ships with the SDK for Java does not correctly handle @dll directives on inner classes or classes that contain inner class declarations. @dll Directives Do Not Work on Applets (or Only Works Within the Microsoft Visual J++ Environment)Because the use of J/Direct can compromise security, its use is restricted to Java applications and signed Java applets. See Signing a Cabinet File with Java Permissions for more information about signing applets. Using J/Direct Makes Class UnusableAny use of J/Direct within a class marks that class as unsafe and unusable by untrusted code, even if the J/Direct methods are not actually invoked. J/Direct Throws a ParameterCountMismatchError After Calling a Native FunctionThe ParameterCountMismatchError exception alerts you to the fact that the called function consumed (popped off the stack) more or fewer parameters than was passed by J/Direct. This error normally indicates that the parameters in the Java method declaration do not match up with the parameters expected by the DLL function. If the function pops off no arguments, it is assumed to be using the cdecl calling convention and an exception is not thrown, even if the Java method declares a non-zero number of arguments. Caution You should not attempt to catch and deal with the ParameterCountMismatchError exception. This exception was designed to assist developers in catching bugs during the development stage. For performance reasons, parameter count checking is performed only when the application is running under a Java debugger. It is also important to note that J/Direct performs this check after the function call has been completed. Because this exception indicates that one or more invalid parameters might have been passed to the function call, it cannot be guaranteed that the process can recover. J/Direct Does Not Unload a DLLJ/Direct unloads a DLL when the Microsoft VM discards the Java class that imported the DLL. For a Java application running under jview, this does not occur until the process exits. For a trusted Java applet, this happens at some undetermined time after the browser has left the page containing the applet. The Microsoft VM attempts to keep Java classes loaded for several pages afterward in order to optimize applet refresh time in case the page is revisited. If you need explicit control over the loading and unloading of DLLs, you need to call the Windows loader explicitly and use the call entrypoint to invoke functions dynamically. For more information on how to do this, see the section in this article on Dynamically Loading and Invoking DLLs.
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |