home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / COM / CustomMarshal / template / TemplateMarshaler.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  7.5 KB  |  203 lines

  1. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2.  
  3. #pragma hdrstop
  4.  
  5. #include <windows.h>
  6. #include "native.h" // Raw Native Interface declarations.
  7.  
  8.  
  9. // TODO: Replace this typedef with your own definition of ETYPE, and/or replace
  10. // all occurrences of ETYPE, PETYPE and PPETYPE with your own type.
  11. typedef struct {
  12.     int dummy;
  13. } ETYPE;
  14.  
  15. typedef ETYPE *PETYPE, **PPETYPE;
  16.  
  17.  
  18. // TODO: Define JTYPE with the appropriate type.
  19. //
  20. //   If your Java type is           replace JTYPE with
  21. //   --------------------           ------------------
  22. //   byte                           char            (see below)
  23. //   char                           unsigned short  (see below)
  24. //   short                          short           (see below)
  25. //   int                            long
  26. //   long                           __int64
  27. //   boolean                        BOOL
  28. //   float                          float
  29. //   double                         double
  30. //   an object type                 OBJECT* or output of msjavah.exe
  31. //   an array                       HArrayOf<elemtype> (see native.h or
  32. //                                   output of msjavah)
  33. //
  34. //
  35. //  IMPORTANT NOTE:
  36. //     If your java type is byte, char, or short, the return types
  37. //     of toJava and toUninitJava must be declared as "long" and your
  38. //     C function must expand the result to a full 32-bit signed integer
  39. //     (RNI does not expand short integer return values on your behalf)
  40. //
  41. //     If your java type is boolean, your C function must return
  42. //     0 or 1 only (RNI does not normalize boolean return values.)
  43. //
  44.  
  45. typedef int JTYPE;
  46.  
  47.  
  48. #ifdef __cplusplus
  49. #define EXTERNC     extern "C"
  50. #else
  51. #define EXTERNC
  52. #endif
  53.  
  54.  
  55. // Macro for declaring RNI Java methods's (and encapsulating the java class package.)
  56. // TODO: Replace "TemplateMarshaler" with the name of your hook class. 
  57. #define JAVAMETHOD(typ, name) \
  58.     __declspec(dllexport) \
  59.     EXTERNC \
  60.     typ __cdecl TemplateMarshaler_##name
  61.  
  62.  
  63. // This export tells what RNI version we were built under.  This is a
  64. // NEW REQUIREMENT that was not needed for previous versions of the VM.
  65. // DO NOT REMOVE THIS FUNCTION.  Without it, the VM will be unable to
  66. // access your hook classes.   
  67. DWORD __cdecl RNIGetCompatibleVersion()
  68. {
  69.   return RNIVER;
  70. }
  71.  
  72.  
  73. //==========================================================================
  74. // toJava
  75. //==========================================================================
  76. JAVAMETHOD(JTYPE, toJava) (OBJECT*x, PPETYPE ppetype, int flags)
  77. {
  78.     PETYPE petype = *ppetype;
  79.     // TODO: Add code to convert *petype to a value of type JTYPE.
  80.     // If JTYPE is an object or array type, this method should return
  81.     // a newly created instance of JTYPE.
  82.     return 0;
  83. }
  84.  
  85.  
  86. //==========================================================================
  87. // copyToExternal
  88. //==========================================================================
  89. JAVAMETHOD(void, copyToExternal) (OBJECT*x, JTYPE javaval, PPETYPE ppetype, int flags)
  90. {
  91.     PETYPE petype = *ppetype;
  92.     // TODO: Add code to convert javaval into an ETYPE and store the resulting
  93.     // ETYPE in the (already allocated) memory pointed to by petype. Do
  94.     // not assume anything about the initial contents of *petype.
  95. }
  96.  
  97.  
  98. //==========================================================================
  99. // releaseByValExternal
  100. //==========================================================================
  101. JAVAMETHOD(void, releaseByValExternal) (OBJECT*x, PPETYPE ppetype, int flags)
  102. {
  103.     PETYPE petype = *ppetype;
  104.     // TODO: Add code to destroy any embedded resources owned by *petype.
  105.     // Do not free the memory for *petype itself (if you need to do this,
  106.     // do it in releaseExternal()).
  107.     //
  108.     // If no cleanup code is needed here, this method can be deleted.
  109.     // (do not forget to remove the reference to in the .def file.)
  110. }
  111.  
  112.  
  113. //==========================================================================
  114. // copyToJava
  115. //==========================================================================
  116. JAVAMETHOD(void, copyToJava) (OBJECT*x, PPETYPE ppetype, JTYPE javaval, int flags)
  117. {
  118.     PETYPE petype = *ppetype;
  119.     // TODO: Add code to modify "javaval" so it is 'equivalent' to *petype.
  120.     // Do not modify *petype or *ppetype.
  121.     // If JTYPE is not mutable, or you do not need to support "[out]"
  122.     // parameters, this method can be deleted.
  123.     // (do not forget to remove the reference to in the .def file.)
  124. }
  125.  
  126.  
  127. //==========================================================================
  128. // toUninitJava
  129. //==========================================================================
  130. JAVAMETHOD(JTYPE, toUninitJava) (OBJECT*x, PPETYPE ppetype, int flags)
  131. {
  132.     PETYPE petype = *ppetype;
  133.     // TODO: Add code to convert *petype to an uninitialized value of
  134.     // type JTYPE.
  135.     // If JTYPE is an object or array type, this method should return
  136.     // a newly created instance of JTYPE.
  137.     // If JTYPE is not mutable, or you do not need to support "[out]"
  138.     // parameters, this method can be deleted.
  139.     // (do not forget to remove the reference to in the .def file.)
  140.     return 0;
  141. }
  142.  
  143.  
  144. //==========================================================================
  145. // toExternal
  146. //==========================================================================
  147. JAVAMETHOD(void, toExternal) (OBJECT*x, JTYPE javaval, int flags, PPETYPE ppetype)
  148. {
  149.     PETYPE petype = NULL;
  150.     // TODO: Add code to allocate a new ETYPE, and initialize it to be
  151.     // "equivalent" to javaval. Store a pointer to the new ETYPE in petype.
  152.     // If you do not require ETYPE's that outlive method calls, this method
  153.     // can be deleted.
  154.     // (do not forget to remove the reference to in the .def file.)
  155.     *ppetype = petype;
  156. }
  157.  
  158.  
  159. //==========================================================================
  160. // releaseExternal
  161. //==========================================================================
  162. JAVAMETHOD(void, releaseExternal) (OBJECT*x, PPETYPE ppetype, int flags)
  163. {
  164.     PETYPE petype = *ppetype;
  165.  
  166.     // TODO: Add code to free the memory pointed to by petype. In addition,
  167.     // if you have implemented releaseByValExternal, call it first.
  168.     //
  169.     // If you do not require ETYPE's that outlive method calls, this method
  170.     // can be deleted.
  171.     // (do not forget to remove the reference to in the .def file.)
  172. }
  173.  
  174.  
  175. //==========================================================================
  176. // toUninitExternal
  177. //==========================================================================
  178. JAVAMETHOD(void, toUninitExternal) (OBJECT*x, JTYPE javaval, int flags, PPETYPE ppetype)
  179. {
  180.     PETYPE petype = NULL;
  181.     // TODO: Add code to allocate a new ETYPE. It is not necessary to initialize
  182.     // its contents. The value of javaval should be used only to determine
  183.     // the size of the allocation.
  184.     // If you do not require ETYPE's that outlive method calls, or you do not
  185.     // need to support [out] parameters, this method can be deleted.
  186.     // (do not forget to remove the reference to in the .def file.)
  187.     *ppetype = petype;
  188. }
  189.  
  190.  
  191.  
  192.  
  193. //==========================================================================
  194. // TODO: Remove this copy of DllMain if you are embedding this file in your
  195. //  own DLL.
  196. // DLL Loader entry point.
  197. //==========================================================================
  198. BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason,
  199.                                 PVOID pvReserved)
  200. {
  201.    return TRUE;
  202. }
  203.