Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / System.Runtime.InteropServices / Marshal.cs
1 // System.Runtime.InteropServices.Marshal.cs
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 // Paolo Molaro (lupus@ximian.com)
5 // Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) 2001-2002 Ximian, Inc.
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using System.Runtime.CompilerServices;
33 using System;
34 using System.Security;
35 using System.Reflection;
36 using System.Threading;
37
38 #if NET_2_0
39 using System.Runtime.ConstrainedExecution;
40 #endif
41
42 namespace System.Runtime.InteropServices
43 {
44         [SuppressUnmanagedCodeSecurity ()]
45         public
46 #if NET_2_0
47         static
48 #else
49         sealed
50 #endif
51         class Marshal
52         {
53                 /* fields */
54                 public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
55                 public static readonly int SystemDefaultCharSize = 2;
56
57 #if !NET_2_0
58                 private Marshal () {}
59 #endif
60
61                 [MonoTODO]
62                 public static int AddRef (IntPtr pUnk) {
63                         throw new NotImplementedException ();
64                 }
65
66                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
67                 public extern static IntPtr AllocCoTaskMem (int cb);
68
69                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
70 #if NET_2_0
71                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
72 #endif
73                 public extern static IntPtr AllocHGlobal (IntPtr cb);
74
75 #if NET_2_0
76                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
77 #endif
78                 public static IntPtr AllocHGlobal (int cb) {
79                         return AllocHGlobal ((IntPtr)cb);
80                 }
81
82                 [MonoTODO]
83                 public static object BindToMoniker (string monikerName) {
84                         throw new NotImplementedException ();
85                 }
86
87                 [MonoTODO]
88                 public static void ChangeWrapperHandleStrength (object otp, bool fIsWeak) {
89                         throw new NotImplementedException ();
90                 }
91
92                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
93                 extern static void copy_to_unmanaged (Array source, int startIndex,
94                                                       IntPtr destination, int length);
95
96                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
97                 extern static void copy_from_unmanaged (IntPtr source, int startIndex,
98                                                         Array destination, int length);
99
100                 public static void Copy (byte[] source, int startIndex, IntPtr destination, int length) {
101                         copy_to_unmanaged (source, startIndex, destination, length);
102                 }
103
104                 public static void Copy (char[] source, int startIndex, IntPtr destination, int length) {
105                         copy_to_unmanaged (source, startIndex, destination, length);
106                 }
107
108                 public static void Copy (short[] source, int startIndex, IntPtr destination, int length) {
109                         copy_to_unmanaged (source, startIndex, destination, length);
110                 }
111
112                 public static void Copy (int[] source, int startIndex, IntPtr destination, int length) {
113                         copy_to_unmanaged (source, startIndex, destination, length);
114                 }
115
116                 public static void Copy (long[] source, int startIndex, IntPtr destination, int length) {
117                         copy_to_unmanaged (source, startIndex, destination, length);
118                 }
119
120                 public static void Copy (float[] source, int startIndex, IntPtr destination, int length) {
121                         copy_to_unmanaged (source, startIndex, destination, length);
122                 }
123
124                 public static void Copy (double[] source, int startIndex, IntPtr destination, int length) {
125                         copy_to_unmanaged (source, startIndex, destination, length);
126                 }
127
128                 public static void Copy (IntPtr source, byte[] destination, int startIndex, int length) {
129                         copy_from_unmanaged (source, startIndex, destination, length);
130                 }
131
132                 public static void Copy (IntPtr source, char[] destination, int startIndex, int length) {
133                         copy_from_unmanaged (source, startIndex, destination, length);
134                 }
135
136                 public static void Copy (IntPtr source, short[] destination, int startIndex, int length) {
137                         copy_from_unmanaged (source, startIndex, destination, length);
138                 }
139
140                 public static void Copy (IntPtr source, int[] destination, int startIndex, int length) {
141                         copy_from_unmanaged (source, startIndex, destination, length);
142                 }
143
144                 public static void Copy (IntPtr source, long[] destination, int startIndex, int length) {
145                         copy_from_unmanaged (source, startIndex, destination, length);
146                 }
147
148                 public static void Copy (IntPtr source, float[] destination, int startIndex, int length) {
149                         copy_from_unmanaged (source, startIndex, destination, length);
150                 }
151
152                 public static void Copy (IntPtr source, double[] destination, int startIndex, int length) {
153                         copy_from_unmanaged (source, startIndex, destination, length);
154                 }
155
156                 [MonoTODO]
157                 public static object CreateWrapperOfType (object o, Type t) {
158                         throw new NotImplementedException ();
159                 }
160
161                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
162                 public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
163
164                 [MonoTODO]
165                 public static void FreeBSTR (IntPtr ptr) {
166                         throw new NotImplementedException ();
167                 }
168
169                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
170                 public extern static void FreeCoTaskMem (IntPtr ptr);
171
172                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
173 #if NET_2_0
174                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
175 #endif
176                 public extern static void FreeHGlobal (IntPtr hglobal);
177
178 #if NET_2_0
179                 [MonoTODO]
180                 public static void ZeroFreeBSTR (IntPtr ptr) {
181                         throw new NotImplementedException ();
182                 }
183
184                 [MonoTODO]
185                 public static void ZeroFreeCoTaskMemAnsi (IntPtr ptr) {
186                         throw new NotImplementedException ();
187                 }
188
189                 [MonoTODO]
190                 public static void ZeroFreeCoTaskMemUni (IntPtr ptr) {
191                         throw new NotImplementedException ();
192                 }
193
194                 [MonoTODO]
195                 public static void ZeroFreeGlobalAllocAnsi (IntPtr hglobal) {
196                         throw new NotImplementedException ();
197                 }
198
199                 [MonoTODO]
200                 public static void ZeroFreeGlobalAllocUni (IntPtr hglobal) {
201                         throw new NotImplementedException ();
202                 }
203 #endif
204
205                 [MonoTODO]
206                 public static Guid GenerateGuidForType (Type type) {
207                         throw new NotImplementedException ();
208                 }
209
210                 [MonoTODO]
211                 public static string GenerateProgIdForType (Type type) {
212                         throw new NotImplementedException ();
213                 }
214
215                 [MonoTODO]
216                 public static object GetActiveObject (string progID) {
217                         throw new NotImplementedException ();
218                 }
219
220                 [MonoTODO]
221                 public static IntPtr GetComInterfaceForObject (object o, Type T) {
222                         throw new NotImplementedException ();
223                 }
224
225 #if NET_2_0
226                 [MonoTODO]
227                 public static IntPtr GetComInterfaceForObjectInContext (object o, Type t) {
228                         throw new NotImplementedException ();
229                 }
230 #endif
231
232                 [MonoTODO]
233                 public static object GetComObjectData (object obj, object key) {
234                         throw new NotImplementedException ();
235                 }
236
237                 [MonoTODO]
238                 public static int GetComSlotForMethodInfo (MemberInfo m) {
239                         throw new NotImplementedException ();
240                 }
241
242                 [MonoTODO]
243                 public static int GetEndComSlot (Type t) {
244                         throw new NotImplementedException ();
245                 }
246
247                 [MonoTODO]
248                 public static int GetExceptionCode() {
249                         throw new NotImplementedException ();
250                 }
251
252                 [MonoTODO]
253                 public static IntPtr GetExceptionPointers() {
254                         throw new NotImplementedException ();
255                 }
256
257                 [MonoTODO]
258                 public static IntPtr GetHINSTANCE (Module m) {
259                         throw new NotImplementedException ();
260                 }
261
262                 [MonoTODO]
263                 public static int GetHRForException (Exception e) {
264                         throw new NotImplementedException ();
265                 }
266
267                 [MonoTODO]
268                 public static int GetHRForLastWin32Error() {
269                         throw new NotImplementedException ();
270                 }
271
272                 [MonoTODO]
273                 public static IntPtr GetIDispatchForObject (object o) {
274                         throw new NotImplementedException ();
275                 }
276
277 #if NET_2_0
278                 [MonoTODO]
279                 public static IntPtr GetIDispatchForObjectInContext (object o) {
280                         throw new NotImplementedException ();
281                 }
282 #endif
283
284                 [MonoTODO]
285                 public static IntPtr GetITypeInfoForType (Type t) {
286                         throw new NotImplementedException ();
287                 }
288
289                 [MonoTODO]
290                 public static IntPtr GetIUnknownForObject (object o) {
291                         throw new NotImplementedException ();
292                 }
293
294 #if NET_2_0
295                 [MonoTODO]
296                 public static IntPtr GetIUnknownForObjectInContext (object o) {
297                         throw new NotImplementedException ();
298                 }
299 #endif
300
301                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
302 #if NET_2_0
303                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
304 #endif
305                 public static extern int GetLastWin32Error();
306
307                 [MonoTODO]
308                 public static IntPtr GetManagedThunkForUnmanagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
309                         throw new NotImplementedException ();
310                 }
311
312                 [MonoTODO]
313                 public static MemberInfo GetMethodInfoForComSlot (Type t, int slot, ref ComMemberType memberType) {
314                         throw new NotImplementedException ();
315                 }
316
317                 [MonoTODO]
318                 public static void GetNativeVariantForObject (object obj, IntPtr pDstNativeVariant) {
319                         throw new NotImplementedException ();
320                 }
321
322                 [MonoTODO]
323                 public static object GetObjectForIUnknown (IntPtr pUnk) {
324                         throw new NotImplementedException ();
325                 }
326
327                 [MonoTODO]
328                 public static object GetObjectForNativeVariant (IntPtr pSrcNativeVariant) {
329                         throw new NotImplementedException ();
330                 }
331
332                 [MonoTODO]
333                 public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant, int cVars) {
334                         throw new NotImplementedException ();
335                 }
336
337                 [MonoTODO]
338                 public static int GetStartComSlot (Type t) {
339                         throw new NotImplementedException ();
340                 }
341
342                 [MonoTODO]
343                 public static Thread GetThreadFromFiberCookie (int cookie) {
344                         throw new NotImplementedException ();
345                 }
346
347                 [MonoTODO]
348                 public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t) {
349                         throw new NotImplementedException ();
350                 }
351
352                 [MonoTODO]
353                 public static Type GetTypeForITypeInfo (IntPtr piTypeInfo) {
354                         throw new NotImplementedException ();
355                 }
356
357 #if NET_2_0
358                 [Obsolete]
359 #endif
360                 [MonoTODO]
361                 public static string GetTypeInfoName (UCOMITypeInfo pTI) {
362                         throw new NotImplementedException ();
363                 }
364
365 #if NET_2_0
366                 [Obsolete]
367 #endif
368                 [MonoTODO]
369                 public static Guid GetTypeLibGuid (UCOMITypeLib pTLB) {
370                         throw new NotImplementedException ();
371                 }
372
373                 [MonoTODO]
374                 public static Guid GetTypeLibGuidForAssembly (Assembly asm) {
375                         throw new NotImplementedException ();
376                 }
377
378 #if NET_2_0
379                 [Obsolete]
380 #endif
381                 [MonoTODO]
382                 public static int GetTypeLibLcid (UCOMITypeLib pTLB) {
383                         throw new NotImplementedException ();
384                 }
385
386 #if NET_2_0
387                 [Obsolete]
388 #endif
389                 [MonoTODO]
390                 public static string GetTypeLibName (UCOMITypeLib pTLB) {
391                         throw new NotImplementedException ();
392                 }
393
394 #if NET_2_0
395                 [MonoTODO]
396                 public static void GetTypeLibVersionForAssembly (Assembly inputAssembly, out int majorVersion, out int minorVersion) {
397                         throw new NotImplementedException ();
398                 }
399 #endif
400
401                 [MonoTODO]
402                 public static IntPtr GetUnmanagedThunkForManagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
403                         throw new NotImplementedException ();
404                 }
405
406                 [MonoTODO]
407                 public static bool IsComObject (object o) {
408                         throw new NotImplementedException ();
409                 }
410
411                 [MonoTODO]
412                 public static bool IsTypeVisibleFromCom (Type t) {
413                         throw new NotImplementedException ();
414                 }
415
416                 [MonoTODO]
417                 public static int NumParamBytes (MethodInfo m) {
418                         throw new NotImplementedException ();
419                 }
420
421                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
422                 public extern static IntPtr OffsetOf (Type t, string fieldName);
423
424                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
425                 public extern static void Prelink (MethodInfo m);
426
427                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
428                 public extern static void PrelinkAll (Type c);
429
430                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
431                 public extern static string PtrToStringAnsi (IntPtr ptr);
432                 
433                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
434                 public extern static string PtrToStringAnsi (IntPtr ptr, int len);
435
436                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
437                 public extern static string PtrToStringAuto (IntPtr ptr);
438                 
439                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
440                 public extern static string PtrToStringAuto (IntPtr ptr, int len);
441
442                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
443                 public extern static string PtrToStringUni (IntPtr ptr);
444
445                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
446                 public extern static string PtrToStringUni (IntPtr ptr, int len);
447
448                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
449                 public extern static string PtrToStringBSTR (IntPtr ptr);
450                 
451                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
452                 public extern static void PtrToStructure (IntPtr ptr, object structure);
453
454                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
455                 public extern static object PtrToStructure (IntPtr ptr, Type structureType);
456
457                 [MonoTODO]
458                 public static int QueryInterface (IntPtr pUnk, ref Guid iid, out IntPtr ppv) {
459                         throw new NotImplementedException ();
460                 }
461
462                 public static byte ReadByte (IntPtr ptr) {
463                         return ReadByte (ptr, 0);
464                 }
465
466                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
467                 public extern static byte ReadByte (IntPtr ptr, int ofs);
468
469                 [MonoTODO]
470                 public static byte ReadByte ([In, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs) {
471                         throw new NotImplementedException ();
472                 }
473
474                 public static short ReadInt16 (IntPtr ptr) {
475                         return ReadInt16 (ptr, 0);
476                 }
477
478                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
479                 public extern static short ReadInt16 (IntPtr ptr, int ofs);
480
481                 [MonoTODO]
482                 public static short ReadInt16 ([In, MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs) {
483                         throw new NotImplementedException ();
484                 }
485
486 #if NET_2_0
487                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
488 #endif
489                 public static int ReadInt32 (IntPtr ptr) {
490                         return ReadInt32 (ptr, 0);
491                 }
492
493 #if NET_2_0
494                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
495 #endif
496                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
497                 public extern static int ReadInt32 (IntPtr ptr, int ofs);
498
499 #if NET_2_0
500                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
501 #endif
502                 [MonoTODO]
503                 public static int ReadInt32 ([In, MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs) {
504                         throw new NotImplementedException ();
505                 }
506
507 #if NET_2_0
508                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
509 #endif
510                 public static long ReadInt64 (IntPtr ptr) {
511                         return ReadInt64 (ptr, 0);
512                 }
513
514 #if NET_2_0
515                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
516 #endif
517                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
518                 public extern static long ReadInt64 (IntPtr ptr, int ofs);
519
520 #if NET_2_0
521                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
522 #endif
523                 [MonoTODO]
524                 public static long ReadInt64 ([In, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs) {
525                         throw new NotImplementedException ();
526                 }
527
528 #if NET_2_0
529                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
530 #endif
531                 public static IntPtr ReadIntPtr (IntPtr ptr) {
532                         return ReadIntPtr (ptr, 0);
533                 }
534                 
535 #if NET_2_0
536                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
537 #endif
538                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
539                 public extern static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
540
541 #if NET_2_0
542                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
543 #endif
544                 [MonoTODO]
545                 public static IntPtr ReadIntPtr ([In, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs) {
546                         throw new NotImplementedException ();
547                 }
548
549                 [MonoTODO]
550                 public static IntPtr ReAllocCoTaskMem (IntPtr pv, int cb) {
551                         throw new NotImplementedException ();
552                 }
553
554                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
555                 public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
556
557 #if NET_2_0
558                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
559 #endif
560                 [MonoTODO]
561                 public static int Release (IntPtr pUnk) {
562                         throw new NotImplementedException ();
563                 }
564
565                 [MonoTODO]
566                 public static int ReleaseComObject (object o) {
567                         throw new NotImplementedException ();
568                 }
569
570 #if NET_2_0
571                 [Obsolete]
572 #endif
573                 [MonoTODO]
574                 public static void ReleaseThreadCache() {
575                         throw new NotImplementedException ();
576                 }
577
578                 [MonoTODO]
579                 public static bool SetComObjectData (object obj, object key, object data) {
580                         throw new NotImplementedException ();
581                 }
582
583                 public static int SizeOf (object structure) {
584                         return SizeOf (structure.GetType ());
585                 }
586
587                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
588                 public extern static int SizeOf (Type t);
589
590                 [MonoTODO]
591                 public static IntPtr StringToBSTR (string s) {
592                         throw new NotImplementedException ();
593                 }
594
595                 public static IntPtr StringToCoTaskMemAnsi (string s) {
596                         int length = s.Length + 1;
597                         IntPtr ctm = AllocCoTaskMem (length);
598
599                         byte[] asBytes = new byte[length];
600                         for (int i = 0; i < s.Length; i++)
601                                 asBytes[i] = (byte)s[i];
602                         asBytes[s.Length] = 0;
603
604                         copy_to_unmanaged (asBytes, 0, ctm, length);
605                         return ctm;
606                 }
607
608                 [MonoTODO]
609                 public static IntPtr StringToCoTaskMemAuto (string s) {
610                         throw new NotImplementedException ();
611                 }
612
613                 public static IntPtr StringToCoTaskMemUni (string s) {
614                         int length = s.Length + 1;
615                         IntPtr ctm = AllocCoTaskMem (length * 2);
616
617                         char[] asChars = new char[length];
618                         s.CopyTo (0, asChars, 0, s.Length);
619                         asChars[s.Length] = '\0';
620
621                         copy_to_unmanaged (asChars, 0, ctm, length);
622                         return ctm;
623                 }
624
625                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
626                 public extern static IntPtr StringToHGlobalAnsi (string s);
627
628                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
629                 public extern static IntPtr StringToHGlobalAuto (string s);
630
631                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
632                 public extern static IntPtr StringToHGlobalUni (string s);
633
634 #if NET_2_0
635                 [MonoTODO]
636                 public static IntPtr SecureStringToBSTR (SecureString s) {
637                         throw new NotImplementedException ();
638                 }
639
640                 [MonoTODO]
641                 public static IntPtr SecureStringToCoTaskMemAnsi (SecureString s) {
642                         throw new NotImplementedException ();
643                 }
644
645                 [MonoTODO]
646                 public static IntPtr SecureStringToCoTaskMemUni (SecureString s) {
647                         throw new NotImplementedException ();
648                 }
649
650                 [MonoTODO]
651                 public static IntPtr SecureStringToGlobalAllocAnsi (SecureString s) {
652                         throw new NotImplementedException ();
653                 }
654
655                 [MonoTODO]
656                 public static IntPtr SecureStringToGlobalAllocUni (SecureString s) {
657                         throw new NotImplementedException ();
658                 }
659 #endif
660
661 #if NET_2_0
662                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
663 #endif
664                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
665                 public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
666
667                 [MonoTODO]
668                 public static void ThrowExceptionForHR (int errorCode) {
669                         throw new NotImplementedException ();
670                 }
671
672                 [MonoTODO]
673                 public static void ThrowExceptionForHR (int errorCode, IntPtr errorInfo) {
674                         throw new NotImplementedException ();
675                 }
676
677                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
678                 public extern static IntPtr UnsafeAddrOfPinnedArrayElement (Array arr, int index);
679
680                 public static void WriteByte (IntPtr ptr, byte val) {
681                         WriteByte (ptr, 0, val);
682                 }
683
684                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
685                 public extern static void WriteByte (IntPtr ptr, int ofs, byte val);
686
687                 [MonoTODO]
688                 public static void WriteByte ([In, Out, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs, byte val) {
689                         throw new NotImplementedException ();
690                 }
691
692                 public static void WriteInt16 (IntPtr ptr, short val) {
693                         WriteInt16 (ptr, 0, val);
694                 }
695
696                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
697                 public extern static void WriteInt16 (IntPtr ptr, int ofs, short val);
698
699                 [MonoTODO]
700                 public static void WriteInt16 ([In, Out, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs, short val) {
701                         throw new NotImplementedException ();
702                 }
703
704                 public static void WriteInt16 (IntPtr ptr, char val) {
705                         WriteInt16 (ptr, 0, val);
706                 }
707
708                 [MonoTODO]
709                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
710                 public extern static void WriteInt16 (IntPtr ptr, int ofs, char val);
711
712                 [MonoTODO]
713                 public static void WriteInt16([In, Out] object ptr, int ofs, char val) {
714                         throw new NotImplementedException ();
715                 }
716
717                 public static void WriteInt32 (IntPtr ptr, int val) {
718                         WriteInt32 (ptr, 0, val);
719                 }
720
721                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
722                 public extern static void WriteInt32 (IntPtr ptr, int ofs, int val);
723
724                 [MonoTODO]
725                 public static void WriteInt32([In, Out, MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs, int val) {
726                         throw new NotImplementedException ();
727                 }
728
729                 public static void WriteInt64 (IntPtr ptr, long val) {
730                         WriteInt64 (ptr, 0, val);
731                 }
732
733                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
734                 public extern static void WriteInt64 (IntPtr ptr, int ofs, long val);
735
736                 [MonoTODO]
737                 public static void WriteInt64 ([In, Out, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs, long val) {
738                         throw new NotImplementedException ();
739                 }
740
741                 public static void WriteIntPtr (IntPtr ptr, IntPtr val) {
742                         WriteIntPtr (ptr, 0, val);
743                 }
744
745                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
746                 public extern static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
747
748                 [MonoTODO]
749                 public static void WriteIntPtr([In, Out, MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs, IntPtr val) {
750                         throw new NotImplementedException ();
751                 }
752
753 #if NET_2_0
754                 [MonoTODO]
755                 public static int FinalReleaseComObject (object o) {
756                         throw new NotImplementedException ();
757                 }
758
759                 [MonoTODO]
760                 public static Exception GetExceptionForHR (int errorCode) {
761                         throw new NotImplementedException ();
762                 }
763
764                 [MonoTODO]
765                 public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo) {
766                         throw new NotImplementedException ();
767                 }
768
769                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
770                 private static extern Delegate GetDelegateForFunctionPointerInternal (IntPtr ptr, Type t);
771
772                 public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t) {
773                         if (!t.IsSubclassOf (typeof (MulticastDelegate)) || (t == typeof (MulticastDelegate)))
774                                 throw new ArgumentException ("Type is not a delegate", "t");
775                         if (ptr == IntPtr.Zero)
776                                 throw new ArgumentNullException ("ptr");
777
778                         return GetDelegateForFunctionPointerInternal (ptr, t);
779                 }
780
781                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
782                 private static extern IntPtr GetFunctionPointerForDelegateInternal (Delegate d);
783                 
784                 public static IntPtr GetFunctionPointerForDelegate (Delegate d) {
785                         if (d == null)
786                                 throw new ArgumentNullException ("d");
787                         
788                         return GetFunctionPointerForDelegateInternal (d);
789                 }
790 #endif
791         }
792 }