@@ -53,14 +53,14 @@ public static class Marshal
53
53
public static readonly int SystemMaxDBCSCharSize = 2 ; // don't know what this is
54
54
public static readonly int SystemDefaultCharSize = Environment . IsRunningOnWindows ? 2 : 1 ;
55
55
56
- #if ! MOBILE
56
+ #if ! MOBILE || UNITY_AOT
57
57
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
58
58
private extern static int AddRefInternal ( IntPtr pUnk ) ;
59
59
#endif
60
60
61
61
public static int AddRef ( IntPtr pUnk )
62
62
{
63
- #if ! MOBILE
63
+ #if ! MOBILE || UNITY_AOT
64
64
if ( pUnk == IntPtr . Zero )
65
65
throw new ArgumentException ( "Value cannot be null." , "pUnk" ) ;
66
66
return AddRefInternal ( pUnk ) ;
@@ -210,7 +210,9 @@ public static IntPtr CreateAggregatedObject<T> (IntPtr pOuter, T o) {
210
210
211
211
public static object CreateWrapperOfType ( object o , Type t )
212
212
{
213
- #if FULL_AOT_RUNTIME
213
+ #if UNITY_AOT
214
+ throw new NotImplementedException ( "Marshal.CreateWrapperOfType is not implemented." ) ;
215
+ #elif FULL_AOT_RUNTIME
214
216
throw new PlatformNotSupportedException ( ) ;
215
217
#else
216
218
__ComObject co = o as __ComObject ;
@@ -307,7 +309,7 @@ public static void ZeroFreeGlobalAllocUnicode (IntPtr s)
307
309
FreeHGlobal ( s ) ;
308
310
}
309
311
310
- #if ! FULL_AOT_RUNTIME
312
+ #if ! FULL_AOT_RUNTIME || UNITY_AOT
311
313
public static Guid GenerateGuidForType ( Type type )
312
314
{
313
315
return type . GUID ;
@@ -342,23 +344,25 @@ public static object GetActiveObject (string progID)
342
344
throw new NotImplementedException ( ) ;
343
345
}
344
346
345
- #if ! MOBILE
347
+ #if ! MOBILE || UNITY_AOT
346
348
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
347
349
private extern static IntPtr GetCCW ( object o , Type T ) ;
348
350
349
351
private static IntPtr GetComInterfaceForObjectInternal ( object o , Type T )
350
352
{
353
+ #if ! UNITY_AOT
351
354
if ( IsComObject ( o ) )
352
355
return ( ( __ComObject ) o ) . GetInterface ( T ) ;
353
356
else
357
+ #endif
354
358
return GetCCW ( o , T ) ;
355
359
}
356
360
#endif
357
361
#endif // !FULL_AOT_RUNTIME
358
362
359
363
public static IntPtr GetComInterfaceForObject ( object o , Type T )
360
364
{
361
- #if MOBILE
365
+ #if MOBILE && ! UNITY_AOT
362
366
throw new PlatformNotSupportedException ( ) ;
363
367
#else
364
368
IntPtr pItf = GetComInterfaceForObjectInternal ( o , T ) ;
@@ -377,7 +381,7 @@ public static IntPtr GetComInterfaceForObject<T, TInterface> (T o) {
377
381
return GetComInterfaceForObject ( ( object ) o , typeof ( T ) ) ;
378
382
}
379
383
380
- #if ! FULL_AOT_RUNTIME
384
+ #if ! FULL_AOT_RUNTIME || UNITY_AOT
381
385
[ MonoTODO ]
382
386
public static IntPtr GetComInterfaceForObjectInContext ( object o , Type t )
383
387
{
@@ -430,7 +434,7 @@ public static IntPtr GetHINSTANCE (Module m)
430
434
431
435
return m . GetHINSTANCE ( ) ;
432
436
}
433
- #endif // !FULL_AOT_RUNTIME
437
+ #endif // !FULL_AOT_RUNTIME || UNITY_AOT
434
438
435
439
public static int GetExceptionCode ( )
436
440
{
@@ -453,14 +457,14 @@ public static int GetHRForException (Exception e)
453
457
[ ReliabilityContract ( Consistency . WillNotCorruptState , Cer . Success ) ]
454
458
public static int GetHRForLastWin32Error ( )
455
459
{
456
- #if FULL_AOT_RUNTIME
460
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
457
461
throw new PlatformNotSupportedException ( ) ;
458
462
#else
459
463
throw new NotImplementedException ( ) ;
460
464
#endif
461
465
}
462
-
463
- #if ! FULL_AOT_RUNTIME
466
+
467
+ #if ! FULL_AOT_RUNTIME || UNITY_AOT
464
468
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
465
469
private extern static IntPtr GetIDispatchForObjectInternal ( object o ) ;
466
470
@@ -471,7 +475,9 @@ public static IntPtr GetIDispatchForObject (object o)
471
475
AddRef ( pUnk ) ;
472
476
return pUnk ;
473
477
}
478
+ #endif // !FULL_AOT_RUNTIME || UNITY_AOT
474
479
480
+ #if ! FULL_AOT_RUNTIME
475
481
[ MonoTODO ]
476
482
public static IntPtr GetIDispatchForObjectInContext ( object o )
477
483
{
@@ -502,15 +508,16 @@ public static MemberInfo GetMethodInfoForComSlot (Type t, int slot, ref ComMembe
502
508
{
503
509
throw new NotImplementedException ( ) ;
504
510
}
511
+ #endif // !FULL_AOT_RUNTIME
505
512
513
+ #if ! FULL_AOT_RUNTIME || UNITY_AOT
506
514
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
507
515
private extern static IntPtr GetIUnknownForObjectInternal ( object o ) ;
508
-
509
- #endif // !FULL_AOT_RUNTIME
516
+ #endif // !FULL_AOT_RUNTIME || UNITY_AOT
510
517
511
518
public static IntPtr GetIUnknownForObject ( object o )
512
519
{
513
- #if FULL_AOT_RUNTIME
520
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
514
521
throw new PlatformNotSupportedException ( ) ;
515
522
#else
516
523
IntPtr pUnk = GetIUnknownForObjectInternal ( o ) ;
@@ -522,7 +529,7 @@ public static IntPtr GetIUnknownForObject (object o)
522
529
523
530
public static void GetNativeVariantForObject ( object obj , IntPtr pDstNativeVariant )
524
531
{
525
- #if FULL_AOT_RUNTIME
532
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
526
533
throw new PlatformNotSupportedException ( ) ;
527
534
#else
528
535
Variant vt = new Variant ( ) ;
@@ -535,29 +542,31 @@ public static void GetNativeVariantForObject<T> (T obj, IntPtr pDstNativeVariant
535
542
GetNativeVariantForObject ( ( object ) obj , pDstNativeVariant ) ;
536
543
}
537
544
538
- #if ! MOBILE && ! FULL_AOT_RUNTIME
545
+ #if ( ! MOBILE && ! FULL_AOT_RUNTIME ) || UNITY_AOT
539
546
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
540
547
private static extern object GetObjectForCCW ( IntPtr pUnk ) ;
541
548
#endif
542
549
543
550
public static object GetObjectForIUnknown ( IntPtr pUnk )
544
551
{
545
- #if MOBILE || FULL_AOT_RUNTIME
552
+ #if ( MOBILE || FULL_AOT_RUNTIME ) && ! UNITY_AOT
546
553
throw new PlatformNotSupportedException ( ) ;
547
554
#else
548
555
object obj = GetObjectForCCW ( pUnk ) ;
556
+ #if ! UNITY_AOT
549
557
// was not a CCW
550
558
if ( obj == null ) {
551
559
ComInteropProxy proxy = ComInteropProxy . GetProxy ( pUnk , typeof ( __ComObject ) ) ;
552
560
obj = proxy . GetTransparentProxy ( ) ;
553
561
}
562
+ #endif
554
563
return obj ;
555
564
#endif
556
565
}
557
566
558
567
public static object GetObjectForNativeVariant ( IntPtr pSrcNativeVariant )
559
568
{
560
- #if FULL_AOT_RUNTIME
569
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
561
570
throw new PlatformNotSupportedException ( ) ;
562
571
#else
563
572
Variant vt = ( Variant ) Marshal . PtrToStructure ( pSrcNativeVariant , typeof ( Variant ) ) ;
@@ -567,7 +576,7 @@ public static object GetObjectForNativeVariant (IntPtr pSrcNativeVariant)
567
576
568
577
public static T GetObjectForNativeVariant < T > ( IntPtr pSrcNativeVariant )
569
578
{
570
- #if FULL_AOT_RUNTIME
579
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
571
580
throw new PlatformNotSupportedException ( ) ;
572
581
#else
573
582
Variant vt = ( Variant ) Marshal . PtrToStructure ( pSrcNativeVariant , typeof ( Variant ) ) ;
@@ -577,7 +586,7 @@ public static T GetObjectForNativeVariant<T> (IntPtr pSrcNativeVariant)
577
586
578
587
public static object [ ] GetObjectsForNativeVariants ( IntPtr aSrcNativeVariant , int cVars )
579
588
{
580
- #if FULL_AOT_RUNTIME
589
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
581
590
throw new PlatformNotSupportedException ( ) ;
582
591
#else
583
592
if ( cVars < 0 )
@@ -592,7 +601,7 @@ public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant, in
592
601
593
602
public static T [ ] GetObjectsForNativeVariants < T > ( IntPtr aSrcNativeVariant , int cVars )
594
603
{
595
- #if FULL_AOT_RUNTIME
604
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
596
605
throw new PlatformNotSupportedException ( ) ;
597
606
#else
598
607
if ( cVars < 0 )
@@ -608,7 +617,7 @@ public static T[] GetObjectsForNativeVariants<T> (IntPtr aSrcNativeVariant, int
608
617
[ MonoTODO ]
609
618
public static int GetStartComSlot ( Type t )
610
619
{
611
- #if FULL_AOT_RUNTIME
620
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
612
621
throw new PlatformNotSupportedException ( ) ;
613
622
#else
614
623
throw new NotImplementedException ( ) ;
@@ -735,7 +744,7 @@ public static object GetUniqueObjectForIUnknown (IntPtr unknown)
735
744
throw new PlatformNotSupportedException ( ) ;
736
745
}
737
746
738
- #if ! MOBILE
747
+ #if ! MOBILE || UNITY_AOT
739
748
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
740
749
public extern static bool IsComObject ( object o ) ;
741
750
#else
@@ -815,14 +824,14 @@ public static T PtrToStructure<T> (IntPtr ptr) {
815
824
return ( T ) PtrToStructure ( ptr , typeof ( T ) ) ;
816
825
}
817
826
818
- #if ! MOBILE
827
+ #if ! MOBILE || UNITY_AOT
819
828
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
820
829
private extern static int QueryInterfaceInternal ( IntPtr pUnk , ref Guid iid , out IntPtr ppv ) ;
821
830
#endif
822
831
823
832
public static int QueryInterface ( IntPtr pUnk , ref Guid iid , out IntPtr ppv )
824
833
{
825
- #if ! MOBILE
834
+ #if ! MOBILE || UNITY_AOT
826
835
if ( pUnk == IntPtr . Zero )
827
836
throw new ArgumentException ( "Value cannot be null." , "pUnk" ) ;
828
837
return QueryInterfaceInternal ( pUnk , ref iid , out ppv ) ;
@@ -986,7 +995,7 @@ public static IntPtr ReadIntPtr ([In, MarshalAs (UnmanagedType.AsAny)] object pt
986
995
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
987
996
public extern static IntPtr ReAllocHGlobal ( IntPtr pv , IntPtr cb ) ;
988
997
989
- #if ! MOBILE
998
+ #if ! MOBILE || UNITY_AOT
990
999
[ ReliabilityContractAttribute ( Consistency . WillNotCorruptState , Cer . Success ) ]
991
1000
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
992
1001
private extern static int ReleaseInternal ( IntPtr pUnk ) ;
@@ -995,7 +1004,7 @@ public static IntPtr ReadIntPtr ([In, MarshalAs (UnmanagedType.AsAny)] object pt
995
1004
[ ReliabilityContract ( Consistency . WillNotCorruptState , Cer . Success ) ]
996
1005
public static int Release ( IntPtr pUnk )
997
1006
{
998
- #if ! MOBILE
1007
+ #if ! MOBILE || UNITY_AOT
999
1008
if ( pUnk == IntPtr . Zero )
1000
1009
throw new ArgumentException ( "Value cannot be null." , "pUnk" ) ;
1001
1010
@@ -1005,14 +1014,14 @@ public static int Release (IntPtr pUnk)
1005
1014
#endif
1006
1015
}
1007
1016
1008
- #if ! FULL_AOT_RUNTIME
1017
+ #if ! FULL_AOT_RUNTIME || UNITY_AOT
1009
1018
[ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
1010
1019
private extern static int ReleaseComObjectInternal ( object co ) ;
1011
1020
#endif
1012
1021
1013
1022
public static int ReleaseComObject ( object o )
1014
1023
{
1015
- #if FULL_AOT_RUNTIME
1024
+ #if FULL_AOT_RUNTIME && ! UNITY_AOT
1016
1025
throw new PlatformNotSupportedException ( ) ;
1017
1026
#else
1018
1027
if ( o == null )
@@ -1752,7 +1761,7 @@ internal static void SetLastWin32Error (int error)
1752
1761
{
1753
1762
}
1754
1763
1755
- #if FEATURE_COMINTEROP || MONO_COM
1764
+ #if FEATURE_COMINTEROP || MONO_COM || UNITY_AOT
1756
1765
// Copied from referencesource/mscorlib/system/runtime/interopservices/marshal.cs
1757
1766
//====================================================================
1758
1767
// return the raw IUnknown* for a COM Object not related to current
0 commit comments