Hello,
Here is the brief implementation of what you need, I didn't test it - so you may need make some corrections:
[StructLayout(LayoutKind.Explicit)]
class PICTDESC
{
[FieldOffset(0)]
uint cbSizeofstruct;
[FieldOffset(4)]
uint picType;
[FieldOffset(8)]
IntPtr hbitmap;
[FieldOffset(8)]
IntPtr hmeta;
[FieldOffset(8)]
IntPtr hicon;
[FieldOffset(8)]
IntPtr hemf;
[FieldOffset(12)]
HPALETTE hpal;
[FieldOffset(12)]
HPALETTE xExt;
[FieldOffset(16)]
HPALETTE yExt;
}
[StructLayout(LayoutKind.Sequential)]
class RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[ComImport, System.Security.SuppressUnmanagedCodeSecurity]
[Guid("7BF80980-BF32-101A-8BBB-00AA00300CAB")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IPicture
{
[PreserveSig]
int get_Handle([Out] out IntPtr pHandle);
[PreserveSig]
int get_hPal([Out] out IntPtr phPal);
[PreserveSig]
int get_Type( [Out] out short pType);
[PreserveSig]
int get_Width( [Out] out int pWidth);
[PreserveSig]
int get_Height( [Out] out int pHeight);
[PreserveSig]
int Render(
[In] IntPtr hDC,
[In] int x,
[In] int y,
[In] int cx,
[In] int cy,
[In] int xSrc,
[In] int ySrc,
[In] int cxSrc,
[In] int cySrc,
[In,MarshalAs(UnmanagedType.LPStruct)] RECT pRcWBounds);
[PreserveSig]
int set_hPal( [In] IntPtr hPal);
[PreserveSig]
int get_CurDC( [Out] out IntPtr phDC);
[PreserveSig]
int SelectPicture( IntPtr hDCIn,[Out] out IntPtr phDCOut,[Out] out IntPtr phBmpOut);
[PreserveSig]
int get_KeepOriginalFormat( [Out,MarshalAs(UnmanagedType.Bool)] out bool pKeep);
[PreserveSig]
int put_KeepOriginalFormat([In,MarshalAs(UnmanagedType.Bool)] bool keep);
[PreserveSig]
int PictureChanged( );
[PreserveSig]
int SaveAsFile([In] System.Runtime.InteropServices.ComTypes.IStream pStream,
[In,MarshalAs(UnmanagedType.Bool)] bool fSaveMemCopy,[Out] out int pCbSize);
[PreserveSig]
int get_Attributes([Out] out uint pDwAttr);
}
[DllImport("olepro32.dll")]
static extern int OleCreatePictureIndirect(
[In, MarshalAs(UnmanagedType.LPStruct)] PICTDESC pPictDesc,
[In] ref Guid riid,
[In, MarshalAs(UnmanagedType.Bool)] bool fOwn,
[Out] out object ppvObj);
PICTDESC _desc = new PICTDESC();
object _object;
Guid _guid = typeof(IPicture).GUID;
if (0 == OleCreatePictureIndirect(_desc, ref _guid, true, out _object))
{
IPicture _picture = (IPicture)_object;
Marshal.ReleaseComObject(_picture);
}
Regards,
Maxim.