1 // System.Runtime.InteropServices.Marshal.cs
3 // Sean MacIsaac (macisaac@ximian.com)
4 // Paolo Molaro (lupus@ximian.com)
5 // Dietmar Maurer (dietmar@ximian.com)
7 // (C) 2001-2002 Ximian, Inc.
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Runtime
.CompilerServices
;
34 using System
.Security
;
35 using System
.Reflection
;
36 using System
.Threading
;
39 using System
.Runtime
.ConstrainedExecution
;
42 namespace System
.Runtime
.InteropServices
44 [SuppressUnmanagedCodeSecurity ()]
54 public static readonly int SystemMaxDBCSCharSize
= 2; // don't know what this is
55 public static readonly int SystemDefaultCharSize
= 2;
62 public static int AddRef (IntPtr pUnk
) {
63 throw new NotImplementedException ();
66 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
67 public extern static IntPtr
AllocCoTaskMem (int cb
);
69 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
70 public extern static IntPtr
AllocHGlobal (IntPtr cb
);
72 public static IntPtr
AllocHGlobal (int cb
) {
73 return AllocHGlobal ((IntPtr
)cb
);
77 public static object BindToMoniker (string monikerName
) {
78 throw new NotImplementedException ();
82 public static void ChangeWrapperHandleStrength (object otp
, bool fIsWeak
) {
83 throw new NotImplementedException ();
86 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
87 extern static void copy_to_unmanaged (Array source
, int startIndex
,
88 IntPtr destination
, int length
);
90 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
91 extern static void copy_from_unmanaged (IntPtr source
, int startIndex
,
92 Array destination
, int length
);
94 public static void Copy (byte[] source
, int startIndex
, IntPtr destination
, int length
) {
95 copy_to_unmanaged (source
, startIndex
, destination
, length
);
98 public static void Copy (char[] source
, int startIndex
, IntPtr destination
, int length
) {
99 copy_to_unmanaged (source
, startIndex
, destination
, length
);
102 public static void Copy (short[] source
, int startIndex
, IntPtr destination
, int length
) {
103 copy_to_unmanaged (source
, startIndex
, destination
, length
);
106 public static void Copy (int[] source
, int startIndex
, IntPtr destination
, int length
) {
107 copy_to_unmanaged (source
, startIndex
, destination
, length
);
110 public static void Copy (long[] source
, int startIndex
, IntPtr destination
, int length
) {
111 copy_to_unmanaged (source
, startIndex
, destination
, length
);
114 public static void Copy (float[] source
, int startIndex
, IntPtr destination
, int length
) {
115 copy_to_unmanaged (source
, startIndex
, destination
, length
);
118 public static void Copy (double[] source
, int startIndex
, IntPtr destination
, int length
) {
119 copy_to_unmanaged (source
, startIndex
, destination
, length
);
122 public static void Copy (IntPtr source
, byte[] destination
, int startIndex
, int length
) {
123 copy_from_unmanaged (source
, startIndex
, destination
, length
);
126 public static void Copy (IntPtr source
, char[] destination
, int startIndex
, int length
) {
127 copy_from_unmanaged (source
, startIndex
, destination
, length
);
130 public static void Copy (IntPtr source
, short[] destination
, int startIndex
, int length
) {
131 copy_from_unmanaged (source
, startIndex
, destination
, length
);
134 public static void Copy (IntPtr source
, int[] destination
, int startIndex
, int length
) {
135 copy_from_unmanaged (source
, startIndex
, destination
, length
);
138 public static void Copy (IntPtr source
, long[] destination
, int startIndex
, int length
) {
139 copy_from_unmanaged (source
, startIndex
, destination
, length
);
142 public static void Copy (IntPtr source
, float[] destination
, int startIndex
, int length
) {
143 copy_from_unmanaged (source
, startIndex
, destination
, length
);
146 public static void Copy (IntPtr source
, double[] destination
, int startIndex
, int length
) {
147 copy_from_unmanaged (source
, startIndex
, destination
, length
);
151 public static object CreateWrapperOfType (object o
, Type t
) {
152 throw new NotImplementedException ();
155 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
156 public extern static void DestroyStructure (IntPtr ptr
, Type structuretype
);
159 public static void FreeBSTR (IntPtr ptr
) {
160 throw new NotImplementedException ();
163 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
164 public extern static void FreeCoTaskMem (IntPtr ptr
);
166 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
167 public extern static void FreeHGlobal (IntPtr hglobal
);
171 public static void ZeroFreeBSTR (IntPtr ptr
) {
172 throw new NotImplementedException ();
176 public static void ZeroFreeCoTaskMemAnsi (IntPtr ptr
) {
177 throw new NotImplementedException ();
181 public static void ZeroFreeCoTaskMemUni (IntPtr ptr
) {
182 throw new NotImplementedException ();
186 public static void ZeroFreeGlobalAllocAnsi (IntPtr hglobal
) {
187 throw new NotImplementedException ();
191 public static void ZeroFreeGlobalAllocUni (IntPtr hglobal
) {
192 throw new NotImplementedException ();
197 public static Guid
GenerateGuidForType (Type type
) {
198 throw new NotImplementedException ();
202 public static string GenerateProgIdForType (Type type
) {
203 throw new NotImplementedException ();
207 public static object GetActiveObject (string progID
) {
208 throw new NotImplementedException ();
212 public static IntPtr
GetComInterfaceForObject (object o
, Type T
) {
213 throw new NotImplementedException ();
218 public static IntPtr
GetComInterfaceForObjectInContext (object o
, Type t
) {
219 throw new NotImplementedException ();
224 public static object GetComObjectData (object obj
, object key
) {
225 throw new NotImplementedException ();
229 public static int GetComSlotForMethodInfo (MemberInfo m
) {
230 throw new NotImplementedException ();
234 public static int GetEndComSlot (Type t
) {
235 throw new NotImplementedException ();
239 public static int GetExceptionCode() {
240 throw new NotImplementedException ();
244 public static IntPtr
GetExceptionPointers() {
245 throw new NotImplementedException ();
249 public static IntPtr
GetHINSTANCE (Module m
) {
250 throw new NotImplementedException ();
254 public static int GetHRForException (Exception e
) {
255 throw new NotImplementedException ();
259 public static int GetHRForLastWin32Error() {
260 throw new NotImplementedException ();
264 public static IntPtr
GetIDispatchForObject (object o
) {
265 throw new NotImplementedException ();
270 public static IntPtr
GetIDispatchForObjectInContext (object o
) {
271 throw new NotImplementedException ();
276 public static IntPtr
GetITypeInfoForType (Type t
) {
277 throw new NotImplementedException ();
281 public static IntPtr
GetIUnknownForObject (object o
) {
282 throw new NotImplementedException ();
287 public static IntPtr
GetIUnknownForObjectInContext (object o
) {
288 throw new NotImplementedException ();
292 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
293 public static extern int GetLastWin32Error();
296 public static IntPtr
GetManagedThunkForUnmanagedMethodPtr (IntPtr pfnMethodToWrap
, IntPtr pbSignature
, int cbSignature
) {
297 throw new NotImplementedException ();
301 public static MemberInfo
GetMethodInfoForComSlot (Type t
, int slot
, ref ComMemberType memberType
) {
302 throw new NotImplementedException ();
306 public static void GetNativeVariantForObject (object obj
, IntPtr pDstNativeVariant
) {
307 throw new NotImplementedException ();
311 public static object GetObjectForIUnknown (IntPtr pUnk
) {
312 throw new NotImplementedException ();
316 public static object GetObjectForNativeVariant (IntPtr pSrcNativeVariant
) {
317 throw new NotImplementedException ();
321 public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant
, int cVars
) {
322 throw new NotImplementedException ();
326 public static int GetStartComSlot (Type t
) {
327 throw new NotImplementedException ();
331 public static Thread
GetThreadFromFiberCookie (int cookie
) {
332 throw new NotImplementedException ();
336 public static object GetTypedObjectForIUnknown (IntPtr pUnk
, Type t
) {
337 throw new NotImplementedException ();
341 public static Type
GetTypeForITypeInfo (IntPtr piTypeInfo
) {
342 throw new NotImplementedException ();
349 public static string GetTypeInfoName (UCOMITypeInfo pTI
) {
350 throw new NotImplementedException ();
357 public static Guid
GetTypeLibGuid (UCOMITypeLib pTLB
) {
358 throw new NotImplementedException ();
362 public static Guid
GetTypeLibGuidForAssembly (Assembly asm
) {
363 throw new NotImplementedException ();
370 public static int GetTypeLibLcid (UCOMITypeLib pTLB
) {
371 throw new NotImplementedException ();
378 public static string GetTypeLibName (UCOMITypeLib pTLB
) {
379 throw new NotImplementedException ();
384 public static void GetTypeLibVersionForAssembly (Assembly inputAssembly
, out int majorVersion
, out int minorVersion
) {
385 throw new NotImplementedException ();
390 public static IntPtr
GetUnmanagedThunkForManagedMethodPtr (IntPtr pfnMethodToWrap
, IntPtr pbSignature
, int cbSignature
) {
391 throw new NotImplementedException ();
395 public static bool IsComObject (object o
) {
396 throw new NotImplementedException ();
400 public static bool IsTypeVisibleFromCom (Type t
) {
401 throw new NotImplementedException ();
405 public static int NumParamBytes (MethodInfo m
) {
406 throw new NotImplementedException ();
409 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
410 public extern static IntPtr
OffsetOf (Type t
, string fieldName
);
412 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
413 public extern static void Prelink (MethodInfo m
);
415 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
416 public extern static void PrelinkAll (Type c
);
418 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
419 public extern static string PtrToStringAnsi (IntPtr ptr
);
421 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
422 public extern static string PtrToStringAnsi (IntPtr ptr
, int len
);
424 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
425 public extern static string PtrToStringAuto (IntPtr ptr
);
427 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
428 public extern static string PtrToStringAuto (IntPtr ptr
, int len
);
430 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
431 public extern static string PtrToStringUni (IntPtr ptr
);
433 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
434 public extern static string PtrToStringUni (IntPtr ptr
, int len
);
436 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
437 public extern static string PtrToStringBSTR (IntPtr ptr
);
439 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
440 public extern static void PtrToStructure (IntPtr ptr
, object structure
);
442 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
443 public extern static object PtrToStructure (IntPtr ptr
, Type structureType
);
446 public static int QueryInterface (IntPtr pUnk
, ref Guid iid
, out IntPtr ppv
) {
447 throw new NotImplementedException ();
450 public static byte ReadByte (IntPtr ptr
) {
451 return ReadByte (ptr
, 0);
454 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
455 public extern static byte ReadByte (IntPtr ptr
, int ofs
);
458 public static byte ReadByte ([In
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
) {
459 throw new NotImplementedException ();
462 public static short ReadInt16 (IntPtr ptr
) {
463 return ReadInt16 (ptr
, 0);
466 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
467 public extern static short ReadInt16 (IntPtr ptr
, int ofs
);
470 public static short ReadInt16 ([In
, MarshalAs(UnmanagedType
.AsAny
)] object ptr
, int ofs
) {
471 throw new NotImplementedException ();
475 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
477 public static int ReadInt32 (IntPtr ptr
) {
478 return ReadInt32 (ptr
, 0);
482 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
484 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
485 public extern static int ReadInt32 (IntPtr ptr
, int ofs
);
488 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
491 public static int ReadInt32 ([In
, MarshalAs(UnmanagedType
.AsAny
)] object ptr
, int ofs
) {
492 throw new NotImplementedException ();
496 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
498 public static long ReadInt64 (IntPtr ptr
) {
499 return ReadInt64 (ptr
, 0);
503 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
505 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
506 public extern static long ReadInt64 (IntPtr ptr
, int ofs
);
509 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
512 public static long ReadInt64 ([In
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
) {
513 throw new NotImplementedException ();
517 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
519 public static IntPtr
ReadIntPtr (IntPtr ptr
) {
520 return ReadIntPtr (ptr
, 0);
524 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
526 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
527 public extern static IntPtr
ReadIntPtr (IntPtr ptr
, int ofs
);
530 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
533 public static IntPtr
ReadIntPtr ([In
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
) {
534 throw new NotImplementedException ();
538 public static IntPtr
ReAllocCoTaskMem (IntPtr pv
, int cb
) {
539 throw new NotImplementedException ();
542 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
543 public extern static IntPtr
ReAllocHGlobal (IntPtr pv
, IntPtr cb
);
546 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.Success
)]
549 public static int Release (IntPtr pUnk
) {
550 throw new NotImplementedException ();
554 public static int ReleaseComObject (object o
) {
555 throw new NotImplementedException ();
562 public static void ReleaseThreadCache() {
563 throw new NotImplementedException ();
567 public static bool SetComObjectData (object obj
, object key
, object data
) {
568 throw new NotImplementedException ();
571 public static int SizeOf (object structure
) {
572 return SizeOf (structure
.GetType ());
575 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
576 public extern static int SizeOf (Type t
);
579 public static IntPtr
StringToBSTR (string s
) {
580 throw new NotImplementedException ();
583 public static IntPtr
StringToCoTaskMemAnsi (string s
) {
584 int length
= s
.Length
+ 1;
585 IntPtr ctm
= AllocCoTaskMem (length
);
587 byte[] asBytes
= new byte[length
];
588 for (int i
= 0; i
< s
.Length
; i
++)
589 asBytes
[i
] = (byte)s
[i
];
590 asBytes
[s
.Length
] = 0;
592 copy_to_unmanaged (asBytes
, 0, ctm
, length
);
597 public static IntPtr
StringToCoTaskMemAuto (string s
) {
598 throw new NotImplementedException ();
601 public static IntPtr
StringToCoTaskMemUni (string s
) {
602 int length
= s
.Length
+ 1;
603 IntPtr ctm
= AllocCoTaskMem (length
* 2);
605 char[] asChars
= new char[length
];
606 s
.CopyTo (0, asChars
, 0, s
.Length
);
607 asChars
[s
.Length
] = '\0';
609 copy_to_unmanaged (asChars
, 0, ctm
, length
);
613 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
614 public extern static IntPtr
StringToHGlobalAnsi (string s
);
616 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
617 public extern static IntPtr
StringToHGlobalAuto (string s
);
619 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
620 public extern static IntPtr
StringToHGlobalUni (string s
);
624 public static IntPtr
SecureStringToBSTR (SecureString s
) {
625 throw new NotImplementedException ();
629 public static IntPtr
SecureStringToCoTaskMemAnsi (SecureString s
) {
630 throw new NotImplementedException ();
634 public static IntPtr
SecureStringToCoTaskMemUni (SecureString s
) {
635 throw new NotImplementedException ();
639 public static IntPtr
SecureStringToGlobalAllocAnsi (SecureString s
) {
640 throw new NotImplementedException ();
644 public static IntPtr
SecureStringToGlobalAllocUni (SecureString s
) {
645 throw new NotImplementedException ();
650 [ReliabilityContractAttribute (Consistency
.WillNotCorruptState
, CER
.MayFail
)]
652 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
653 public extern static void StructureToPtr (object structure
, IntPtr ptr
, bool fDeleteOld
);
656 public static void ThrowExceptionForHR (int errorCode
) {
657 throw new NotImplementedException ();
661 public static void ThrowExceptionForHR (int errorCode
, IntPtr errorInfo
) {
662 throw new NotImplementedException ();
665 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
666 public extern static IntPtr
UnsafeAddrOfPinnedArrayElement (Array arr
, int index
);
668 public static void WriteByte (IntPtr ptr
, byte val
) {
669 WriteByte (ptr
, 0, val
);
672 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
673 public extern static void WriteByte (IntPtr ptr
, int ofs
, byte val
);
676 public static void WriteByte ([In
, Out
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
, byte val
) {
677 throw new NotImplementedException ();
680 public static void WriteInt16 (IntPtr ptr
, short val
) {
681 WriteInt16 (ptr
, 0, val
);
684 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
685 public extern static void WriteInt16 (IntPtr ptr
, int ofs
, short val
);
688 public static void WriteInt16 ([In
, Out
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
, short val
) {
689 throw new NotImplementedException ();
692 public static void WriteInt16 (IntPtr ptr
, char val
) {
693 WriteInt16 (ptr
, 0, val
);
697 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
698 public extern static void WriteInt16 (IntPtr ptr
, int ofs
, char val
);
701 public static void WriteInt16([In
, Out
, MarshalAs(UnmanagedType
.AsAny
)] object ptr
, int ofs
, char val
) {
702 throw new NotImplementedException ();
705 public static void WriteInt32 (IntPtr ptr
, int val
) {
706 WriteInt32 (ptr
, 0, val
);
709 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
710 public extern static void WriteInt32 (IntPtr ptr
, int ofs
, int val
);
713 public static void WriteInt32([In
, Out
, MarshalAs(UnmanagedType
.AsAny
)] object ptr
, int ofs
, int val
) {
714 throw new NotImplementedException ();
717 public static void WriteInt64 (IntPtr ptr
, long val
) {
718 WriteInt64 (ptr
, 0, val
);
721 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
722 public extern static void WriteInt64 (IntPtr ptr
, int ofs
, long val
);
725 public static void WriteInt64 ([In
, Out
, MarshalAs (UnmanagedType
.AsAny
)] object ptr
, int ofs
, long val
) {
726 throw new NotImplementedException ();
729 public static void WriteIntPtr (IntPtr ptr
, IntPtr val
) {
730 WriteIntPtr (ptr
, 0, val
);
733 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
734 public extern static void WriteIntPtr (IntPtr ptr
, int ofs
, IntPtr val
);
737 public static void WriteIntPtr([In
, Out
, MarshalAs(UnmanagedType
.AsAny
)] object ptr
, int ofs
, IntPtr val
) {
738 throw new NotImplementedException ();
743 public static int FinalReleaseComObject (object o
) {
744 throw new NotImplementedException ();
748 public static Exception
GetExceptionForHR (int errorCode
) {
749 throw new NotImplementedException ();
753 public static Exception
GetExceptionForHR (int errorCode
, IntPtr errorInfo
) {
754 throw new NotImplementedException ();
757 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
758 private static extern Delegate
GetDelegateForFunctionPointerInternal (IntPtr ptr
, Type t
);
760 public static Delegate
GetDelegateForFunctionPointer (IntPtr ptr
, Type t
) {
761 if (!t
.IsSubclassOf (typeof (MulticastDelegate
)) || (t
== typeof (MulticastDelegate
)))
762 throw new ArgumentException ("Type is not a delegate", "t");
763 if (ptr
== IntPtr
.Zero
)
764 throw new ArgumentNullException ("ptr");
766 return GetDelegateForFunctionPointerInternal (ptr
, t
);
769 [MethodImplAttribute(MethodImplOptions
.InternalCall
)]
770 private static extern IntPtr
GetFunctionPointerForDelegateInternal (Delegate d
);
772 public static IntPtr
GetFunctionPointerForDelegate (Delegate d
) {
774 throw new ArgumentNullException ("d");
776 return GetFunctionPointerForDelegateInternal (d
);