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

  1. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2.  
  3. #pragma hdrstop
  4.  
  5. #define INITGUID 1
  6. #include <windows.h>
  7. #include "native.h" // Raw Native Interface declarations.
  8.  
  9.  
  10.  
  11. typedef POINT *PPOINT, **PPPOINT;
  12.  
  13.  
  14. typedef OBJECT* JPoint;
  15.  
  16. #ifdef __cplusplus
  17. #define EXTERNC     extern "C"
  18. #else
  19. #define EXTERNC
  20. #endif
  21.  
  22.  
  23. // Macro for declaring RNI Java methods's (and encapsulating the java class package.)
  24. #define JAVAMETHOD(typ, name) \
  25.     __declspec(dllexport) \
  26.     EXTERNC \
  27.     typ __cdecl PointMarshaler_##name
  28.  
  29.  
  30.  
  31. #define LOGCALL(hookname) OutputDebugString("PointMarshaler." hookname "() called.\n")
  32.  
  33.  
  34. // Export that tells what RNI version we were built under.
  35. DWORD __cdecl RNIGetCompatibleVersion()
  36. {
  37.   return RNIVER;
  38. }
  39.  
  40.  
  41. // Cache the various class and fields we will need.
  42. ClassClass*         gPointClass;
  43. struct fieldblock*  gPointXField;
  44. struct fieldblock*  gPointYField;
  45.  
  46.  
  47.  
  48. //==========================================================================
  49. // toJava
  50. //==========================================================================
  51. JAVAMETHOD(JPoint, toJava) (OBJECT*x, PPPOINT ppPOINT, int flags)
  52. {
  53.     PPOINT pPOINT = *ppPOINT;
  54.     JPoint jpoint;
  55.  
  56.     LOGCALL("toJava");
  57.  
  58.     jpoint = execute_java_constructor(NULL, NULL, gPointClass, "(II)", pPOINT->x, pPOINT->y);
  59.     return jpoint;
  60. }
  61.  
  62.  
  63. //==========================================================================
  64. // copyToExternal
  65. //==========================================================================
  66. JAVAMETHOD(void, copyToExternal) (OBJECT*x, JPoint javaval, PPPOINT ppPOINT, int flags)
  67. {
  68.     PPOINT pPOINT = *ppPOINT;
  69.  
  70.     LOGCALL("copyToExternal");
  71.  
  72.     pPOINT->x = Field_GetInt(javaval, gPointXField);
  73.     pPOINT->y = Field_GetInt(javaval, gPointYField);
  74.  
  75. }
  76.  
  77.  
  78.  
  79.  
  80. //==========================================================================
  81. // copyToJava
  82. //==========================================================================
  83. JAVAMETHOD(void, copyToJava) (OBJECT*x, PPPOINT ppPOINT, JPoint javaval, int flags)
  84. {
  85.     PPOINT pPOINT = *ppPOINT;    \
  86.  
  87.     LOGCALL("copyToJava");
  88.  
  89.  
  90.     Field_SetInt(javaval, gPointXField, pPOINT->x);
  91.     Field_SetInt(javaval, gPointYField, pPOINT->y);
  92.  
  93. }
  94.  
  95.  
  96. //==========================================================================
  97. // toUninitJava
  98. //==========================================================================
  99. JAVAMETHOD(JPoint, toUninitJava) (OBJECT*x, PPPOINT ppPOINT, int flags)
  100. {
  101.     JPoint jpoint;
  102.  
  103.     LOGCALL("toUninitJava");
  104.  
  105.     jpoint = execute_java_constructor(NULL, NULL, gPointClass, "(II)", -1, -1);
  106.     return jpoint;
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113. //==========================================================================
  114. // TODO: Remove this copy of DllMain if you are embedding this file in your
  115. //  own DLL.
  116. // DLL Loader entry point.
  117. //==========================================================================
  118. BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason,
  119.                                 PVOID pvReserved)
  120. {
  121.    return TRUE;
  122. }
  123.  
  124.  
  125.  
  126. //==========================================================================
  127. // classInit (one time initialization routine)
  128. //==========================================================================
  129. JAVAMETHOD(void, classInit) (OBJECT*x)
  130. {
  131.     gPointClass = FindClass(NULL, "java/awt/Point", TRUE);
  132.     if (!gPointClass) {
  133.         SignalErrorPrintf("java/lang/ClassNotFoundException", "Could not preload java.awt.Point class!");
  134.     }
  135.  
  136.     gPointXField = Class_GetField(gPointClass, "x");
  137.     if (!gPointXField) {
  138.         SignalErrorPrintf("java/lang/ClassNotFoundException", "Bogus java.awt.Point class!");
  139.     }
  140.  
  141.     gPointYField = Class_GetField(gPointClass, "y");
  142.     if (!gPointYField) {
  143.         SignalErrorPrintf("java/lang/ClassNotFoundException", "Bogus java.awt.Point class!");
  144.     }
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.