home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Include / Include / nativcom.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  8.3 KB  |  193 lines

  1. /*++
  2.  
  3. Copyright (c) 1995-1999  Microsoft Corporation.  All rights reserved.
  4.  
  5. Module Name:
  6.  
  7.     nativcom.h
  8.  
  9. Abstract:
  10.  
  11.     Public header for COM-marshaling facilities provided by msjava.dll.
  12.  
  13. --*/
  14.  
  15. #ifndef _NATIVCOM_
  16. #define _NATIVCOM_
  17.  
  18. #include <windows.h>
  19. #include <native.h>
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. //----------------------------------------------------------------------------
  26. // COM and J/Direct data wrapper helpers...
  27. //----------------------------------------------------------------------------
  28.  
  29. //  Replaces the data pointer contained in the data wrapper with a new blob of
  30. //  non-GC'ed heap memory.  The previous blob, if any, will be freed if its
  31. //  owned by the VM.
  32. JAVAVMAPI void* __cdecl jcdwNewData(Hjava_lang_Object * phJCDW, unsigned int
  33.     numBytes);
  34.  
  35. //  Returns the data pointer to the non GC'ed heap memory contained by the data
  36. //  wrapper object.
  37. JAVAVMAPI void* __cdecl jcdwGetData(Hjava_lang_Object * phJCDW);
  38.  
  39. //  Replaces the data pointer that this data wrapper represents with the
  40. //  specified
  41. JAVAVMAPI int __cdecl jcdwSetData(Hjava_lang_Object * phJCDW, LPVOID pv);
  42.  
  43. //  Returns TRUE if the VM allocated the non GC'ed heap memory contained by the
  44. //  data wrapper.
  45. JAVAVMAPI int __cdecl jcdw_memory_freed_on_gc(Hjava_lang_Object *phJCDW);
  46.  
  47. //  Returns TRUE if the VM frees the non GC'ed heap memory that this data
  48. //  wrapper contains when the data wrapper is garbage collected.
  49. JAVAVMAPI int __cdecl jcdw_java_owned(Hjava_lang_Object *phJCDW);
  50.  
  51. //  Returns the size of the non GC'ed heap memory contained by the data wrapper
  52. //  object.
  53. JAVAVMAPI unsigned int __cdecl jcdwSizeOf(Hjava_lang_Object * phJCDW);
  54.  
  55. //  Returns the size of the non GC'ed heap memory used by instances of the
  56. //  supplied java/lang/Class object.
  57. JAVAVMAPI unsigned int __cdecl jcdwClassSizeOf(Hjava_lang_Object * phJavaClass);
  58.  
  59. //  Returns the byte offset within the non GC'ed heap memory to the specified
  60. //  field name.
  61. JAVAVMAPI unsigned int __cdecl jcdwOffsetOf(Hjava_lang_Object * phJCDW, const
  62.     char *pFieldName);
  63.  
  64. //  Returns the byte offset within the non GC'ed heap memory to the specified
  65. //  field name from the supplied java/lang/Class object.
  66. JAVAVMAPI unsigned int __cdecl jcdwClassOffsetOf(Hjava_lang_Object * phJCDWClass,
  67.     const char *pFieldName);
  68.  
  69. // Given an object, propagates field values from the Java object to the object's
  70. //  associated native memory.
  71. // Returns FALSE on error, else TRUE.
  72. JAVAVMAPI int __cdecl jcdwPropagateToNative( Hjava_lang_Object *phJCDW );
  73.  
  74. // Given an object, propagates field values from the object's associated native
  75. //  memory to the Java object.  If fFreeIndirectNativeMemory is TRUE, the native
  76. //  memory used for any reference fields (Strings, custom marshaled fields, ...)
  77. //  will be released.
  78. // Returns FALSE on error, else TRUE.
  79. JAVAVMAPI int __cdecl jcdwPropagateToJava( Hjava_lang_Object *phJCDW, BOOL 
  80.     fFreeIndirectNativeMemory );
  81.  
  82. //  Returns a Java callable wrapper that can be used to access the specified
  83. //  interface pointer.  The VM will keep a reference to this interface pointer.
  84. //  If 'fAssumeThreadSafe' is FALSE, the VM will auto-marshal all COM calls to
  85. //  the current COM context.
  86. JAVAVMAPI Hjava_lang_Object * __cdecl convert_IUnknown_to_Java_Object(IUnknown
  87.     *punk, Hjava_lang_Object *phJavaClass, int fAssumeThreadSafe);
  88.  
  89. //  Returns a Java callable wrapper that can be used to access the specified
  90. //  interface pointer.  The VM will keep a reference to this interface pointer.
  91. //  If 'fAssumeThreadSafe' is FALSE, the VM will auto-marshal all COM calls to
  92. //  the current COM context.
  93. JAVAVMAPI Hjava_lang_Object * __cdecl convert_IUnknown_to_Java_Object2(IUnknown
  94.     *punk, ClassClass  *pClassClass, int fFreeThreaded);
  95.  
  96. //  Returns an interface pointer usable from the current COM context.
  97. JAVAVMAPI IUnknown * __cdecl convert_Java_Object_to_IUnknown(Hjava_lang_Object
  98.     *phJavaObject, const IID *pIID);
  99.  
  100. //  Returns a data wrapper object of the supplied Class type that points at the
  101. //  supplied data pointer.  The memory is not owned by the VM.
  102. JAVAVMAPI Hjava_lang_Object * __cdecl convert_ptr_to_jcdw(void *pExtData,
  103.     Hjava_lang_Object *phJavaClass);
  104.  
  105. //----------------------------------------------------------------------------
  106. // Map HRESULT to ComException.
  107. //----------------------------------------------------------------------------
  108. JAVAVMAPI void    __cdecl SignalErrorHResult(HRESULT theHRESULT);
  109.  
  110. //----------------------------------------------------------------------------
  111. // Map Java exception to HRESULT.
  112. //----------------------------------------------------------------------------
  113. JAVAVMAPI HRESULT __cdecl HResultFromException(OBJECT* exception_object);
  114.  
  115. typedef Hjava_lang_Object *JAVAARG;
  116.  
  117. //----------------------------------------------------------------------------
  118. // Information structure for Java->COM Custom Method hook.
  119. //----------------------------------------------------------------------------
  120. typedef struct {
  121.     DWORD                   cbSize;         // size of structure in bytes
  122.     IUnknown               *punk;           // pointer to interface being invoked
  123.     const volatile JAVAARG *pJavaArgs;      // pointer to Java argument stack
  124. } J2CMethodHookInfo;
  125.  
  126. //----------------------------------------------------------------------------
  127. // Information structure for COM->Java Custom Method hook.
  128. //----------------------------------------------------------------------------
  129. typedef struct {
  130.     DWORD                      cbSize;         // size of structure in bytes
  131.     struct methodblock        *javaMethod;     // java method to call
  132.     LPVOID                     pComArgs;       // pointer to COM method argument stack
  133.     const volatile JAVAARG    *ppThis;         // pointer to pointer to Java this
  134.  
  135.     // Store the COM result here.
  136.     union {
  137.         HRESULT                         resHR;
  138.         DWORD                           resDWORD;
  139.         double                          resDouble;
  140.     };
  141. } C2JMethodHookInfo;
  142.  
  143. JAVAVMAPI WORD __cdecl j2chook_getsizeofuserdata(J2CMethodHookInfo *phookinfo);
  144. JAVAVMAPI LPVOID __cdecl j2chook_getuserdata(J2CMethodHookInfo *phookinfo);
  145.  
  146. // Returns the vtable index of the target method.
  147. JAVAVMAPI WORD __cdecl j2chook_getvtblindex(J2CMethodHookInfo *phookinfo);
  148.  
  149. // Returns the methodblock of the target method.
  150. JAVAVMAPI struct methodblock* __cdecl j2chook_getmethodblock(J2CMethodHookInfo *phookinfo);
  151.  
  152. JAVAVMAPI WORD __cdecl c2jhook_getsizeofuserdata(C2JMethodHookInfo *phookinfo);
  153. JAVAVMAPI LPVOID __cdecl c2jhook_getuserdata(C2JMethodHookInfo *phookinfo);
  154.  
  155. // Returns the class defining the interface method.  This is the class
  156. // containing the MCCustomMethod descriptor.
  157. JAVAVMAPI ClassClass * __cdecl c2jhook_getexposingclass(C2JMethodHookInfo *phookinfo);
  158.  
  159. //----------------------------------------------------------------------------
  160. // Thread marshaling helpers
  161. //
  162. // The MarshalCall<> APIs will reexecute the RNI method on the supplied thread
  163. // id or on the apartment thread for the supplied Java object.  The APIs will
  164. // return the following sets of HRESULTS:
  165. //
  166. //      S_OK     The call successfully was marshaled to the target thread.
  167. //               The marshaled call may have generated an exception, which can
  168. //               bechecked by calling exceptionOccurred.
  169. //      S_FALSE  The call did not require marshaling to the other thread--
  170. //               the currently executing thread is the target thread.
  171. //      E_<>     An error occurred inside the MarshalCall<> API (invalid
  172. //               arguments, out of memory, etc).
  173. //
  174. // The typical use of these APIs is to call the appropriate MarshalCall<> API
  175. // and if the HRESULT is S_FALSE, then execute the rest of the RNI method,
  176. // otherwise return with the value contained in pResult.
  177. //----------------------------------------------------------------------------
  178. typedef void * JAVATID;
  179.  
  180. #define JAVATID_MAIN_APARTMENT          ((JAVATID) 0x00000001)
  181. #define JAVATID_SERVER_APARTMENT        ((JAVATID) 0x00000002)
  182.  
  183. JAVAVMAPI HRESULT __cdecl MarshalCallToJavaThreadId(JAVATID tid, int64_t
  184.     *pResult);
  185. JAVAVMAPI HRESULT __cdecl MarshalCallToJavaObjectHostThread(Hjava_lang_Object
  186.     *phobj, int64_t *pResult);
  187.  
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191.  
  192. #endif
  193.