Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Marshal.cs
Go to the documentation of this file.
8using System.Text;
10
12
13public static class Marshal
14{
15 internal static Guid IID_IUnknown = new Guid(0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70);
16
17 public static readonly int SystemDefaultCharSize = 2;
18
19 public static readonly int SystemMaxDBCSCharSize = GetSystemMaxDBCSCharSize();
20
21 internal static bool IsBuiltInComSupported { get; } = IsBuiltInComSupportedInternal();
22
23
24 [MethodImpl(MethodImplOptions.InternalCall)]
25 internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);
26
27 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "Trimming doesn't affect types eligible for marshalling. Different exception for invalid inputs doesn't matter.")]
28 public static IntPtr OffsetOf(Type t, string fieldName)
29 {
30 if ((object)t == null)
31 {
32 throw new ArgumentNullException("t");
33 }
34 FieldInfo field = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
35 if ((object)field == null)
36 {
38 }
39 if (!(field is RtFieldInfo f))
40 {
42 }
43 return OffsetOfHelper(f);
44 }
45
46 [MethodImpl(MethodImplOptions.InternalCall)]
47 private static extern IntPtr OffsetOfHelper(IRuntimeFieldInfo f);
48
49 public static byte ReadByte(object ptr, int ofs)
50 {
51 return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset));
52 }
53
54 public static short ReadInt16(object ptr, int ofs)
55 {
56 return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset));
57 }
58
59 public static int ReadInt32(object ptr, int ofs)
60 {
61 return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset));
62 }
63
64 public static long ReadInt64([In][MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
65 {
66 return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt64(nativeHome, offset));
67 }
68
69 private unsafe static T ReadValueSlow<T>(object ptr, int ofs, Func<IntPtr, int, T> readValueHelper)
70 {
71 if (ptr == null)
72 {
73 throw new AccessViolationException();
74 }
76 AsAnyMarshaler asAnyMarshaler = new AsAnyMarshaler(new IntPtr(&marshalerState));
77 IntPtr intPtr = IntPtr.Zero;
78 try
79 {
80 intPtr = asAnyMarshaler.ConvertToNative(ptr, 285147391);
81 return readValueHelper(intPtr, ofs);
82 }
83 finally
84 {
85 asAnyMarshaler.ClearNative(intPtr);
86 }
87 }
88
89 public static void WriteByte(object ptr, int ofs, byte val)
90 {
91 WriteValueSlow(ptr, ofs, val, delegate(IntPtr nativeHome, int offset, byte value)
92 {
93 WriteByte(nativeHome, offset, value);
94 });
95 }
96
97 public static void WriteInt16(object ptr, int ofs, short val)
98 {
99 WriteValueSlow(ptr, ofs, val, delegate(IntPtr nativeHome, int offset, short value)
100 {
101 WriteInt16(nativeHome, offset, value);
102 });
103 }
104
105 public static void WriteInt32(object ptr, int ofs, int val)
106 {
107 WriteValueSlow(ptr, ofs, val, delegate(IntPtr nativeHome, int offset, int value)
108 {
109 WriteInt32(nativeHome, offset, value);
110 });
111 }
112
113 public static void WriteInt64(object ptr, int ofs, long val)
114 {
115 WriteValueSlow(ptr, ofs, val, delegate(IntPtr nativeHome, int offset, long value)
116 {
117 WriteInt64(nativeHome, offset, value);
118 });
119 }
120
121 private unsafe static void WriteValueSlow<T>(object ptr, int ofs, T val, Action<IntPtr, int, T> writeValueHelper)
122 {
123 if (ptr == null)
124 {
125 throw new AccessViolationException();
126 }
128 AsAnyMarshaler asAnyMarshaler = new AsAnyMarshaler(new IntPtr(&marshalerState));
129 IntPtr intPtr = IntPtr.Zero;
130 try
131 {
132 intPtr = asAnyMarshaler.ConvertToNative(ptr, 822018303);
133 writeValueHelper(intPtr, ofs, val);
134 asAnyMarshaler.ConvertToManaged(ptr, intPtr);
135 }
136 finally
137 {
138 asAnyMarshaler.ClearNative(intPtr);
139 }
140 }
141
142 [MethodImpl(MethodImplOptions.InternalCall)]
143 public static extern int GetLastPInvokeError();
144
145 [MethodImpl(MethodImplOptions.InternalCall)]
146 public static extern void SetLastPInvokeError(int error);
147
148 private static void PrelinkCore(MethodInfo m)
149 {
150 if (!(m is RuntimeMethodInfo runtimeMethodInfo))
151 {
153 }
154 InternalPrelink(((IRuntimeMethodInfo)runtimeMethodInfo).Value);
155 GC.KeepAlive(runtimeMethodInfo);
156 }
157
158 [DllImport("QCall", CharSet = CharSet.Unicode)]
159 private static extern void InternalPrelink(RuntimeMethodHandleInternal m);
160
161 [MethodImpl(MethodImplOptions.InternalCall)]
162 public static extern IntPtr GetExceptionPointers();
163
164 [MethodImpl(MethodImplOptions.InternalCall)]
165 public static extern int GetExceptionCode();
166
167 [MethodImpl(MethodImplOptions.InternalCall)]
168 public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld);
169
170 [MethodImpl(MethodImplOptions.InternalCall)]
171 private static extern void PtrToStructureHelper(IntPtr ptr, object structure, bool allowValueClasses);
172
173 [MethodImpl(MethodImplOptions.InternalCall)]
174 public static extern void DestroyStructure(IntPtr ptr, Type structuretype);
175
176 [MethodImpl(MethodImplOptions.InternalCall)]
177 internal static extern bool IsPinnable(object obj);
178
179 [DllImport("QCall")]
180 private static extern bool IsBuiltInComSupportedInternal();
181
182 public static IntPtr GetHINSTANCE(Module m)
183 {
184 if ((object)m == null)
185 {
186 throw new ArgumentNullException("m");
187 }
188 RuntimeModule module = m as RuntimeModule;
189 if ((object)module != null)
190 {
191 return GetHINSTANCE(new QCallModule(ref module));
192 }
193 return (IntPtr)(-1);
194 }
195
196 [DllImport("QCall", CharSet = CharSet.Unicode)]
197 private static extern IntPtr GetHINSTANCE(QCallModule m);
198
199 [MethodImpl(MethodImplOptions.InternalCall)]
200 internal static extern Exception GetExceptionForHRInternal(int errorCode, IntPtr errorInfo);
201
202 [MethodImpl(MethodImplOptions.InternalCall)]
203 public static extern int GetHRForException(Exception? e);
204
205 [SupportedOSPlatform("windows")]
206 public static string GetTypeInfoName(ITypeInfo typeInfo)
207 {
208 if (typeInfo == null)
209 {
210 throw new ArgumentNullException("typeInfo");
211 }
212 typeInfo.GetDocumentation(-1, out string strName, out string _, out int _, out string _);
213 return strName;
214 }
215
216 internal static Type GetTypeFromCLSID(Guid clsid, string server, bool throwOnError)
217 {
219 {
221 }
222 Type o = null;
223 GetTypeFromCLSID(in clsid, server, ObjectHandleOnStack.Create(ref o));
224 return o;
225 }
226
227 [DllImport("QCall", CharSet = CharSet.Unicode)]
228 private static extern void GetTypeFromCLSID(in Guid clsid, string server, ObjectHandleOnStack retType);
229
230 [SupportedOSPlatform("windows")]
231 public static IntPtr GetIUnknownForObject(object o)
232 {
233 if (o == null)
234 {
235 throw new ArgumentNullException("o");
236 }
238 }
239
240 [MethodImpl(MethodImplOptions.InternalCall)]
241 private static extern IntPtr GetIUnknownForObjectNative(object o);
242
243 [SupportedOSPlatform("windows")]
244 public static IntPtr GetIDispatchForObject(object o)
245 {
246 if (o == null)
247 {
248 throw new ArgumentNullException("o");
249 }
251 }
252
253 [MethodImpl(MethodImplOptions.InternalCall)]
254 private static extern IntPtr GetIDispatchForObjectNative(object o);
255
256 [SupportedOSPlatform("windows")]
257 public static IntPtr GetComInterfaceForObject(object o, Type T)
258 {
259 if (o == null)
260 {
261 throw new ArgumentNullException("o");
262 }
263 if ((object)T == null)
264 {
265 throw new ArgumentNullException("T");
266 }
267 return GetComInterfaceForObjectNative(o, T, fEnableCustomizedQueryInterface: true);
268 }
269
270 [SupportedOSPlatform("windows")]
271 public static IntPtr GetComInterfaceForObject<T, TInterface>([DisallowNull] T o)
272 {
273 return GetComInterfaceForObject(o, typeof(TInterface));
274 }
275
276 [SupportedOSPlatform("windows")]
278 {
279 if (o == null)
280 {
281 throw new ArgumentNullException("o");
282 }
283 if ((object)T == null)
284 {
285 throw new ArgumentNullException("T");
286 }
287 bool fEnableCustomizedQueryInterface = mode == CustomQueryInterfaceMode.Allow;
288 return GetComInterfaceForObjectNative(o, T, fEnableCustomizedQueryInterface);
289 }
290
291 [MethodImpl(MethodImplOptions.InternalCall)]
292 private static extern IntPtr GetComInterfaceForObjectNative(object o, Type t, bool fEnableCustomizedQueryInterface);
293
294 [SupportedOSPlatform("windows")]
295 public static object GetObjectForIUnknown(IntPtr pUnk)
296 {
297 if (pUnk == IntPtr.Zero)
298 {
299 throw new ArgumentNullException("pUnk");
300 }
301 return GetObjectForIUnknownNative(pUnk);
302 }
303
304 [MethodImpl(MethodImplOptions.InternalCall)]
305 private static extern object GetObjectForIUnknownNative(IntPtr pUnk);
306
307 [SupportedOSPlatform("windows")]
308 public static object GetUniqueObjectForIUnknown(IntPtr unknown)
309 {
310 if (unknown == IntPtr.Zero)
311 {
312 throw new ArgumentNullException("unknown");
313 }
314 return GetUniqueObjectForIUnknownNative(unknown);
315 }
316
317 [MethodImpl(MethodImplOptions.InternalCall)]
318 private static extern object GetUniqueObjectForIUnknownNative(IntPtr unknown);
319
320 [MethodImpl(MethodImplOptions.InternalCall)]
321 [SupportedOSPlatform("windows")]
322 public static extern object GetTypedObjectForIUnknown(IntPtr pUnk, Type t);
323
324 [SupportedOSPlatform("windows")]
325 public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
326 {
328 {
330 }
331 return CreateAggregatedObjectNative(pOuter, o);
332 }
333
334 [MethodImpl(MethodImplOptions.InternalCall)]
335 private static extern IntPtr CreateAggregatedObjectNative(IntPtr pOuter, object o);
336
337 [SupportedOSPlatform("windows")]
338 public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : notnull
339 {
341 {
343 }
344 return CreateAggregatedObject(pOuter, (object)o);
345 }
346
347 [MethodImpl(MethodImplOptions.InternalCall)]
348 public static extern void CleanupUnusedObjectsInCurrentContext();
349
350 [MethodImpl(MethodImplOptions.InternalCall)]
351 public static extern bool AreComObjectsAvailableForCleanup();
352
353 public static bool IsComObject(object o)
354 {
355 if (o == null)
356 {
357 throw new ArgumentNullException("o");
358 }
359 return o is __ComObject;
360 }
361
362 [SupportedOSPlatform("windows")]
363 public static int ReleaseComObject(object o)
364 {
366 {
368 }
369 if (o == null)
370 {
371 throw new NullReferenceException();
372 }
373 if (!(o is __ComObject _ComObject))
374 {
376 }
377 return _ComObject.ReleaseSelf();
378 }
379
380 [MethodImpl(MethodImplOptions.InternalCall)]
381 internal static extern int InternalReleaseComObject(object o);
382
383 [SupportedOSPlatform("windows")]
384 public static int FinalReleaseComObject(object o)
385 {
387 {
389 }
390 if (o == null)
391 {
392 throw new ArgumentNullException("o");
393 }
394 if (!(o is __ComObject _ComObject))
395 {
397 }
398 _ComObject.FinalReleaseSelf();
399 return 0;
400 }
401
402 [MethodImpl(MethodImplOptions.InternalCall)]
403 internal static extern void InternalFinalReleaseComObject(object o);
404
405 [SupportedOSPlatform("windows")]
406 public static object? GetComObjectData(object obj, object key)
407 {
409 {
411 }
412 if (obj == null)
413 {
414 throw new ArgumentNullException("obj");
415 }
416 if (key == null)
417 {
418 throw new ArgumentNullException("key");
419 }
420 if (!(obj is __ComObject _ComObject))
421 {
423 }
424 return _ComObject.GetData(key);
425 }
426
427 [SupportedOSPlatform("windows")]
428 public static bool SetComObjectData(object obj, object key, object? data)
429 {
431 {
433 }
434 if (obj == null)
435 {
436 throw new ArgumentNullException("obj");
437 }
438 if (key == null)
439 {
440 throw new ArgumentNullException("key");
441 }
442 if (!(obj is __ComObject _ComObject))
443 {
445 }
446 return _ComObject.SetData(key, data);
447 }
448
449 [SupportedOSPlatform("windows")]
450 [return: NotNullIfNotNull("o")]
451 public static object? CreateWrapperOfType(object? o, Type t)
452 {
454 {
456 }
457 if ((object)t == null)
458 {
459 throw new ArgumentNullException("t");
460 }
461 if (!t.IsCOMObject)
462 {
464 }
465 if (t.IsGenericType)
466 {
468 }
469 if (o == null)
470 {
471 return null;
472 }
473 if (!o.GetType().IsCOMObject)
474 {
476 }
477 if (o.GetType() == t)
478 {
479 return o;
480 }
481 object obj = GetComObjectData(o, t);
482 if (obj == null)
483 {
485 if (!SetComObjectData(o, t, obj))
486 {
487 obj = GetComObjectData(o, t);
488 }
489 }
490 return obj;
491 }
492
493 [SupportedOSPlatform("windows")]
494 public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o)
495 {
497 {
499 }
500 return (TWrapper)CreateWrapperOfType(o, typeof(TWrapper));
501 }
502
503 [MethodImpl(MethodImplOptions.InternalCall)]
504 private static extern object InternalCreateWrapperOfType(object o, Type t);
505
506 [MethodImpl(MethodImplOptions.InternalCall)]
507 public static extern bool IsTypeVisibleFromCom(Type t);
508
509 [SupportedOSPlatform("windows")]
510 public static void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
511 {
513 {
515 }
516 GetNativeVariantForObjectNative(obj, pDstNativeVariant);
517 }
518
519 [MethodImpl(MethodImplOptions.InternalCall)]
520 private static extern void GetNativeVariantForObjectNative(object obj, IntPtr pDstNativeVariant);
521
522 [SupportedOSPlatform("windows")]
523 public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
524 {
526 {
528 }
529 GetNativeVariantForObject((object?)obj, pDstNativeVariant);
530 }
531
532 [SupportedOSPlatform("windows")]
533 public static object? GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
534 {
536 {
538 }
539 return GetObjectForNativeVariantNative(pSrcNativeVariant);
540 }
541
542 [MethodImpl(MethodImplOptions.InternalCall)]
543 private static extern object GetObjectForNativeVariantNative(IntPtr pSrcNativeVariant);
544
545 [SupportedOSPlatform("windows")]
546 public static T? GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
547 {
549 {
551 }
552 return (T)GetObjectForNativeVariant(pSrcNativeVariant);
553 }
554
555 [SupportedOSPlatform("windows")]
556 public static object?[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
557 {
559 {
561 }
562 return GetObjectsForNativeVariantsNative(aSrcNativeVariant, cVars);
563 }
564
565 [MethodImpl(MethodImplOptions.InternalCall)]
566 private static extern object[] GetObjectsForNativeVariantsNative(IntPtr aSrcNativeVariant, int cVars);
567
568 [SupportedOSPlatform("windows")]
569 public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
570 {
572 {
574 }
575 object[] objectsForNativeVariants = GetObjectsForNativeVariants(aSrcNativeVariant, cVars);
576 T[] array = new T[objectsForNativeVariants.Length];
577 Array.Copy(objectsForNativeVariants, array, objectsForNativeVariants.Length);
578 return array;
579 }
580
581 [MethodImpl(MethodImplOptions.InternalCall)]
582 [SupportedOSPlatform("windows")]
583 public static extern int GetStartComSlot(Type t);
584
585 [MethodImpl(MethodImplOptions.InternalCall)]
586 [SupportedOSPlatform("windows")]
587 public static extern int GetEndComSlot(Type t);
588
589 [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")]
590 [SupportedOSPlatform("windows")]
591 public static object BindToMoniker(string monikerName)
592 {
594 {
596 }
597 CreateBindCtx(0u, out var ppbc);
598 MkParseDisplayName(ppbc, monikerName, out var _, out var ppmk);
599 BindMoniker(ppmk, 0u, ref IID_IUnknown, out var ppvResult);
600 return ppvResult;
601 }
602
603 [DllImport("ole32.dll", PreserveSig = false)]
604 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", Justification = "The calling method is annotated with RequiresUnreferencedCode")]
605 private static extern void CreateBindCtx(uint reserved, out IBindCtx ppbc);
606
607 [DllImport("ole32.dll", PreserveSig = false)]
608 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", Justification = "The calling method is annotated with RequiresUnreferencedCode")]
609 private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk);
610
611 [DllImport("ole32.dll", PreserveSig = false)]
612 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", Justification = "The calling method is annotated with RequiresUnreferencedCode")]
613 private static extern void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult);
614
615 [MethodImpl(MethodImplOptions.InternalCall)]
616 [SupportedOSPlatform("windows")]
617 public static extern void ChangeWrapperHandleStrength(object otp, bool fIsWeak);
618
619 [MethodImpl(MethodImplOptions.InternalCall)]
621
622 [MethodImpl(MethodImplOptions.InternalCall)]
624
625 public static IntPtr AllocHGlobal(int cb)
626 {
627 return AllocHGlobal((IntPtr)cb);
628 }
629
630 public unsafe static string? PtrToStringAnsi(IntPtr ptr)
631 {
632 if (IsNullOrWin32Atom(ptr))
633 {
634 return null;
635 }
636 return new string((sbyte*)(void*)ptr);
637 }
638
639 public unsafe static string PtrToStringAnsi(IntPtr ptr, int len)
640 {
641 if (ptr == IntPtr.Zero)
642 {
643 throw new ArgumentNullException("ptr");
644 }
645 if (len < 0)
646 {
648 }
649 return new string((sbyte*)(void*)ptr, 0, len);
650 }
651
652 public unsafe static string? PtrToStringUni(IntPtr ptr)
653 {
654 if (IsNullOrWin32Atom(ptr))
655 {
656 return null;
657 }
658 return new string((char*)(void*)ptr);
659 }
660
661 public unsafe static string PtrToStringUni(IntPtr ptr, int len)
662 {
663 if (ptr == IntPtr.Zero)
664 {
665 throw new ArgumentNullException("ptr");
666 }
667 if (len < 0)
668 {
670 }
671 return new string((char*)(void*)ptr, 0, len);
672 }
673
674 public unsafe static string? PtrToStringUTF8(IntPtr ptr)
675 {
676 if (IsNullOrWin32Atom(ptr))
677 {
678 return null;
679 }
680 int byteLength = string.strlen((byte*)(void*)ptr);
681 return string.CreateStringFromEncoding((byte*)(void*)ptr, byteLength, Encoding.UTF8);
682 }
683
684 public unsafe static string PtrToStringUTF8(IntPtr ptr, int byteLen)
685 {
686 if (ptr == IntPtr.Zero)
687 {
688 throw new ArgumentNullException("ptr");
689 }
690 if (byteLen < 0)
691 {
693 }
694 return string.CreateStringFromEncoding((byte*)(void*)ptr, byteLen, Encoding.UTF8);
695 }
696
697 public static int SizeOf(object structure)
698 {
699 if (structure == null)
700 {
701 throw new ArgumentNullException("structure");
702 }
703 return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
704 }
705
706 public static int SizeOf<T>(T structure)
707 {
708 if (structure == null)
709 {
710 throw new ArgumentNullException("structure");
711 }
712 return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
713 }
714
715 public static int SizeOf(Type t)
716 {
717 if ((object)t == null)
718 {
719 throw new ArgumentNullException("t");
720 }
721 if (!t.IsRuntimeImplemented())
722 {
724 }
725 if (t.IsGenericType)
726 {
728 }
729 return SizeOfHelper(t, throwIfNotMarshalable: true);
730 }
731
732 public static int SizeOf<T>()
733 {
734 Type typeFromHandle = typeof(T);
735 if (typeFromHandle.IsGenericType)
736 {
738 }
739 return SizeOfHelper(typeFromHandle, throwIfNotMarshalable: true);
740 }
741
742 public unsafe static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
743 {
744 if (pUnk == IntPtr.Zero)
745 {
746 throw new ArgumentNullException("pUnk");
747 }
748 fixed (Guid* ptr = &iid)
749 {
750 fixed (IntPtr* ptr2 = &ppv)
751 {
752 return ((delegate* unmanaged<IntPtr, Guid*, IntPtr*, int>)(*(*(IntPtr**)(void*)pUnk)))(pUnk, ptr, ptr2);
753 }
754 }
755 }
756
757 public unsafe static int AddRef(IntPtr pUnk)
758 {
759 if (pUnk == IntPtr.Zero)
760 {
761 throw new ArgumentNullException("pUnk");
762 }
763 return ((delegate* unmanaged<IntPtr, int>)(*(IntPtr*)((nint)(*(IntPtr*)(void*)pUnk) + sizeof(void*))))(pUnk);
764 }
765
766 public unsafe static int Release(IntPtr pUnk)
767 {
768 if (pUnk == IntPtr.Zero)
769 {
770 throw new ArgumentNullException("pUnk");
771 }
772 return ((delegate* unmanaged<IntPtr, int>)(*(IntPtr*)((nint)(*(IntPtr*)(void*)pUnk) + (nint)2 * (nint)sizeof(void*))))(pUnk);
773 }
774
775 public unsafe static IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
776 {
777 if (arr == null)
778 {
779 throw new ArgumentNullException("arr");
780 }
781 void* ptr = Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(arr));
782 return (IntPtr)((byte*)ptr + (nuint)((nint)(uint)index * (nint)arr.GetElementSize()));
783 }
784
785 public unsafe static IntPtr UnsafeAddrOfPinnedArrayElement<T>(T[] arr, int index)
786 {
787 if (arr == null)
788 {
789 throw new ArgumentNullException("arr");
790 }
791 void* ptr = Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(arr));
792 return (IntPtr)((byte*)ptr + (nuint)((nint)(uint)index * (nint)Unsafe.SizeOf<T>()));
793 }
794
795 public static IntPtr OffsetOf<T>(string fieldName)
796 {
797 return OffsetOf(typeof(T), fieldName);
798 }
799
800 public static void Copy(int[] source, int startIndex, IntPtr destination, int length)
801 {
802 CopyToNative(source, startIndex, destination, length);
803 }
804
805 public static void Copy(char[] source, int startIndex, IntPtr destination, int length)
806 {
807 CopyToNative(source, startIndex, destination, length);
808 }
809
810 public static void Copy(short[] source, int startIndex, IntPtr destination, int length)
811 {
812 CopyToNative(source, startIndex, destination, length);
813 }
814
815 public static void Copy(long[] source, int startIndex, IntPtr destination, int length)
816 {
817 CopyToNative(source, startIndex, destination, length);
818 }
819
820 public static void Copy(float[] source, int startIndex, IntPtr destination, int length)
821 {
822 CopyToNative(source, startIndex, destination, length);
823 }
824
825 public static void Copy(double[] source, int startIndex, IntPtr destination, int length)
826 {
827 CopyToNative(source, startIndex, destination, length);
828 }
829
830 public static void Copy(byte[] source, int startIndex, IntPtr destination, int length)
831 {
832 CopyToNative(source, startIndex, destination, length);
833 }
834
835 public static void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
836 {
837 CopyToNative(source, startIndex, destination, length);
838 }
839
840 private unsafe static void CopyToNative<T>(T[] source, int startIndex, IntPtr destination, int length)
841 {
842 if (source == null)
843 {
844 throw new ArgumentNullException("source");
845 }
846 if (destination == IntPtr.Zero)
847 {
848 throw new ArgumentNullException("destination");
849 }
851 }
852
853 public static void Copy(IntPtr source, int[] destination, int startIndex, int length)
854 {
855 CopyToManaged(source, destination, startIndex, length);
856 }
857
858 public static void Copy(IntPtr source, char[] destination, int startIndex, int length)
859 {
860 CopyToManaged(source, destination, startIndex, length);
861 }
862
863 public static void Copy(IntPtr source, short[] destination, int startIndex, int length)
864 {
865 CopyToManaged(source, destination, startIndex, length);
866 }
867
868 public static void Copy(IntPtr source, long[] destination, int startIndex, int length)
869 {
870 CopyToManaged(source, destination, startIndex, length);
871 }
872
873 public static void Copy(IntPtr source, float[] destination, int startIndex, int length)
874 {
875 CopyToManaged(source, destination, startIndex, length);
876 }
877
878 public static void Copy(IntPtr source, double[] destination, int startIndex, int length)
879 {
880 CopyToManaged(source, destination, startIndex, length);
881 }
882
883 public static void Copy(IntPtr source, byte[] destination, int startIndex, int length)
884 {
885 CopyToManaged(source, destination, startIndex, length);
886 }
887
888 public static void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
889 {
890 CopyToManaged(source, destination, startIndex, length);
891 }
892
893 private unsafe static void CopyToManaged<T>(IntPtr source, T[] destination, int startIndex, int length)
894 {
895 if (source == IntPtr.Zero)
896 {
897 throw new ArgumentNullException("source");
898 }
899 if (destination == null)
900 {
901 throw new ArgumentNullException("destination");
902 }
903 if (startIndex < 0)
904 {
906 }
907 if (length < 0)
908 {
910 }
912 }
913
914 public unsafe static byte ReadByte(IntPtr ptr, int ofs)
915 {
916 try
917 {
918 byte* ptr2 = (byte*)(void*)ptr + ofs;
919 return *ptr2;
920 }
922 {
923 throw new AccessViolationException();
924 }
925 }
926
927 public static byte ReadByte(IntPtr ptr)
928 {
929 return ReadByte(ptr, 0);
930 }
931
932 public unsafe static short ReadInt16(IntPtr ptr, int ofs)
933 {
934 try
935 {
936 byte* ptr2 = (byte*)(void*)ptr + ofs;
937 if (((int)ptr2 & 1) == 0)
938 {
939 return *(short*)ptr2;
940 }
941 return Unsafe.ReadUnaligned<short>(ptr2);
942 }
944 {
945 throw new AccessViolationException();
946 }
947 }
948
949 public static short ReadInt16(IntPtr ptr)
950 {
951 return ReadInt16(ptr, 0);
952 }
953
954 public unsafe static int ReadInt32(IntPtr ptr, int ofs)
955 {
956 try
957 {
958 byte* ptr2 = (byte*)(void*)ptr + ofs;
959 if (((int)ptr2 & 3) == 0)
960 {
961 return *(int*)ptr2;
962 }
963 return Unsafe.ReadUnaligned<int>(ptr2);
964 }
966 {
967 throw new AccessViolationException();
968 }
969 }
970
971 public static int ReadInt32(IntPtr ptr)
972 {
973 return ReadInt32(ptr, 0);
974 }
975
976 public static IntPtr ReadIntPtr(object ptr, int ofs)
977 {
978 return (IntPtr)ReadInt64(ptr, ofs);
979 }
980
981 public static IntPtr ReadIntPtr(IntPtr ptr, int ofs)
982 {
983 return (IntPtr)ReadInt64(ptr, ofs);
984 }
985
986 public static IntPtr ReadIntPtr(IntPtr ptr)
987 {
988 return ReadIntPtr(ptr, 0);
989 }
990
991 public unsafe static long ReadInt64(IntPtr ptr, int ofs)
992 {
993 try
994 {
995 byte* ptr2 = (byte*)(void*)ptr + ofs;
996 if (((int)ptr2 & 7) == 0)
997 {
998 return *(long*)ptr2;
999 }
1000 return Unsafe.ReadUnaligned<long>(ptr2);
1001 }
1003 {
1004 throw new AccessViolationException();
1005 }
1006 }
1007
1008 public static long ReadInt64(IntPtr ptr)
1009 {
1010 return ReadInt64(ptr, 0);
1011 }
1012
1013 public unsafe static void WriteByte(IntPtr ptr, int ofs, byte val)
1014 {
1015 try
1016 {
1017 byte* ptr2 = (byte*)(void*)ptr + ofs;
1018 *ptr2 = val;
1019 }
1021 {
1022 throw new AccessViolationException();
1023 }
1024 }
1025
1026 public static void WriteByte(IntPtr ptr, byte val)
1027 {
1028 WriteByte(ptr, 0, val);
1029 }
1030
1031 public unsafe static void WriteInt16(IntPtr ptr, int ofs, short val)
1032 {
1033 try
1034 {
1035 byte* ptr2 = (byte*)(void*)ptr + ofs;
1036 if (((int)ptr2 & 1) == 0)
1037 {
1038 *(short*)ptr2 = val;
1039 }
1040 else
1041 {
1042 Unsafe.WriteUnaligned(ptr2, val);
1043 }
1044 }
1046 {
1047 throw new AccessViolationException();
1048 }
1049 }
1050
1051 public static void WriteInt16(IntPtr ptr, short val)
1052 {
1053 WriteInt16(ptr, 0, val);
1054 }
1055
1056 public static void WriteInt16(IntPtr ptr, int ofs, char val)
1057 {
1058 WriteInt16(ptr, ofs, (short)val);
1059 }
1060
1061 public static void WriteInt16([In][Out] object ptr, int ofs, char val)
1062 {
1063 WriteInt16(ptr, ofs, (short)val);
1064 }
1065
1066 public static void WriteInt16(IntPtr ptr, char val)
1067 {
1068 WriteInt16(ptr, 0, (short)val);
1069 }
1070
1071 public unsafe static void WriteInt32(IntPtr ptr, int ofs, int val)
1072 {
1073 try
1074 {
1075 byte* ptr2 = (byte*)(void*)ptr + ofs;
1076 if (((int)ptr2 & 3) == 0)
1077 {
1078 *(int*)ptr2 = val;
1079 }
1080 else
1081 {
1082 Unsafe.WriteUnaligned(ptr2, val);
1083 }
1084 }
1086 {
1087 throw new AccessViolationException();
1088 }
1089 }
1090
1091 public static void WriteInt32(IntPtr ptr, int val)
1092 {
1093 WriteInt32(ptr, 0, val);
1094 }
1095
1096 public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
1097 {
1098 WriteInt64(ptr, ofs, (long)val);
1099 }
1100
1101 public static void WriteIntPtr(object ptr, int ofs, IntPtr val)
1102 {
1103 WriteInt64(ptr, ofs, (long)val);
1104 }
1105
1106 public static void WriteIntPtr(IntPtr ptr, IntPtr val)
1107 {
1108 WriteIntPtr(ptr, 0, val);
1109 }
1110
1111 public unsafe static void WriteInt64(IntPtr ptr, int ofs, long val)
1112 {
1113 try
1114 {
1115 byte* ptr2 = (byte*)(void*)ptr + ofs;
1116 if (((int)ptr2 & 7) == 0)
1117 {
1118 *(long*)ptr2 = val;
1119 }
1120 else
1121 {
1122 Unsafe.WriteUnaligned(ptr2, val);
1123 }
1124 }
1126 {
1127 throw new AccessViolationException();
1128 }
1129 }
1130
1131 public static void WriteInt64(IntPtr ptr, long val)
1132 {
1133 WriteInt64(ptr, 0, val);
1134 }
1135
1136 public static void Prelink(MethodInfo m)
1137 {
1138 if ((object)m == null)
1139 {
1140 throw new ArgumentNullException("m");
1141 }
1142 PrelinkCore(m);
1143 }
1144
1145 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "This only needs to prelink methods that are actually used")]
1146 public static void PrelinkAll(Type c)
1147 {
1148 if ((object)c == null)
1149 {
1150 throw new ArgumentNullException("c");
1151 }
1152 MethodInfo[] methods = c.GetMethods();
1153 for (int i = 0; i < methods.Length; i++)
1154 {
1155 Prelink(methods[i]);
1156 }
1157 }
1158
1159 public static void StructureToPtr<T>([DisallowNull] T structure, IntPtr ptr, bool fDeleteOld)
1160 {
1161 StructureToPtr((object)structure, ptr, fDeleteOld);
1162 }
1163
1164 public static object? PtrToStructure(IntPtr ptr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type structureType)
1165 {
1166 if (ptr == IntPtr.Zero)
1167 {
1168 return null;
1169 }
1170 if ((object)structureType == null)
1171 {
1172 throw new ArgumentNullException("structureType");
1173 }
1174 if (structureType.IsGenericType)
1175 {
1176 throw new ArgumentException(SR.Argument_NeedNonGenericType, "structureType");
1177 }
1178 if (!structureType.IsRuntimeImplemented())
1179 {
1180 throw new ArgumentException(SR.Argument_MustBeRuntimeType, "structureType");
1181 }
1182 object obj = Activator.CreateInstance(structureType, nonPublic: true);
1183 PtrToStructureHelper(ptr, obj, allowValueClasses: true);
1184 return obj;
1185 }
1186
1187 public static void PtrToStructure(IntPtr ptr, object structure)
1188 {
1189 PtrToStructureHelper(ptr, structure, allowValueClasses: false);
1190 }
1191
1192 public static void PtrToStructure<T>(IntPtr ptr, [DisallowNull] T structure)
1193 {
1194 PtrToStructureHelper(ptr, structure, allowValueClasses: false);
1195 }
1196
1197 public static T? PtrToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(IntPtr ptr)
1198 {
1199 if (ptr == IntPtr.Zero)
1200 {
1201 return (T)(object)null;
1202 }
1203 Type typeFromHandle = typeof(T);
1204 if (typeFromHandle.IsGenericType)
1205 {
1207 }
1208 object obj = Activator.CreateInstance(typeFromHandle, nonPublic: true);
1209 PtrToStructureHelper(ptr, obj, allowValueClasses: true);
1210 return (T)obj;
1211 }
1212
1213 public static void DestroyStructure<T>(IntPtr ptr)
1214 {
1215 DestroyStructure(ptr, typeof(T));
1216 }
1217
1218 public static Exception? GetExceptionForHR(int errorCode)
1219 {
1220 return GetExceptionForHR(errorCode, IntPtr.Zero);
1221 }
1222
1223 public static Exception? GetExceptionForHR(int errorCode, IntPtr errorInfo)
1224 {
1225 if (errorCode >= 0)
1226 {
1227 return null;
1228 }
1229 return GetExceptionForHRInternal(errorCode, errorInfo);
1230 }
1231
1232 public static void ThrowExceptionForHR(int errorCode)
1233 {
1234 if (errorCode < 0)
1235 {
1236 throw GetExceptionForHR(errorCode);
1237 }
1238 }
1239
1240 public static void ThrowExceptionForHR(int errorCode, IntPtr errorInfo)
1241 {
1242 if (errorCode < 0)
1243 {
1244 throw GetExceptionForHR(errorCode, errorInfo);
1245 }
1246 }
1247
1249 {
1250 if (s == null)
1251 {
1253 }
1254 return s.MarshalToBSTR();
1255 }
1256
1258 {
1259 if (s == null)
1260 {
1262 }
1263 return s.MarshalToString(globalAlloc: false, unicode: false);
1264 }
1265
1267 {
1268 if (s == null)
1269 {
1271 }
1272 return s.MarshalToString(globalAlloc: false, unicode: true);
1273 }
1274
1276 {
1277 if (s == null)
1278 {
1280 }
1281 return s.MarshalToString(globalAlloc: true, unicode: false);
1282 }
1283
1285 {
1286 if (s == null)
1287 {
1289 }
1290 return s.MarshalToString(globalAlloc: true, unicode: true);
1291 }
1292
1293 public unsafe static IntPtr StringToHGlobalAnsi(string? s)
1294 {
1295 if (s == null)
1296 {
1297 return IntPtr.Zero;
1298 }
1299 long num = (long)(s.Length + 1) * (long)SystemMaxDBCSCharSize;
1300 int num2 = (int)num;
1301 if (num2 != num)
1302 {
1304 }
1305 IntPtr intPtr = AllocHGlobal((IntPtr)num2);
1306 StringToAnsiString(s, (byte*)(void*)intPtr, num2);
1307 return intPtr;
1308 }
1309
1310 public unsafe static IntPtr StringToHGlobalUni(string? s)
1311 {
1312 if (s == null)
1313 {
1314 return IntPtr.Zero;
1315 }
1316 int num = (s.Length + 1) * 2;
1317 if (num < s.Length)
1318 {
1320 }
1321 IntPtr intPtr = AllocHGlobal((IntPtr)num);
1322 s.CopyTo(new Span<char>((void*)intPtr, s.Length));
1323 *(short*)((byte*)(void*)intPtr + (nint)s.Length * (nint)2) = 0;
1324 return intPtr;
1325 }
1326
1327 public unsafe static IntPtr StringToCoTaskMemUni(string? s)
1328 {
1329 if (s == null)
1330 {
1331 return IntPtr.Zero;
1332 }
1333 int num = (s.Length + 1) * 2;
1334 if (num < s.Length)
1335 {
1337 }
1338 IntPtr intPtr = AllocCoTaskMem(num);
1339 s.CopyTo(new Span<char>((void*)intPtr, s.Length));
1340 *(short*)((byte*)(void*)intPtr + (nint)s.Length * (nint)2) = 0;
1341 return intPtr;
1342 }
1343
1344 public unsafe static IntPtr StringToCoTaskMemUTF8(string? s)
1345 {
1346 if (s == null)
1347 {
1348 return IntPtr.Zero;
1349 }
1350 int maxByteCount = Encoding.UTF8.GetMaxByteCount(s.Length);
1351 IntPtr intPtr = AllocCoTaskMem(maxByteCount + 1);
1352 byte* ptr = (byte*)(void*)intPtr;
1353 int bytes;
1354 fixed (char* chars = s)
1355 {
1356 bytes = Encoding.UTF8.GetBytes(chars, s.Length, ptr, maxByteCount);
1357 }
1358 ptr[bytes] = 0;
1359 return intPtr;
1360 }
1361
1362 public unsafe static IntPtr StringToCoTaskMemAnsi(string? s)
1363 {
1364 if (s == null)
1365 {
1366 return IntPtr.Zero;
1367 }
1368 long num = (long)(s.Length + 1) * (long)SystemMaxDBCSCharSize;
1369 int num2 = (int)num;
1370 if (num2 != num)
1371 {
1373 }
1374 IntPtr intPtr = AllocCoTaskMem(num2);
1375 StringToAnsiString(s, (byte*)(void*)intPtr, num2);
1376 return intPtr;
1377 }
1378
1380 {
1381 if ((object)type == null)
1382 {
1383 throw new ArgumentNullException("type");
1384 }
1385 if (!type.IsRuntimeImplemented())
1386 {
1388 }
1389 return type.GUID;
1390 }
1391
1392 public static string? GenerateProgIdForType(Type type)
1393 {
1394 if ((object)type == null)
1395 {
1396 throw new ArgumentNullException("type");
1397 }
1398 if (type.IsImport)
1399 {
1401 }
1402 if (type.IsGenericType)
1403 {
1405 }
1407 if (customAttribute != null)
1408 {
1409 return customAttribute.Value ?? string.Empty;
1410 }
1411 return type.FullName;
1412 }
1413
1415 {
1416 if (ptr == IntPtr.Zero)
1417 {
1418 throw new ArgumentNullException("ptr");
1419 }
1420 if ((object)t == null)
1421 {
1422 throw new ArgumentNullException("t");
1423 }
1424 if (!t.IsRuntimeImplemented())
1425 {
1427 }
1428 if (t.IsGenericType)
1429 {
1431 }
1432 if (t.BaseType != typeof(MulticastDelegate) && t != typeof(MulticastDelegate))
1433 {
1434 throw new ArgumentException(SR.Arg_MustBeDelegate, "t");
1435 }
1437 }
1438
1440 {
1441 if (ptr == IntPtr.Zero)
1442 {
1443 throw new ArgumentNullException("ptr");
1444 }
1445 Type typeFromHandle = typeof(TDelegate);
1446 if (typeFromHandle.IsGenericType)
1447 {
1448 throw new ArgumentException(SR.Argument_NeedNonGenericType, "TDelegate");
1449 }
1450 if (typeFromHandle.BaseType != typeof(MulticastDelegate) && typeFromHandle != typeof(MulticastDelegate))
1451 {
1452 throw new ArgumentException(SR.Arg_MustBeDelegate, "TDelegate");
1453 }
1454 return (TDelegate)(object)GetDelegateForFunctionPointerInternal(ptr, typeFromHandle);
1455 }
1456
1458 {
1459 if ((object)d == null)
1460 {
1461 throw new ArgumentNullException("d");
1462 }
1464 }
1465
1466 public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull
1467 {
1468 return GetFunctionPointerForDelegate((Delegate)(object)d);
1469 }
1470
1471 public static int GetHRForLastWin32Error()
1472 {
1473 int lastPInvokeError = GetLastPInvokeError();
1474 if ((lastPInvokeError & 0x80000000u) == 2147483648u)
1475 {
1476 return lastPInvokeError;
1477 }
1478 return (lastPInvokeError & 0xFFFF) | -2147024896;
1479 }
1480
1481 public unsafe static void ZeroFreeBSTR(IntPtr s)
1482 {
1483 if (!(s == IntPtr.Zero))
1484 {
1485 Buffer.ZeroMemory((byte*)(void*)s, SysStringByteLen(s));
1486 FreeBSTR(s);
1487 }
1488 }
1489
1490 public static void ZeroFreeCoTaskMemAnsi(IntPtr s)
1491 {
1493 }
1494
1495 public unsafe static void ZeroFreeCoTaskMemUnicode(IntPtr s)
1496 {
1497 if (!(s == IntPtr.Zero))
1498 {
1499 Buffer.ZeroMemory((byte*)(void*)s, (nuint)string.wcslen((char*)(void*)s) * (nuint)2u);
1501 }
1502 }
1503
1504 public unsafe static void ZeroFreeCoTaskMemUTF8(IntPtr s)
1505 {
1506 if (!(s == IntPtr.Zero))
1507 {
1508 Buffer.ZeroMemory((byte*)(void*)s, (nuint)string.strlen((byte*)(void*)s));
1510 }
1511 }
1512
1513 public unsafe static void ZeroFreeGlobalAllocAnsi(IntPtr s)
1514 {
1515 if (!(s == IntPtr.Zero))
1516 {
1517 Buffer.ZeroMemory((byte*)(void*)s, (nuint)string.strlen((byte*)(void*)s));
1518 FreeHGlobal(s);
1519 }
1520 }
1521
1522 public unsafe static void ZeroFreeGlobalAllocUnicode(IntPtr s)
1523 {
1524 if (!(s == IntPtr.Zero))
1525 {
1526 Buffer.ZeroMemory((byte*)(void*)s, (nuint)string.wcslen((char*)(void*)s) * (nuint)2u);
1527 FreeHGlobal(s);
1528 }
1529 }
1530
1531 public unsafe static IntPtr StringToBSTR(string? s)
1532 {
1533 if (s == null)
1534 {
1535 return IntPtr.Zero;
1536 }
1537 IntPtr intPtr = AllocBSTR(s.Length);
1538 s.CopyTo(new Span<char>((void*)intPtr, s.Length));
1539 return intPtr;
1540 }
1541
1542 public static string PtrToStringBSTR(IntPtr ptr)
1543 {
1544 if (ptr == IntPtr.Zero)
1545 {
1546 throw new ArgumentNullException("ptr");
1547 }
1548 return PtrToStringUni(ptr, (int)(SysStringByteLen(ptr) / 2));
1549 }
1550
1551 internal unsafe static uint SysStringByteLen(IntPtr s)
1552 {
1553 return *(uint*)((byte*)(void*)s - 4);
1554 }
1555
1556 [SupportedOSPlatform("windows")]
1557 public static Type? GetTypeFromCLSID(Guid clsid)
1558 {
1559 return GetTypeFromCLSID(clsid, null, throwOnError: false);
1560 }
1561
1562 public static void InitHandle(SafeHandle safeHandle, IntPtr handle)
1563 {
1564 safeHandle.SetHandle(handle);
1565 }
1566
1567 public static int GetLastWin32Error()
1568 {
1569 return GetLastPInvokeError();
1570 }
1571
1572 public static string? PtrToStringAuto(IntPtr ptr, int len)
1573 {
1574 return PtrToStringUni(ptr, len);
1575 }
1576
1577 public static string? PtrToStringAuto(IntPtr ptr)
1578 {
1579 return PtrToStringUni(ptr);
1580 }
1581
1582 public static IntPtr StringToHGlobalAuto(string? s)
1583 {
1584 return StringToHGlobalUni(s);
1585 }
1586
1587 public static IntPtr StringToCoTaskMemAuto(string? s)
1588 {
1589 return StringToCoTaskMemUni(s);
1590 }
1591
1592 private unsafe static int GetSystemMaxDBCSCharSize()
1593 {
1595 if (Interop.Kernel32.GetCPInfo(0u, &cPINFO) == Interop.BOOL.FALSE)
1596 {
1597 return 2;
1598 }
1599 return cPINFO.MaxCharSize;
1600 }
1601
1602 private static bool IsNullOrWin32Atom(IntPtr ptr)
1603 {
1604 long num = (long)ptr;
1605 return (num & -65536) == 0;
1606 }
1607
1608 internal unsafe static int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
1609 {
1610 uint dwFlags = ((!bestFit) ? 1024u : 0u);
1611 uint num = 0u;
1612 int num2;
1613 fixed (char* lpWideCharStr = s)
1614 {
1615 num2 = Interop.Kernel32.WideCharToMultiByte(0u, dwFlags, lpWideCharStr, s.Length, buffer, bufferLength, IntPtr.Zero, throwOnUnmappableChar ? new IntPtr(&num) : IntPtr.Zero);
1616 }
1617 if (num != 0)
1618 {
1620 }
1621 buffer[num2] = 0;
1622 return num2;
1623 }
1624
1626 {
1627 int num;
1628 if (chars.Length == 0)
1629 {
1630 num = 0;
1631 }
1632 else
1633 {
1634 fixed (char* lpWideCharStr = chars)
1635 {
1636 num = Interop.Kernel32.WideCharToMultiByte(0u, 1024u, lpWideCharStr, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
1637 if (num <= 0)
1638 {
1639 throw new ArgumentException();
1640 }
1641 }
1642 }
1643 return checked(num + 1);
1644 }
1645
1647 {
1648 int num;
1649 if (chars.Length == 0)
1650 {
1651 num = 0;
1652 }
1653 else
1654 {
1655 fixed (char* lpWideCharStr = chars)
1656 {
1657 fixed (byte* lpMultiByteStr = bytes)
1658 {
1659 num = Interop.Kernel32.WideCharToMultiByte(0u, 1024u, lpWideCharStr, chars.Length, lpMultiByteStr, bytes.Length, IntPtr.Zero, IntPtr.Zero);
1660 if (num <= 0)
1661 {
1662 throw new ArgumentException();
1663 }
1664 }
1665 }
1666 }
1667 bytes[num] = 0;
1668 }
1669
1670 public static IntPtr AllocHGlobal(IntPtr cb)
1671 {
1672 IntPtr intPtr = Interop.Kernel32.LocalAlloc(0u, (nuint)(nint)cb);
1673 if (intPtr == IntPtr.Zero)
1674 {
1675 throw new OutOfMemoryException();
1676 }
1677 return intPtr;
1678 }
1679
1680 public static void FreeHGlobal(IntPtr hglobal)
1681 {
1682 if (!IsNullOrWin32Atom(hglobal))
1683 {
1684 Interop.Kernel32.LocalFree(hglobal);
1685 }
1686 }
1687
1688 public static IntPtr ReAllocHGlobal(IntPtr pv, IntPtr cb)
1689 {
1690 if (pv == IntPtr.Zero)
1691 {
1692 return AllocHGlobal(cb);
1693 }
1694 IntPtr intPtr = Interop.Kernel32.LocalReAlloc(pv, (nuint)(nint)cb, 2u);
1695 if (intPtr == IntPtr.Zero)
1696 {
1697 throw new OutOfMemoryException();
1698 }
1699 return intPtr;
1700 }
1701
1702 public static IntPtr AllocCoTaskMem(int cb)
1703 {
1704 IntPtr intPtr = Interop.Ole32.CoTaskMemAlloc((uint)cb);
1705 if (intPtr == IntPtr.Zero)
1706 {
1707 throw new OutOfMemoryException();
1708 }
1709 return intPtr;
1710 }
1711
1712 public static void FreeCoTaskMem(IntPtr ptr)
1713 {
1714 if (!IsNullOrWin32Atom(ptr))
1715 {
1717 }
1718 }
1719
1720 public static IntPtr ReAllocCoTaskMem(IntPtr pv, int cb)
1721 {
1722 IntPtr intPtr = Interop.Ole32.CoTaskMemRealloc(pv, (uint)cb);
1723 if (intPtr == IntPtr.Zero && cb != 0)
1724 {
1725 throw new OutOfMemoryException();
1726 }
1727 return intPtr;
1728 }
1729
1730 internal static IntPtr AllocBSTR(int length)
1731 {
1733 if (intPtr == IntPtr.Zero)
1734 {
1735 throw new OutOfMemoryException();
1736 }
1737 return intPtr;
1738 }
1739
1740 internal static IntPtr AllocBSTRByteLen(uint length)
1741 {
1743 if (intPtr == IntPtr.Zero)
1744 {
1745 throw new OutOfMemoryException();
1746 }
1747 return intPtr;
1748 }
1749
1750 public static void FreeBSTR(IntPtr ptr)
1751 {
1752 if (!IsNullOrWin32Atom(ptr))
1753 {
1755 }
1756 }
1757
1758 internal static Type GetTypeFromProgID(string progID, string server, bool throwOnError)
1759 {
1760 if (progID == null)
1761 {
1762 throw new ArgumentNullException("progID");
1763 }
1764 Guid lpclsid;
1765 int num = Interop.Ole32.CLSIDFromProgID(progID, out lpclsid);
1766 if (num < 0)
1767 {
1768 if (throwOnError)
1769 {
1770 throw GetExceptionForHR(num, new IntPtr(-1));
1771 }
1772 return null;
1773 }
1774 return GetTypeFromCLSID(lpclsid, server, throwOnError);
1775 }
1776
1777 public static int GetLastSystemError()
1778 {
1779 return Interop.Kernel32.GetLastError();
1780 }
1781
1782 public static void SetLastSystemError(int error)
1783 {
1785 }
1786}
static unsafe BOOL GetCPInfo(uint codePage, CPINFO *lpCpInfo)
static void SetLastError(int errorCode)
static IntPtr LocalFree(IntPtr hMem)
static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, char *lpWideCharStr, int cchWideChar, byte *lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar)
static IntPtr LocalReAlloc(IntPtr hMem, nuint uBytes, uint uFlags)
static int GetLastError()
static IntPtr LocalAlloc(uint uFlags, nuint uBytes)
static IntPtr CoTaskMemRealloc(IntPtr pv, nuint cb)
static void CoTaskMemFree(IntPtr ptr)
static IntPtr CoTaskMemAlloc(nuint cb)
static int CLSIDFromProgID(string lpszProgID, out Guid lpclsid)
static IntPtr SysAllocStringLen(IntPtr src, uint len)
static void SysFreeString(IntPtr bstr)
static IntPtr SysAllocStringByteLen(byte[] str, uint len)
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static ? Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
Definition Attribute.cs:411
static unsafe void ZeroMemory(byte *dest, nuint len)
Definition Buffer.cs:188
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static unsafe int AddRef(IntPtr pUnk)
Definition Marshal.cs:757
static ? object[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
Definition Marshal.cs:556
static void Copy(IntPtr source, double[] destination, int startIndex, int length)
Definition Marshal.cs:878
static void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
Definition Marshal.cs:510
static unsafe void ZeroFreeGlobalAllocUnicode(IntPtr s)
Definition Marshal.cs:1522
static IntPtr GetIUnknownForObjectNative(object o)
static unsafe void WriteByte(IntPtr ptr, int ofs, byte val)
Definition Marshal.cs:1013
static IntPtr GetFunctionPointerForDelegate< TDelegate >(TDelegate d)
Definition Marshal.cs:1466
static unsafe int StringToAnsiString(string s, byte *buffer, int bufferLength, bool bestFit=false, bool throwOnUnmappableChar=false)
Definition Marshal.cs:1608
static T[] GetObjectsForNativeVariants< T >(IntPtr aSrcNativeVariant, int cVars)
Definition Marshal.cs:569
static void WriteInt32(object ptr, int ofs, int val)
Definition Marshal.cs:105
static TDelegate GetDelegateForFunctionPointer< TDelegate >(IntPtr ptr)
Definition Marshal.cs:1439
static void DestroyStructure< T >(IntPtr ptr)
Definition Marshal.cs:1213
static void WriteInt16(IntPtr ptr, char val)
Definition Marshal.cs:1066
static unsafe void CopyToNative< T >(T[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:840
static bool IsNullOrWin32Atom(IntPtr ptr)
Definition Marshal.cs:1602
static byte ReadByte(IntPtr ptr)
Definition Marshal.cs:927
static Exception GetExceptionForHRInternal(int errorCode, IntPtr errorInfo)
static IntPtr AllocBSTR(int length)
Definition Marshal.cs:1730
static unsafe string PtrToStringAnsi(IntPtr ptr, int len)
Definition Marshal.cs:639
static ? object GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
Definition Marshal.cs:533
static void Copy(double[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:825
static IntPtr OffsetOf< T >(string fieldName)
Definition Marshal.cs:795
static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
Definition Marshal.cs:277
static void CleanupUnusedObjectsInCurrentContext()
static void WriteInt16(object ptr, int ofs, short val)
Definition Marshal.cs:97
static void Copy(char[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:805
static long ReadInt64(IntPtr ptr)
Definition Marshal.cs:1008
static object GetUniqueObjectForIUnknown(IntPtr unknown)
Definition Marshal.cs:308
static ? object CreateWrapperOfType(object? o, Type t)
Definition Marshal.cs:451
static void WriteInt16(IntPtr ptr, int ofs, char val)
Definition Marshal.cs:1056
static unsafe string PtrToStringUni(IntPtr ptr, int len)
Definition Marshal.cs:661
static void GetNativeVariantForObject< T >(T? obj, IntPtr pDstNativeVariant)
Definition Marshal.cs:523
static IntPtr ReAllocHGlobal(IntPtr pv, IntPtr cb)
Definition Marshal.cs:1688
static object GetObjectForIUnknownNative(IntPtr pUnk)
static void PrelinkCore(MethodInfo m)
Definition Marshal.cs:148
static void WriteInt64(IntPtr ptr, long val)
Definition Marshal.cs:1131
static void CreateBindCtx(uint reserved, out IBindCtx ppbc)
static void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld)
static IntPtr GetIDispatchForObject(object o)
Definition Marshal.cs:244
static void InternalFinalReleaseComObject(object o)
static ? Type GetTypeFromCLSID(Guid clsid)
Definition Marshal.cs:1557
static unsafe long ReadInt64(IntPtr ptr, int ofs)
Definition Marshal.cs:991
static ? Exception GetExceptionForHR(int errorCode, IntPtr errorInfo)
Definition Marshal.cs:1223
static IntPtr SecureStringToCoTaskMemAnsi(SecureString s)
Definition Marshal.cs:1257
static void ThrowExceptionForHR(int errorCode, IntPtr errorInfo)
Definition Marshal.cs:1240
static int ReleaseComObject(object o)
Definition Marshal.cs:363
static void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
Definition Marshal.cs:888
static void WriteByte(IntPtr ptr, byte val)
Definition Marshal.cs:1026
static void Copy(float[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:820
static void Copy(short[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:810
static unsafe void WriteValueSlow< T >(object ptr, int ofs, T val, Action< IntPtr, int, T > writeValueHelper)
Definition Marshal.cs:121
static void Copy(IntPtr source, short[] destination, int startIndex, int length)
Definition Marshal.cs:863
static ? string PtrToStringAuto(IntPtr ptr, int len)
Definition Marshal.cs:1572
static IntPtr GetIDispatchForObjectNative(object o)
static unsafe int ReadInt32(IntPtr ptr, int ofs)
Definition Marshal.cs:954
static IntPtr GetFunctionPointerForDelegate(Delegate d)
Definition Marshal.cs:1457
static IntPtr ReadIntPtr(IntPtr ptr, int ofs)
Definition Marshal.cs:981
static IntPtr SecureStringToGlobalAllocUnicode(SecureString s)
Definition Marshal.cs:1284
static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
Definition Marshal.cs:1414
static unsafe T ReadValueSlow< T >(object ptr, int ofs, Func< IntPtr, int, T > readValueHelper)
Definition Marshal.cs:69
static void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk)
static void PtrToStructure< T >(IntPtr ptr, [DisallowNull] T structure)
Definition Marshal.cs:1192
static IntPtr ReadIntPtr(object ptr, int ofs)
Definition Marshal.cs:976
static IntPtr SecureStringToGlobalAllocAnsi(SecureString s)
Definition Marshal.cs:1275
static IntPtr ReadIntPtr(IntPtr ptr)
Definition Marshal.cs:986
static unsafe IntPtr StringToCoTaskMemUni(string? s)
Definition Marshal.cs:1327
static object GetTypedObjectForIUnknown(IntPtr pUnk, Type t)
static IntPtr GetComInterfaceForObject(object o, Type T)
Definition Marshal.cs:257
static ? Exception GetExceptionForHR(int errorCode)
Definition Marshal.cs:1218
static object BindToMoniker(string monikerName)
Definition Marshal.cs:591
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static long ReadInt64([In][MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
Definition Marshal.cs:64
static IntPtr GetHINSTANCE(Module m)
Definition Marshal.cs:182
static int ReadInt32(object ptr, int ofs)
Definition Marshal.cs:59
static unsafe void WriteInt64(IntPtr ptr, int ofs, long val)
Definition Marshal.cs:1111
static readonly int SystemDefaultCharSize
Definition Marshal.cs:17
static unsafe void ZeroFreeCoTaskMemUTF8(IntPtr s)
Definition Marshal.cs:1504
static void FreeCoTaskMem(IntPtr ptr)
Definition Marshal.cs:1712
static unsafe void ZeroFreeBSTR(IntPtr s)
Definition Marshal.cs:1481
static unsafe int Release(IntPtr pUnk)
Definition Marshal.cs:766
static void WriteInt32(IntPtr ptr, int val)
Definition Marshal.cs:1091
static byte ReadByte(object ptr, int ofs)
Definition Marshal.cs:49
static bool IsTypeVisibleFromCom(Type t)
static unsafe short ReadInt16(IntPtr ptr, int ofs)
Definition Marshal.cs:932
static Guid GenerateGuidForType(Type type)
Definition Marshal.cs:1379
static unsafe IntPtr StringToCoTaskMemUTF8(string? s)
Definition Marshal.cs:1344
static void WriteByte(object ptr, int ofs, byte val)
Definition Marshal.cs:89
static object GetObjectForIUnknown(IntPtr pUnk)
Definition Marshal.cs:295
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
static void WriteIntPtr(IntPtr ptr, IntPtr val)
Definition Marshal.cs:1106
static unsafe? string PtrToStringAnsi(IntPtr ptr)
Definition Marshal.cs:630
static object[] GetObjectsForNativeVariantsNative(IntPtr aSrcNativeVariant, int cVars)
static int ReadInt32(IntPtr ptr)
Definition Marshal.cs:971
static Delegate GetDelegateForFunctionPointerInternal(IntPtr ptr, Type t)
static unsafe uint SysStringByteLen(IntPtr s)
Definition Marshal.cs:1551
static int InternalReleaseComObject(object o)
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static void Copy(IntPtr source, byte[] destination, int startIndex, int length)
Definition Marshal.cs:883
static void Copy(IntPtr source, long[] destination, int startIndex, int length)
Definition Marshal.cs:868
static IntPtr AllocHGlobal(IntPtr cb)
Definition Marshal.cs:1670
static void Prelink(MethodInfo m)
Definition Marshal.cs:1136
static IntPtr CreateAggregatedObjectNative(IntPtr pOuter, object o)
static short ReadInt16(object ptr, int ofs)
Definition Marshal.cs:54
static Type GetTypeFromProgID(string progID, string server, bool throwOnError)
Definition Marshal.cs:1758
static ? string GenerateProgIdForType(Type type)
Definition Marshal.cs:1392
static IntPtr GetIUnknownForObject(object o)
Definition Marshal.cs:231
static void WriteInt16(IntPtr ptr, short val)
Definition Marshal.cs:1051
static object InternalCreateWrapperOfType(object o, Type t)
static void Copy(IntPtr source, int[] destination, int startIndex, int length)
Definition Marshal.cs:853
static void Copy(IntPtr source, char[] destination, int startIndex, int length)
Definition Marshal.cs:858
static IntPtr SecureStringToCoTaskMemUnicode(SecureString s)
Definition Marshal.cs:1266
static void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult)
static unsafe int GetAnsiStringByteCount(ReadOnlySpan< char > chars)
Definition Marshal.cs:1625
static bool IsComObject(object o)
Definition Marshal.cs:353
static unsafe IntPtr StringToBSTR(string? s)
Definition Marshal.cs:1531
static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
Definition Marshal.cs:325
static ? object PtrToStructure(IntPtr ptr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type structureType)
Definition Marshal.cs:1164
static unsafe byte ReadByte(IntPtr ptr, int ofs)
Definition Marshal.cs:914
static IntPtr GetComInterfaceForObjectNative(object o, Type t, bool fEnableCustomizedQueryInterface)
static void ZeroFreeCoTaskMemAnsi(IntPtr s)
Definition Marshal.cs:1490
static unsafe IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
Definition Marshal.cs:775
static IntPtr AllocCoTaskMem(int cb)
Definition Marshal.cs:1702
static TWrapper CreateWrapperOfType< T, TWrapper >(T? o)
Definition Marshal.cs:494
static IntPtr StringToCoTaskMemAuto(string? s)
Definition Marshal.cs:1587
static bool SetComObjectData(object obj, object key, object? data)
Definition Marshal.cs:428
static void Copy(long[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:815
static unsafe void WriteInt32(IntPtr ptr, int ofs, int val)
Definition Marshal.cs:1071
static int SizeOf(object structure)
Definition Marshal.cs:697
static IntPtr GetHINSTANCE(QCallModule m)
static unsafe IntPtr UnsafeAddrOfPinnedArrayElement< T >(T[] arr, int index)
Definition Marshal.cs:785
static unsafe void CopyToManaged< T >(IntPtr source, T[] destination, int startIndex, int length)
Definition Marshal.cs:893
static void PtrToStructureHelper(IntPtr ptr, object structure, bool allowValueClasses)
static IntPtr GetFunctionPointerForDelegateInternal(Delegate d)
static object GetUniqueObjectForIUnknownNative(IntPtr unknown)
static unsafe IntPtr StringToCoTaskMemAnsi(string? s)
Definition Marshal.cs:1362
static void PtrToStructure(IntPtr ptr, object structure)
Definition Marshal.cs:1187
static short ReadInt16(IntPtr ptr)
Definition Marshal.cs:949
static void ThrowExceptionForHR(int errorCode)
Definition Marshal.cs:1232
static Type GetTypeFromCLSID(Guid clsid, string server, bool throwOnError)
Definition Marshal.cs:216
static void SetLastSystemError(int error)
Definition Marshal.cs:1782
static void GetTypeFromCLSID(in Guid clsid, string server, ObjectHandleOnStack retType)
static bool IsPinnable(object obj)
static unsafe? string PtrToStringUTF8(IntPtr ptr)
Definition Marshal.cs:674
static string PtrToStringBSTR(IntPtr ptr)
Definition Marshal.cs:1542
static void GetNativeVariantForObjectNative(object obj, IntPtr pDstNativeVariant)
static IntPtr OffsetOfHelper(IRuntimeFieldInfo f)
static unsafe void GetAnsiStringBytes(ReadOnlySpan< char > chars, Span< byte > bytes)
Definition Marshal.cs:1646
static void InternalPrelink(RuntimeMethodHandleInternal m)
static unsafe void ZeroFreeGlobalAllocAnsi(IntPtr s)
Definition Marshal.cs:1513
static void DestroyStructure(IntPtr ptr, Type structuretype)
static unsafe void ZeroFreeCoTaskMemUnicode(IntPtr s)
Definition Marshal.cs:1495
static ? string PtrToStringAuto(IntPtr ptr)
Definition Marshal.cs:1577
static IntPtr GetComInterfaceForObject< T, TInterface >([DisallowNull] T o)
Definition Marshal.cs:271
static unsafe IntPtr StringToHGlobalAnsi(string? s)
Definition Marshal.cs:1293
static object GetObjectForNativeVariantNative(IntPtr pSrcNativeVariant)
static void WriteInt64(object ptr, int ofs, long val)
Definition Marshal.cs:113
static void ChangeWrapperHandleStrength(object otp, bool fIsWeak)
static int SizeOfHelper(Type t, bool throwIfNotMarshalable)
static IntPtr ReAllocCoTaskMem(IntPtr pv, int cb)
Definition Marshal.cs:1720
static readonly int SystemMaxDBCSCharSize
Definition Marshal.cs:19
static void WriteInt16([In][Out] object ptr, int ofs, char val)
Definition Marshal.cs:1061
static void Copy(IntPtr source, float[] destination, int startIndex, int length)
Definition Marshal.cs:873
static IntPtr SecureStringToBSTR(SecureString s)
Definition Marshal.cs:1248
static void SetLastPInvokeError(int error)
static string GetTypeInfoName(ITypeInfo typeInfo)
Definition Marshal.cs:206
static unsafe IntPtr StringToHGlobalUni(string? s)
Definition Marshal.cs:1310
static int GetHRForException(Exception? e)
static void WriteIntPtr(object ptr, int ofs, IntPtr val)
Definition Marshal.cs:1101
static void StructureToPtr< T >([DisallowNull] T structure, IntPtr ptr, bool fDeleteOld)
Definition Marshal.cs:1159
static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
Definition Marshal.cs:1096
static unsafe int GetSystemMaxDBCSCharSize()
Definition Marshal.cs:1592
static IntPtr AllocBSTRByteLen(uint length)
Definition Marshal.cs:1740
static IntPtr AllocHGlobal(int cb)
Definition Marshal.cs:625
static unsafe string PtrToStringUTF8(IntPtr ptr, int byteLen)
Definition Marshal.cs:684
static void InitHandle(SafeHandle safeHandle, IntPtr handle)
Definition Marshal.cs:1562
static int FinalReleaseComObject(object o)
Definition Marshal.cs:384
static unsafe void WriteInt16(IntPtr ptr, int ofs, short val)
Definition Marshal.cs:1031
static IntPtr StringToHGlobalAuto(string? s)
Definition Marshal.cs:1582
static void FreeBSTR(IntPtr ptr)
Definition Marshal.cs:1750
static ? object GetComObjectData(object obj, object key)
Definition Marshal.cs:406
static IntPtr CreateAggregatedObject< T >(IntPtr pOuter, T o)
Definition Marshal.cs:338
static unsafe int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
Definition Marshal.cs:742
static ? T GetObjectForNativeVariant< T >(IntPtr pSrcNativeVariant)
Definition Marshal.cs:546
static void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:835
static void Copy(byte[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:830
static IntPtr OffsetOf(Type t, string fieldName)
Definition Marshal.cs:28
static unsafe ref byte GetArrayDataReference(Array array)
static string NotSupported_COM
Definition SR.cs:2190
static string Argument_OffsetOfFieldNotFound
Definition SR.cs:826
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_NeedNonGenericType
Definition SR.cs:794
static string Argument_TypeMustNotBeComImport
Definition SR.cs:894
static string Argument_ObjNotComObject
Definition SR.cs:820
static string ArgumentOutOfRange_StartIndex
Definition SR.cs:1106
static string Arg_MustBeDelegate
Definition SR.cs:268
static string Argument_MustBeRuntimeMethodInfo
Definition SR.cs:778
static string Argument_TypeNotComObject
Definition SR.cs:898
static string Interop_Marshal_Unmappable_Char
Definition SR.cs:1374
static string Argument_MustBeRuntimeFieldInfo
Definition SR.cs:776
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
static string Argument_MustBeRuntimeType
Definition SR.cs:782
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowArgumentNullException(string name)
bool IsCOMObject
Definition Type.cs:223
FieldInfo? GetField(string name)
Definition Type.cs:607
virtual bool IsGenericType
Definition Type.cs:111
bool IsRuntimeImplemented()
Definition Type.cs:470
Type? BaseType
Definition Type.cs:295
string? FullName
Definition Type.cs:47
MethodInfo[] GetMethods()
Definition Type.cs:788
void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile)
static readonly IntPtr Zero
Definition IntPtr.cs:18
void CopyTo(Span< T > destination)
Definition Span.cs:224
IntPtr ConvertToNative(object pManagedHome, int dwFlags)
void ClearNative(IntPtr pNativeHome)
unsafe void ConvertToManaged(object pManagedHome, IntPtr pNativeHome)