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