JDirect
 
 

JDirect    PreviousJDirect
About J/Direct     Previous JDirect

 


Frequently Asked Questions

In this section, answers to the following questions about Microsoft® J/Direct™ are provided.
What versions of the Microsoft Compiler for Java support J/Direct?
What versions of the Microsoft virtual machine support J/Direct?
Where can I find more code samples that use J/Direct?
Where can I get prewritten declarations for the Win32 functions and constants?
How can I programatically learn whether the auto modifier will select Unicode or ANSI on a given platform?
Where I can find more services helpful for DLL calling?
How do I obtain the application instance handle?
How do I obtain the parameters passed to the WinMain function?
How do I turn my Java application into an .exe file?

What versions of the Microsoft Compiler for Java support J/Direct?

The version of the compiler available with the Microsoft SDK for Java version 3.0 pre-release 2 supports J/Direct. Use that version or later. To display the version number, execute jvc with no arguments on the command line. If you are copying the compiler manually, be aware that the Microsoft compiler is composed of three executables: jvc.exe, jps.dll, and msjvc.dll. See the SDK release notes for version numbers corresponding to that release.



What versions of the Microsoft virtual machine support J/Direct?

The version of the Microsoft VM available with the SDK for Java version 3.0 pre-release 2 and with Internet Explorer 4.0 supports J/Direct. Use that version or later. See the SDK release notes for version numbers corresponding to that release.

To find out what version is installed using Windows Explorer, you need to find the executable msjava.dll, which is normally installed in your windows\system directory. Make sure that Windows Explorer is configured to show all files. (To do this, open the windows\system folder, pull down the View menu, select the Options item to display the Options dialog box. Select the view tab, and select Show all files.) Find msjava.dll in the folder and right-click it. From the pop-up menu, select the Properties item to display the Properties dialog box. Select the Version tab. You will see the version number displayed next to File Version.



Where can I find more code samples that use J/Direct?

You can find code samples under \MsVmJava\Samples\JDirect\ in the directory in which you install the SDK for Java.



Where can I get prewritten declarations for the Win32 functions and constants?

Prewritten declarations for the most common Win32 functions and constants can be downloaded separately. From the SDK for Java 3.0 pre-release 2 Component Download menu, select the check box next to Win32 API Java Package.



How can I programatically learn whether the auto modifier will select Unicode or ANSI on a given platform?

The system class com.ms.dll.DllLib has a public integer field named systemDefaultCharSize. Its value is set to 1 (for ANSI) or 2 (for Unicode).



Where I can find more services helpful for DLL calling?

The com.ms.dll package includes several classes (especially DllLib) that contain useful methods for extracting strings from native memory blocks, mapping raw pointers onto @dll.struct classes, copying bytes between various types, and other helpful tasks.



How do I obtain the application instance handle?

Many Windows functions (in particular, the USER32 functions) require the application instance handle as a parameter. In Win32, an instance handle is defined to be the same as a module handle. Thus, the instance handle can be obtained by passing NULL to the GetModuleHandle function.


  /** @dll.import("KERNEL32") */
  private static native int GetModuleHandle(String modName);

  int hInst = GetModuleHandle(null);



How do I obtain the parameters passed to the WinMain function?

Windows applications written in C have a WinMain function where execution begins. Java applications written in C have a main function instead.

The Microsoft® Windows® operating system passes four parameters to WinMain. Here is how to obtain these values from Java.
The application instance handle: Pass NULL to the GetModuleHandle function. For more information, see the How do I obtain the application instance handle? FAQ in this section.
The previous instance handle: In Win32, this value is always NULL.
The command line: Passed as the String args[] parameter to main.
The default value to pass to ShowWindow: Can be obtained by GetStartupInfo. However, Microsoft® Win32® applications are encouraged to pass SW_SHOWDEFAULT to ShowWindow rather than using the value passed to WinMain.



How do I turn my Java application into an .exe file?

The jexegen tool can be used to create an .exe file that can be launched like a normal Windows application. When using jexegen, you can select whether to build a GUI executable or a console executable. The default is console, but you can select GUI by specifying the /W switch. For example, consider the following Java application.


public class app
{
  public static void main(String args[])
  {
    int hInst = GetModuleHandle(null);
    MessageBox(0,"Instance handle is " + 
               Integer.toHexString(hInst),"",0);             
  }

  /** @dll.import("KERNEL32") */
  private static native int GetModuleHandle(String modName);

  /** @dll.import("USER32") */
  private static native int MessageBox(int hWndOwner,String text,
                                       String title,int fuStyle); 
} 

This class can be converted to a GUI executable by executing the following command lines.


  jvc app
  jexegen /W /out:app.exe /main:app *.class

For details on the using the jexegen tool, see the Introduction to Jexegen article.



Top © 1998 Microsoft Corporation. All rights reserved. Terms of use.