Simple J/Direct Sample

This sample is located in \Samples\JDirect\Simple.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

This sample uses the @dll.import directive to call the MessageBox API.

Using the Sample

To run the sample

Run Go.bat in the \Samples\JDirect\Simple directory.

Key Project Files

Simple.java

This class contains the call by @dll.import to USER32.DLL. There is a try-catch code block that notifies the user if Microsoft® J/Direct™ is correctly installed, or it displays one of two error messages if J/Direct is incorrectly installed or non-existent.

For the following code to work, you must import the com.ms.win32 package, which is included with the Microsoft® Win32® API classes for J/Direct.

/* Copyright (C) 1997 Microsoft Corporation. All rights reserved.
 *
 * This example calls the MessageBox API using the new @dll.import
 * directive.
 *
 */
import com.ms.win32.*;
public class Simple
{
  public static void main(String args[])
    {
      try {
        User32.MessageBox(0, "MessageBox successfully called.", 
       "Java", 0);
        } catch (UnsatisfiedLinkError ule) {
          System.err.println("Caught exception: " + ule);
          System.err.println("Probably wrong version of Java compiler.");
    }
  }
}

Technologies Demonstrated

Microsoft J/Direct

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