2 // System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Jonathan Chambers (joncham@gmail.com)
8 // (C) 2003 Martin Willemoes Hansen
9 // (C) 2007 Jonathan Chambers
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
38 namespace System.Runtime.InteropServices.CustomMarshalers
40 public class EnumeratorToEnumVariantMarshaler : ICustomMarshaler
42 static EnumeratorToEnumVariantMarshaler instance;
43 public void CleanUpManagedData (object pManagedObj) {
44 throw new NotImplementedException ();
47 public void CleanUpNativeData (IntPtr pNativeData) {
48 Marshal.Release (pNativeData);
51 public static ICustomMarshaler GetInstance (string pstrCookie) {
53 instance = new EnumeratorToEnumVariantMarshaler ();
57 public int GetNativeDataSize () {
58 throw new NotImplementedException ();
61 public IntPtr MarshalManagedToNative (object pManagedObj) {
62 throw new NotImplementedException ();
65 public object MarshalNativeToManaged (IntPtr pNativeData) {
66 IEnumVARIANT ienumvariant = (IEnumVARIANT)Marshal.GetObjectForIUnknown (pNativeData);
67 VARIANTEnumerator e = new VARIANTEnumerator (ienumvariant);
72 [Guid ("00020404-0000-0000-C000-000000000046")]
73 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
74 interface IEnumVARIANT
76 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
77 void Next (int celt, [MarshalAs (UnmanagedType.Struct)]out object rgvar, out uint pceltFetched);
78 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
79 void Skip (uint celt);
80 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
82 [return: MarshalAs (UnmanagedType.Interface)]
83 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
84 IEnumVARIANT Clone ();
88 class VARIANTEnumerator : IEnumerator
90 IEnumVARIANT com_enum;
92 public VARIANTEnumerator (IEnumVARIANT com_enum) {
93 this.com_enum = com_enum;
95 #region IEnumerator Members
97 public object Current {
103 public bool MoveNext () {
106 com_enum.Next (1, out val, out fetched);
113 public void Reset () {