Marshal.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. // System.Runtime.InteropServices.Marshal
  2. //
  3. // Sean MacIsaac ([email protected])
  4. // Paolo Molaro ([email protected])
  5. // Dietmar Maurer ([email protected])
  6. //
  7. // (C) 2001-2002 Ximian, Inc.
  8. using System.Runtime.CompilerServices;
  9. using System;
  10. using System.Reflection;
  11. using System.Threading;
  12. namespace System.Runtime.InteropServices
  13. {
  14. public sealed class Marshal
  15. {
  16. /* fields */
  17. public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
  18. public static readonly int SystemDefaultCharSize = 2;
  19. private Marshal () {}
  20. [MonoTODO]
  21. public static int AddRef (IntPtr pUnk) {
  22. throw new NotImplementedException ();
  23. }
  24. [MonoTODO]
  25. public static IntPtr AllocCoTaskMem (int cb) {
  26. throw new NotImplementedException ();
  27. }
  28. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  29. public extern static IntPtr AllocHGlobal (IntPtr cb);
  30. public static IntPtr AllocHGlobal (int cb) {
  31. return AllocHGlobal ((IntPtr)cb);
  32. }
  33. [MonoTODO]
  34. public static object BindToMoniker (string monikerName) {
  35. throw new NotImplementedException ();
  36. }
  37. [MonoTODO]
  38. public static void ChangeWrapperHandleStrength (object otp, bool fIsWeak) {
  39. throw new NotImplementedException ();
  40. }
  41. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  42. extern static void copy_to_unmanaged (Array source, int startIndex,
  43. IntPtr destination, int length);
  44. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  45. extern static void copy_from_unmanaged (IntPtr source, int startIndex,
  46. Array destination, int length);
  47. public static void Copy (byte[] source, int startIndex, IntPtr destination, int length) {
  48. copy_to_unmanaged (source, startIndex, destination, length);
  49. }
  50. public static void Copy (char[] source, int startIndex, IntPtr destination, int length) {
  51. copy_to_unmanaged (source, startIndex, destination, length);
  52. }
  53. public static void Copy (short[] source, int startIndex, IntPtr destination, int length) {
  54. copy_to_unmanaged (source, startIndex, destination, length);
  55. }
  56. public static void Copy (int[] source, int startIndex, IntPtr destination, int length) {
  57. copy_to_unmanaged (source, startIndex, destination, length);
  58. }
  59. public static void Copy (long[] source, int startIndex, IntPtr destination, int length) {
  60. copy_to_unmanaged (source, startIndex, destination, length);
  61. }
  62. public static void Copy (float[] source, int startIndex, IntPtr destination, int length) {
  63. copy_to_unmanaged (source, startIndex, destination, length);
  64. }
  65. public static void Copy (double[] source, int startIndex, IntPtr destination, int length) {
  66. copy_to_unmanaged (source, startIndex, destination, length);
  67. }
  68. public static void Copy (IntPtr source, byte[] destination, int startIndex, int length) {
  69. copy_from_unmanaged (source, startIndex, destination, length);
  70. }
  71. public static void Copy (IntPtr source, char[] destination, int startIndex, int length) {
  72. copy_from_unmanaged (source, startIndex, destination, length);
  73. }
  74. public static void Copy (IntPtr source, short[] destination, int startIndex, int length) {
  75. copy_from_unmanaged (source, startIndex, destination, length);
  76. }
  77. public static void Copy (IntPtr source, int[] destination, int startIndex, int length) {
  78. copy_from_unmanaged (source, startIndex, destination, length);
  79. }
  80. public static void Copy (IntPtr source, long[] destination, int startIndex, int length) {
  81. copy_from_unmanaged (source, startIndex, destination, length);
  82. }
  83. public static void Copy (IntPtr source, float[] destination, int startIndex, int length) {
  84. copy_from_unmanaged (source, startIndex, destination, length);
  85. }
  86. public static void Copy (IntPtr source, double[] destination, int startIndex, int length) {
  87. copy_from_unmanaged (source, startIndex, destination, length);
  88. }
  89. [MonoTODO]
  90. public static object CreateWrapperOfType (object o, Type t) {
  91. throw new NotImplementedException ();
  92. }
  93. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  94. public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
  95. [MonoTODO]
  96. public static void FreeBSTR (IntPtr ptr) {
  97. throw new NotImplementedException ();
  98. }
  99. [MonoTODO]
  100. public static void FreeCoTaskMem (IntPtr ptr) {
  101. throw new NotImplementedException ();
  102. }
  103. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  104. public extern static void FreeHGlobal (IntPtr hglobal);
  105. [MonoTODO]
  106. public static Guid GenerateGuidForType (Type type) {
  107. throw new NotImplementedException ();
  108. }
  109. [MonoTODO]
  110. public static string GenerateProgIdForType (Type type) {
  111. throw new NotImplementedException ();
  112. }
  113. [MonoTODO]
  114. public static object GetActiveObject (string progID) {
  115. throw new NotImplementedException ();
  116. }
  117. [MonoTODO]
  118. public static IntPtr GetComInterfaceForObject (object o, Type T) {
  119. throw new NotImplementedException ();
  120. }
  121. [MonoTODO]
  122. public static object GetComObjectData (object obj, object key) {
  123. throw new NotImplementedException ();
  124. }
  125. [MonoTODO]
  126. public static int GetComSlotForMethodInfo (MemberInfo m) {
  127. throw new NotImplementedException ();
  128. }
  129. [MonoTODO]
  130. public static int GetEndComSlot (Type t) {
  131. throw new NotImplementedException ();
  132. }
  133. [MonoTODO]
  134. public static int GetExceptionCode() {
  135. throw new NotImplementedException ();
  136. }
  137. [MonoTODO]
  138. public static IntPtr GetExceptionPointers() {
  139. throw new NotImplementedException ();
  140. }
  141. [MonoTODO]
  142. public static IntPtr GetHINSTANCE (Module m) {
  143. throw new NotImplementedException ();
  144. }
  145. [MonoTODO]
  146. public static int GetHRForException (Exception e) {
  147. throw new NotImplementedException ();
  148. }
  149. [MonoTODO]
  150. public static int GetHRForLastWin32Error() {
  151. throw new NotImplementedException ();
  152. }
  153. [MonoTODO]
  154. public static IntPtr GetIDispatchForObject (object o) {
  155. throw new NotImplementedException ();
  156. }
  157. [MonoTODO]
  158. public static IntPtr GetITypeInfoForType (Type t) {
  159. throw new NotImplementedException ();
  160. }
  161. [MonoTODO]
  162. public static IntPtr GetIUnknownForObject (object o) {
  163. throw new NotImplementedException ();
  164. }
  165. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  166. public static extern int GetLastWin32Error();
  167. [MonoTODO]
  168. public static IntPtr GetManagedThunkForUnmanagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
  169. throw new NotImplementedException ();
  170. }
  171. [MonoTODO]
  172. public static MemberInfo GetMethodInfoForComSlot (Type t, int slot, ref ComMemberType memberType) {
  173. throw new NotImplementedException ();
  174. }
  175. [MonoTODO]
  176. public static void GetNativeVariantForObject (object obj, IntPtr pDstNativeVariant) {
  177. throw new NotImplementedException ();
  178. }
  179. [MonoTODO]
  180. public static object GetObjectForIUnknown (IntPtr pUnk) {
  181. throw new NotImplementedException ();
  182. }
  183. [MonoTODO]
  184. public static object GetObjectForNativeVariant (IntPtr pSrcNativeVariant) {
  185. throw new NotImplementedException ();
  186. }
  187. [MonoTODO]
  188. public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant, int cVars) {
  189. throw new NotImplementedException ();
  190. }
  191. [MonoTODO]
  192. public static int GetStartComSlot (Type t) {
  193. throw new NotImplementedException ();
  194. }
  195. [MonoTODO]
  196. public static Thread GetThreadFromFiberCookie (int cookie) {
  197. throw new NotImplementedException ();
  198. }
  199. [MonoTODO]
  200. public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t) {
  201. throw new NotImplementedException ();
  202. }
  203. [MonoTODO]
  204. public static Type GetTypeForITypeInfo (IntPtr piTypeInfo) {
  205. throw new NotImplementedException ();
  206. }
  207. [MonoTODO]
  208. public static string GetTypeInfoName (UCOMITypeInfo pTI) {
  209. throw new NotImplementedException ();
  210. }
  211. [MonoTODO]
  212. public static Guid GetTypeLibGuid (UCOMITypeLib pTLB) {
  213. throw new NotImplementedException ();
  214. }
  215. [MonoTODO]
  216. public static Guid GetTypeLibGuidForAssembly (Assembly asm) {
  217. throw new NotImplementedException ();
  218. }
  219. [MonoTODO]
  220. public static int GetTypeLibLcid (UCOMITypeLib pTLB) {
  221. throw new NotImplementedException ();
  222. }
  223. [MonoTODO]
  224. public static string GetTypeLibName (UCOMITypeLib pTLB) {
  225. throw new NotImplementedException ();
  226. }
  227. [MonoTODO]
  228. public static IntPtr GetUnmanagedThunkForManagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature) {
  229. throw new NotImplementedException ();
  230. }
  231. [MonoTODO]
  232. public static bool IsComObject (object o) {
  233. throw new NotImplementedException ();
  234. }
  235. [MonoTODO]
  236. public static bool IsTypeVisibleFromCom (Type t) {
  237. throw new NotImplementedException ();
  238. }
  239. [MonoTODO]
  240. public static int NumParamBytes (MethodInfo m) {
  241. throw new NotImplementedException ();
  242. }
  243. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  244. public extern static IntPtr OffsetOf (Type t, string fieldName);
  245. [MonoTODO]
  246. public static void Prelink (MethodInfo m) {
  247. throw new NotImplementedException ();
  248. }
  249. [MonoTODO]
  250. public static void PrelinkAll (Type c) {
  251. throw new NotImplementedException ();
  252. }
  253. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  254. public extern static string PtrToStringAnsi (IntPtr ptr);
  255. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  256. public extern static string PtrToStringAnsi (IntPtr ptr, int len);
  257. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  258. public extern static string PtrToStringAuto (IntPtr ptr);
  259. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  260. public extern static string PtrToStringAuto (IntPtr ptr, int len);
  261. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  262. public extern static string PtrToStringUni (IntPtr ptr);
  263. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  264. public extern static string PtrToStringUni (IntPtr ptr, int len);
  265. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  266. public extern static string PtrToStringBSTR (IntPtr ptr);
  267. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  268. public extern static void PtrToStructure (IntPtr ptr, object structure);
  269. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  270. public extern static object PtrToStructure (IntPtr ptr, Type structureType);
  271. [MonoTODO]
  272. public static int QueryInterface (IntPtr pUnk, ref Guid iid, out IntPtr ppv) {
  273. throw new NotImplementedException ();
  274. }
  275. public static byte ReadByte (IntPtr ptr) {
  276. return ReadByte (ptr, 0);
  277. }
  278. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  279. public extern static byte ReadByte (IntPtr ptr, int ofs);
  280. [MonoTODO]
  281. public static byte ReadByte (object ptr, int ofs) {
  282. throw new NotImplementedException ();
  283. }
  284. public static short ReadInt16 (IntPtr ptr) {
  285. return ReadInt16 (ptr, 0);
  286. }
  287. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  288. public extern static short ReadInt16 (IntPtr ptr, int ofs);
  289. [MonoTODO]
  290. public static short ReadInt16 (object ptr, int ofs) {
  291. throw new NotImplementedException ();
  292. }
  293. public static int ReadInt32 (IntPtr ptr) {
  294. return ReadInt32 (ptr, 0);
  295. }
  296. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  297. public extern static int ReadInt32 (IntPtr ptr, int ofs);
  298. [MonoTODO]
  299. public static int ReadInt32 (object ptr, int ofs) {
  300. throw new NotImplementedException ();
  301. }
  302. public static long ReadInt64 (IntPtr ptr) {
  303. return ReadInt64 (ptr, 0);
  304. }
  305. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  306. public extern static long ReadInt64 (IntPtr ptr, int ofs);
  307. [MonoTODO]
  308. public static long ReadInt64(object ptr, int ofs) {
  309. throw new NotImplementedException ();
  310. }
  311. public static IntPtr ReadIntPtr (IntPtr ptr) {
  312. return ReadIntPtr (ptr, 0);
  313. }
  314. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  315. public extern static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
  316. [MonoTODO]
  317. public static IntPtr ReadIntPtr(object ptr, int ofs) {
  318. throw new NotImplementedException ();
  319. }
  320. [MonoTODO]
  321. public static IntPtr ReAllocCoTaskMem (IntPtr pv, int cb) {
  322. throw new NotImplementedException ();
  323. }
  324. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  325. public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
  326. [MonoTODO]
  327. public static int Release (IntPtr pUnk) {
  328. throw new NotImplementedException ();
  329. }
  330. [MonoTODO]
  331. public static int ReleaseComObject (object o) {
  332. throw new NotImplementedException ();
  333. }
  334. [MonoTODO]
  335. public static void ReleaseThreadCache() {
  336. throw new NotImplementedException ();
  337. }
  338. [MonoTODO]
  339. public static bool SetComObjectData (object obj, object key, object data) {
  340. throw new NotImplementedException ();
  341. }
  342. public static int SizeOf (object structure) {
  343. return SizeOf (structure.GetType ());
  344. }
  345. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  346. public extern static int SizeOf (Type t);
  347. [MonoTODO]
  348. public static IntPtr StringToBSTR (string s) {
  349. throw new NotImplementedException ();
  350. }
  351. [MonoTODO]
  352. public static IntPtr StringToCoTaskMemAnsi (string s) {
  353. throw new NotImplementedException ();
  354. }
  355. [MonoTODO]
  356. public static IntPtr StringToCoTaskMemAuto (string s) {
  357. throw new NotImplementedException ();
  358. }
  359. [MonoTODO]
  360. public static IntPtr StringToCoTaskMemUni (string s) {
  361. throw new NotImplementedException ();
  362. }
  363. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  364. public extern static IntPtr StringToHGlobalAnsi (string s);
  365. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  366. public extern static IntPtr StringToHGlobalAuto (string s);
  367. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  368. public extern static IntPtr StringToHGlobalUni (string s);
  369. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  370. public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
  371. [MonoTODO]
  372. public static void ThrowExceptionForHR (int errorCode) {
  373. throw new NotImplementedException ();
  374. }
  375. [MonoTODO]
  376. public static void ThrowExceptionForHR (int errorCode, IntPtr errorInfo) {
  377. throw new NotImplementedException ();
  378. }
  379. [MonoTODO]
  380. public static IntPtr UnsafeAddrOfPinnedArrayElement (Array arr, int index) {
  381. throw new NotImplementedException ();
  382. }
  383. public static void WriteByte (IntPtr ptr, byte val) {
  384. WriteByte (ptr, 0, val);
  385. }
  386. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  387. public extern static void WriteByte (IntPtr ptr, int ofs, byte val);
  388. [MonoTODO]
  389. public static void WriteByte(object ptr, int ofs, byte val) {
  390. throw new NotImplementedException ();
  391. }
  392. public static void WriteInt16 (IntPtr ptr, short val) {
  393. WriteInt16 (ptr, 0, val);
  394. }
  395. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  396. public extern static void WriteInt16 (IntPtr ptr, int ofs, short val);
  397. [MonoTODO]
  398. public static void WriteInt16(object ptr, int ofs, short val) {
  399. throw new NotImplementedException ();
  400. }
  401. public static void WriteInt32 (IntPtr ptr, int val) {
  402. WriteInt32 (ptr, 0, val);
  403. }
  404. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  405. public extern static void WriteInt32 (IntPtr ptr, int ofs, int val);
  406. [MonoTODO]
  407. public static void WriteInt32(object ptr, int ofs, int val) {
  408. throw new NotImplementedException ();
  409. }
  410. public static void WriteInt64 (IntPtr ptr, long val) {
  411. WriteInt64 (ptr, 0, val);
  412. }
  413. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  414. public extern static void WriteInt64 (IntPtr ptr, int ofs, long val);
  415. [MonoTODO]
  416. public static void WriteInt64(object ptr, int ofs, long val) {
  417. throw new NotImplementedException ();
  418. }
  419. public static void WriteIntPtr (IntPtr ptr, IntPtr val) {
  420. WriteIntPtr (ptr, 0, val);
  421. }
  422. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  423. public extern static void WriteIntPtr (IntPtr ptr, int ofs, IntPtr val);
  424. [MonoTODO]
  425. public static void WriteIntPtr(object ptr, int ofs, IntPtr val) {
  426. throw new NotImplementedException ();
  427. }
  428. }
  429. }