Microsoft SDK for Java

com.ms.dll Package Overview

Microsoft Packages Overview

The com.ms.dll package helps you link your Java code with dynamic-link libraries (DLLs). You can use the methods in the com.ms.dll package along with Microsoft® J/Direct™ technology to call functions located in Win32 DLLs, OLE API functions, and third-party DLLs. This overview discusses some of the most frequently used classes of the package.

This package contains the following:

Classes

Hierarchy

The DllLib class offers a variety of methods that are used in conjunction with the @dll.import directive. The ptrToXXX methods can be used to treat a parameter as a LPTSTR. Several copy methods, as well as read and write methods, allow your Java code to read and write data from raw pointers. The ptrToStruct method provides another way to read and write data through a raw pointer by wrapping the raw pointer in an instance of a class that was declared with the @dll.struct directive. DllLib also contains methods that copy strings to native memory blocks, convert native strings to Java String objects, and free and allocate native memory blocks.

You can extend the Callback class to create Callback objects in Java. Your derived Callback class must contain one non-static method whose name is callback (all lowercase). The callback method has limited return types, and all the parameters must be of type int. After the Callback class has been created, you can use the @dll.import compiler directive to call a Win32 function that takes a Callback as a parameter.

The Root class provides a way for you to protect a Java object from garbage collection by creating a 32-bit root handle for the object. This is helpful when you have created a Callback object that will be used across function calls. By wrapping the Callback inside a root handle, you can keep the Callback from being reclaimed by garbage collection. When you no longer need the Callback, you should explicitly free its root handle using the dll.Root.free method.

You can use the Win32Exception class to create objects that contain error descriptions for error codes set by Win32 functions. When you call Win32 functions using the @dll.import compiler directive, you can use the setLastError modifier to tell the VM to capture the error code immediately after the function is called. You can then use the dll.dllLib.getLastWin32Error method to obtain the error code, and you can wrap it in a Java Win32Exception object that describes the error.

See Also

Java/Win32 Integration with J/DirectCompiler Directives Reference

© 1999 Microsoft Corporation. All rights reserved. Terms of use.