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

  1. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2. //=====================================================================
  3. // Sample Java/COM Marshaling Hook Class.
  4. //
  5. // Java Type:  double
  6. // Com  Type:  struct {
  7. //                 WORD     fract;
  8. //                 short    value;
  9. //             } FIXED;
  10. //=====================================================================
  11.  
  12.  
  13.  
  14. #pragma hdrstop
  15.  
  16. #include <windows.h>
  17. #include "native.h" // Raw Native Interface declarations.
  18.  
  19.  
  20. typedef FIXED *PFIXED, **PPFIXED;
  21.  
  22.  
  23.  
  24. #ifdef __cplusplus
  25. #define EXTERNC     extern "C"
  26. #else
  27. #define EXTERNC
  28. #endif
  29.  
  30.  
  31. // Macro for declaring RNI Java methods's (and encapsulating the java class package.)
  32. #define JAVAMETHOD(typ, name) \
  33.     __declspec(dllexport) \
  34.     EXTERNC \
  35.     typ __cdecl FixedPtMarshaler_##name
  36.  
  37.  
  38. #define LOGCALL(hookname) OutputDebugString("FixedPtMarshaler." hookname "() called.\n")
  39.  
  40. // Export that tells what RNI version we were built under.
  41. DWORD __cdecl RNIGetCompatibleVersion()
  42. {
  43.   return RNIVER;
  44. }
  45.  
  46.  
  47. //==========================================================================
  48. // toJava
  49. //==========================================================================
  50. JAVAMETHOD(double, toJava) (OBJECT*x, PPFIXED ppFIXED, int flags)
  51. {
  52.     const FIXED *pFIXED = *ppFIXED;
  53.  
  54.     LOGCALL("toJava");
  55.  
  56.     // Convert FIXED to double.
  57.     return ((double)(pFIXED->value)) + ((double)(pFIXED->fract)) / 65536.0;
  58. }
  59.  
  60.  
  61. //==========================================================================
  62. // copyToExternal
  63. //==========================================================================
  64. JAVAMETHOD(void, copyToExternal) (OBJECT*x, double javaval, PPFIXED ppFIXED, int flags)
  65. {
  66.     FIXED *pFIXED = *ppFIXED;
  67.  
  68.     LOGCALL("copyToExternal");
  69.  
  70.     // Convert double to FIXED.
  71.     if (javaval > 32767.0 || javaval < -32768.0) {
  72.         SignalErrorPrintf("java/lang/IllegalArgumentException", "Overflow on double->FIXED conversion.");
  73.     } else {
  74.         pFIXED->value = (short)javaval;
  75.         pFIXED->fract = (short) ((javaval - (short)javaval) * 65536.0);
  76.     }
  77. }
  78.  
  79.  
  80.  
  81.  
  82. //==========================================================================
  83. // TODO: Remove this copy of DllMain if you are embedding this file in your
  84. //  own DLL.
  85. // DLL Loader entry point.
  86. //==========================================================================
  87. BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason,
  88.                                 PVOID pvReserved)
  89. {
  90.    return TRUE;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.