8391cce39c37330c56affce4481f68b96dc6d444
[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.Reflection;
12 using System.Threading;
13
14 namespace System.Runtime.InteropServices
15 {
16         public sealed class Marshal
17         {
18                 /* fields */
19                 public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
20                 public static readonly int SystemDefaultCharSize = 2;
21                 
22                 private Marshal () {}
23
24                 [MonoTODO]
25                 public static int AddRef (IntPtr pUnk) {
26                         throw new NotImplementedException ();
27                 }
28                 [MonoTODO]
29                 public static IntPtr AllocCoTaskMem (int cb) {
30                         throw new NotImplementedException ();
31                 }
32
33                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
34                 public extern static IntPtr AllocHGlobal (IntPtr cb);
35
36                 public static IntPtr AllocHGlobal (int cb) {
37                         return AllocHGlobal ((IntPtr)cb);
38                 }
39
40                 [MonoTODO]
41                 public static object BindToMoniker (string monikerName) {
42                         throw new NotImplementedException ();
43                 }
44
45                 [MonoTODO]
46                 public static void ChangeWrapperHandleStrength (object otp, bool fIsWeak) {
47                         throw new NotImplementedException ();
48                 }
49
50                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
51                 extern static void copy_to_unmanaged (Array source, int startIndex,
52                                                       IntPtr destination, int length);
53
54                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
55                 extern static void copy_from_unmanaged (IntPtr source, int startIndex,
56                                                         Array destination, int length);
57
58                 public static void Copy (byte[] source, int startIndex, IntPtr destination, int length) {
59                         copy_to_unmanaged (source, startIndex, destination, length);
60                 }
61
62                 public static void Copy (char[] source, int startIndex, IntPtr destination, int length) {
63                         copy_to_unmanaged (source, startIndex, destination, length);
64                 }
65
66                 public static void Copy (short[] source, int startIndex, IntPtr destination, int length) {
67                         copy_to_unmanaged (source, startIndex, destination, length);
68                 }
69
70                 public static void Copy (int[] source, int startIndex, IntPtr destination, int length) {
71                         copy_to_unmanaged (source, startIndex, destination, length);
72                 }
73
74                 public static void Copy (long[] source, int startIndex, IntPtr destination, int length) {
75                         copy_to_unmanaged (source, startIndex, destination, length);
76                 }
77
78                 public static void Copy (float[] source, int startIndex, IntPtr destination, int length) {
79                         copy_to_unmanaged (source, startIndex, destination, length);
80                 }
81
82                 public static void Copy (double[] source, int startIndex, IntPtr destination, int length) {
83                         copy_to_unmanaged (source, startIndex, destination, length);
84                 }
85
86                 public static void Copy (IntPtr source, byte[] destination, int startIndex, int length) {
87                         copy_from_unmanaged (source, startIndex, destination, length);
88                 }
89
90                 public static void Copy (IntPtr source, char[] destination, int startIndex, int length) {
91                         copy_from_unmanaged (source, startIndex, destination, length);
92                 }
93
94                 public static void Copy (IntPtr source, short[] destination, int startIndex, int length) {
95                         copy_from_unmanaged (source, startIndex, destination, length);
96                 }
97
98                 public static void Copy (IntPtr source, int[] destination, int startIndex, int length) {
99                         copy_from_unmanaged (source, startIndex, destination, length);
100                 }
101
102                 public static void Copy (IntPtr source, long[] destination, int startIndex, int length) {
103                         copy_from_unmanaged (source, startIndex, destination, length);
104                 }
105
106                 public static void Copy (IntPtr source, float[] destination, int startIndex, int length) {
107                         copy_from_unmanaged (source, startIndex, destination, length);
108                 }
109
110                 public static void Copy (IntPtr source, double[] destination, int startIndex, int length) {
111                         copy_from_unmanaged (source, startIndex, destination, length);
112                 }
113
114                 [MonoTODO]
115                 public static object CreateWrapperOfType (object o, Type t) {
116                         throw new NotImplementedException ();
117                 }
118
119                 [MonoTODO]
120                 public static void DestroyStructure (IntPtr ptr, Type structuretype) {
121                         throw new NotImplementedException ();
122                 }
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                 [MonoTODO]
311                 public static IntPtr OffsetOf (Type t, string fieldName) {
312                         throw new NotImplementedException ();
313                 }
314
315                 [MonoTODO]
316                 public static void Prelink (MethodInfo m) {
317                         throw new NotImplementedException ();
318                 }
319
320                 [MonoTODO]
321                 public static void PrelinkAll (Type c) {
322                         throw new NotImplementedException ();
323                 }
324
325                 [MonoTODO]
326                 public static string PtrToStringAnsi (IntPtr ptr) {
327                         throw new NotImplementedException ();
328                 }
329
330                 [MonoTODO]
331                 public static string PtrToStringAnsi (IntPtr ptr, int len) {
332                         throw new NotImplementedException ();
333                 }
334
335                 [MonoTODO]
336                 public static string PtrToStringAuto (IntPtr ptr, int len) {
337                         throw new NotImplementedException ();
338                 }
339
340                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
341                 public static extern string PtrToStringAuto (IntPtr ptr);
342                 
343                 [MonoTODO]
344                 public static string PtrToStringBSTR (IntPtr ptr) {
345                         throw new NotImplementedException ();
346                 }
347
348                 [MonoTODO]
349                 public static string PtrToStringUni (IntPtr ptr) {
350                         throw new NotImplementedException ();
351                 }
352
353                 [MonoTODO]
354                 public static string PtrToStringUni (IntPtr ptr, int len) {
355                         throw new NotImplementedException ();
356                 }
357
358                 [MonoTODO]
359                 public static void PtrToStructure (IntPtr ptr, object structure) {
360                         throw new NotImplementedException ();
361                 }
362
363                 [MonoTODO]
364                 public static object PtrToStructure (IntPtr ptr, Type structureType) {
365                         throw new NotImplementedException ();
366                 }
367
368                 [MonoTODO]
369                 public static int QueryInterface (IntPtr pUnk, ref Guid iid, out IntPtr ppv) {
370                         throw new NotImplementedException ();
371                 }
372
373                 public static byte ReadByte (IntPtr ptr) {
374                         return ReadByte (ptr, 0);
375                 }
376
377                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
378                 public extern static byte ReadByte (IntPtr ptr, int ofs);
379
380                 [MonoTODO]
381                 public static byte ReadByte (object ptr, int ofs) {
382                         throw new NotImplementedException ();
383                 }
384
385                 public static short ReadInt16 (IntPtr ptr) {
386                         return ReadInt16 (ptr, 0);
387                 }
388
389                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
390                 public extern static short ReadInt16 (IntPtr ptr, int ofs);
391
392                 [MonoTODO]
393                 public static short ReadInt16 (object ptr, int ofs) {
394                         throw new NotImplementedException ();
395                 }
396
397                 public static int ReadInt32 (IntPtr ptr) {
398                         return ReadInt32 (ptr, 0);
399                 }
400
401                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
402                 public extern static int ReadInt32 (IntPtr ptr, int ofs);
403
404                 [MonoTODO]
405                 public static int ReadInt32 (object ptr, int ofs) {
406                         throw new NotImplementedException ();
407                 }
408
409                 public static long ReadInt64 (IntPtr ptr) {
410                         return ReadInt64 (ptr, 0);
411                 }
412
413                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
414                 public extern static long ReadInt64 (IntPtr ptr, int ofs);
415
416                 [MonoTODO]
417                 public static long ReadInt64(object ptr, int ofs) {
418                         throw new NotImplementedException ();
419                 }
420
421                 public static IntPtr ReadIntPtr (IntPtr ptr) {
422                         return ReadIntPtr (ptr, 0);
423                 }
424                 
425                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
426                 public extern static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
427
428                 [MonoTODO]
429                 public static IntPtr ReadIntPtr(object ptr, int ofs) {
430                         throw new NotImplementedException ();
431                 }
432
433                 [MonoTODO]
434                 public static IntPtr ReAllocCoTaskMem (IntPtr pv, int cb) {
435                         throw new NotImplementedException ();
436                 }
437
438                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
439                 public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
440
441                 [MonoTODO]
442                 public static int Release (IntPtr pUnk) {
443                         throw new NotImplementedException ();
444                 }
445
446                 [MonoTODO]
447                 public static int ReleaseComObject (object o) {
448                         throw new NotImplementedException ();
449                 }
450
451                 [MonoTODO]
452                 public static void ReleaseThreadCache() {
453                         throw new NotImplementedException ();
454                 }
455
456                 [MonoTODO]
457                 public static bool SetComObjectData (object obj, object key, object data) {
458                         throw new NotImplementedException ();
459                 }
460
461                 public static int SizeOf (object structure) {
462                         return SizeOf (structure.GetType ());
463                 }
464
465                 [MonoTODO]
466                 public static int SizeOf (Type t) {
467                         throw new NotImplementedException ();
468                 }
469
470                 [MonoTODO]
471                 public static IntPtr StringToBSTR (string s) {
472                         throw new NotImplementedException ();
473                 }
474
475                 [MonoTODO]
476                 public static IntPtr StringToCoTaskMemAnsi (string s) {
477                         throw new NotImplementedException ();
478                 }
479
480                 [MonoTODO]
481                 public static IntPtr StringToCoTaskMemAuto (string s) {
482                         throw new NotImplementedException ();
483                 }
484
485                 [MonoTODO]
486                 public static IntPtr StringToCoTaskMemUni (string s) {
487                         throw new NotImplementedException ();
488                 }
489
490                 [MonoTODO]
491                 public static IntPtr StringToHGlobalAnsi (string s) {
492                         throw new NotImplementedException ();
493                 }
494
495                 [MonoTODO]
496                 public static IntPtr StringToHGlobalAuto (string s) {
497                         throw new NotImplementedException ();
498                 }
499
500                 [MonoTODO]
501                 public static IntPtr StringToHGlobalUni (string s) {
502                         throw new NotImplementedException ();
503                 }
504
505                 [MonoTODO]
506                 public static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld) {
507                         throw new NotImplementedException ();
508                 }
509
510                 [MonoTODO]
511                 public static void ThrowExceptionForHR (int errorCode) {
512                         throw new NotImplementedException ();
513                 }
514
515                 [MonoTODO]
516                 public static void ThrowExceptionForHR (int errorCode, IntPtr errorInfo) {
517                         throw new NotImplementedException ();
518                 }
519
520                 [MonoTODO]
521                 public static IntPtr UnsafeAddrOfPinnedArrayElement (Array arr, int index) {
522                         throw new NotImplementedException ();
523                 }
524
525                 public static void WriteByte (IntPtr ptr, byte val) {
526                         WriteByte (ptr, 0, val);
527                 }
528
529                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
530                 public extern static void WriteByte (IntPtr ptr, int ofs, byte val);
531
532                 [MonoTODO]
533                 public static void WriteByte(object ptr, int ofs, byte val) {
534                         throw new NotImplementedException ();
535                 }
536
537                 public static void WriteInt16 (IntPtr ptr, short val) {
538                         WriteInt16 (ptr, 0, val);
539                 }
540
541                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
542                 public extern static void WriteInt16 (IntPtr ptr, int ofs, short val);
543
544                 [MonoTODO]
545                 public static void WriteInt16(object ptr, int ofs, short val) {
546                         throw new NotImplementedException ();
547                 }
548
549                 public static void WriteInt32 (IntPtr ptr, int val) {
550                         WriteInt32 (ptr, 0, val);
551                 }
552
553                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
554                 public extern static void WriteInt32 (IntPtr ptr, int ofs, int val);
555
556                 [MonoTODO]
557                 public static void WriteInt32(object ptr, int ofs, int val) {
558                         throw new NotImplementedException ();
559                 }
560
561                 public static void WriteInt64 (IntPtr ptr, long val) {
562                         WriteInt64 (ptr, 0, val);
563                 }
564
565                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
566                 public extern static void WriteInt64 (IntPtr ptr, int ofs, long val);
567
568                 [MonoTODO]
569                 public static void WriteInt64(object ptr, int ofs, long val) {
570                         throw new NotImplementedException ();
571                 }
572
573                 public static void WriteIntPtr (IntPtr ptr, IntPtr val) {
574                         WriteIntPtr (ptr, 0, val);
575                 }
576
577                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
578                 public extern static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
579
580                 [MonoTODO]
581                 public static void WriteIntPtr(object ptr, int ofs, IntPtr val) {
582                         throw new NotImplementedException ();
583                 }
584
585         }
586 }