MarshalingUtils.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "MarshalingUtils.h"
  2. #include "il2cpp-pinvoke-support.h"
  3. namespace il2cpp
  4. {
  5. namespace utils
  6. {
  7. void MarshalingUtils::MarshalStructToNative(void* managedStructure, void* marshaledStructure, const Il2CppInteropData* interopData)
  8. {
  9. #if RUNTIME_TINY
  10. IL2CPP_ASSERT(0 && "Not supported with the Tiny runtime");
  11. #else
  12. IL2CPP_ASSERT(interopData);
  13. IL2CPP_ASSERT(interopData->pinvokeMarshalToNativeFunction);
  14. interopData->pinvokeMarshalToNativeFunction(managedStructure, marshaledStructure);
  15. #endif
  16. }
  17. void MarshalingUtils::MarshalStructFromNative(void* marshaledStructure, void* managedStructure, const Il2CppInteropData* interopData)
  18. {
  19. #if RUNTIME_TINY
  20. IL2CPP_ASSERT(0 && "Not supported with the Tiny runtime");
  21. #else
  22. IL2CPP_ASSERT(interopData);
  23. IL2CPP_ASSERT(interopData->pinvokeMarshalFromNativeFunction);
  24. interopData->pinvokeMarshalFromNativeFunction(marshaledStructure, managedStructure);
  25. #endif
  26. }
  27. bool MarshalingUtils::MarshalFreeStruct(void* marshaledStructure, const Il2CppInteropData* interopData)
  28. {
  29. #if RUNTIME_TINY
  30. IL2CPP_ASSERT(0 && "Not supported with the Tiny runtime");
  31. return false;
  32. #else
  33. if (interopData == NULL)
  34. return false;
  35. PInvokeMarshalCleanupFunc cleanup = interopData->pinvokeMarshalCleanupFunction;
  36. if (cleanup == NULL)
  37. return false;
  38. cleanup(marshaledStructure);
  39. return true;
  40. #endif
  41. }
  42. } // namespace utils
  43. } // namespace il2cpp