home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / JDirect / structs / Structs.java < prev   
Encoding:
Java Source  |  2000-05-04  |  1.7 KB  |  60 lines

  1. /* (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2.  *
  3.  * This example shows how to pass a pointer to a simple structure.
  4.  * To declare a native structure in Java, use the "@dll.struct"
  5.  * directive as shown the MEMORYSTATUS structure. 
  6.  */
  7.  
  8.  
  9. import com.ms.dll.DllLib;
  10.  
  11. public class Structs
  12. {
  13.     public static void main(String args[])
  14.     {
  15.         MEMORYSTATUS mstatus = new MEMORYSTATUS();
  16.         GlobalMemoryStatus(mstatus);
  17.  
  18.         System.out.println("Total     physical memory = " +
  19.                            Integer.toHexString(mstatus.dwTotalPhys));
  20.  
  21.         System.out.println("Available physical memory = " +
  22.                            Integer.toHexString(mstatus.dwAvailPhys));
  23.  
  24.         System.out.println("Total     page file       = " +
  25.                            Integer.toHexString(mstatus.dwTotalPageFile));
  26.  
  27.         System.out.println("Available page file       = " +
  28.                            Integer.toHexString(mstatus.dwAvailPageFile));
  29.  
  30.         System.out.println("Total     virtual memory  = " +
  31.                            Integer.toHexString(mstatus.dwTotalVirtual));
  32.  
  33.         System.out.println("Available virtual memory  = " +
  34.                            Integer.toHexString(mstatus.dwAvailVirtual));
  35.  
  36.  
  37.     }
  38.  
  39.  
  40.     /** @dll.import("KERNEL32") */
  41.     static native void GlobalMemoryStatus(MEMORYSTATUS lptMemStat);
  42. }
  43.  
  44.  
  45. /** @dll.struct() */
  46. class MEMORYSTATUS {
  47.  
  48.     public int dwLength = DllLib.sizeOf(MEMORYSTATUS.class);
  49.     public int dwMemoryLoad;
  50.     public int dwTotalPhys;
  51.     public int dwAvailPhys;
  52.     public int dwTotalPageFile;
  53.     public int dwAvailPageFile;
  54.     public int dwTotalVirtual;
  55.     public int dwAvailVirtual;
  56.  
  57.  
  58. }
  59.  
  60.