Click here to Skip to main content
11,477,044 members (75,368 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi everyone, I want to p/invoke OleCreatePictureIndirect() function in C#, I searched it in http://www.pinvoke.net/[^] but I didnt find it, please help me solve this problem, thanks.
Posted 12-Oct-12 5:13am
Comments
Sergey Alexandrovich Kryukov at 12-Oct-12 12:29pm
   
Why doing it, ever? Isn't GDI+ or, better, DirectX-based WPF could be more then enough for you?
--SA
Andrewpeter at 12-Oct-12 22:24pm
   
Thanks SA, I want to get images from dll file, this is VB6 article:

http://www.codeproject.com/Articles/6953/Loading-Bitmap-pictures-from-external-DLL-on-VB-6?

In this article I see him use OleCreatePictureIndirect() API, i want to convert that code to C# code; i cant find any information about this API with C#. Could you help me? Thank you very much.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Andrewpeter at 13-Oct-12 3:01am
   
Thank you, SA. I read it, but i dont get images from C# dll (class library of C#), my dll is WIN32 dll (e.g: Shell32.dll,....). That topic (in your link) uses C# dll. I can convert all VB6 code above to C# code but the third parameter of OleCreatePictureIndirect() (it is "IPic As IPicture") - my main question is "What type of C# does equivalent with IPicture in VB6?". Thanks. My vote is 5 for your answer, hope you help me more.
Sergey Alexandrovich Kryukov at 14-Oct-12 1:32am
   
This is not a question of "equivalent". "IPicture", as well as most of the types (all except language aliases) do not belong in language. A type is the type. Wrong question.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
// initalize picture desc
object _object;
Guid _guid = typeof(IPicture).GUID;
if (0 == OleCreatePictureIndirect(_desc, ref _guid, true, out _object))
{
    IPicture _picture = (IPicture)_object;
    // Working with _picture
    Marshal.ReleaseComObject(_picture);
}

Regards,
Maxim.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100