2003-11-18 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
[mono.git] / mcs / class / corlib / System.Runtime.InteropServices / Marshal.cs
1 // System.Runtime.InteropServices.Marshal
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 using System.Runtime.CompilerServices;
10 using System;
11 using System.Security;
12 using System.Reflection;
13 using System.Threading;
14
15 namespace System.Runtime.InteropServices
16 {
17         [SuppressUnmanagedCodeSecurity ()]
18         public sealed class Marshal
19         {
20                 /* fields */
21                 public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
22                 public static readonly int SystemDefaultCharSize = 2;
23                 
24                 private Marshal () {}
25
26                 [MonoTODO]
27                 public static int AddRef (IntPtr pUnk) {
28                         throw new NotImplementedException ();
29                 }
30                 [MonoTODO]
31                 public static IntPtr AllocCoTaskMem (int cb) {
32                         throw new NotImplementedException ();
33                 }
34
35                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
36                 public extern static IntPtr AllocHGlobal (IntPtr cb);
37
38                 public static IntPtr AllocHGlobal (int cb) {
39                         return AllocHGlobal ((IntPtr)cb);
40                 }
41
42                 [MonoTODO]
43                 public static object BindToMoniker (string monikerName) {
44                         throw new NotImplementedException ();
45                 }
46
47                 [MonoTODO]
48                 public static void ChangeWrapperHandleStrength (object otp, bool fIsWeak) {
49                         throw new NotImplementedException ();
50                 }
51
52                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
53                 extern static void copy_to_unmanaged (Array source, int startIndex,
54                                                       IntPtr destination, int length);
55
56                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
57                 extern static void copy_from_unmanaged (IntPtr source, int startIndex,
58                                                         Array destination, int length);
59
60                 public static void Copy (byte[] source, int startIndex, IntPtr destination, int length) {
61                         copy_to_unmanaged (source, startIndex, destination, length);
62                 }
63
64                 public static void Copy (char[] source, int startIndex, IntPtr destination, int length) {
65                         copy_to_unmanaged (source, startIndex, destination, length);
66                 }
67
68                 public static void Copy (short[] source, int startIndex, IntPtr destination, int length) {
69                         copy_to_unmanaged (source, startIndex, destination, length);
70                 }
71
72                 public static void Copy (int[] source, int startIndex, IntPtr destination, int length) {
73                         copy_to_unmanaged (source, startIndex, destination, length);
74                 }
75
76                 public static void Copy (long[] source, int startIndex, IntPtr destination, int length) {
77                         copy_to_unmanaged (source, startIndex, destination, length);
78                 }
79
80                 public static void Copy (float[] source, int startIndex, IntPtr destination, int length) {
81                         copy_to_unmanaged (source, startIndex, destination, length);
82                 }
83
84                 public static void Copy (double[] source, int startIndex, IntPtr destination, int length) {
85                         copy_to_unmanaged (source, startIndex, destination, length);
86                 }
87
88                 public static void Copy (IntPtr source, byte[] destination, int startIndex, int length) {
89                         copy_from_unmanaged (source, startIndex, destination, length);
90                 }
91
92                 public static void Copy (IntPtr source, char[] destination, int startIndex, int length) {
93                         copy_from_unmanaged (source, startIndex, destination, length);
94                 }
95
96                 public static void Copy (IntPtr source, short[] destination, int startIndex, int length) {
97                         copy_from_unmanaged (source, startIndex, destination, length);
98                 }
99
100                 public static void Copy (IntPtr source, int[] destination, int startIndex, int length) {
101                         copy_from_unmanaged (source, startIndex, destination, length);
102                 }
103
104                 public static void Copy (IntPtr source, long[] destination, int startIndex, int length) {
105                         copy_from_unmanaged (source, startIndex, destination, length);
106                 }
107
108                 public static void Copy (IntPtr source, float[] destination, int startIndex, int length) {
109                         copy_from_unmanaged (source, startIndex, destination, length);
110                 }
111
112                 public static void Copy (IntPtr source, double[] destination, int startIndex, int length) {
113                         copy_from_unmanaged (source, startIndex, destination, length);
114                 }
115
116                 [MonoTODO]
117                 public static object CreateWrapperOfType (object o, Type t) {
118                         throw new NotImplementedException ();
119                 }
120
121                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
122                 public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
123
124                 [MonoTODO]
125                 public static void FreeBSTR (IntPtr ptr) {
126                         throw new NotImplementedException ();
127                 }
128
129                 [MonoTODO]
130                 public static void FreeCoTaskMem (IntPtr ptr) {
131                         throw new NotImplementedException ();
132                 }
133
134                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
135                 public extern static void FreeHGlobal (IntPtr hglobal);
136
137                 [MonoTODO]
138                 public static Guid GenerateGuidForType (Type type) {
139                         throw new NotImplementedException ();
140                 }
141
142                 [MonoTODO]
143                 public static string GenerateProgIdForType (Type type) {
144                         throw new NotImplementedException ();
145                 }
146
147                 [MonoTODO]
148                 public static object GetActiveObject (string progID) {
149                         throw new NotImplementedException ();
150                 }
151
152                 [MonoTODO]
153                 public static IntPtr GetComInterfaceForObject (object o, Type T) {
154                         throw new NotImplementedException ();
155                 }
156
157                 [MonoTODO]
158                 public static object GetComObjectData (object obj, object key) {
159                         throw new NotImplementedException ();
160                 }
161
162                 [MonoTODO]
163                 public static int GetComSlotForMethodInfo (MemberInfo m) {
164                         throw new NotImplementedException ();
165                 }
166
167                 [MonoTODO]
168                 public static int GetEndComSlot (Type t) {
169                         throw new NotImplementedException ();
170                 }
171
172                 [MonoTODO]
173                 public static int GetExceptionCode() {
174                         throw new NotImplementedException ();
175                 }
176
177                 [MonoTODO]
178                 public static IntPtr GetExceptionPointers() {
179                         throw new NotImplementedException ();
180                 }
181
182                 [MonoTODO]
183                 public static IntPtr GetHINSTANCE (Module m) {
184                         throw new NotImplementedException ();
185                 }
186
187                 [MonoTODO]
188                 public static int GetHRForException (Exception e) {
189                         throw new NotImplementedException ();
190                 }
191
192                 [MonoTODO]
193                 public static int GetHRForLastWin32Error() {
194                         throw new NotImplementedException ();
195                 }
196
197                 [MonoTODO]
198                 public static IntPtr GetIDispatchForObject (object o) {
199                         throw new NotImplementedException ();
200                 }
201
202                 [MonoTODO]
203                 public static IntPtr GetITypeInfoForType (Type t) {
204                         throw new NotImplementedException ();
205                 }
206
207                 [MonoTODO]
208                 public static IntPtr GetIUnknownForObject (object o) {
209                         throw new NotImplementedException ();
210                 }
211
212                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
213                 public static extern int GetLastWin32Error();
214
215                 [MonoTODO]
216                 public static IntPtr GetManagedThunkForUnmanagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
217                         throw new NotImplementedException ();
218                 }
219
220                 [MonoTODO]
221                 public static MemberInfo GetMethodInfoForComSlot (Type t, int slot, ref ComMemberType memberType) {
222                         throw new NotImplementedException ();
223                 }
224
225                 [MonoTODO]
226                 public static void GetNativeVariantForObject (object obj, IntPtr pDstNativeVariant) {
227                         throw new NotImplementedException ();
228                 }
229
230                 [MonoTODO]
231                 public static object GetObjectForIUnknown (IntPtr pUnk) {
232                         throw new NotImplementedException ();
233                 }
234
235                 [MonoTODO]
236                 public static object GetObjectForNativeVariant (IntPtr pSrcNativeVariant) {
237                         throw new NotImplementedException ();
238                 }
239
240                 [MonoTODO]
241                 public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant, int cVars) {
242                         throw new NotImplementedException ();
243                 }
244
245                 [MonoTODO]
246                 public static int GetStartComSlot (Type t) {
247                         throw new NotImplementedException ();
248                 }
249
250                 [MonoTODO]
251                 public static Thread GetThreadFromFiberCookie (int cookie) {
252                         throw new NotImplementedException ();
253                 }
254
255                 [MonoTODO]
256                 public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t) {
257                         throw new NotImplementedException ();
258                 }
259
260                 [MonoTODO]
261                 public static Type GetTypeForITypeInfo (IntPtr piTypeInfo) {
262                         throw new NotImplementedException ();
263                 }
264
265                 [MonoTODO]
266                 public static string GetTypeInfoName (UCOMITypeInfo pTI) {
267                         throw new NotImplementedException ();
268                 }
269
270                 [MonoTODO]
271                 public static Guid GetTypeLibGuid (UCOMITypeLib pTLB) {
272                         throw new NotImplementedException ();
273                 }
274
275                 [MonoTODO]
276                 public static Guid GetTypeLibGuidForAssembly (Assembly asm) {
277                         throw new NotImplementedException ();
278                 }
279
280                 [MonoTODO]
281                 public static int GetTypeLibLcid (UCOMITypeLib pTLB) {
282                         throw new NotImplementedException ();
283                 }
284
285                 [MonoTODO]
286                 public static string GetTypeLibName (UCOMITypeLib pTLB) {
287                         throw new NotImplementedException ();
288                 }
289
290                 [MonoTODO]
291                 public static IntPtr GetUnmanagedThunkForManagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
292                         throw new NotImplementedException ();
293                 }
294
295                 [MonoTODO]
296                 public static bool IsComObject (object o) {
297                         throw new NotImplementedException ();
298                 }
299
300                 [MonoTODO]
301                 public static bool IsTypeVisibleFromCom (Type t) {
302                         throw new NotImplementedException ();
303                 }
304
305                 [MonoTODO]
306                 public static int NumParamBytes (MethodInfo m) {
307                         throw new NotImplementedException ();
308                 }
309
310                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
311                 public extern static IntPtr OffsetOf (Type t, string fieldName);
312
313                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
314                 public extern static void Prelink (MethodInfo m);
315
316                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
317                 public extern static void PrelinkAll (Type c);
318
319                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
320                 public extern static string PtrToStringAnsi (IntPtr ptr);
321                 
322                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
323                 public extern static string PtrToStringAnsi (IntPtr ptr, int len);
324
325                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
326                 public extern static string PtrToStringAuto (IntPtr ptr);
327                 
328                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
329                 public extern static string PtrToStringAuto (IntPtr ptr, int len);
330
331                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
332                 public extern static string PtrToStringUni (IntPtr ptr);
333
334                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
335                 public extern static string PtrToStringUni (IntPtr ptr, int len);
336
337                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
338                 public extern static string PtrToStringBSTR (IntPtr ptr);
339                 
340                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
341                 public extern static void PtrToStructure (IntPtr ptr, object structure);
342
343                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
344                 public extern static object PtrToStructure (IntPtr ptr, Type structureType);
345
346                 [MonoTODO]
347                 public static int QueryInterface (IntPtr pUnk, ref Guid iid, out IntPtr ppv) {
348                         throw new NotImplementedException ();
349                 }
350
351                 public static byte ReadByte (IntPtr ptr) {
352                         return ReadByte (ptr, 0);
353                 }
354
355                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
356                 public extern static byte ReadByte (IntPtr ptr, int ofs);
357
358                 [MonoTODO]
359                 public static byte ReadByte ([In] object ptr, int ofs) {
360                         throw new NotImplementedException ();
361                 }
362
363                 public static short ReadInt16 (IntPtr ptr) {
364                         return ReadInt16 (ptr, 0);
365                 }
366
367                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
368                 public extern static short ReadInt16 (IntPtr ptr, int ofs);
369
370                 [MonoTODO]
371                 public static short ReadInt16 ([In] object ptr, int ofs) {
372                         throw new NotImplementedException ();
373                 }
374
375                 public static int ReadInt32 (IntPtr ptr) {
376                         return ReadInt32 (ptr, 0);
377                 }
378
379                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
380                 public extern static int ReadInt32 (IntPtr ptr, int ofs);
381
382                 [MonoTODO]
383                 public static int ReadInt32 ([In] object ptr, int ofs) {
384                         throw new NotImplementedException ();
385                 }
386
387                 public static long ReadInt64 (IntPtr ptr) {
388                         return ReadInt64 (ptr, 0);
389                 }
390
391                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
392                 public extern static long ReadInt64 (IntPtr ptr, int ofs);
393
394                 [MonoTODO]
395                 public static long ReadInt64([In] object ptr, int ofs) {
396                         throw new NotImplementedException ();
397                 }
398
399                 public static IntPtr ReadIntPtr (IntPtr ptr) {
400                         return ReadIntPtr (ptr, 0);
401                 }
402                 
403                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
404                 public extern static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
405
406                 [MonoTODO]
407                 public static IntPtr ReadIntPtr([In] object ptr, int ofs) {
408                         throw new NotImplementedException ();
409                 }
410
411                 [MonoTODO]
412                 public static IntPtr ReAllocCoTaskMem (IntPtr pv, int cb) {
413                         throw new NotImplementedException ();
414                 }
415
416                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
417                 public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
418
419                 [MonoTODO]
420                 public static int Release (IntPtr pUnk) {
421                         throw new NotImplementedException ();
422                 }
423
424                 [MonoTODO]
425                 public static int ReleaseComObject (object o) {
426                         throw new NotImplementedException ();
427                 }
428
429                 [MonoTODO]
430                 public static void ReleaseThreadCache() {
431                         throw new NotImplementedException ();
432                 }
433
434                 [MonoTODO]
435                 public static bool SetComObjectData (object obj, object key, object data) {
436                         throw new NotImplementedException ();
437                 }
438
439                 public static int SizeOf (object structure) {
440                         return SizeOf (structure.GetType ());
441                 }
442
443                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
444                 public extern static int SizeOf (Type t);
445
446                 [MonoTODO]
447                 public static IntPtr StringToBSTR (string s) {
448                         throw new NotImplementedException ();
449                 }
450
451                 [MonoTODO]
452                 public static IntPtr StringToCoTaskMemAnsi (string s) {
453                         throw new NotImplementedException ();
454                 }
455
456                 [MonoTODO]
457                 public static IntPtr StringToCoTaskMemAuto (string s) {
458                         throw new NotImplementedException ();
459                 }
460
461                 [MonoTODO]
462                 public static IntPtr StringToCoTaskMemUni (string s) {
463                         throw new NotImplementedException ();
464                 }
465
466                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
467                 public extern static IntPtr StringToHGlobalAnsi (string s);
468
469                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
470                 public extern static IntPtr StringToHGlobalAuto (string s);
471
472                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
473                 public extern static IntPtr StringToHGlobalUni (string s);
474
475                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
476                 public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
477
478                 [MonoTODO]
479                 public static void ThrowExceptionForHR (int errorCode) {
480                         throw new NotImplementedException ();
481                 }
482
483                 [MonoTODO]
484                 public static void ThrowExceptionForHR (int errorCode, IntPtr errorInfo) {
485                         throw new NotImplementedException ();
486                 }
487
488                 [MonoTODO]
489                 public static IntPtr UnsafeAddrOfPinnedArrayElement (Array arr, int index) {
490                         throw new NotImplementedException ();
491                 }
492
493                 public static void WriteByte (IntPtr ptr, byte val) {
494                         WriteByte (ptr, 0, val);
495                 }
496
497                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
498                 public extern static void WriteByte (IntPtr ptr, int ofs, byte val);
499
500                 [MonoTODO]
501                 public static void WriteByte([In,Out] object ptr, int ofs, byte val) {
502                         throw new NotImplementedException ();
503                 }
504
505                 public static void WriteInt16 (IntPtr ptr, short val) {
506                         WriteInt16 (ptr, 0, val);
507                 }
508
509                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
510                 public extern static void WriteInt16 (IntPtr ptr, int ofs, short val);
511
512                 [MonoTODO]
513                 public static void WriteInt16([In,Out] object ptr, int ofs, short val) {
514                         throw new NotImplementedException ();
515                 }
516
517                 public static void WriteInt32 (IntPtr ptr, int val) {
518                         WriteInt32 (ptr, 0, val);
519                 }
520
521                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
522                 public extern static void WriteInt32 (IntPtr ptr, int ofs, int val);
523
524                 [MonoTODO]
525                 public static void WriteInt32([In,Out] object ptr, int ofs, int val) {
526                         throw new NotImplementedException ();
527                 }
528
529                 public static void WriteInt64 (IntPtr ptr, long val) {
530                         WriteInt64 (ptr, 0, val);
531                 }
532
533                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
534                 public extern static void WriteInt64 (IntPtr ptr, int ofs, long val);
535
536                 [MonoTODO]
537                 public static void WriteInt64([In] object ptr, int ofs, long val) {
538                         throw new NotImplementedException ();
539                 }
540
541                 public static void WriteIntPtr (IntPtr ptr, IntPtr val) {
542                         WriteIntPtr (ptr, 0, val);
543                 }
544
545                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
546                 public extern static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
547
548                 [MonoTODO]
549                 public static void WriteIntPtr([In] object ptr, int ofs, IntPtr val) {
550                         throw new NotImplementedException ();
551                 }
552
553         }
554 }