//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
+//
+// Copyright (C) 2005 Kornél Pál
+//
+
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using System.Runtime.InteropServices.ComTypes;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
+#else
+using IStream = System.Runtime.InteropServices.UCOMIStream;
#endif
namespace System.Drawing
private delegate int WriteDelegate(IntPtr @this, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] pv, int cb, IntPtr pcbWritten);
private delegate int SeekDelegate(IntPtr @this, long dlibMove, int dwOrigin, IntPtr plibNewPosition);
private delegate int SetSizeDelegate(IntPtr @this, long libNewSize);
- private delegate int CopyToDelegate(IntPtr @this, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))]
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
+ private delegate int CopyToDelegate(IntPtr @this, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
private delegate int CommitDelegate(IntPtr @this, int grfCommitFlags);
private delegate int RevertDelegate(IntPtr @this);
private delegate int LockRegionDelegate(IntPtr @this, long libOffset, long cb, int dwLockType);
private static readonly IntPtr comVtable;
private static readonly VtableDestructor vtableDestructor;
- private readonly
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface;
+ private readonly IStream managedInterface;
private readonly IntPtr comInterface;
// Keeps the object alive when it has no managed references
private readonly GCHandle gcHandle;
vtableDestructor = new VtableDestructor();
}
- private ManagedToNativeWrapper(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface)
+ private ManagedToNativeWrapper(IStream managedInterface)
{
IStreamInterface newInterface;
GC.SuppressFinalize(this);
}
- internal static
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- GetUnderlyingInterface(IntPtr comInterface, bool outParam)
+ internal static IStream GetUnderlyingInterface(IntPtr comInterface, bool outParam)
{
if (Marshal.ReadIntPtr(comInterface) == comVtable)
{
-
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface = GetObject(comInterface).managedInterface;
+ IStream managedInterface = GetObject(comInterface).managedInterface;
if (outParam)
Release(comInterface);
return null;
}
- internal static IntPtr CreateInterface(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface)
+ internal static IntPtr CreateInterface(IStream managedInterface)
{
IntPtr comInterface;
#endif
}
- private static int CopyTo(IntPtr @this,
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
+ private static int CopyTo(IntPtr @this, IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
#if MAP_EX_TO_HR
try
try
{
#endif
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- newInterface;
+ IStream newInterface;
IntPtr newWrapper;
ppstm = IntPtr.Zero;
}
// Managed Runtime Callable Wrapper implementation
- private sealed class NativeToManagedWrapper :
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
+ private sealed class NativeToManagedWrapper : IStream
{
private readonly IntPtr comInterface;
private readonly IStreamVtbl managedVtable;
GC.SuppressFinalize(this);
}
- internal static IntPtr GetUnderlyingInterface(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface)
+ internal static IntPtr GetUnderlyingInterface(IStream managedInterface)
{
if (managedInterface is NativeToManagedWrapper)
{
return IntPtr.Zero;
}
- internal static
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- CreateInterface(IntPtr comInterface, bool outParam)
+ internal static IStream CreateInterface(IntPtr comInterface, bool outParam)
{
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface;
+ IStream managedInterface;
if (comInterface == IntPtr.Zero)
return null;
#if !RECURSIVE_WRAPPING
else if ((managedInterface = ManagedToNativeWrapper.GetUnderlyingInterface(comInterface, outParam)) == null)
#endif
- managedInterface = (
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- )new NativeToManagedWrapper(comInterface, outParam);
+ managedInterface = (IStream)new NativeToManagedWrapper(comInterface, outParam);
return managedInterface;
}
- internal static void DisposeInterface(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- managedInterface)
+ internal static void DisposeInterface(IStream managedInterface)
{
if (managedInterface != null && managedInterface is NativeToManagedWrapper)
((NativeToManagedWrapper)managedInterface).Dispose();
CheckHResult(managedVtable.SetSize(comInterface, libNewSize));
}
- public void CopyTo(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
+ public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
CheckHResult(managedVtable.CopyTo(comInterface, pstm, cb, pcbRead, pcbWritten));
}
CheckHResult(managedVtable.Stat(comInterface, out pstatstg, grfStatFlag));
}
- public void Clone(out
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- ppstm)
+ public void Clone(out IStream ppstm)
{
IntPtr newInterface;
public IntPtr MarshalManagedToNative(object managedObj)
{
#if RECURSIVE_WRAPPING
- managedObj = NativeToManagedWrapper.CreateInterface(ManagedToNativeWrapper.CreateInterface((
-#if NET_2_0
- IStream
-#else
- UCOMIStream
+ managedObj = NativeToManagedWrapper.CreateInterface(ManagedToNativeWrapper.CreateInterface((IStream)managedObj), true);
#endif
- )managedObj), true);
-#endif
- return ManagedToNativeWrapper.CreateInterface((
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- )managedObj);
+ return ManagedToNativeWrapper.CreateInterface((IStream)managedObj);
}
public void CleanUpNativeData(IntPtr pNativeData)
public void CleanUpManagedData(object managedObj)
{
- NativeToManagedWrapper.DisposeInterface((
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- )managedObj);
+ NativeToManagedWrapper.DisposeInterface((IStream)managedObj);
}
public int GetNativeDataSize()
//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
+//
+// Copyright (C) 2005 Kornél Pál
+//
+
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using System.Runtime.InteropServices.ComTypes;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
+#else
+using IStream = System.Runtime.InteropServices.UCOMIStream;
#endif
namespace System.Drawing
{
// Stream to IStream wrapper for COM interop
- internal sealed class ComIStreamWrapper :
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
+ internal sealed class ComIStreamWrapper : IStream
{
private const int STG_E_INVALIDFUNCTION = unchecked((int)0x80030001);
baseStream.SetLength(libNewSize);
}
- public void CopyTo(
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
+ public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
byte[] buffer = new byte[4096];
long written = 0;
pstatstg.cbSize = baseStream.Length;
}
- public void Clone(out
-#if NET_2_0
- IStream
-#else
- UCOMIStream
-#endif
- ppstm)
+ public void Clone(out IStream ppstm)
{
ppstm = null;
throw new ExternalException(null, STG_E_INVALIDFUNCTION);
using System;
using System.IO;
using System.Runtime.InteropServices;
-#if NET_2_0
-using System.Runtime.InteropServices.ComTypes;
-#endif
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
+#if NET_2_0
+using System.Runtime.InteropServices.ComTypes;
+#else
+using IStream = System.Runtime.InteropServices.UCOMIStream;
+#endif
namespace System.Drawing
{
// Stream functions for Win32 (original Win32 ones)
[DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
- internal static extern Status GdipLoadImageFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))]
- #if NET_2_0
- IStream
- #else
- UCOMIStream
- #endif
- stream, out IntPtr image);
+ internal static extern Status GdipLoadImageFromStream([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, out IntPtr image);
[DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
- internal static extern Status GdipSaveImageToStream(HandleRef image, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))]
- #if NET_2_0
- IStream
- #else
- UCOMIStream
- #endif
- stream, [In()] ref Guid clsidEncoder, HandleRef encoderParams);
+ internal static extern Status GdipSaveImageToStream(HandleRef image, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(ComIStreamMarshaler))] IStream stream, [In()] ref Guid clsidEncoder, HandleRef encoderParams);
[DllImport("gdiplus.dll")]