home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Native / Invocation / invokevm.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  1.4 KB  |  50 lines

  1. //
  2. //  invokevm.c
  3. //
  4. //  (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  5. //
  6. //  Demonstrates the use of the PrepareThreadForJava and UnprepareThreadForJava
  7. //  invocation APIs.
  8. //
  9.  
  10. #include <windows.h>
  11. #include <stdio.h>
  12. #include <native.h>
  13.  
  14. void main(int argc, char *argv[])
  15. {
  16.     HRESULT hr;
  17.     ThreadEntryFrame threadEntryFrame;
  18.     ClassClass *pClass;
  19.  
  20.     hr = CoInitialize(NULL);
  21.  
  22.     if (hr == S_OK) {
  23.  
  24.         //  Call this API before calling into the Microsoft Java VM to allow the
  25.         //  VM to allocate any per-thread structures and to do any first-time
  26.         //  initialization.  After return from this call, Java objects may be
  27.         //  accessed or RNI APIs may be called.
  28.         if (PrepareThreadForJava(&threadEntryFrame)) {
  29.  
  30.             pClass = FindClass(NULL, "TestClass", TRUE);
  31.  
  32.             if (pClass != NULL) {
  33.                 execute_java_static_method(NULL, pClass, "someMethod", "()V");
  34.             } else {
  35.                 printf("Failed to find class!\n");
  36.             }
  37.  
  38.             //  Detaches the "entry frame" from this thread.  After return from
  39.             //  this call, it is no longer safe to directly touch Java objects
  40.             //  or call RNI APIs.
  41.             UnprepareThreadForJava(&threadEntryFrame);
  42.  
  43.         } else {
  44.             printf("Failed to initialize thread!\n");
  45.         }
  46.  
  47.         CoUninitialize();
  48.     }
  49. }
  50.